How kratos06/codedog works
Project Type & Purpose
• Codedog is an open-source, Python-based AI-powered code-review assistant. It’s shipped both as a library and a command-line tool (CLI) that integrates with GitHub/GitLab, uses Large Language Models (OpenAI, Azure OpenAI, DeepSeek) to fetch pull/merge requests, generate summaries, suggestions, and optionally email reports.
File-Structure Analysis
• Top-level:
• codedog/ : core library
– actors/ (reporters)
– chains/ (LLM-prompt chains)
– models/ (data structures: PR, diff, commit, etc.)
– processors/ (business logic orchestrator)
– retrievers/ (GitHub/GitLab connectors)
– templates/ (language-specific prompt templates)
– utils/ (config loader, diff utils, email, Git hooks, LangChain helpers)
• run_codedog*.py, examples/ : CLI entrypoints & examples
• tests/ : unit + integration tests
• docs/ : user/setup guides + auto-generated API docs
• Config files: .env.sample, pyproject.toml/poetry.toml, GitHub Actions/workflows for CI/CD.
README Insights
• Purpose: “Automatically review your pull requests… provide summaries and suggestions”
• Features: PR summarization, diff summarization, code review feedback, multi-LLM & multi-language support, email notifications, commit hooks.
• Architecture hints: retriever → LLM chains → reporters.
a. Main Components:
• CLI / Runner
• Config Loader (.env, env vars)
• Processor
• Retrievers (GitHub, GitLab)
• Models (PR, Diff, Commit, Repository)
• Chains (Prompt builders + LLM clients)
• Actors / Reporters (PR summary, code review, email reporter)
• Templates (EN/CN prompts)
• External Services:
– VCS APIs (GitHub, GitLab REST APIs)
– LLM Providers (OpenAI / Azure / DeepSeek)
– Email / SMTP server (optional)
b. Relationships & Data Flow:
1. User runs CLI (run_codedog.py) → CLI loads Config
2. CLI → Processor.pull_request_processor
3. Processor selects Retriever → calls VCS API → returns raw PR data
4. Retriever maps to Models (PullRequest, Diff, etc.)
5. Processor invokes Chains:
– For diff: code_review_chain (build prompts via templates) → LLM API → returns suggestions
– For PR: pr_summary_chain → LLM API → returns summary
6. Actors/Reporters format LLM results into Markdown/Email
7. Reporter outputs to console or via EmailUtils to SMTP
c. Architectural Patterns & Principles:
• Modular plugin architecture for retrievers & LLM models
• Chain-of-Responsibility pattern via LangChain-style chains
• Separation of concerns: data modeling vs. prompt building vs. output formatting
• Dependency injection for easy testing/mocking (see tests/)
d. Key Technologies & Frameworks:
• Python 3.10+, Poetry for dependency management
• Requests or HTTPX for API calls (wrapped in retrievers)
• LangChain utilities (codedog/utils/langchain_utils.py)
• dotenv for config (.env)
• SMTP (smtplib) for email
• pytest for testing