Sentry

SYSTEM OVERVIEW

How Sentry reviews a pull request

Sentry turns a GitHub PR URL into a structured merge-readiness report by fetching the full PR context, building a deterministic prompt, and asking an LLM to respond with strict JSON.

End-to-end flow

flowchart LR user[User_PR_URL] --> ui[HTML_UI] ui --> api[Express_API_/api/analyze] api --> gh[GitHub_REST_API] gh --> chunk[Diff_Chunker] chunk --> prompt[Prompt_Builder] prompt --> llm[OpenRouter_LLM] llm --> parse[Report_Formatter_JSON_Parse_Retry] parse --> api api --> ui api --> db[(MongoDB_Reports)] ui --> reportsApi[Express_API_/api/reports] reportsApi --> db
  1. User submits PR URL via the home page form.
  2. Express API receives the request at POST /api/analyze.
  3. GitHub REST fetch loads PR metadata, changed files (patches), commits, inline review comments, conversation comments, and review states.
  4. Diff chunker keeps context within limits: prioritizes non-test files, truncates huge patches, and summarizes test files when needed.
  5. Prompt builder constructs a labeled prompt (metadata → commits → file changes → reviews/comments) plus an explicit JSON schema the model must follow.
  6. OpenRouter LLM call runs with a 60s timeout and retry-on-5xx.
  7. Report formatter parses JSON. If parsing fails, Sentry retries once with a stricter “JSON only” reminder.
  8. Response returned as a consistent envelope: success: true with report and metadata.
  9. (Optional) MongoDB persistence stores successful reports and the home page shows “Recent Reports” cards via GET /api/reports.

API endpoints

  • POST /api/analyze — analyze a PR URL
  • GET /api/health — health check
  • GET /api/reports — recent saved reports (MongoDB)

Core modules

  • lib/github.js — GitHub fetch + pagination + rate-limit errors
  • lib/chunker.js — diff sizing/truncation strategy
  • lib/prompt-builder.js — deterministic prompt + strict schema
  • lib/openrouter.js — LLM call + timeout/retry
  • lib/report-formatter.js — parse + retry + envelope
  • lib/report-store.js — MongoDB persistence