System Architecture
Nectr is a distributed system with three main components:- Frontend — Next.js 15 app (Vercel)
- Backend — FastAPI app (Railway)
- Databases — PostgreSQL (Supabase) + Neo4j (Aura)
Tech Stack
Frontend
| Component | Technology | Version |
|---|---|---|
| Framework | Next.js | 15.5.12 |
| UI Library | React | 19.1.0 |
| Styling | TailwindCSS | 4 |
| Data Fetching | TanStack Query | 5.90.21 |
| HTTP Client | Axios | 1.13.6 |
| Charts | Recharts | 3.7.0 |
| Themes | next-themes | 0.4.6 |
nectr-web/
Backend
| Component | Technology | Version |
|---|---|---|
| Framework | FastAPI | 0.129.0 |
| ASGI Server | Uvicorn | 0.41.0 |
| Language | Python | 3.14 |
| ORM | SQLAlchemy | 2.0.46 |
| Migrations | Alembic | 1.18.4 |
| Async Driver | asyncpg | 0.31.0 |
| AI SDK | Anthropic | 0.83.0 |
| Graph Driver | neo4j | 5.0+ |
| Memory | mem0ai | 0.1.98+ |
| MCP | mcp | 1.0.0+ |
app/
Databases
| Type | Purpose | Technology |
|---|---|---|
| Relational | Users, repos, events, workflows | PostgreSQL (asyncpg) |
| Graph | Files, PRs, developers, relationships | Neo4j (async driver) |
| Semantic | Project patterns, developer habits | Mem0 (cloud API) |
External Services
| Service | Purpose |
|---|---|
| Anthropic Claude | AI PR reviews (Sonnet 4.6) |
| GitHub API | OAuth, webhooks, PR data, comments |
| Mem0 | Semantic memory layer |
| Linear MCP | Linked issues (optional) |
| Sentry MCP | Production errors (optional) |
| Slack MCP | Channel messages (optional) |
Data Flow
1. Authentication Flow
Key files:- Frontend:
nectr-web/src/app/page.tsx - Backend:
app/auth/router.py - JWT utils:
app/auth/jwt_utils.py - Encryption:
app/auth/token_encryption.py
2. PR Review Flow
See Review Flow for detailed diagram. Summary:- Developer opens/updates PR on GitHub
- GitHub sends webhook to
/api/v1/webhooks/github - Backend verifies HMAC signature, creates Event, returns 200
- BackgroundTask processes PR:
- Fetch diff and files from GitHub
- Build context (Neo4j + Mem0 + MCP)
- Run AI analysis (Claude with agentic tools)
- Post review comment on GitHub
- Index PR in Neo4j
- Extract memories to Mem0
- Webhook:
app/api/v1/webhooks.py - Orchestrator:
app/services/pr_review_service.py - AI:
app/services/ai_service.py - Context:
app/services/context_service.py
3. Repo Connection Flow
Key files:- Frontend:
nectr-web/src/hooks/useRepos.ts - Backend:
app/api/v1/repos.py - Webhook manager:
app/integrations/github/webhook_manager.py - Graph builder:
app/services/graph_builder.py
Security Architecture
Authentication
- GitHub OAuth — User signs in with GitHub
- JWT tokens — Signed with
SECRET_KEY(HS256) - httpOnly cookies — Prevents XSS attacks
- SameSite=None; Secure — Cross-origin support (frontend on Vercel, backend on Railway)
Token Encryption
GitHub access tokens are encrypted at rest using Fernet (AES-128-CBC):app/auth/token_encryption.py.
Webhook Verification
GitHub webhooks are verified using HMAC-SHA256:app/api/v1/webhooks.py:30-40.
CORS Configuration
CORS is locked down to specific origins:app/main.py:143-157.
Async Architecture
Backend (FastAPI)
All I/O operations are async:- Database:
asyncpg+ SQLAlchemy async - Neo4j:
neo4jasync driver - HTTP:
httpx.AsyncClient - Anthropic:
anthropic.AsyncAnthropic
app/services/pr_review_service.py.
Parallel Execution
asyncio.gather() runs multiple operations concurrently:app/services/pr_review_service.py:512-523.
MCP Architecture
Nectr implements Model Context Protocol bidirectionally:Nectr as MCP Server (Outbound)
External agents (e.g., Claude Desktop) can query Nectr’s data: Endpoint:GET /mcp/sse (SSE transport)
Tools exposed:
get_recent_reviews— Recent PR reviews with verdictsget_contributor_stats— Top contributorsget_pr_verdict— Verdict for specific PRget_repo_health— Repository health score
app/mcp/server.py (FastMCP)
Nectr as MCP Client (Inbound)
Nectr pulls live context from third-party MCP servers during PR reviews:- Linear MCP — Linked issues + task descriptions
- Sentry MCP — Production errors for changed files
- Slack MCP — Relevant channel messages
app/mcp/client.py (MCPClientManager)
See Backend Architecture for details.
Deployment Architecture
Production
Startup Sequence
Seeapp/main.py:88-131 (lifespan context manager):
- Run Alembic migrations (
alembic upgrade head) - Create PostgreSQL tables (belt-and-suspenders)
- Initialize Neo4j driver
- Create Neo4j schema (constraints + indexes)
- Background task: Scan repos not yet indexed in Neo4j
- Yield (app starts serving requests)
- Shutdown: Close database connections
Performance Considerations
Database Connection Pooling
PostgreSQL (SQLAlchemy):Webhook Processing
Webhook endpoint returns 200 immediately and processes PR in background:app/api/v1/webhooks.py:116-158.
Deduplication
Prevents duplicate PR reviews when GitHub sends the same webhook multiple times:app/api/v1/webhooks.py:95-105.
Observability
Logging
Structured logging with Pythonlogging module:
DEBUG— Local developmentINFO— ProductionWARNING— Non-fatal errors (e.g., MCP integration unavailable)ERROR— Fatal errors
Health Check
Endpoint:GET /health
Returns:
app/main.py:190-219.
Request Logging
All requests are logged with duration:app/main.py:180-188.
Next Steps
Backend Architecture
Deep dive into FastAPI backend
Frontend Architecture
Deep dive into Next.js frontend
Review Flow
Complete PR review workflow
Local Development
Set up Nectr locally