# kidcher1412/ai-coder architecture

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

- Interactive diagram: https://gitdiagram.com/kidcher1412/ai-coder
- Repository: https://github.com/kidcher1412/ai-coder

## Overview

##### Main Components

A. Frontend Layer:
- Streamlit UI (src/ui/streamlit_app.py)
- Style components (src/ui/styles)

B. Backend Services Layer:
- Core AI Services:
- AI Coder Model Service (src/services/ai_coder_model.py)
- Code Generator (src/services/code_generator.py)
- Code Analyzer (src/services/code_analyzer.py)

- Supporting Services:
- Template Manager (src/services/template_manager.py)
- Project Generator (src/services/project_generator.py)
- Documentation Services (src/services/doc_generator.py, src/services/api_doc_generator.py)
- Performance & Security (src/services/performance_profiler.py, src/services/security_scanner.py)
- Usage & Analytics (src/services/usage_tracker.py, src/services/analytics.py)

C. Model Layer:
- AI Model Components (src/models/ai_coder_v1)
- Configuration Management (src/config)

D. External Integrations:
- Ollama LLM Integration
- Optional Cloud AI Services

**[User Interface Layer]**
- ↓
**[Service Layer]**
- ↓
**[Model Layer]**
- ↓
**[External Services Layer]**

##### Connection Types

- Double lines: Data flow paths

##### Key Relationships to Highlight

- How the Streamlit UI interfaces with various services
- Relationship between services and the AI model
- Demonstrate how external LLM services integrate with the system
- Flow of code generation and analysis processes

##### Additional Elements

- Template and project generation workflows
- Testing components and their relationship to services

##### Specific Implementation Details

- Use rectangles for services
- Use clouds for external services
- Version information and supported model types

##### Important Notes

- How the base_service.py is inherited by other services
- Separation between local and external model processing
- Analytics and usage tracking flow

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef support fill:#f1c40f,stroke:#f39c12,color:black
    classDef model fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    
    %% User Interface Layer
    subgraph UI
        StreamlitUI["Streamlit UI"]:::ui
        Styles["Style Components"]:::ui
    end

    %% Core Services Layer
    subgraph CoreServices
        BaseService["Base Service"]:::core
        AICoder["AI Coder Model Service"]:::core
        CodeGen["Code Generator"]:::core
        CodeAnalyzer["Code Analyzer"]:::core
    end

    %% Supporting Services Layer
    subgraph SupportServices
        TemplateManager["Template Manager"]:::support
        ProjectGen["Project Generator"]:::support
        DocGen["Documentation Generator"]:::support
        APIDocGen["API Doc Generator"]:::support
        PerfProfiler["Performance Profiler"]:::support
        SecScanner["Security Scanner"]:::security
        UsageTracker["Usage Tracker"]:::support
        Analytics["Analytics"]:::support
    end

    %% Model Layer
    subgraph ModelLayer
        AIModel["AI Model Components"]:::model
        ModelConfig["Model Configuration"]:::model
        PromptTemplates["Prompt Templates"]:::model
        ConfigMgmt["Configuration Management"]:::model
    end

    %% External Services
    subgraph External
        Ollama["Ollama LLM"]:::external
        CloudAI["Cloud AI Services"]:::external
    end

    %% Backend Layer
    subgraph Backend
        MainBackend["Main Backend"]:::core
        APIService["API Service"]:::core
    end

    %% Testing Components
    subgraph Testing
        ServiceTests["Service Tests"]:::support
    end

    %% Relationships
    StreamlitUI --> MainBackend
    MainBackend --> BaseService
    BaseService --> |Inherits| AICoder
    BaseService --> |Inherits| CodeGen
    BaseService --> |Inherits| CodeAnalyzer
    AICoder --> AIModel
    CodeGen --> TemplateManager
    CodeGen --> ProjectGen
    CodeAnalyzer --> PerfProfiler
    CodeAnalyzer --> SecScanner
    AIModel --> Ollama
    AIModel -.-> CloudAI
    MainBackend --> UsageTracker
    UsageTracker --> Analytics
    ServiceTests -.-> CodeGen
    APIService --> AICoder
    DocGen --> APIDocGen
    AIModel --> ModelConfig
    AIModel --> PromptTemplates
    AIModel --> ConfigMgmt

    %% Click Events
    click StreamlitUI "https://github.com/kidcher1412/ai-coder/blob/main/src/ui/streamlit_app.py"
    click Styles "https://github.com/kidcher1412/ai-coder/blob/main/src/ui/styles/main.css"
    click BaseService "https://github.com/kidcher1412/ai-coder/blob/main/src/services/base_service.py"
    click AICoder "https://github.com/kidcher1412/ai-coder/blob/main/src/services/ai_coder_model.py"
    click CodeGen "https://github.com/kidcher1412/ai-coder/blob/main/src/services/code_generator.py"
    click CodeAnalyzer "https://github.com/kidcher1412/ai-coder/blob/main/src/services/code_analyzer.py"
    click TemplateManager "https://github.com/kidcher1412/ai-coder/blob/main/src/services/template_manager.py"
    click ProjectGen "https://github.com/kidcher1412/ai-coder/blob/main/src/services/project_generator.py"
    click DocGen "https://github.com/kidcher1412/ai-coder/blob/main/src/services/doc_generator.py"
    click APIDocGen "https://github.com/kidcher1412/ai-coder/blob/main/src/services/api_doc_generator.py"
    click PerfProfiler "https://github.com/kidcher1412/ai-coder/blob/main/src/services/performance_profiler.py"
    click SecScanner "https://github.com/kidcher1412/ai-coder/blob/main/src/services/security_scanner.py"
    click UsageTracker "https://github.com/kidcher1412/ai-coder/blob/main/src/services/usage_tracker.py"
    click Analytics "https://github.com/kidcher1412/ai-coder/blob/main/src/services/analytics.py"
    click AIModel "https://github.com/kidcher1412/ai-coder/tree/main/src/models/ai_coder_v1"
    click ModelConfig "https://github.com/kidcher1412/ai-coder/blob/main/src/models/ai_coder_v1/config.json"
    click PromptTemplates "https://github.com/kidcher1412/ai-coder/blob/main/src/models/ai_coder_v1/prompt_templates.json"
    click ConfigMgmt "https://github.com/kidcher1412/ai-coder/blob/main/src/config/models.py"
    click MainBackend "https://github.com/kidcher1412/ai-coder/blob/main/src/backend/main.py"
    click APIService "https://github.com/kidcher1412/ai-coder/blob/main/src/services/api.py"
    click ServiceTests "https://github.com/kidcher1412/ai-coder/blob/main/tests/services/test_code_generator.py"
```
