How ayush488-glitch/ai-pr-review-agent works
Purpose and entry points
AI PR Review Agent is a modular monolith that receives GitHub pull-request webhooks, runs parallel AI reviews, persists review/audit/economic data, posts results to GitHub, and exposes a dashboard plus human-approval workflow. Backend HTTP startup is backend/main.py; webhook ingress is backend/webhook_receiver/router.py; the asynchronous worker is backend/job_queue/arq_worker.py. The operator UI is a Next.js application rooted at frontend/src/app/page.tsx.
Ingress, validation, and asynchronous boundary
GitHub webhook payloads are parsed and validated before becoming review work. The ingress boundary includes webhook parsing/validation and API-facing queue dispatch: backend/webhook_receiver/parser.py, backend/webhook_receiver/validator.py, and backend/api/queue.py. Redis plus ARQ separates request acknowledgement from potentially long-running LLM orchestration; Docker Compose provisions API, worker, and Redis (docker-compose.yml, backend/job_queue/arq_worker.py).
Review workflow orchestration
A queued review is executed by a LangGraph-oriented orchestration layer that owns state, fan-out/fan-in, checkpoints, aggregation, and downstream routing/posting. Its central graph and node definitions are backend/orchestrator/graph.py, backend/orchestrator/nodes.py, and backend/orchestrator/state.py; an alternate/core workflow abstraction exists in backend/core/workflow_engine.py. This is the control-plane boundary between durable job execution and agent/model/tool calls.
Specialist agents and reasoning layer
Four domain agents—security, quality, tests, and documentation—share contracts/base behavior while producing structured findings for aggregation. Core paths are backend/agents/base_agent.py, backend/agents/contracts.py, and representative implementations such as backend/agents/security_agent.py and backend/agents/quality_agent.py. Prompt versions are externalized under backend/prompts/templates/, while LLM selection and invocation are mediated by backend/tools/model_router.py and backend/tools/llm_client.py; OpenAI GPT-4o is the stated model service.
Context, tools, and execution safety
Agents enrich PR diffs with semantic codebase context and may use registered, capability-scoped tools. Memory access is centered on Tiger/Timescale-compatible clients and retrieval: backend/memory/tiger_client.py, backend/memory/context_retriever.py, and backend/memory/embedder.py. The tree also retains backend/memory/qdrant_client.py, so migration/compatibility boundaries should be verified rather than assuming Qdrant is inactive. Tool execution is bounded by backend/tools/tool_registry.py, backend/tools/capability_scope.py, and Docker sandboxing in backend/tools/sandbox.py.
Persistence, observability, and economics
Tiger Cloud/TimescaleDB is the intended consolidated data layer: structured records, vector-backed context, and time-series agent events. Database access and schema models reside in backend/database/postgres.py, backend/database/repository.py, and backend/database/models.py; provisioning DDL is scripts/migrations/2026-06-tiger-init.sql. Observability records events, audits, and traces through backend/observability/events.py, backend/observability/audit.py, and backend/observability/tracing.py. Cost budgets and routing decisions consume this telemetry via backend/economics/budget.py, backend/economics/cost_repository.py, and backend/economics/routing_advisor.py.
Human governance and user-facing APIs
Low-confidence or disputed findings move to a human-in-the-loop queue for approval, escalation, and feedback, implemented by backend/hitl/queue.py, backend/hitl/escalation.py, and backend/hitl/feedback.py. REST surfaces are separated into review, HITL, and economics routers: backend/api/reviews.py, backend/api/hitl_router.py, and backend/api/economics_router.py. The frontend consumes these APIs for review detail, HITL actions, and economics views (frontend/src/app/reviews/[id]/page.tsx, frontend/src/app/hitl/page.tsx, frontend/src/app/economics/page.tsx).
Reliability, security, deployment
The service applies idempotency, retry, timeout, and circuit-breaker controls around external and asynchronous work (backend/reliability/idempotency.py, backend/reliability/retry.py, backend/reliability/circuit_breaker.py). Security boundaries include RBAC, injection protection, and data masking in backend/security/rbac.py, backend/security/injection_guard.py, and backend/security/masking.py. Deployment targets include containerized local/runtime deployment and Railway configuration (Dockerfile, Procfile, railway.toml), with GitHub, Redis, Tiger Cloud, OpenAI, and Docker as material external dependencies.
Main entry points: graph.py LangGraph orchestration · base_agent.py Specialist review agents · reviews.py Review, HITL & economics APIs · router.py Webhook validation
Components 20
Ingress & API
- Backend HTTP service
backend/main.py - Webhook validation
backend/webhook_receiver/router.py - Payload parser & validator
backend/webhook_receiver/parser.py - Review, HITL & economics APIs
backend/api/reviews.py
Review Execution
- Redis + ARQ · Acknowledges webhooks before durable asynchronous work.
backend/job_queue/arq_worker.py - Review worker
backend/job_queue/arq_worker.py - LangGraph orchestration · Owns review state, fan-out/fan-in, checkpoints, and result routing.
backend/orchestrator/graph.py - Workflow nodes & state
backend/orchestrator/nodes.py
Agents & Context
- Specialist review agents · Security, quality, tests, and documentation findings share common contracts.
backend/agents/base_agent.py - Versioned prompts
- LLM router & client · Selects and invokes OpenAI GPT-4o.
backend/tools/model_router.py - Semantic context retrieval
backend/memory/context_retriever.py - Scoped tool sandbox
backend/tools/tool_registry.py
Data & Governance
- Tiger Cloud / TimescaleDB · Stores records, vectors, and time-series agent events.
backend/database/postgres.py - Events, audit & tracing
backend/observability/events.py - Budget & routing advisor
backend/economics/budget.py - Human approval workflow · Approves, escalates, and feeds back on uncertain findings.
backend/hitl/queue.py
Operator UI
- Next.js dashboard
frontend/src/app/page.tsx
Other components
- GitHub · Sends PR webhooks and receives review results.
- OpenAI GPT-4o
Connections 24
- GitHub → Webhook validation: PR webhook
- Backend HTTP service → Webhook validation: mounts
- Webhook validation → Payload parser & validator: parses and validates
- Payload parser & validator → Redis + ARQ: dispatches review job
- Redis + ARQ → Review worker: executes asynchronously
- Review worker → LangGraph orchestration: runs review graph
- LangGraph orchestration → Workflow nodes & state: state and fan-out
- LangGraph orchestration → Specialist review agents: parallel specialist reviews
- Specialist review agents → Versioned prompts: uses
- Specialist review agents → LLM router & client: requests inference
- LLM router & client → OpenAI GPT-4o: invokes
- Specialist review agents → Semantic context retrieval: retrieves code context
- Semantic context retrieval → Tiger Cloud / TimescaleDB: vector and record access
- Specialist review agents → Scoped tool sandbox: capability-scoped calls
- LangGraph orchestration → Tiger Cloud / TimescaleDB: persists review results
- LangGraph orchestration → Events, audit & tracing: emits events and traces
- Events, audit & tracing → Budget & routing advisor: cost telemetry
- Budget & routing advisor → LLM router & client: routing and budget decisions
- LangGraph orchestration → Human approval workflow: routes uncertain findings
- LangGraph orchestration → GitHub: posts review results
- Next.js dashboard → Review, HITL & economics APIs: dashboard requests
- Review, HITL & economics APIs → Tiger Cloud / TimescaleDB: reads review data
- Review, HITL & economics APIs → Human approval workflow: approval actions
- Review, HITL & economics APIs → Budget & routing advisor: economics views