# erlichliu/deepclaude architecture

> Architecture diagram of the GitHub repository erlichliu/deepclaude, 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/erlichliu/deepclaude
- Repository: https://github.com/erlichliu/deepclaude

## Overview

##### Main Components
- API Gateway / Server: Represent the FastAPI app (app/main.py) that handles incoming HTTP requests on designated endpoints (including the configuration endpoints). This is the core entry point.
- Model and Client Layer: Organize the modules under the “app” directory into subcomponents:
- Clients: Under app/clients (base_client.py, claude_client.py, deepseek_client.py, openai_compatible_client.py) are the modules abstracting communications with external LLM services.
- Core Processing: The “deepclaude” module (app/deepclaude/deepclaude.py) that implements the main business logic and workflow for combining different model responses.
- Model Manager: The “app/manager” and “app/model_manager” (including model_configs.json) handle configurations and updates of model-related parameters and state.
- Composite Layer: The “openai_composite” module likely deals with aggregating or transforming responses to fit the OpenAI-compatible interface.
- Utilities: The “app/utils” directory provides common functionalities such as authentication and logging.
- Frontend Interface: Represent the static resources (HTML/CSS/JS under the frontend folder) that provide a graphical configuration interface for administrators/users to set API keys and manage model configurations.
- Deployment/Operations: Include Dockerfile, docker-compose.yml, and GitHub Actions files to indicate how the service is containerized, deployed, and automatically updated.
- Package Manager & Environment: Represent the usage of uv (uv lock, pyproject.toml) as a key dependency manager for running and managing the Python environment.

##### Relationships and Data Flow
- Logging and Authentication: Include extras showing supporting utilities that ensure secure communication and logging of operations.

