# filiksyos/gittodoc architecture

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

- Interactive diagram: https://gitdiagram.com/filiksyos/gittodoc
- Repository: https://github.com/filiksyos/gittodoc

## Overview

##### Project Type and Purpose
- This is a full-stack Python application with both a CLI tool (“gitingest”) and an HTTP server (“Gittodoc”) for converting Git repositories into documentation links consumable by AI coding tools.
- The CLI and server share a core ingestion library (“src/gitingest”), and the server uses FastAPI + Jinja2 + Tailwind CSS for its web front-end.

##### File-Structure Analysis
- Top-level entrypoints & config
- Dockerfile, docker-compose.yml, Heroku scripts (setup-heroku.sh, heroku-prebuild.sh)
- .env.example, runtime.txt, pyproject.toml, requirements.txt/dev
- Core library (src/gitingest)
- cli.py, entrypoint.py – CLI entrypoint & command definitions
- cloning.py, ingestion.py, cloud_uploader.py – pipeline stages
- query_parsing.py, output_formatters.py – transforming and formatting data
- schemas/ – JSON schemas for validation
- utils/ – shared helpers (git_utils, file_utils, timeout, exceptions, etc.)
- HTTP server (src/server)
- main.py – FastAPI app instantiation
- routers/ (index.py, dynamic.py) – HTTP routes/controllers
- query_processor.py – orchestrates ingestion & parsing on request
- templates/ + static/ – Jinja2 views and Tailwind CSS/JS assets
- Tests under tests/ validate both CLI and ingestion components.

##### Key Components
a. Entry Points
- CLI Tool (“gitingest”): runs locally, invokes ingestion pipeline, outputs a doc‐link or uploads via cloud_uploader.
- HTTP Server (“Gittodoc”): FastAPI app exposing a web UI and API endpoints.
b. Core Ingestion Library
- Git Cloning Service (cloning.py → uses git_utils)
- Ingestion Engine (ingestion.py → uses ingestion_utils, timeout_wrapper)
- Query Parser (query_parsing.py → query_parser_utils)
- Output Formatter (output_formatters.py)
- Cloud Uploader (cloud_uploader.py) – optional persistence to S3/GCS/etc.
- Configuration (config.py) & Schemas (filesystem_schema, ingestion_schema)
c. HTTP Server Layer
- FastAPI App (main.py)
- Routers/Controllers (routers/index, routers/dynamic)
- Query Processor Service (query_processor.py) orchestrates ingestion for web requests
- Templating Engine (Jinja2 templates + components)
- Static Assets (Tailwind CSS, JS utilities)
d. External Services
- Git Hosts (GitHub, GitLab, etc.)
- Cloud Storage (if using cloud_uploader)
- AI tools / tiktoken for token estimation (library dependency)

##### Relationships & Data Flow
- CLI Flow:
[CLI Entrypoint] → [Config] → [Cloning Service] → [Ingestion Engine] → [Query Parser] → [Output Formatter] → [Local STDOUT or Cloud Uploader]
- HTTP Flow:
Browser → HTTP Request → [FastAPI Router] → [Query Processor] → (same core ingestion pipeline modules) → [Render Jinja2 Template] + [Static Assets] → Browser

