# jnsahaj/lumen architecture

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

- Interactive diagram: https://gitdiagram.com/jnsahaj/lumen
- Repository: https://github.com/jnsahaj/lumen

## Overview

##### Main Components

a) Core Application Layer:
- Command Processing Module (src/command/*)
- Configuration Management (src/config/*)
- Git Integration Layer (src/git_entity/*)
- AI Provider Interface (src/provider/*)
- Error Handling System (src/error.rs)

b) External Systems:
- Git Repository
- Multiple AI Providers (Phind, OpenAI, Claude, Groq, Ollama, OpenRouter)
- Configuration Files (lumen.config.json)

**┌─ User Interface Layer ─────────────────────┐**
- CLI Interface (main.rs)                    │
- ┬─────────────────────────┘
- ↓
**┌─ Command Layer ──────────────────────────┐**
- Draft Command   - Explain Command      │
- List Command                          │
- ┬────────────────────────┘
- ↓
**┌─ Core Services Layer ────────────────────┐**
- ┌─────────────┐  ┌──────────────┐       │
- Git Entity   │  │AI Provider   │       │
- Manager      │←→│Interface     │       │
- ┘  └──────────────┘       │
- ┌─────────────┐                         │
- Config       │                         │
- Manager      │                         │
- ┘                         │
- ┬───────────────┬─────────────┘
- ↓               ↓
**┌─ External Systems ─────────────────────┐**
- ┌─────────┐ ┌─────────────────────┐   │
- Git Repo │ │AI Provider Services │   │
- ┘ └─────────────────────┘   │
- ┘

##### Key Relationships to Highlight

a) Command Flow:
- How user input flows from CLI through the command processors
- How commands interact with both git and AI services

b) Provider Interface:
- Demonstrate the abstract provider interface and its concrete implementations
- How the configuration system determines which provider to use

c) Git Integration:
- Relationship between git commands and the git_entity module
- How diff and commit information flows through the system

##### Important Details

a) Configuration Management:
- Three-tier configuration system (CLI flags → Config file → Environment variables)
- Configuration inheritance and override patterns

b) Provider Architecture:
- Provider interface and how it abstracts different AI services
- Relationship between provider configuration and implementation

c) Error Handling:
- How errors propagate through the system
- Error boundaries and handling mechanisms

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CLI["User Interface Layer"]
        Main["CLI Interface"]
    end

    subgraph Commands["Command Layer"]
        Draft["Draft Command"]
        Explain["Explain Command"]
        List["List Command"]
    end

    subgraph Core["Core Services Layer"]
        GitEntity["Git Entity Manager"]
        AIProvider["AI Provider Interface"]
        Config["Configuration Manager"]
        ErrorHandler["Error Handler"]
        AiPrompt["AI Prompt Manager"]
        CommitRef["Commit Reference Handler"]
    end

    subgraph External["External Systems"]
        Git["Git Repository"]
        
        subgraph AIS["AI Services"]
            Claude["Claude"]
            Groq["Groq"]
            Ollama["Ollama"]
            OpenAI["OpenAI"]
            OpenRouter["OpenRouter"]
            Phind["Phind"]
        end
    end

    %% Relationships
    Main --> Draft
    Main --> Explain
    Main --> List

    Draft --> GitEntity
    Draft --> AIProvider
    Draft --> Config
    
    Explain --> GitEntity
    Explain --> AIProvider
    Explain --> Config
    
    List --> GitEntity
    List --> Config

    GitEntity --> Git
    AIProvider --> AIS
    
    AIProvider --> AiPrompt
    GitEntity --> CommitRef
    
    %% Error handling relationships
    ErrorHandler -.-> Main
    ErrorHandler -.-> Commands
    ErrorHandler -.-> Core

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef external fill:#d9f7be,stroke:#389e0d
    classDef core fill:#bae7ff,stroke:#1890ff
    classDef command fill:#fff7e6,stroke:#fa8c16
    classDef error fill:#fff1f0,stroke:#f5222d
    
    class Main,Commands command
    class Core,GitEntity,AIProvider,Config core
    class External,Git,AIS external
    class ErrorHandler error
    
    %% Click events
    click Main "https://github.com/jnsahaj/lumen/blob/main/src/main.rs"
    click Draft "https://github.com/jnsahaj/lumen/blob/main/src/command/draft.rs"
    click Explain "https://github.com/jnsahaj/lumen/blob/main/src/command/explain.rs"
    click List "https://github.com/jnsahaj/lumen/blob/main/src/command/list.rs"
    click GitEntity "https://github.com/jnsahaj/lumen/blob/main/src/git_entity/mod.rs"
    click AIProvider "https://github.com/jnsahaj/lumen/blob/main/src/provider/mod.rs"
    click Config "https://github.com/jnsahaj/lumen/blob/main/src/config/mod.rs"
    click ErrorHandler "https://github.com/jnsahaj/lumen/blob/main/src/error.rs"
    click AiPrompt "https://github.com/jnsahaj/lumen/blob/main/src/ai_prompt.rs"
    click CommitRef "https://github.com/jnsahaj/lumen/blob/main/src/commit_reference.rs"
    click Claude "https://github.com/jnsahaj/lumen/blob/main/src/provider/claude.rs"
    click Groq "https://github.com/jnsahaj/lumen/blob/main/src/provider/groq.rs"
    click Ollama "https://github.com/jnsahaj/lumen/blob/main/src/provider/ollama.rs"
    click OpenAI "https://github.com/jnsahaj/lumen/blob/main/src/provider/openai.rs"
    click OpenRouter "https://github.com/jnsahaj/lumen/blob/main/src/provider/openrouter.rs"
    click Phind "https://github.com/jnsahaj/lumen/blob/main/src/provider/phind.rs"
```
