# meritdemos/lh-merit-demo-repo architecture

> Architecture diagram of the GitHub repository meritdemos/lh-merit-demo-repo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/meritdemos/lh-merit-demo-repo
- Repository: https://github.com/meritdemos/lh-merit-demo-repo

## Overview

##### Project Type and Purpose
- Type: A single‐binar y Rust command‐line application.
- Purpose:
– Interact with a local Git repository (git2).
– Analyze changes and contributors.
– Call external AI provider APIs (OpenAI, Anthropic Claude, DeepSeek, Gemini) to generate commit messages and analysis.
– Present an interactive CLI (dialoguer).

##### Main Components
a. CLI / UI Layer
– File: src/ui.rs
– Handles user prompts and menu selection (dialoguer).
– Entry point: src/main.rs calls into UI.
b. Modes / Controller Layer
– File: src/modes.rs
– Implements the logic for each menu option: generate commit, file analysis, contributor analysis.
c. Git Integration Layer
– File: src/git.rs
– Wrapper around git2 to:
- Read diffs, commits, repo metadata.
– File: src/git_analysis.rs
– High‐level analysis functions (e.g., computing file‐change impact, contributor stats).
d. AI Provider Layer
– Directory: src/providers
- openai.rs
- claude.rs
- deepseek.rs
- gemini.rs
- mod.rs (provider selection & abstraction)
– Uses reqwest + tokio to call each provider’s HTTP API.
– Exchanges JSON payloads, returns AI‐generated text.
e. Configuration / Environment
– .env / dotenv: loads API keys at startup.
– src/lib.rs: may expose shared utilities (e.g., env loader, HTTP client config).
f. External Systems
– Local Git repository on disk (file system).
– AI provider endpoints (OpenAI, Anthropic, DeepSeek, Google Gemini).
g. Runtime
– Tokio async runtime for concurrent HTTP calls.
– Single process, event‐driven.

##### Relationships & Data Flow
1. User invokes CLI (shell → binary).
2. main.rs initializes dotenv, tokio runtime, and calls UI.
3. UI presents options → user selects a mode.
4. modes.rs routes request to:
a. Git layer (git.rs, git_analysis.rs) to fetch diffs or stats.
b. AI Provider layer (providers/mod.rs) if generation is needed.
5. Git layer reads from local .git folder → returns diff/metadata.
6. Modes layer constructs prompt → calls selected provider module → HTTP request → AI response.
7. Modes layer formats output → UI layer prints results.

##### Architectural Patterns & Principles
- Layered architecture: UI → Controller/Modes → Domain (Git, Analysis) → Infrastructure (HTTP, Git2).
- Dependency inversion: modes depend on abstracted provider interface (providers/mod.rs).
- Single Responsibility: each module has a clear purpose.
- Async boundary: HTTP calls run via tokio.

##### Elements
– Annotate technologies: “git2”, “reqwest + tokio”, “dialoguer”, “dotenv”.
– Show the .env file upstream of the binary.

[User Terminal]
│
▼
+--------+            +--------------+
|  main  |─loads env─▶|  Config (.env)|
+--------+            +--------------+
│
▼
+--------+            +----------------+
|  UI    |◀─prompts───|  dialoguer lib |
+--------+            +----------------+
│
▼
+--------------+
|   Modes/     |───┐
| Controller   |   ├─calls─▶+-----------+
+--------------+   │        | Git Layer |
│             │        +-----------+
│             │              │
│             │              ▼
│             │        +----------------+
│             │        | git2 + fs I/O  |
│             │        +----------------+
│             │
│             └─calls─▶+-------------------+
│                      | AI Provider Layer  |
│                      | (providers/mod.rs) |
│                      +-------------------+
│                               │
│                          ┌────┼────┐
│                          ▼         ▼
│                    +--------+  +--------+
│                    |OpenAI |  | Claude |
│                    +--------+  +--------+
│                    +--------+  +--------+
│                    |DeepSeek|  | Gemini|
│                    +--------+  +--------+
▼
+--------+
| Output |
+--------+

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User Terminal"]:::external
    Main["main\n(src/main.rs)"]:::internal
    Config["Config (.env)"]:::config
    Shared["Shared Utils\n(src/lib.rs)"]:::internal
    UI["UI (dialoguer)\n(src/ui.rs)"]:::internal
    Modes["Modes / Controller\n(src/modes.rs)"]:::internal
    GitWrapper["Git Wrapper\n(src/git.rs)"]:::internal
    GitAnalysis["Git Analysis\n(src/git_analysis.rs)"]:::internal
    Providers["AI Provider Layer\n(src/providers/mod.rs)"]:::internal
    subgraph "Providers Modules"
        OAI["OpenAI\n(src/providers/openai.rs)"]:::internal
        Claude["Claude\n(src/providers/claude.rs)"]:::internal
        Deepseek["DeepSeek\n(src/providers/deepseek.rs)"]:::internal
        Gemini["Gemini\n(src/providers/gemini.rs)"]:::internal
    end
    GitRepo(["Local Git Repo"]):::external
    subgraph "AI Services"
        AI1["OpenAI API"]:::external
        AI2["Claude API"]:::external
        AI3["DeepSeek API"]:::external
        AI4["Gemini API"]:::external
    end
    Output["Output"]:::internal

    User --> Main
    Main --> Config
    Main --> Shared
    Main --> UI
    UI --> Modes
    Modes --> GitWrapper
    Modes --> GitAnalysis
    Modes --> Providers
    GitWrapper --> GitRepo
    Providers --> OAI
    Providers --> Claude
    Providers --> Deepseek
    Providers --> Gemini
    OAI --> AI1
    Claude --> AI2
    Deepseek --> AI3
    Gemini --> AI4
    Modes --> Output

    click Main "https://github.com/meritdemos/lh-merit-demo-repo/blob/master/src/main.rs"
    click Config "https://github.com/meritdemos/lh-merit-demo-repo/blob/master/.env.example"
    click Shared "https://github.com/meritdemos/lh-merit-demo-repo/blob/master/src/lib.rs"
    click UI "https://github.com/meritdemos/lh-merit-demo-repo/blob/master/src/ui.rs"
    click Modes "https://github.com/meritdemos/lh-merit-demo-repo/blob/master/src/modes.rs"
    click GitWrapper "https://github.com/meritdemos/lh-merit-demo-repo/blob/master/src/git.rs"
    click GitAnalysis "https://github.com/meritdemos/lh-merit-demo-repo/blob/master/src/git_analysis.rs"
    click Providers "https://github.com/meritdemos/lh-merit-demo-repo/blob/master/src/providers/mod.rs"
    click OAI "https://github.com/meritdemos/lh-merit-demo-repo/blob/master/src/providers/openai.rs"
    click Claude "https://github.com/meritdemos/lh-merit-demo-repo/blob/master/src/providers/claude.rs"
    click Deepseek "https://github.com/meritdemos/lh-merit-demo-repo/blob/master/src/providers/deepseek.rs"
    click Gemini "https://github.com/meritdemos/lh-merit-demo-repo/blob/master/src/providers/gemini.rs"

    classDef internal fill:#bbdefb,stroke:#0d47a1,color:#0d47a1
    classDef external fill:#c8e6c9,stroke:#1b5e20,color:#1b5e20
    classDef config fill:#fff9c4,stroke:#f57f17,color:#f57f17
```
