# vietnguyen1612/gitdiagram architecture

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

- Interactive diagram: https://gitdiagram.com/vietnguyen1612/gitdiagram
- Repository: https://github.com/vietnguyen1612/gitdiagram

## Overview

##### Main Components
- Frontend:
- Located primarily in the “src” directory.
- Built using Next.js with TypeScript, Tailwind CSS, and ShadCN components.
- Contains pages, reusable UI components (buttons, dialogs, cards, etc.), and server-side and client-side logic (e.g., API key dialogs, hooks like useDiagram).

- Backend:
- Found under the “backend” directory.
- Implements a FastAPI server in Python.
- Contains Dockerfile, deployment scripts, and an Nginx configuration for API gateways.

- Database:
- Managed via a PostgreSQL instance (with the schema and database operations living in “src/server/db” using Drizzle ORM).
- Supported by a shell script (start-database.sh) that starts a containerized Postgres instance.

- External Services:
- GitHub integration is key (both for public and private repositories).
- AI integration with OpenAI’s o3-mini and references to Anthropic API.
- These integrations are managed in the “services” subdirectory in the backend.

- Infrastructure/Deployment:
- Docker-compose configuration ensures containerized deployment of backend services and the database.
- CI/CD pipelines are provided via GitHub Actions located in “.github/workflows”.
- Deployment is split with Frontend hosted on Vercel and Backend on EC2.
- Nginx configuration is used for routing and load balancing the API traffic.

##### Relationships and Interactions
- The backend also interacts with the repository’s metadata (from GitHub, potentially via the GitHub service) and might use caching or rate limiting (as hinted in “limiter.py” in the core).
- The Database stores relevant metadata and application state using PostgreSQL, which is connected via the backend through Drizzle ORM.
- CI/CD pipelines (GitHub Actions) trigger build and deploy steps ensuring that changes in code are reflected in container deployments, with Docker-compose managing the backend and database.

##### Architectural Patterns and Principles
- Modular Separation: Clear separation between frontend, backend, and database with dedicated directories.
- API-Centric Communication: The frontend communicates with backend endpoints using REST or server actions.
- Service-Oriented Components: Backend “services” for abstracting integrations with GitHub and AI providers.
- Containerization: Docker and docker-compose ensure replicable and isolated environments.
- Scalability & Maintainability: Rate limiting, prompt automation, and external API modularity hint at a scalable design.
- Infrastructure-as-Code: Use of GitHub Actions and Dockerfiles reflect best practices for automation and continuous deployment.

##### Relevant Technologies and Tools
- Frontend: Next.js, TypeScript, Tailwind CSS, ShadCN UI components.
- Backend: FastAPI (Python), Docker containerization, Nginx configuration, prompt engineering with a strong reliance on AI services.
- Database: PostgreSQL integrated using Drizzle ORM.
- External APIs: OpenAI o3-mini, Anthropic API, GitHub API.
- CI/CD: GitHub Actions for automation.
- Deployment: Vercel for frontend and EC2 for backend.

## Diagram (Mermaid)

