AAnvio
Architecture

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:

  1. CLI — the primary interface; fully operational on its own with no other surface running.
  2. API — an optional REST layer (apps/api, NestJS) for programmatic or multi-user access.
  3. 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

Rendering diagram…

@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 guides

Dependency 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

ConcernPackage(s)
Schemas & portscore
Compositionplatform
Workspace loading & session storeworkspace
Storage backendsstorage
Auth (optional plugin)auth
Agent runtime & orchestrationagents
Memory providersmemory
Events (local bus + NATS)events
Learning / skill evolutionlearning
Tool gateway (73 built-in tools)tools
Channel harness & connectionsharness
Model providers & routingmodels
Multi-platform channel adapterschannels
Voice (STT/TTS)voice
Knowledge base ingestknowledge
Runtime providers (local, Cursor, Docker, SSH, Daytona, Modal)runtimes
Editor integrationacp
Souls / identitysouls, soul-gate
Goals, kanban, batch, automation, blueprints, workflowsgoals, kanban, batch, automation, blueprints, workflows
Credential poolscredentials
Event hookshooks
Code execution sandboxexecution
Skills catalogskills
Persona templatespersonas
MCP integration registryintegrations
Observabilityobservability
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

Rendering diagram…
LevelStorageAuthEventsBest for
1Filesystem (sessions/ JSONL)Model API key or mock; no platform loginIn-processSolo dev, first run in 5 minutes
2SQLite (state.db + FTS5)+ vendor OAuth (setup-token) + channel connectionsLocal / NATSSmall team + gateway/API
3PostgreSQL + QdrantJWT + OAuthNATS JetStreamMulti-user production
4Kubernetes + managed DBFull RBACDistributedOrganization 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/platform as 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/api controllers or apps/cli command handlers — put it in a package and call it from the thin app layer, preserving the apps → platform → packages → core rule.
  • 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

Edit on GitHub

Last updated on

On this page