##### Architectural Patterns & Principles
- Layered Architecture:
- Presentation Layer (CLI or HTTP + Templates)
- Application Layer (CLI commands or FastAPI routers)
- Domain/Service Layer (ingestion, parsing, formatting)
- Infrastructure Layer (Git cloning, file I/O, cloud storage)
- Single-Source-of-Truth core library that is invoked by both CLI and server.
- MVC-like pattern in the server: Routers (Controllers) → Templates (Views) → Core Library (Model/Services).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    GH["Git Hosts"]:::external
    CS["Cloud Storage"]:::external
    AI["AI Tools / tiktoken"]:::external

    %% Entry Points Layer
    subgraph "Entry Points" 
        direction TB
        CLI["CLI Tool\n(gitingest Entrypoint)"]:::entry
        CLI_CMD["CLI Commands"]:::entry
        WEB_CLIENT["Browser"]:::entry
    end

    %% HTTP Server Layer
    subgraph "HTTP Server (Gittodoc)" 
        direction TB
        FASTAPI["FastAPI App"]:::entry
        subgraph "Routers / Controllers"
            INDEX["routers/index.py"]:::entry
            DYNAMIC["routers/dynamic.py"]:::entry
        end
        QUERY_PROC["Query Processor Service"]:::entry
        TEMPLATES["Jinja2 Templates"]:::static
        STATIC["Static Assets\n(Tailwind CSS, JS)"]:::static
    end

    %% Core Ingestion Library
    subgraph "Core Ingestion Library" 
        direction TB
        CONFIG["config.py"]:::core
        SCHEMA_FS["filesystem_schema.py"]:::core
        SCHEMA_ING["ingestion_schema.py"]:::core
        subgraph "Infrastructure Layer"
            GIT_UTILS["git_utils.py"]:::infra
            TIMEOUT["timeout_wrapper.py"]:::infra
        end
        CLONING["cloning.py"]:::core
        INGESTION["ingestion.py"]:::core
        ING_HELP["ingestion_utils.py"]:::core
        PARSER["query_parsing.py"]:::core
        PARSER_UTILS["query_parser_utils.py"]:::core
        FORMATTER["output_formatters.py"]:::core
        CLOUD_UP["cloud_uploader.py"]:::core
    end

    %% Deployment Configs
    subgraph "Deployment Configs" 
        direction TB
        DOCKERFILE["Dockerfile"]:::infra
        COMPOSE["docker-compose.yml"]:::infra
        PROCFILE["Procfile"]:::infra
        HEROKU_SETUP["setup-heroku.sh"]:::infra
        HEROKU_PRE["heroku-prebuild.sh"]:::infra
    end

    %% Flows: CLI
    CLI -->|"runs entrypoint"| CLI_CMD
    CLI_CMD -->|"load config"| CONFIG
    CONFIG -->|"clone repo"| CLONING
    CLONING -->|"uses git_utils"| GIT_UTILS
    CLONING -->|"returns repo"| INGESTION
    INGESTION -->|"uses ingestion_utils\nand timeout"| ING_HELP
    ING_HELP --> TIMEOUT
    INGESTION -->|"process data"| PARSER
    PARSER -->|"uses parser_utils"| PARSER_UTILS
    PARSER -->|"format output"| FORMATTER
    FORMATTER -->|"stdout or upload"| CLOUD_UP
    CLOUD_UP -->|"persist to cloud"| CS
    CLOUD_UP -->|"estimate tokens"| AI

    %% Flows: HTTP
    WEB_CLIENT -->|"HTTP Request"| FASTAPI
    FASTAPI -->|"route request"| INDEX
    FASTAPI -->|"route request"| DYNAMIC
    INDEX -->|"call processor"| QUERY_PROC
    DYNAMIC -->|"call processor"| QUERY_PROC
    QUERY_PROC -->|"invoke core pipeline"| CLONING
    QUERY_PROC --> PARSER
    QUERY_PROC --> FORMATTER
    FORMATTER -->|"render template"| TEMPLATES
    TEMPLATES -->|"HTML+Assets"| WEB_CLIENT
    STATIC -->|"serve static"| WEB_CLIENT

    %% External dependencies
    CLONING -->|"git clone"| GH
    CLOUD_UP -->|"upload"| CS

    %% Click events
    click CLI "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/entrypoint.py"
    click CLI_CMD "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/cli.py"
    click CLONING "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/cloning.py"
    click GIT_UTILS "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/utils/git_utils.py"
    click INGESTION "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/ingestion.py"
    click ING_HELP "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/utils/ingestion_utils.py"
    click TIMEOUT "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/utils/timeout_wrapper.py"
    click PARSER "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/query_parsing.py"
    click PARSER_UTILS "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/utils/query_parser_utils.py"
    click FORMATTER "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/output_formatters.py"
    click CLOUD_UP "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/cloud_uploader.py"
    click CONFIG "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/config.py"
    click SCHEMA_FS "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/schemas/filesystem_schema.py"
    click SCHEMA_ING "https://github.com/filiksyos/gittodoc/blob/main/src/gitingest/schemas/ingestion_schema.py"
    click FASTAPI "https://github.com/filiksyos/gittodoc/blob/main/src/server/main.py"
    click INDEX "https://github.com/filiksyos/gittodoc/blob/main/src/server/routers/index.py"
    click DYNAMIC "https://github.com/filiksyos/gittodoc/blob/main/src/server/routers/dynamic.py"
    click QUERY_PROC "https://github.com/filiksyos/gittodoc/blob/main/src/server/query_processor.py"
    click TEMPLATES "https://github.com/filiksyos/gittodoc/tree/main/src/server/templates/"
    click STATIC "https://github.com/filiksyos/gittodoc/blob/main/src/static/js/utils.js"
    click STATIC "https://github.com/filiksyos/gittodoc/blob/main/src/static/robots.txt"
    click DOCKERFILE "https://github.com/filiksyos/gittodoc/tree/main/Dockerfile"
    click COMPOSE "https://github.com/filiksyos/gittodoc/blob/main/docker-compose.yml"
    click PROCFILE "https://github.com/filiksyos/gittodoc/tree/main/Procfile"
    click HEROKU_SETUP "https://github.com/filiksyos/gittodoc/blob/main/setup-heroku.sh"
    click HEROKU_PRE "https://github.com/filiksyos/gittodoc/blob/main/heroku-prebuild.sh"

    %% Styling
    classDef entry fill:#cce5ff,stroke:#004085,color:#004085
    classDef core fill:#d4edda,stroke:#155724,color:#155724
    classDef infra fill:#fff3cd,stroke:#856404,color:#856404
    classDef static fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef external fill:#f8d7da,stroke:#721c24,color:#721c24
```
