Skip to main content

Database Technology

Nectr uses PostgreSQL with async SQLAlchemy for all relational data.
  • Driver: asyncpg (pure-async PostgreSQL driver)
  • ORM: SQLAlchemy 2.0 (async session API)
  • Migrations: Alembic
  • Connection Pool: Managed by SQLAlchemy

Table Overview

Users

Table: users
Model: app/models/user.py
Stores GitHub OAuth users who have logged into Nectr.
Token Encryption: github_access_token is encrypted using Fernet (AES-128-CBC) before storing. The encryption key is SECRET_KEY from environment variables.

Installations

Table: installations
Model: app/models/installation.py
Tracks connected repositories (repos that have webhook installed).
Per-Repo Webhook Secrets: Each installation has its own webhook_secret for HMAC-SHA256 signature verification. This is more secure than a global secret.

Events

Table: events
Model: app/models/event.py
Records incoming webhook events from GitHub.
  1. pending - Event received, not yet processed
  2. completed - Background task finished successfully
  3. failed - Background task encountered an error

Workflow Runs

Table: workflow_runs
Model: app/models/workflow.py
Tracks execution of background workflows (PR reviews, error triage, etc.).
  • pr_review - AI-powered PR review
  • error_triage - Sentry error classification (future)
  • ticket_sync - Linear ticket updates (future)

OAuth States

Table: oauth_states
Model: app/models/oauth_state.py
Stores CSRF state tokens for GitHub OAuth flow.
CSRF Protection: State tokens prevent CSRF attacks by ensuring the OAuth callback is for a session we initiated. States expire after 5 minutes and can only be used once.

Database Initialization

File: app/core/database.py

Migrations (Alembic)

Directory: alembic/versions/ Nectr uses Alembic for schema migrations.
  1. Generate migration:
  2. Apply migration:
  3. Automatic on startup:

Connection Pooling

SQLAlchemy manages a connection pool to handle concurrent requests:
  • Pool size: 10 connections
  • Max overflow: 20 connections (30 total)
  • Pool recycle: 1 hour (prevents stale connections)
  • Pool timeout: 30 seconds
Railway (hosting provider) free tier supports up to 50 concurrent connections. The pool configuration keeps us well under that limit.

Query Patterns

Data Retention

Currently, Nectr stores all events and workflow runs indefinitely. Future roadmap includes:
  • Archive old events (> 90 days) to cold storage
  • Delete failed events (> 30 days)
  • Compress payloads for storage efficiency

Next Steps

Neo4j Graph

Learn about the knowledge graph schema

Backend Architecture

Explore FastAPI routes and middleware