How forkbikash/opencode works
Project type and purpose
• This is a full-stack, multi-client monorepo that delivers:
• A terminal-first CLI/TUI (“OpenCode”) agent (packages/opencode + packages/tui).
• A web-based “console” management UI (packages/console/app + packages/console/core + serverless functions + mail + resource infra).
• A public landing site (packages/web).
• Language SDKs (packages/sdk/go, sdk/js, sdk/stainless).
• A VSCode extension (sdks/vscode).
• Purpose: provide an LLM-powered coding assistant with local CLI/TUI clients, remote server for state, multi-client frontend, database, mail, and pluggable LLM providers.
File structure
• Top-level “packages/…” directories map to deployable components:
• packages/opencode: Node/TS CLI logic (bin/opencode) and language-model agent core.
• packages/tui: Go-based terminal UI library.
• packages/console/app: React/Remix-style web console.
• packages/console/core: shared business logic, database schema (Drizzle), migrations.
• packages/console/function: serverless handlers (auth, log processing).
• packages/console/mail: email templates and renderer.
• packages/console/resource: SST definitions for AWS resources.
• packages/web: Astro-based marketing/docs site.
• packages/sdk: generated client libraries.
• sdks/vscode: VSCode extension bundling the core CLI.
• “infra/”: SST stacks deploying the app, console, desktop, and staging environments.
• Config files (bunfig.toml, tsconfig.json, turbo.json, workflow YAMLs) orchestrate build/test/deploy.
README for additional insights
• Mentions client/server architecture: CLI/TUI client can drive a remote server.
• Recommends Anthropic, but provider-agnostic.
• Uses Bun, Go, SST for local development and infra.
Main components
a. Clients (green cluster)
– Terminal CLI/TUI (TS binary + Go TUI library)
– VSCode extension
– Web console UI (React/Remix)
– Public landing site (Astro)
b. API Layer (blue cluster)
– API Gateway / HTTP endpoints (handled by serverless functions in packages/console/function)
– Auth service (OAuth + session management)
– Core server (packages/opencode/src/server & packages/console/core)
– Event bus / message queue (for logging & session events)
c. Data stores (orange cluster)
– Relational DB (Postgres via Drizzle ORM + migrations)
– Blob store / S3 (for attachments, logs)
– Key-value store / Cloudflare KV (optional, for caches)
– Mail templates & rendering engine (packages/console/mail)
d. Infrastructure (gray cluster)
– SST stacks (infra/app.ts, infra/console.ts, infra/desktop.ts, infra/stage.ts)
– CI/CD pipelines (GitHub Actions workflows)
e. External services (purple cluster)
– LLM providers (Anthropic, OpenAI, Google, local models)
– Email provider (SES or SMTP)
– Stripe (billing webhook)
– Git hosting (GitHub API)
Relationships and interactions
• CLI/TUI, VSCode, Web console → API Gateway → Auth → Core server → DB
• Core server emits events → Event bus → Log processor → Storage
• Core server triggers mail → Mail service → Email provider
• Infrastructure provisions resources via SST → AWS (Lambda, API Gateway, RDS, S3, CloudFront)
• SDKs are generated from stainless schemas after server-side changes (server.ts)
Architectural patterns & principles
• Client/Server separation: multiple thin clients talking HTTP/websocket to the same backend.
• Serverless microservices: discrete Lambda functions for auth, billing, chat (“zen”) endpoints.
• Shared core library: business logic and DB layer centralized in packages/console/core and packages/opencode/src/server.
• Event-driven logging and asynchronous tasks via an internal bus.
• Monorepo orchestration: Turborepo + Bun + Go + SST.
• Provider-agnostic LLM interface: pluggable providers under src/session and src/provider.