# gittodiagram/gittodiagram-be architecture

> Architecture diagram of the GitHub repository gittodiagram/gittodiagram-be, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gittodiagram/gittodiagram-be
- Repository: https://github.com/gittodiagram/gittodiagram-be

## Overview

##### Project type and purpose
- Frontend = Next.js + TypeScript + Tailwind;
Backend = FastAPI + Python;
Database = PostgreSQL;
AI services = OpenAI / Claude;
Proxy = Nginx;
Orchestration = Docker Compose;
Deploy = Vercel (frontend), EC2 (backend).

##### File structure
Top-level:
- Dockerfile / docker-compose.yml / entrypoint.sh → container definitions for backend, DB, Nginx
- nginx/ → reverse-proxy conf (api.conf)
- start-database.sh → launch Postgres
- app/ → FastAPI application
– app/main.py → entry point, mounts routers & middleware
– app/routers/*.py → API endpoints (generate, modify)
– app/services/*.py → wrappers for AI providers & GitHub
– app/core/limiter.py → rate-limiting logic
– app/prompts.py → prompt-engineering pipeline
– app/utils/format_message.py → post-processing responses

##### Extract README insights
- Frontend and backend are separated (hosted on different platforms) but communicate via HTTP.
- PostgreSQL (via Drizzle ORM) persists any usage data, if applicable.
- AI calls are abstracted behind service classes.
- Docker + Nginx sit in front of the FastAPI server in production.

##### Don’t overcomplicate—capture every distinct service or layer.
– Optionally show CI/CD → deployment targets (Vercel, EC2).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["Client (Browser)"]:::frontend
        FrontendApp["Next.js + TypeScript + Tailwind"]:::frontend
    end

    %% CDN/Hosting
    CDN["Vercel (CDN)"]:::infra

    %% Infrastructure Layer
    subgraph "Infrastructure"
        direction TB
        DockerCompose["Docker Compose & Container Setup"]:::infra
        Dockerfile["Dockerfile"]:::infra
        Entrypoint["entrypoint.sh"]:::infra
        subgraph "Nginx Reverse Proxy"
            direction TB
            NginxConf["api.conf"]:::infra
            SetupNginx["setup_nginx.sh"]:::infra
        end
        DBInit["start-database.sh"]:::infra
    end

    %% Backend API Layer
    subgraph "Backend API (FastAPI)"
        direction TB
        FastAPI["FastAPI App (app/main.py)"]:::backend
        GenerateRouter["Generate Endpoint (app/routers/generate.py)"]:::backend
        ModifyRouter["Modify Endpoint (app/routers/modify.py)"]:::backend
        Limiter["Rate Limiter (app/core/limiter.py)"]:::backend
        Prompts["Prompt Pipeline (app/prompts.py)"]:::backend
        FormatUtil["Format Utils (app/utils/format_message.py)"]:::backend
        subgraph "Service Abstractions"
            direction TB
            O4Mini["OpenAI o4-mini (app/services/o4_mini_openai_service.py)"]:::external
            O3Mini["OpenAI o3-mini (app/services/o3_mini_openai_service.py)"]:::external
            O1Mini["OpenAI o1-mini (app/services/o1_mini_openai_service.py)"]:::external
            OpenRouter["OpenRouter (app/services/o3_mini_openrouter_service.py)"]:::external
            Claude["Claude 3.5 Sonnet (app/services/claude_service.py)"]:::external
            GitHubSvc["GitHub API (app/services/github_service.py)"]:::external
        end
        DB["PostgreSQL"]:::database
    end

    %% External APIs
    subgraph "External APIs"
        direction TB
        GitHubAPI["GitHub REST API"]:::external
        OpenAIAPI["OpenAI API"]:::external
        ClaudeAPI["Claude API"]:::external
        OpenRouterAPI["OpenRouter API"]:::external
    end

    %% Data Flows
    Browser -->|"HTTPS"| CDN
    CDN -->|"HTTPS"| FrontendApp
    FrontendApp -->|"REST API (fetch)"| NginxConf
    NginxConf -->|"Proxy to"| FastAPI
    FastAPI --> GenerateRouter
    FastAPI --> ModifyRouter
    GenerateRouter --> Limiter
    ModifyRouter --> Limiter
    Limiter --> Prompts
    Prompts --> O4Mini
    Prompts --> O3Mini
    Prompts --> O1Mini
    Prompts --> OpenRouter
    Prompts --> Claude
    Prompts --> GitHubSvc
    O4Mini -->|">calls"| OpenAIAPI
    O3Mini -->|">calls"| OpenAIAPI
    O1Mini -->|">calls"| OpenAIAPI
    OpenRouter -->|">calls"| OpenRouterAPI
    Claude -->|">calls"| ClaudeAPI
    GitHubSvc -->|">calls"| GitHubAPI
    OpenAIAPI --> FormatUtil
    OpenRouterAPI --> FormatUtil
    ClaudeAPI --> FormatUtil
    GitHubAPI --> FormatUtil
    FormatUtil --> FastAPI
    FastAPI -->|"ORM"| DB
    DB --> FastAPI

    %% CI/CD (optional)
    subgraph "CI/CD"
        GitHubActions["GitHub Actions"]:::infra
        GitHubActions --> FrontendApp
        GitHubActions --> DockerCompose
    end

    %% Click Events
    click DockerCompose "https://github.com/gittodiagram/gittodiagram-be/blob/main/docker-compose.yml"
    click Dockerfile "https://github.com/gittodiagram/gittodiagram-be/tree/main/Dockerfile"
    click Entrypoint "https://github.com/gittodiagram/gittodiagram-be/blob/main/entrypoint.sh"
    click NginxConf "https://github.com/gittodiagram/gittodiagram-be/blob/main/nginx/api.conf"
    click SetupNginx "https://github.com/gittodiagram/gittodiagram-be/blob/main/nginx/setup_nginx.sh"
    click DBInit "https://github.com/gittodiagram/gittodiagram-be/blob/main/start-database.sh"
    click FastAPI "https://github.com/gittodiagram/gittodiagram-be/blob/main/app/main.py"
    click GenerateRouter "https://github.com/gittodiagram/gittodiagram-be/blob/main/app/routers/generate.py"
    click ModifyRouter "https://github.com/gittodiagram/gittodiagram-be/blob/main/app/routers/modify.py"
    click Limiter "https://github.com/gittodiagram/gittodiagram-be/blob/main/app/core/limiter.py"
    click Prompts "https://github.com/gittodiagram/gittodiagram-be/blob/main/app/prompts.py"
    click FormatUtil "https://github.com/gittodiagram/gittodiagram-be/blob/main/app/utils/format_message.py"
    click O4Mini "https://github.com/gittodiagram/gittodiagram-be/blob/main/app/services/o4_mini_openai_service.py"
    click O3Mini "https://github.com/gittodiagram/gittodiagram-be/blob/main/app/services/o3_mini_openai_service.py"
    click O1Mini "https://github.com/gittodiagram/gittodiagram-be/blob/main/app/services/o1_mini_openai_service.py"
    click OpenRouter "https://github.com/gittodiagram/gittodiagram-be/blob/main/app/services/o3_mini_openrouter_service.py"
    click Claude "https://github.com/gittodiagram/gittodiagram-be/blob/main/app/services/claude_service.py"
    click GitHubSvc "https://github.com/gittodiagram/gittodiagram-be/blob/main/app/services/github_service.py"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#000
    classDef backend fill:#d4edda,stroke:#000
    classDef database fill:#fff3cd,stroke:#000
    classDef external fill:#f5c6cb,stroke:#000
    classDef infra fill:#e2e3e5,stroke:#000
```
