Architecture
System architecture, pipeline flow, queue design, and tech stack.
Pipeline Flow
Mneme processes events through a multi-stage pipeline using pg-boss job queues (Postgres-native).
GitHub Webhooks
├── PR events → pr-analysis queue → Analyzer workers → GitHub comment + commit status
└── Other events → raw_events table → signal-processing queue → Signal workers
├── Store normalized signals + entities
├── Enrich open PR analyses
└── memory-processing queue → Memory workers
└── Maintenance jobs (decay, consolidation, evolution)
Nango OAuth Polling (Slack / Linear / Jira / Stripe)
└── Poll worker (every 5 min) → Fetch via Nango proxy → Normalize → Store signals + entities
└── memory-processing queue → Memory workersGitHub Webhook Ingestion
GitHub webhook payloads are signature-verified (HMAC-SHA256 via x-hub-signature-256 header) before processing. Verified payloads are stored in the raw_events table and a processing job is enqueued.
Nango OAuth Polling (Slack, Linear, Jira, Stripe)
Non-GitHub connectors use Nango OAuth for authentication and a poll worker that runs every 5 minutes. The poll worker discovers active connections, fetches new events via Nango's proxy API, normalizes them into signals, and stores them directly — no webhook setup or secret management required.
Signal Processing
The signal worker picks up GitHub raw events and:
- Routes to the GitHub connector
- Normalizes the event into a standard signal format with extracted entities
- Stores the signal and entities in the database
- If PR enrichment is enabled, checks for open PR analyses to enrich
- Enqueues a memory processing job
Memory Processing
The memory worker receives normalized signals and:
- Classifies the signal into a memory type using an LLM (Anthropic Claude)
- Generates embeddings (OpenAI) for similarity search
- Checks for duplicate or related existing memories
- Creates, updates, or corroborates memories as appropriate
PR Analysis
When a pull request is opened or updated:
- The PR analysis worker fetches the diff and changed files
- Retrieves relevant memories from the memory store
- Runs configured analyzers (e.g., Lens visual regression)
- Composes findings into a GitHub PR comment
- Sets a commit status check
Queue Architecture
Mneme uses pg-boss queues backed by Postgres (SKIP LOCKED + LISTEN/NOTIFY):
| Queue | Purpose | Retry | Backoff |
|---|---|---|---|
pr-analysis | PR diff analysis and commenting | 2 retries | Exponential |
signal-processing | Raw event normalization | 2 retries | Exponential |
memory-processing | Memory classification and storage | 2 retries | Exponential |
backfill | Historical signal ingestion | 2 retries | Exponential |
maintenance-decay | Memory confidence decay (every 6h) | 1 retry | Exponential |
maintenance-evolution | Memory evolution (daily) | 1 retry | Exponential |
maintenance-consolidation | Memory consolidation (weekly) | 1 retry | Exponential |
maintenance-promotion | Org-scope promotion (weekly) | 1 retry | Exponential |
health-monitor | System health checks (every 6h) | 0 | — |
Hot-path queues use the stately policy for singletonKey dedup to prevent duplicate processing. Failed jobs are retried with exponential backoff.
Key Design Patterns
Registry Pattern
Analyzers and signal connectors use a registry pattern for plugin extensibility. New analyzers or connectors can be added by registering them with the appropriate registry.
Lazy Singletons
Database (getDb()) and pg-boss (getBoss()) connections are initialized lazily on first use. This avoids connection overhead during testing and allows graceful startup.
Custom Error Hierarchy
All errors extend from MnemeError:
WebhookError— webhook signature verification failuresAnalyzerError— analyzer execution failuresSignalError— signal processing failuresConnectorError— connector-specific failuresMemoryError— memory processing failures
Graceful Shutdown
On SIGTERM or SIGINT, Mneme performs ordered cleanup with a 10-second timeout:
- Stop accepting new requests
- Stop pg-boss (gracefully stops all workers and closes its connection pool)
- Disconnect database
Tech Stack
| Component | Technology |
|---|---|
| Runtime | Node 20, ESM |
| Package Manager | pnpm 10 |
| HTTP Server | Hono |
| Job Queue | pg-boss (Postgres-native) |
| Database | PostgreSQL + Drizzle ORM + postgres driver |
| Embeddings | OpenAI (text-embedding-3-small) |
| LLM | Anthropic Claude (structured output with Zod) |
| Sandbox | E2B Code Interpreter |
| Testing | Vitest |
| Linting | ESLint 9 + typescript-eslint |
| Formatting | Prettier |
| Build | tsup (ESM output) |
| Deployment | Docker multi-stage → Fly.io |