Skip to main content

System Architecture

Data Model

Key Services

Background Job System

  1. Frontend/planner calls POST /tickets/{id}/run
  2. Backend creates a Job record (QUEUED) and enqueues into job_queue table
  3. SQLiteWorker polls the queue, claims the task
  4. Job runs in an isolated worktree, streams logs via in-memory broadcaster
  5. Job result triggers ticket state transition

Periodic Tasks

Async vs Sync Database

  • FastAPI routes: Async SQLAlchemy via database.get_db()
  • Background worker: Sync SQLAlchemy via database_sync.get_sync_db()
  • Models are shared but sessions differ
  • Use db.expunge() before passing objects between contexts

Middleware

Idempotency

Atomic first-writer-wins via SQLite. Key includes (client_id, route, resource_scope, idempotency_key). Returns 409 Conflict for same key + different body.

Rate Limiting

Cost-based budget per client for LLM endpoints. Tracks spending and enforces limits.

Security Headers

Standard security headers (CSP, HSTS, X-Frame-Options) applied to all responses.