##### Important Architectural Patterns
- Modularized Design: Emphasize the isolation of responsibilities with separate modules for client communications, business logic, and configuration management.
- API Gateway Pattern: The FastAPI server acts as a unified entry point that orchestrates request processing and response aggregation.
- Dependency Injection and Configurability: Illustrate how the model manager (and its configuration files such as model_configs.json) is used to dynamically adjust which models and API keys are active.
- Containerization and CI/CD: Include the Docker components and GitHub workflows, showing that build, deployment, and synchronization are automated.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External API Clients
    subgraph "External API Clients"
        EXT1["Cherry Studio"]:::external
        EXT2["ChatBox"]:::external
        EXT3["LobeChat"]:::external
    end

    %% Backend Services
    subgraph "Backend Services"
        A["FastAPI API Server"]:::backend
        %% Clients Modules
        subgraph "Clients Modules"
            C1["Base Client"]:::client
            C2["Claude Client"]:::client
            C3["DeepSeek Client"]:::client
            C4["OpenAI-Compatible Client"]:::client
        end
        D["Core Processing (deepclaude)"]:::backend
        %% Model Manager Subgroup
        subgraph "Model Manager"
            M1["Manager Service"]:::backend
            M2["Model Configs"]:::backend
        end
        O["Composite Layer"]:::backend
        %% Utilities Subgroup
        subgraph "Utilities"
            U1["Authentication"]:::util
            U2["Logging"]:::util
        end
    end

    %% Frontend Interface
    subgraph "Frontend Interface"
        subgraph "Frontend"
            F1["Index Page"]:::frontend
            F2["Stylesheet"]:::frontend
            F3["JS Scripts"]:::frontend
        end
    end

    %% Deployment/Operations
    subgraph "Deployment/Operations"
        DO1["Dockerfile"]:::deployment
        DO2["docker-compose.yml"]:::deployment
        subgraph "GitHub Workflows"
            GH1["docker-build.yml"]:::deployment
            GH2["security-scan.yml"]:::deployment
            GH3["sync.yml"]:::deployment
        end
    end

    %% Package Manager & Environment
    subgraph "Package Manager & Environment"
        PM1["pyproject.toml"]:::env
        PM2["uv.lock"]:::env
    end

    %% External LLM APIs
    subgraph "External LLM APIs"
        L1["DeepSeek API"]:::external
        L2["Claude API"]:::external
        L3["Gemini API"]:::external
        L4["OpenAI API"]:::external
    end

    %% Connections: External Clients to API Server
    EXT1 --> A
    EXT2 --> A
    EXT3 --> A

    %% API Server routing to Clients Modules and Business Logic
    A -->|"calls"| C1
    A -->|"calls"| C2
    A -->|"calls"| C3
    A -->|"calls"| C4
    A -->|"processes"| D
    D -->|"aggregates"| O
    A -->|"configRequest"| M1
    A -->|"configRequest"| M2
    F1 -->|"configUpdate"| M1
    F1 -->|"configEndpoint"| A

    %% Clients communicating with External LLM APIs
    C2 -->|"calls"| L2
    C3 -->|"calls"| L1
    C4 -->|"calls"| L4

    %% Utilities support connections (dotted lines)
    A -.-> U1
    A -.-> U2
    M1 -.-> U1
    M1 -.-> U2

    %% Deployment & Environment supporting Backend
    PM1 -.-> A
    PM2 -.-> A
    DO1 -.-> A
    DO2 -.-> A
    GH1 -.-> A
    GH2 -.-> A
    GH3 -.-> A

    %% Class Definitions for Color Styling
    classDef backend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef client fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef external fill:#c1f0c1,stroke:#000,stroke-width:2px;
    classDef frontend fill:#ffff99,stroke:#000,stroke-width:2px;
    classDef deployment fill:#d3d3d3,stroke:#000,stroke-width:2px;
    classDef env fill:#ffdab9,stroke:#000,stroke-width:2px;
    classDef util fill:#dda0dd,stroke:#000,stroke-width:2px;

    %% Click Events
    click A "https://github.com/erlichliu/deepclaude/blob/main/app/main.py"
    click C1 "https://github.com/erlichliu/deepclaude/blob/main/app/clients/base_client.py"
    click C2 "https://github.com/erlichliu/deepclaude/blob/main/app/clients/claude_client.py"
    click C3 "https://github.com/erlichliu/deepclaude/blob/main/app/clients/deepseek_client.py"
    click C4 "https://github.com/erlichliu/deepclaude/blob/main/app/clients/openai_compatible_client.py"
    click D "https://github.com/erlichliu/deepclaude/blob/main/app/deepclaude/deepclaude.py"
    click M1 "https://github.com/erlichliu/deepclaude/blob/main/app/manager/model_manager.py"
    click M2 "https://github.com/erlichliu/deepclaude/blob/main/app/model_manager/model_configs.json"
    click O "https://github.com/erlichliu/deepclaude/blob/main/app/openai_composite/openai_composite.py"
    click U1 "https://github.com/erlichliu/deepclaude/blob/main/app/utils/auth.py"
    click U2 "https://github.com/erlichliu/deepclaude/blob/main/app/utils/logger.py"
    click F1 "https://github.com/erlichliu/deepclaude/blob/main/frontend/index.html"
    click F2 "https://github.com/erlichliu/deepclaude/blob/main/frontend/css/styles.css"
    click F3 "https://github.com/erlichliu/deepclaude/tree/main/frontend/js/"
    click DO1 "https://github.com/erlichliu/deepclaude/tree/main/Dockerfile"
    click DO2 "https://github.com/erlichliu/deepclaude/blob/main/docker-compose.yml"
    click GH1 "https://github.com/erlichliu/deepclaude/blob/main/.github/workflows/docker-build.yml"
    click GH2 "https://github.com/erlichliu/deepclaude/blob/main/.github/workflows/security-scan.yml"
    click GH3 "https://github.com/erlichliu/deepclaude/blob/main/.github/workflows/sync.yml"
    click PM1 "https://github.com/erlichliu/deepclaude/blob/main/pyproject.toml"
    click PM2 "https://github.com/erlichliu/deepclaude/blob/main/uv.lock"
```
