# getasterisk/deepclaude architecture

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

- Interactive diagram: https://gitdiagram.com/getasterisk/deepclaude
- Repository: https://github.com/getasterisk/deepclaude

## Overview

##### Main Components

a) Frontend Layer:
- Next.js Web Application
- UI Components (shadcn/ui based)
- Client-side Features (PostHog integration, hooks)

b) Backend Layer:
- Rust-based API Server
- Model Clients (DeepSeek, Anthropic)
- Request/Response Handlers

c) External Services:
- DeepSeek API
- Anthropic API
- PostHog Analytics

**[Client Layer]**
- Web Browser
- API Consumers

- v
**[Frontend Layer (Next.js)]**
- Pages (chat, docs)
- UI Components
- PostHog Provider

- v
**[Backend Layer (Rust)]**
- API Server
- Model Clients
- Request/Response Handlers

- v
**[External Services]**
- DeepSeek API
- Anthropic API

##### Key Relationships to Highlight

a) Data Flow:
- Client requests → Frontend → Backend → External APIs
- Streaming responses from models back to client
- Analytics data to PostHog

b) Component Interactions:
- Frontend-Backend API communication
- Backend parallel processing of model requests
- Response aggregation and streaming

##### Technical Details

Frontend:
- Next.js 14 App Router
- React Components
- TypeScript
- Tailwind CSS

Backend:
- Rust HTTP Server
- Model Client Implementations
- Error Handling
- Configuration Management

##### Architectural Patterns to Emphasize

- API Gateway Pattern
- Streaming Response Pattern
- BYOK (Bring Your Own Keys) Architecture
- Component-based UI Architecture

##### Implementation Notes

- Request Flow
- Response Flow
- Configuration Management
- Security Boundaries
- Monitoring/Analytics

- The dual-model approach
- Streaming capabilities
- Security measures
- Configuration flexibility

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
        APIConsumers["API Consumers"]
    end

    subgraph FrontendLayer
        NextApp["Next.js App"]:::frontend
        click NextApp "https://github.com/getAsterisk/deepclaude/tree/main/frontend/app"
        
        subgraph UIComponents
            ChatUI["Chat Interface"]:::frontend
            click ChatUI "https://github.com/getAsterisk/deepclaude/blob/main/frontend/components/chat.tsx"
            SettingsUI["Settings Interface"]:::frontend
            click SettingsUI "https://github.com/getAsterisk/deepclaude/blob/main/frontend/components/settings.tsx"
            UILib["UI Components Library"]:::frontend
            click UILib "https://github.com/getAsterisk/deepclaude/tree/main/frontend/components/ui"
        end
        
        subgraph Analytics
            PostHogProvider["PostHog Provider"]:::frontend
            click PostHogProvider "https://github.com/getAsterisk/deepclaude/blob/main/frontend/providers/posthog.tsx"
            FeatureFlags["Feature Flags"]:::frontend
            click FeatureFlags "https://github.com/getAsterisk/deepclaude/blob/main/frontend/hooks/use-feature-flags.ts"
        end
    end

    subgraph BackendLayer
        RustServer["Rust API Server"]:::backend
        click RustServer "https://github.com/getAsterisk/deepclaude/blob/main/src/main.rs"
        
        subgraph Core
            RequestHandler["Request Handler"]:::backend
            click RequestHandler "https://github.com/getAsterisk/deepclaude/blob/main/src/handlers.rs"
            ResponseHandler["Response Handler"]:::backend
            click ResponseHandler "https://github.com/getAsterisk/deepclaude/blob/main/src/handlers.rs"
            ErrorHandler["Error Handler"]:::backend
            click ErrorHandler "https://github.com/getAsterisk/deepclaude/blob/main/src/error.rs"
        end
        
        subgraph Models
            RequestModel["Request Model"]:::backend
            click RequestModel "https://github.com/getAsterisk/deepclaude/blob/main/src/models/request.rs"
            ResponseModel["Response Model"]:::backend
            click ResponseModel "https://github.com/getAsterisk/deepclaude/blob/main/src/models/response.rs"
        end
        
        subgraph Clients
            DeepSeekClient["DeepSeek Client"]:::backend
            click DeepSeekClient "https://github.com/getAsterisk/deepclaude/blob/main/src/clients/deepseek.rs"
            AnthropicClient["Anthropic Client"]:::backend
            click AnthropicClient "https://github.com/getAsterisk/deepclaude/blob/main/src/clients/anthropic.rs"
        end
        
        ConfigMgr["Configuration Manager"]:::backend
        click ConfigMgr "https://github.com/getAsterisk/deepclaude/blob/main/src/config.rs"
    end

    subgraph ExternalServices
        DeepSeekAPI["DeepSeek API"]:::external
        AnthropicAPI["Anthropic API"]:::external
        PostHogAPI["PostHog Analytics"]:::external
    end

    subgraph Configuration
        ConfigFile["config.toml"]:::config
        click ConfigFile "https://github.com/getAsterisk/deepclaude/blob/main/config.toml"
        DockerConfig["Docker Config"]:::config
        click DockerConfig "https://github.com/getAsterisk/deepclaude/tree/main/Dockerfile"
    end

    %% Connections
    Browser --> NextApp
    APIConsumers --> RustServer
    NextApp --> RustServer
    ChatUI --> NextApp
    SettingsUI --> NextApp
    UILib --> NextApp
    PostHogProvider --> PostHogAPI
    FeatureFlags --> PostHogProvider
    
    RustServer --> RequestHandler
    RequestHandler --> RequestModel
    RequestModel --> DeepSeekClient
    RequestModel --> AnthropicClient
    DeepSeekClient --> DeepSeekAPI
    AnthropicClient --> AnthropicAPI
    DeepSeekAPI --> ResponseHandler
    AnthropicAPI --> ResponseHandler
    ResponseHandler --> ResponseModel
    ErrorHandler --> ResponseHandler
    ConfigMgr --> ConfigFile
    
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:#fff
    classDef backend fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef external fill:#9b59b6,stroke:#8e44ad,color:#fff
    classDef config fill:#e67e22,stroke:#d35400,color:#fff

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        External["External Service"]:::external
        Config["Configuration"]:::config
    end
```
