How sunmh207/ai-codereview-gitlab works
Project type and purpose
• This is a backend‐centric, event‑driven code‑review tool with a lightweight web dashboard. It exposes an HTTP API for webhook callbacks (api.py), processes review tasks in a worker (biz/queue/worker.py), and hosts a Streamlit UI (ui.py) for monitoring and reporting. It integrates with GitLab/GitHub, multiple LLM providers, and enterprise IM services.
File structure
• Top‑level:
• api.py – HTTP entry point for webhooks and manual CLI commands.
• ui.py – Streamlit dashboard.
• biz/ – business logic subdivided into:
– cmd/ – CLI commands (review, complex metrics, directory scan, etc.)
– github/ & gitlab/ – webhook handlers.
– event/ – central EventManager for dispatching review events.
– llm/ – factory and client adapters for multiple LLM providers.
– queue/ – worker that consumes tasks.
– service/ – core review orchestration (review_service.py).
– utils/ – helpers (code parsing, config, IM notifications, logging, queue abstraction).
• conf/ – .env templates, prompt templates, supervisord configs.
• docker-compose.yml & Dockerfile – containerization.
README insights
• The flow: GitLab/GitHub → webhook → API → enqueue review task → worker → LLM call → post back to MR/Commit → push notifications → dashboard/logging.
• Supports multiple providers (DeepSeek, OpenAI, etc.) and multiple IM channels (DingTalk, Feishu, WeCom).
Diagramming the architecture
a. Main components:
• External Systems: GitLab/GitHub, LLM Providers, IM Platforms (DingTalk, Feishu, WeCom)
• API Service (api.py + biz/github + biz/gitlab + biz/event)
• Task Queue (biz/utils/queue + supervisord.worker)
• Worker Service (biz/queue/worker + biz/service/review_service + biz/llm)
• Configuration Store (conf/.env, prompt_templates.yml)
• Data Store (log files under log/, optional local file storage)
• Dashboard UI (ui.py + biz/utils/reporter)
• CLI Tool (python -m biz.cmd.review)
b. Relationships & data flow:
1. GitLab/GitHub sends webhook → API Service
2. API parses event → EventManager → enqueues a Review Task into the Task Queue
3. Worker Service pulls task → CodeParser & CodeReviewer → ReviewService → chooses LLM Client via Factory → sends code to LLM Provider → receives review results
4. Worker posts results via webhook API back to GitLab/GitHub MR or Commit Note
5. Worker pushes notifications to IM services via Notifier utils
6. Dashboard polls or subscribes to log data / uses Reporter utils to display metrics
c. Architectural patterns & principles:
• Event‑driven / Pub‑Sub between API and Worker
• Adapter pattern for LLM client interfaces
• Separation of concerns: Webhook handling, business logic, third‑party integrations, presentation
• Supervisord to orchestrate independent processes (API, Worker)
• Containerization for consistent deployment
d. Key technologies & frameworks:
• Python 3.10+, Flask or similar HTTP framework in api.py
• Streamlit for UI
• Docker & docker-compose
• Supervisord for process management
• YAML for prompt templates & configs
• HTTP/Webhook integrations with GitLab/GitHub
• REST calls to LLM providers and IM webhooks
Essential elements
• Clear component labels (e.g., “GitLab Webhook Handler”, “ReviewService”)
• Deployment context (Docker containers, ports)
• Process manager (supervisord) overseeing API & Worker
• Config layer feeding all components