Skip to content

khanalsaroj/typegen-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Typegen Server

Typegen Logo

Core code generation and schema engine for Typegen
Fast β€’ Secure β€’ Extensible


πŸ—„οΈ Typegen Server

The Typegen Server is the core backend service of the Typegen platform. It is responsible for database schema introspection, validation, and deterministic code generation across supported languages and styles. The API exposes generation capabilities used by the CLI and Dashboard while enforcing strict option schemas, security controls, and runtime validation.

Important: The Typegen Server can be run as a standalone service, but the recommended best practice is to manage its lifecycle, configuration, and runtime using (typegenctl) and the UI Dashboard, which provide a safer and more convenient control plane for the entire Typegen ecosystem.

How to use Description
Typegenctl Typegenctl GitHub
Typegen UI Typegen-Dashboard GitHub

✨ Features

  • Current Support Database Connection: MySQL/Mariadb, MSSQL, and PostgreSQL.
  • Code Generation:
    • Typescript: DTOs and Zod schemas.
    • Java: Records and DTOs.
    • Mappers: Java XML and Annotation-based mappers.
  • Security: Rate limiting, and CORS support.
  • Health Monitoring: Integrated health check endpoints.

πŸ‹ Docker Image

Pre-built Docker images are available for this project and can be pulled from the registry:

docker pull ghcr.io/khanalsaroj/typegen-server:latest

πŸ“‚ Project Structure

β”œβ”€β”€ cmd/
β”‚   └── api/                # Application entry point
β”œβ”€β”€ data/                   # SQLite database files
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ config/             # Configuration loading (Viper)
β”‚   β”œβ”€β”€ domain/             # Domain models and interfaces
β”‚   β”œβ”€β”€ infrastructure/     # DB connectors (MySQL, Postgres)
β”‚   β”œβ”€β”€ middleware/         # Gin middlewares (CORS, Logger, Rate Limit)
β”‚   β”œβ”€β”€ modules/            # Business logic by module
β”‚   β”‚   β”œβ”€β”€ connection/     # Connection management
β”‚   β”‚   β”œβ”€β”€ gentype/        # Type generation logic
β”‚   β”‚   β”œβ”€β”€ health/         # Health check logic
β”‚   β”‚   └── mapper/         # Mapper generation logic
β”‚   β”œβ”€β”€ pkg/                # Shared utilities (Crypto, Logger, Response)
β”‚   β”œβ”€β”€ query/              # SQL queries
β”‚   └── server/             # HTTP server setup and routing
β”œβ”€β”€ .env.dev                # Development environment variables
β”œβ”€β”€ Dockerfile              # Multi-stage Docker build
└── go.mod                  # Go module definition

🌐 API Endpoints (Summary)

1. GET /api/v1/health – Health Check

Response:

{
  "status": "ok",
  "version": "v1.2.3",
  "uptime": 172800,
  "database": {
    "connected": true,
    "latency": 12
  }
}

HTTP Status: 200 OK


2. POST /api/v1/connection/test – Test a DB Connection

Request Body Example:

{
  "dbType": "postgres",
  "host": "localhost",
  "port": 5432,
  "username": "admin",
  "password": "securepassword",
  "schemaName": "public",
  "databaseName": "mydb"
}

Response Example:

{
  "connectionId": 123,
  "message": "Connection established successfully",
  "success": true,
  "pingMs": 15,
  "tablesFound": 3,
  "sizeMb": 42.7,
  "tables": [
    {
      "name": "users",
      "columnCount": 12
    },
    {
      "name": "orders",
      "columnCount": 8
    }
  ]
}

HTTP Status: 200 OK


3. POST /api/v1/connection – Create a New DB Connection

Request Body Example:

{
  "dbType": "postgres",
  "host": "localhost",
  "port": 5432,
  "username": "admin",
  "password": "securepassword",
  "schemaName": "public",
  "databaseName": "mydb"
}

Response Success Example:

{
  "success": true,
  "message": "User fetched successfully",
  "connection": {
    "dbType": "postgres",
    "host": "localhost",
    "port": 5432,
    "username": "admin",
    "password": "securepassword",
    "schemaName": "public",
    "databaseName": "mydb"
  }
}

HTTP Status: 200 OK


Response Error Example:

{
  "success": false,
  "message": "Failed to create connection",
  "error": "user not found"
}

HTTP Status: 500 InternalServerError


4. GET /api/v1/connection – List All Connections

Response Example:

[
  {
    "connectionId": 101,
    "name": "main-db",
    "dbType": "postgres",
    "host": "localhost",
    "port": 5432,
    "databaseName": "mydb",
    "schemaName": "public",
    "username": "admin"
  },
  {
    "connectionId": 102,
    "name": "analytics-db",
    "dbType": "mysql",
    "host": "db.example.com",
    "port": 3306,
    "databaseName": "analytics",
    "schemaName": "default",
    "username": "root"
  }
]

HTTP Status: 200 OK


5. POST /api/v1/type – Generate Code Types

Request Body Example:

Note: The options object is dynamic. Its available fields differ depending on the chosen language and style, as each combination exposes its own configuration options. For the full list of supported options, see the documentation here.

{
  "connectionId": 102,
  "options": {
    "getter": true,
    "setter": true,
    "noArgsConstructor": true,
    "allArgsConstructor": true,
    "builder": true,
    "data": true,
    "swaggerAnnotations": true,
    "serializable": true,
    "jacksonAnnotations": true,
    "extraSpacing": true
  },
  "prefix": "Foo",
  "suffix": "Response",
  "style": "DTO",
  "language": "java",
  "tableNames": [
    "users",
    "orders"
  ]
}

Response Example:

"generated message"

HTTP Status: 200 OK


6. POST /api/v1/mapper – Generate Mappers

Request Body Example:

{
  "connectionId": 123,
  "options": {
    "allCrud": true
  },
  "prefix": "Db",
  "suffix": "Type",
  "style": "struct",
  "language": "go",
  "tableNames": [
    "users",
    "orders"
  ]
}

Response Example:

"generated message"

HTTP Status: 200 OK


πŸ” Contact

About

Backend service for TypeGen that analyzes schemas and generates type metadata via a stable API.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors