# mrin247/gitdiagram architecture

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

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

## Overview

##### Main Components Identification
- Frontend: Represented by the “src” directory. It consists of a Next.js application with pages, API client code (in “src/app/_actions”), reusable UI components (in “src/components” including subdirectories like “ui”), and styling.
- Backend: The “backend” folder hosts the FastAPI server with its modular structure comprising routing (under “backend/app/routers”), core functionalities (e.g., rate limiting in “backend/app/core/limiter.py”), prompt engineering (e.g., “backend/app/prompts.py”), and several service integrations (like “claude_service.py”, “github_service.py”, and various OpenAI service implementations).
- Database: Located under “src/server/db” with schema definitions and initialization logic, complemented by the “start-database.sh” script. The README indicates the usage of PostgreSQL.
- CI/CD & Infrastructure: Includes a “docker-compose.yml” for local orchestration, Dockerfiles for containerizing the backend, GitHub Actions (in “.github/workflows”) for the deployment pipeline, and deployment configurations (Vercel for frontend and EC2 for backend).
- External & Utility Services: API analytics, custom rate limiting, and GitHub integrations (for both public and private repositories).

##### Relationships and Data Flow
- The Backend receives these requests, processes them using the routing defined in “backend/app/routers” and integrates with AI services through its “services” modules.
- The backend interacts with the database to store or retrieve persistent information via the “src/server/db” logic.
- CI/CD pipelines and container orchestration (via docker-compose and GitHub Actions) support automated builds and deployments in a multi-environment setup (local development vs. production cloud hosting).

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clear distinction between presentation (frontend) and logic (backend). Additionally, various services in the backend are modularized.
- API-First Design: The application exposes endpoints (with FastAPI) that are consumed both by its internal frontend and potentially other clients.
- Containerization & Orchestration: Use of Docker, docker-compose, and CI/CD for a consistent deployment process.
- Extensibility: The use of prompt engineering and modular services in the backend implies an architecture designed for easy extension or addition of new AI models, integration points, or additional features.

##### Technologies & Frameworks to Highlight
- Frontend: Next.js, TypeScript, Tailwind CSS.
- Backend: FastAPI, Python.
- Database: PostgreSQL, with Drizzle ORM.
- AI Integration: OpenAI’s o3-mini and previous usage of Anthropic’s Claude 3.5 Sonnet.
- Deployment & CI/CD: Docker, docker-compose, GitHub Actions, Vercel, EC2.

##### Specific Elements
- Deployment & CI/CD: Separate blocks for Docker setup, docker-compose orchestration, GitHub Actions, and final deployment targets (Vercel for frontend and EC2 for backend).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Define Styles
    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 cicd fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Frontend (Next.js)"]:::frontend
        FE_App["Pages & API Actions (src/app & src/app/_actions)"]:::frontend
        FE_UI["UI Components (src/components & src/components/ui)"]:::frontend
        FE_API["API Calls (src/lib/fetch-backend.ts)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE["Backend (FastAPI)"]:::backend
        BE_Main["Main (backend/app/main.py)"]:::backend
        BE_Routers["Routers (backend/app/routers)"]:::backend
        BE_Core["Rate Limiter (backend/app/core/limiter.py)"]:::backend
        BE_Prompts["Prompt Engineering (backend/app/prompts.py)"]:::backend
        BE_Services["Services (backend/app/services)"]:::backend
        BE_Utils["Utils (backend/app/utils/format_message.py)"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["Database (PostgreSQL)"]:::database
        DB_Schema["Schema & Index (src/server/db)"]:::database
    end

    %% CI/CD & Infrastructure Layer
    subgraph "CI/CD & Infrastructure"
        CICD["CI/CD & Infra"]:::cicd
        CICD_Git["GitHub Actions (.github/workflows/deploy.yml)"]:::cicd
        CICD_Docker["Containerization (docker-compose.yml, backend/Dockerfile, backend/nginx)"]:::cicd
        CICD_Deploy["Deployment Scripts (backend/deploy.sh, backend/entrypoint.sh)"]:::cicd
    end

    %% External Services
    subgraph "External Services"
        EX_A["OpenAI Service"]:::external
        EX_G["GitHub API"]:::external
        EX_Analytics["Analytics & Utility"]:::external
    end

    %% Data Flow from Frontend to Backend
    FE -->|"API_call"| FE_API
    FE_API -->|"Request"| BE
    BE -->|"Route"| BE_Routers
    BE -->|"CoreLogic"| BE_Core
    BE -->|"PromptInvoke"| BE_Prompts
    BE -->|"ServiceCalls"| BE_Services
    BE -->|"Utility"| BE_Utils
    BE -->|"DataPersist"| DB

    %% Backend to External Services
    BE_Services -->|"Call_OpenAI"| EX_A
    BE_Services -->|"Integrate_GitHub"| EX_G

    %% CI/CD Triggering Deployments
    CICD -->|"Deploy_Frontend"| FE
    CICD -->|"Deploy_Backend"| BE

    %% Click Events for Frontend Components
    click FE "https://github.com/mrin247/gitdiagram/tree/main/src"
    click FE_App "https://github.com/mrin247/gitdiagram/tree/main/src/app"
    click FE_UI "https://github.com/mrin247/gitdiagram/tree/main/src/components"
    click FE_API "https://github.com/mrin247/gitdiagram/blob/main/src/lib/fetch-backend.ts"

    %% Click Events for Backend Components
    click BE "https://github.com/mrin247/gitdiagram/tree/main/backend"
    click BE_Main "https://github.com/mrin247/gitdiagram/blob/main/backend/app/main.py"
    click BE_Routers "https://github.com/mrin247/gitdiagram/tree/main/backend/app/routers"
    click BE_Core "https://github.com/mrin247/gitdiagram/blob/main/backend/app/core/limiter.py"
    click BE_Prompts "https://github.com/mrin247/gitdiagram/blob/main/backend/app/prompts.py"
    click BE_Services "https://github.com/mrin247/gitdiagram/tree/main/backend/app/services"
    click BE_Utils "https://github.com/mrin247/gitdiagram/blob/main/backend/app/utils/format_message.py"

    %% Click Events for Database Components
    click DB "https://github.com/mrin247/gitdiagram/tree/main/src/server/db"
    click DB_Schema "https://github.com/mrin247/gitdiagram/blob/main/src/server/db/schema.ts"
    click DB_Schema "https://github.com/mrin247/gitdiagram/blob/main/src/server/db/index.ts"
    click DB_Schema "https://github.com/mrin247/gitdiagram/blob/main/start-database.sh"

    %% Click Events for CI/CD & Infrastructure Components
    click CICD_Git "https://github.com/mrin247/gitdiagram/blob/main/.github/workflows/deploy.yml"
    click CICD_Docker "https://github.com/mrin247/gitdiagram/blob/main/docker-compose.yml"
    click CICD_Docker "https://github.com/mrin247/gitdiagram/tree/main/backend/Dockerfile"
    click CICD_Docker "https://github.com/mrin247/gitdiagram/tree/main/backend/nginx"
    click CICD_Deploy "https://github.com/mrin247/gitdiagram/blob/main/backend/deploy.sh"
    click CICD_Deploy "https://github.com/mrin247/gitdiagram/blob/main/backend/entrypoint.sh"
```
