High-Level Architecture
How Anvio's CLI, agent runtime, tool gateway, and storage layers fit together, and the dependency rule that keeps them decoupled.
6 min read
Purpose
Understand the shape of the system before diving into individual components, the data flow through a single request, or the underlying event flow. This page is the map; the others are the terrain.
Priority order
Anvio's architecture follows a strict priority order, enforced by design rather than convention:
- CLI — the primary interface; fully operational on its own with no other surface running.
- API — an optional REST layer (
apps/api, NestJS) for programmatic or multi-user access. - Web UI — an optional dashboard, later-phase work.
This is the practical meaning of "CLI-first": you can do everything — chat with agents, run one-shot tasks, manage sessions, configure tools — without ever starting the API or gateway.
Default mode (Level 1)
At the default level, the system runs with:
- No authentication
- Filesystem storage (
workspace/) - Filesystem memory (
workspace/memory/) - In-process events (no NATS)
- No PostgreSQL, Redis, or Docker required
System map
@anvio/platform is the composition root: it reads workspace/anvio.yaml and wires together storage, memory, events, runtime, tool gateway, model router, harness, and automation according to what's enabled. Every entry point (CLI, API, gateway, channels, ACP) calls into the same platform composition — there is exactly one runtime behind all of them.
Monorepo layout and the dependency rule
Anvio/
├── apps/
│ ├── cli/ Primary interface
│ ├── api/ Optional REST (NestJS composition root)
│ ├── worker/ Background job consumer
│ ├── gateway/ WebSocket gateway
│ └── desktop/ Desktop shell scaffold
├── packages/ ~35 packages: core, platform, workspace, storage, auth,
│ agents, memory, events, souls, goals, automation,
│ blueprints, kanban, runtimes, execution, hooks, batch,
│ credentials, models, skills, personas, integrations, acp, …
├── configs/ Bundled skills, blueprints, observability
├── workspace/ Default workspace (your copy)
└── docs/ Architecture & phase guidesDependency rule: apps → platform → packages → core
Domain logic never lives in NestJS controllers (or any app-level code). Apps are thin adapters; @anvio/platform composes everything; packages implement isolated capabilities; @anvio/core defines the shared schemas and ports everything else depends on. This keeps the CLI, API, and gateway interchangeable — none of them owns business logic, so adding a new entry point (or removing one) doesn't touch the runtime.
Package boundaries by concern
| Concern | Package(s) |
|---|---|
| Schemas & ports | core |
| Composition | platform |
| Workspace loading & session store | workspace |
| Storage backends | storage |
| Auth (optional plugin) | auth |
| Agent runtime & orchestration | agents |
| Memory providers | memory |
| Events (local bus + NATS) | events |
| Learning / skill evolution | learning |
| Tool gateway (73 built-in tools) | tools |
| Channel harness & connections | harness |
| Model providers & routing | models |
| Multi-platform channel adapters | channels |
| Voice (STT/TTS) | voice |
| Knowledge base ingest | knowledge |
| Runtime providers (local, Cursor, Docker, SSH, Daytona, Modal) | runtimes |
| Editor integration | acp |
| Souls / identity | souls, soul-gate |
| Goals, kanban, batch, automation, blueprints, workflows | goals, kanban, batch, automation, blueprints, workflows |
| Credential pools | credentials |
| Event hooks | hooks |
| Code execution sandbox | execution |
| Skills catalog | skills |
| Persona templates | personas |
| MCP integration registry | integrations |
| Observability | observability |
| Level 3 database (Drizzle ORM) | db |
See Components for what each app and the most important packages actually do at runtime.
Authentication is a plugin, not a gate
Auth defaults to auth.enabled: false. Local tools — filesystem, browser, memory, sessions — all work without any login. OAuth/JWT only activates when you explicitly enable it, typically because an external MCP provider (GitHub, Google, Slack) requires it, or because you're running a multi-user API deployment. See Runtime OAuth for the distinct concept of vendor runtime OAuth (Claude Code, Cursor, Codex, Antigravity), which is unrelated to platform login.
Progressive enhancement
| Level | Storage | Auth | Events | Best for |
|---|---|---|---|---|
| 1 | Filesystem (sessions/ JSONL) | Model API key or mock; no platform login | In-process | Solo dev, first run in 5 minutes |
| 2 | SQLite (state.db + FTS5) | + vendor OAuth (setup-token) + channel connections | Local / NATS | Small team + gateway/API |
| 3 | PostgreSQL + Qdrant | JWT + OAuth | NATS JetStream | Multi-user production |
| 4 | Kubernetes + managed DB | Full RBAC | Distributed | Organization scale |
Each level is reached by editing workspace/anvio.yaml — never by rewriting agent configs or application code.
Not yet shipped
Level 3's Qdrant semantic memory and Level 4's Kubernetes/Helm deployment are both forward-looking targets in the architecture docs (Qdrant is explicitly "Phase 2" per ADR 0004; the Kubernetes Helm chart is listed under deployment "Phase 4"). Treat both as roadmap, not available today.
Best practices
- Treat
@anvio/platformas the single source of truth for how components are wired — if you're adding a new capability, it should be composed there, not bolted onto an app. - Don't add domain logic to
apps/apicontrollers orapps/clicommand handlers — put it in a package and call it from the thin app layer, preserving theapps → platform → packages → corerule. - Start every new deployment at Level 1 and only escalate storage/auth/events when you hit a concrete need (multi-user, durability, or scale), not preemptively.
Common mistakes
- Assuming the API or gateway is required. Neither is; the CLI alone is a complete product.
- Enabling auth because "it's more secure." Auth is a plugin for a reason — turning it on adds JWT/OAuth complexity that's only needed once you have multiple untrusted users or OAuth-gated MCP tools.
- Confusing platform auth with runtime OAuth. Platform auth (
auth.enabled) gates the REST API for multi-user access. Runtime OAuth (anvio setup-token) authenticates a single agent to a vendor CLI subscription. They're independent settings.
References
Last updated on