Folder Structure
How Anvio's monorepo is organized across apps, platform, packages, and core, and the dependency rule that keeps them decoupled.
5 min read
Anvio is a pnpm + Turborepo monorepo. The layout enforces one rule: domain logic never lives in an app. Apps only compose packages together.
Dependency rule
apps → platform → packages → coreapps/— composition roots only (NestJS modules, CLI entry points). No business logic.packages/platform— the single factory that wires a workspace's config into a running system (agent runtime, channel hub, tool gateway, MCP bridge, etc.).packages/*— roughly 35 domain packages, each independently buildable, each owning one concern (channels, runtimes, models, tools, memory, souls, goals, kanban, ...).packages/core— shared Zod schemas, TypeScript types, and ports (interfaces). Every other package depends oncore;coredepends on nothing else in the workspace.
The rule is structural, not just convention: packages/core has no dependency on any sibling package, and apps/* never import from each other. See ADR 0002 for why NestJS is confined to apps/.
Top-level layout
anvio/
apps/ NestJS/CLI composition roots
packages/ ~35 domain packages + core
workspace/ Default local-first workspace (agents, memory, sessions, mcp config)
configs/ Shared configs (observability dashboards, etc.)
docker/ Container build assets
docs/ Architecture docs, ADRs, phase notes
scripts/ Repo automation (e.g. hermes skills import)
tests/ Cross-package integration testsapps/
| App | Package | Role |
|---|---|---|
apps/cli | @anvio/cli | Primary entry point (anvio binary). Fully operational alone — no other app required. |
apps/api | @anvio/api | Optional REST layer (NestJS). Exposes agents, sessions, health, metrics, and channel webhook controllers (Matrix, WhatsApp, Teams). |
apps/worker | @anvio/worker | Optional background consumer — drains the event bus and runs agent sessions detached from any client connection. |
apps/gateway | @anvio/gateway | Unified gateway daemon (anvio gateway start) — channels + worker + REST + WebSocket in one process, plus a static public/index.html. |
apps/desktop | — | Scaffold only (apps/desktop/README.md). No Electron/Tauri build exists yet. |
Each app has its own package.json, tsconfig.json, and src/main.ts. apps/api/src/ holds NestJS controllers directly (agents.controller.ts, sessions.controller.ts, health.controller.ts, metrics.controller.ts, matrix.controller.ts, whatsapp.controller.ts, teams.controller.ts) plus app.module.ts / app.service.ts.
Not yet shipped
apps/desktop is a README-only scaffold (tray icon, installer). A real Electron/Tauri build is tracked as a separate multi-week project — see docs/69-post-v1.17-gap-register.md, item R6.
packages/ (selected)
| Package | Purpose |
|---|---|
packages/core | Zod schemas, ports, shared types. Depended on by everything. |
packages/platform | Composition factory — reads workspace/anvio.yaml and wires the full system (createPlatform, startUnifiedGateway, RuntimeRoutingAgentRuntime). |
packages/agents | Agent runtime engine, orchestration, subagent delegation. |
packages/runtimes | Runtime providers: local, claude-code, cursor, codex, antigravity, docker, ssh, singularity, remote (daytona, modal). |
packages/models | Model provider adapters, ModelRouter, fallback chain, task classifier. |
packages/channels | Channel adapters (Telegram, Discord, Slack, WhatsApp, ...) + ChannelHub. |
packages/tools | Built-in tool gateway (ToolGateway, packages/tools/src/builtins/). |
packages/integrations | MCP bridge, stdio client, integration registry, first-call approval gate. |
packages/workspace | Workspace loader, session store. |
packages/storage | Pluggable storage backends (filesystem default; sqlite, postgresql, s3). |
packages/memory | Pluggable memory providers (filesystem default; sqlite, postgresql, qdrant, redis, honcho). |
packages/events | Local in-process event bus + optional NATS. |
packages/auth | Optional auth plugin, disabled by default. |
packages/souls, packages/goals, packages/automation, packages/kanban, packages/blueprints | Advanced Agent OS features (identity, persistent goals, cron/automation, kanban, workflow templates). |
packages/execution | Code execution sandbox (CodeExecutor, shell/python/node/go/docker). |
packages/hooks | Event hook dispatcher. |
packages/batch | Batch processing engine. |
packages/credentials | Encrypted credential pools for local runtime API keys. |
packages/skills | Skills catalog and registry. |
packages/personas | Bootstrap persona/profile templates. |
packages/acp | Agent Client Protocol server for editor integration (Cursor, etc.). |
packages/voice | STT/TTS pipeline. |
packages/db | Drizzle ORM schema/migrations for PostgreSQL (Level 3). |
packages/observability | OpenTelemetry SDK init, span helper, Prometheus metrics registry. |
Every package follows the same internal shape:
packages/<name>/
src/
index.ts Public exports
*.ts Implementation
*.spec.ts Vitest unit tests
package.json @anvio/<name>
tsconfig.json extends tsconfig.base.jsonRuntime provider subfolders
packages/runtimes/src/ mirrors the provider list directly:
packages/runtimes/src/
local/ LocalRuntimeProvider — delegates to AgentRuntime directly
claude-code/ ClaudeCodeRuntimeProvider (@anthropic-ai/claude-agent-sdk, OAuth)
cursor/ CursorRuntimeProvider (ACP or `agent -p`)
codex/ CodexRuntimeProvider (`codex exec`)
antigravity/ AntigravityRuntimeProvider (`agy -p`)
docker/ DockerRuntimeProvider (shells out to `docker`)
ssh/ SshRuntimeProvider (execRemote over SSH)
singularity/ SingularityRuntimeProvider (local HPC container exec)
remote/ Daytona / Modal stubs (mock + HTTP exec)
setup-token/ `anvio setup-token` vendor login wrappers
external/ Shared external-CLI process helpers
shared/ Common runtime provider utilities
runtime-factory.ts Instantiates every provider, resolves per-agent chain
runtime-fallback-chain.ts Chain building + auth-failure retry logic
runtime-fallback-executor.ts Executes a runtime chain end to endSee Runtimes & Models overview for how these are selected at request time.
Naming and import conventions
- Package names are always
@anvio/<package-dir-name>(for example@anvio/channels,@anvio/runtimes). - Imports use
NodeNextmodule resolution — relative imports inside a package must include the.jsextension even though the source is.ts(see Coding Standards). - Barrel files: each package exports its public surface from
src/index.ts; nothing outsidecorereaches into another package's internal files directly.
Last updated on