How kmesiab/cadre works
Project type and purpose
• This is a language-agnostic, AI-powered CLI tool (written in Go) named “Cadre CLI” that automates code reviews of GitHub pull requests by fetching diffs, sending them to OpenAI’s ChatGPT API, and rendering the result as Markdown.
File structure
• Top-level Go files:
• main.go / main_test.go: application entrypoint and unit tests
• github_diff_client.go / github_diff_client_mock.go: abstraction & mock for GitHub API
• openai.go: wrapper for OpenAI ChatGPT API calls
• prompt.go: logic to build prompts for ChatGPT
• Makefile: build, test, lint targets
• go.mod / go.sum: dependency management
• assets/: screenshots, documentation only
• .github/workflows/: CI pipelines (build, lint, test)
README for additional insights
• Describes CLI switches (--url, --key, --model)
• Explains review categories (Technical Accuracy, Best Practices, etc.)
• Shows that the core workflow is: fetch diff → build prompt → call ChatGPT → parse response → output Markdown report.
Main components & interactions
a. Components:
1. CLI Frontend (main.go)
2. GitHub Diff Client
3. Prompt Builder
4. OpenAI Client
5. Markdown Renderer / Output Writer
6. External Services:
– GitHub REST API
– OpenAI ChatGPT API
b. Relationships / Data flow:
1. User invokes cadre --url=… --key=… → CLI Frontend
2. CLI calls GitHub Diff Client to fetch pull-request diffs from GitHub REST API
3. Diffs passed into Prompt Builder to assemble language-specific review prompts
4. Prompt sent to OpenAI Client → communicates with OpenAI ChatGPT API → receives review text
5. CLI aggregates responses, passes to Markdown Renderer
6. Markdown report printed to stdout or file
c. Architectural patterns:
• Modular layers (ports & adapters):
• Adapters: GitHubDiffClient, OpenAIClient
• Core business logic: Prompt Builder, Output Renderer
• Dependency injection for testability (github_diff_client_mock.go)
d. Key technologies:
• Go modules, standard library (net/http), CLI flags parsing
• OpenAI API (gpt-3.5-turbo, gpt-4)
• GitHub REST API v3
Additional details to capture
• The environment/configuration node (env var OPENAI_API_KEY, CADRE_COMPLETION_MODEL) feeding into CLI Frontend
• Interfaces vs implementations: mark the GitHub client interface and the concrete/mock implementations