00c1839635
- Replace go-sqlite3 with go-sql-driver/mysql (pure Go, no CGO needed)
- Add joho/godotenv for .env file loading
- Rewrite database/db.go with MySQL-compatible DDL (BIGINT AUTO_INCREMENT, InnoDB, utf8mb4)
- Convert all SQLite-specific SQL: INSERT OR IGNORE → INSERT IGNORE,
INSERT OR REPLACE → INSERT ... ON DUPLICATE KEY UPDATE,
datetime('now') → NOW(), date arithmetic → DATE_SUB()
- Add MySQL config fields to config.go (host/port/user/password/database)
- Add .env.example with connection parameter template
- Update Dockerfile: remove CGO/gcc/musl dependency, smaller build
- Update docker-compose.yml: add MySQL service container with healthcheck
- Update CLAUDE.md documentation
3.4 KiB
3.4 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
PR-Helper is a self-hosted web service that auto-generates PR descriptions from Git history and performs AI-powered code review. Designed for internal/local use only (no auth).
Tech Stack
- Backend: Go + Gin + MySQL + go-git
- Frontend: Go html/template + HTMX + D3.js + diff2html + Tailwind CSS
- LLM: OpenAI-compatible API (SSE streaming)
- Deploy: Docker
Build & Run
# Build
go build -o pr-helper .
# Configure — copy .env.example to .env and set MySQL credentials
cp .env.example .env
# Run (requires MySQL server)
./pr-helper
# Server listens on :8080
# Docker (includes MySQL container)
docker compose up --build
Architecture
handlers/ → HTTP handlers (pages + JSON API + SSE endpoints)
services/ → Business logic (git ops, LLM calls, PDF gen, cache management)
models/ → Data models (repository, settings, analysis)
database/ → MySQL init and migrations
config/ → Configuration loading
templates/ → Go HTML templates (layouts/, pages/, partials/)
static/ → CSS (Tailwind output), JS (graph, diff-viewer, sse), vendor libs
Data flow: Browser ↔ Gin handlers → services (git/llm) → MySQL + filesystem (data/)
Key service layer responsibilities:
services/git.go— clone, diff, graph data extraction via go-gitservices/llm.go— OpenAI-compatible API calls with SSE streamingservices/generate.go— PR description generation (commits + diff → LLM → structured output)services/review.go— AI code review (per-file analysis + summary, Top-N strategy for large diffs)services/cache.go— repository cache lifecycle (clone, expiry cleanup)
Key Patterns
- SSE streaming: Clone progress, PR generation, and AI review all use Server-Sent Events. Handlers write
event:/data:lines; frontend consumes viastatic/js/sse.js. - Large diff handling: Diffs are split per-file, sorted by change size, truncated to Top-N (configurable, default 20). Each file analyzed independently by LLM, then a summary prompt aggregates results.
- Review notes: Three-level scoping —
overall,file,suggestion— stored inreview_notestable. AI output is read-only; users append notes separately. - Diff rendering: diff2html in Split view by default. AI review suggestions are inline-embedded next to code lines via
line+sidefields from SSE.
Frontend Libraries (vendored in static/lib/)
- HTMX 2.x, D3.js 7.x, diff2html 3.x, highlight.js 11.x
- Tailwind CSS compiled to
static/css/style.css - Custom JS:
sse.js(SSE client),graph.js(D3 git graph with click selection),diff-viewer.js(diff2html + file tree sidebar),review-inline.js(inline AI suggestions)
Data Storage
- MySQL database
pr_helper— settings (KV), repositories, analyses, review_notes - Cloned repos cached at
data/repos/with configurable expiry (default 7 days) - Database connection configured via
.envfile (see.env.example)
Development Notes
- No authentication — do not expose to public internet.
- LLM prompts are in
services/generate.goandservices/review.go; model/endpoint/key are configurable via the settings page. - SSE event formats are defined in
handlers/generate.goandhandlers/review.go(server) and consumed bystatic/js/sse.js(client).