Skip to content

System Architecture

OpenCodeHub is a modular monolith built for performance and self-hosting simplicity.

┌─────────────────────────────────────────────────────────────┐
│ CLIENTS │
│ Browser │ Git CLI (HTTP/SSH) │ OpenCodeHub CLI (och) │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ OPENCODEHUB PLATFORM │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Web UI │ │ REST API │ │ GraphQL Endpoint │ │
│ │ (Astro+React)│ │ (175+ routes)│ │ (src/pages/api/) │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Git Server │ │ SSH Server │ │ Pipeline Runner │ │
│ │ (HTTP RPC) │ │ (ssh2) │ │ (Docker executor) │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ PERSISTENCE & INFRASTRUCTURE │
│ PostgreSQL/SQLite/Turso │ Redis │ Pluggable Storage │
└─────────────────────────────────────────────────────────────┘
ProcessCommandPurpose
Main Appnpm run devWeb UI + API + Git HTTP
SSH Gitnpm run git:startSSH git push/pull server
Workernpm run worker:startBackground jobs (BullMQ queues)
Runnernpm run runner:startCI/CD pipeline execution (Docker)
LayerTechnology
FrameworkAstro 4.x (SSR mode, @astrojs/node standalone adapter)
UIReact 18 + Tailwind CSS + Radix UI primitives
Database ORMDrizzle ORM
DB DriversPostgreSQL (pg), SQLite (better-sqlite3), LibSQL/Turso
AuthJWT (jose) + bcryptjs + TOTP (otplib) + OAuth (arctic) + SSO/SAML/OIDC
GitNative git CLI + simple-git + isomorphic-git + nodegit
SSHssh2 library
CI/CDDockerode (Docker API)
StorageAbstract adapter: local filesystem or s3-compatible
AIOpenAI, Anthropic, Google, Groq, Ollama, OpenRouter, Together, Bytez
QueueBullMQ + Redis
ObservabilityOpenTelemetry + Prometheus + Pino
Browser/Git CLI → Astro middleware (auth, rate limit, CSRF)
Route handler (src/pages/api/*.ts)
Business logic (src/lib/*.ts)
Database (src/db/index.ts → Drizzle)
  • Web: Cookie-based JWT (och_session)
  • API: Bearer token (JWT or Personal Access Token och_...)
  • Git HTTP: Basic auth with PAT as password
  • Git SSH: Public key auth against deployKeys table
  • SSO: SAML and OIDC via admin-configured providers
  • HTTP: src/pages/git/ routes → src/lib/git-server.ts → spawns git upload-pack/receive-pack
  • SSH: src/lib/ssh.ts using ssh2 library → spawns git processes
  • Smart HTTP: Full pkt-line protocol implementation with sideband

All blob storage goes through StorageAdapter:

  • LocalStorageAdapter — filesystem at STORAGE_PATH
  • S3StorageAdapter — any S3-compatible store (AWS, MinIO, R2, Garage, Wasabi, etc.)

Path-style addressing is enabled automatically when STORAGE_ENDPOINT is set.

src/db/index.ts provides a factory pattern:

  • Reads DATABASE_DRIVER and DATABASE_URL
  • Returns appropriate Drizzle instance
  • Production: PostgreSQL required (schemas use pgTable)
  • Dev: SQLite or Turso for simplicity

38 schema tables cover users, repos, PRs, issues, projects, workflows, merge queue, stacked PRs, AI reviews, security policies, and more.

The worker process (npm run worker:start) handles:

  • BullMQ job queues for webhooks, notifications, CI triggers
  • Cron jobs (garbage collection, mirror sync, notification digests)
  • Email delivery via SMTP
  • Real-time SSE event broadcasting