How meritdemos/lh-merit-demo-repo works
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 |
+--------+