A robust and flexible tool designed to convert Java and C# Data Transfer Objects (DTOs) into TypeScript interfaces. This project bridges the gap between backend models and frontend type safety, offering both deterministic regex-based conversion and AI-powered fallback using Ollama.
- Dual-Mode Conversion:
- Deterministic: Fast and accurate regex-based parsing for standard Java/C# syntax.
- AI-Powered: Optional fallback to Ollama (LLM) for complex or non-standard code structures.
- Multi-Language Support:
- Java: Handles classes, records, interfaces, and common types (List, Map, etc.).
- C#: Supports classes, properties, and nullable types.
- Smart Type Mapping: Automatically maps backend types (e.g.,
BigDecimal,LocalDateTime,Dictionary) to their TypeScript equivalents. - Nullability Handling: Respects
@NotNull,[Required], and nullable markers to generate accurate optional/required fields. - Multiple Interfaces:
- Web UI: A user-friendly Flask-based web interface for quick conversions.
- CLI: A command-line tool for file-based processing and automation.
- Python: Version 3.8 or higher.
- Ollama (Optional): Required only if you intend to use the AI fallback feature.
- Install Ollama
- Pull a model (default is
deepseek-coder):ollama pull deepseek-coder
-
Clone the repository:
git clone <repository-url> cd TypeScript-Converter
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
Start the Flask application to use the graphical interface.
- Run the app:
python app.py
- Open your browser and navigate to
http://localhost:5000. - Paste your Java or C# code into the input box.
- (Optional) Check "Use Ollama Fallback" for AI-assisted conversion.
- Click Convert to see the TypeScript result.
Use the CLI tool to convert files directly from your terminal.
python cli.py <input_file> [OPTIONS]Arguments:
input_file: Path to the Java or C# file to convert.
Options:
--ollama: Enable Ollama LLM fallback for generation/cleaning.
Example:
python cli.py models/UserDto.java --ollamaYou can configure the Ollama integration using environment variables:
OLLAMA_HOST: The URL of your Ollama instance.- Default (Local):
http://localhost:11434 - Default (Docker):
http://ollama:11434
- Default (Local):
FLASK_HOST: The interface to bind the web server to.- Default (Local):
127.0.0.1 - Default (Docker):
0.0.0.0
- Default (Local):
OLLAMA_MODEL: The model to use for conversion (default:deepseek-coder).
Example:
export OLLAMA_MODEL=llama3
python app.pyapp.py: Flask web application entry point.cli.py: Command-line interface entry point.converter.py: Core logic for regex-based parsing and type conversion.ollama_client.py: Client for interacting with the Ollama API.templates/: HTML templates for the web UI.static/: Static assets (CSS, JS).
Contributions are welcome! Please feel free to submit a Pull Request.