```mermaid
graph TD
    U["User Request"]:::external

    subgraph "Frontend (Next.js)"
        FE_APP["App (src/app)"]:::frontend
        FE_COMP["Components (src/components)"]:::frontend
        FE_HOOK["Hooks (src/hooks)"]:::frontend
    end

    subgraph "Backend (FastAPI)"
        BE_BASE["Backend Base (backend/app)"]:::backend
        BE_ROUTERS["Routers (backend/app/routers)"]:::backend
        BE_SERVICES["Services (backend/app/services)"]:::backend
        BE_PROMPT["Prompt Engineering (backend/app/prompts.py)"]:::backend
        BE_LIMITER["Rate Limiter (backend/app/core/limiter.py)"]:::backend
    end

    subgraph "External Services"
        EXT_GITHUB["GitHub API"]:::external
        EXT_OPENAI["OpenAI (o3-mini)"]:::external
        EXT_ANTH["Anthropic (Claude)"]:::external
    end

    subgraph "Database (PostgreSQL)"
        DB_SCHEMA["Database (src/server/db)"]:::database
        DB_SCRIPT["Start Database (start-database.sh)"]:::database
    end

    subgraph "Infrastructure & Deployment"
        INF_DOCKER["Docker Compose (docker-compose.yml)"]:::infra
        INF_DOCKERFILE["Dockerfile (backend/Dockerfile)"]:::infra
        INF_DEPLOY["Deploy Script (backend/deploy.sh)"]:::infra
        INF_ENTRY["Entrypoint (backend/entrypoint.sh)"]:::infra
        INF_NGINX["Nginx (backend/nginx)"]:::infra
    end

    subgraph "CI/CD Pipeline"
        CICD["GitHub Actions (.github/workflows)"]:::cicd
    end

    U -->|"initiates"| FE_APP
    FE_APP -->|"makes API call"| BE_BASE

    BE_BASE -->|"routes requests"| BE_ROUTERS
    BE_ROUTERS -->|"invokes"| BE_PROMPT
    BE_ROUTERS -->|"invokes"| BE_SERVICES
    BE_ROUTERS -->|"applies"| BE_LIMITER

    BE_PROMPT -->|"calls"| EXT_OPENAI
    BE_SERVICES -->|"integrates with"| EXT_GITHUB
    BE_SERVICES -->|"integrates with"| EXT_ANTH
    BE_SERVICES -->|"integrates with"| EXT_OPENAI

    BE_BASE -->|"persists data"| DB_SCHEMA
    BE_PROMPT -->|"logs data"| DB_SCHEMA

    CICD -->|"deploys via"| INF_DOCKER
    INF_DOCKER --> INF_DOCKERFILE
    INF_DOCKER --> INF_DEPLOY
    INF_DOCKER --> INF_ENTRY
    INF_DOCKER --> INF_NGINX

    click FE_APP "https://github.com/vietnguyen1612/gitdiagram/tree/main/src/app"
    click FE_COMP "https://github.com/vietnguyen1612/gitdiagram/tree/main/src/components"
    click FE_HOOK "https://github.com/vietnguyen1612/gitdiagram/tree/main/src/hooks"

    click BE_BASE "https://github.com/vietnguyen1612/gitdiagram/tree/main/backend/app"
    click BE_ROUTERS "https://github.com/vietnguyen1612/gitdiagram/tree/main/backend/app/routers"
    click BE_SERVICES "https://github.com/vietnguyen1612/gitdiagram/tree/main/backend/app/services"
    click BE_PROMPT "https://github.com/vietnguyen1612/gitdiagram/blob/main/backend/app/prompts.py"
    click BE_LIMITER "https://github.com/vietnguyen1612/gitdiagram/blob/main/backend/app/core/limiter.py"

    click DB_SCHEMA "https://github.com/vietnguyen1612/gitdiagram/tree/main/src/server/db"
    click DB_SCRIPT "https://github.com/vietnguyen1612/gitdiagram/blob/main/start-database.sh"

    click INF_DOCKER "https://github.com/vietnguyen1612/gitdiagram/blob/main/docker-compose.yml"
    click INF_DOCKERFILE "https://github.com/vietnguyen1612/gitdiagram/tree/main/backend/Dockerfile"
    click INF_DEPLOY "https://github.com/vietnguyen1612/gitdiagram/blob/main/backend/deploy.sh"
    click INF_ENTRY "https://github.com/vietnguyen1612/gitdiagram/blob/main/backend/entrypoint.sh"
    click INF_NGINX "https://github.com/vietnguyen1612/gitdiagram/tree/main/backend/nginx"

    click CICD "https://github.com/vietnguyen1612/gitdiagram/tree/main/.github/workflows"

    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef infra fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef cicd fill:#fefefe,stroke:#6c757d,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
