# Architecture overview

How AgenticMind is built. The monorepo, its subsystems and their dependency direction, the request flow of a run, and the principles behind the design.

Source: https://glamorous-boar.cloudvent.net/architecture/

---

## Principles

AgenticMind's architecture follows ten non-negotiable constraints:

1. The canonical, versioned **IR** is the architecture source of truth.
2. The **first-party runtime** is primary; framework integrations are adapters.
3. **Node contracts** are typed, versioned and independent of the visual UI.
4. **Data edges and control-flow edges are distinct.**
5. **Execution traces and evaluation results** are first-class persisted records.
6. **Secrets are referenced**, never embedded in IR, logs, traces or generated source.
7. **Project export** is readable, modular and runnable locally.
8. **Cloud deployment is capability-aware**; never claim every graph runs everywhere.
9. **Custom code** executes with declared permissions and isolation.
10. Every major subsystem has **clear interfaces and tests**.

## Subsystems

<FileTree title="Repository layout">

```
apps/
  api/
  web/
packages/
  ir/
  node-sdk/
  node-registry/
  runtime/
  providers/
  vectorstores/
  compiler/
  deployment/
  plugins/
  evaluation/
  observability/
  sandbox/
  git/
nodes/
  core/
  data/
  rag/
  agents/
  semantic/
examples/
docs/
infra/docker/
```

</FileTree>

| Package | Responsibility |
|---|---|
| `apps/api` | FastAPI control plane: projects and revisions, validation, runs, SSE traces, files, memory, approvals, evaluation, deployment, plugins, settings, secrets, auth, triggers, MCP endpoint, metrics. Persistence with SQLAlchemy. |
| `apps/web` | React 18 + TypeScript + React Flow visual IDE. |
| `packages/ir` | Pydantic models of the graph, published JSON Schema, canonical serialization, content hashing, migrations, secret-reference helpers. Depends on nothing else. |
| `packages/node-sdk` | Port type system, `NodeManifest`, typed config, `NodeContext`/`NodeResult`, `define_node`, test helpers, the `agenticmind-node` CLI. |
| `packages/node-registry` | Discovers node packages through `agenticmind.nodes` entry points, indexes versions, assigns trust. |
| `packages/runtime` | Validation pipeline, execution planning, scheduler, retries, timeouts, cancellation, checkpoints, trace events, redaction, memory, artifacts, the `agenticmind` CLI and MCP server builder. |
| `packages/providers` | Chat and embedding provider adapters (OpenAI-compatible, Anthropic SDK, Gemini, Bedrock, fastembed, mock), streaming, retries. |
| `packages/vectorstores` | 12 vector store adapters behind one contract. |
| `packages/compiler` | IR → standalone FastAPI project. |
| `packages/deployment` | Requirements, target checks, artifacts, hash-bound plans, Local Docker deployer. |
| `packages/plugins` | Wheel installation, permission approval, isolated workers. |
| `packages/evaluation` | Test cases, evaluators, LLM judge, runner, comparison. |
| `packages/observability` | Run → OpenTelemetry spans, OTLP export, Prometheus metrics. |
| `packages/sandbox` | Docker and process code execution. |
| `packages/git` | GitHub client and sync rules. |
| `nodes/*` | First-party node packages: core (inputs, transforms, control, LLM, guardrails, triggers, outputs), data, rag, agents, semantic. |

## Dependency direction

<Diagram caption="Arrows point at dependencies. Core packages never import FastAPI, SQLAlchemy, cloud SDKs or model SDKs.">

```
flowchart RL
  sdk[node-sdk] --> ir
  reg[node-registry] --> sdk
  rt[runtime] --> reg
  api[apps/api] --> rt
  web[apps/web] -- HTTP --> api
  prov[providers] --> sdk
  nodes[nodes/*] --> prov
  reg -. entry points .-> nodes
```

</Diagram>

Keeping the core free of web frameworks, databases and vendor SDKs means the same runtime embeds in the API, the CLI and exported apps.

## Request flow: a run

1. The IDE saves the canvas as a new revision (`PUT /api/projects/{id}`). Drafts may be graph-invalid but must parse as IR.
2. `POST /api/projects/{id}/runs` loads the revision, runs the **validation pipeline**, compiles an **execution plan** (422 with diagnostics if not executable), records a run with an IR snapshot and content hash, and queues a job.
3. A **worker** claims the job under a lease; the **engine** schedules nodes, emits redacted **trace events** (persisted with increasing `seq`), stores outputs and checkpoints, and streams tokens.
4. The IDE subscribes to `GET /api/runs/{id}/events` (SSE), colours nodes by status and shows the trace. Reconnection resumes from `Last-Event-ID`.
5. Finish hooks update metrics and export the OpenTelemetry trace.

## Persistence

SQLAlchemy 2 with SQLite as the zero-setup default and PostgreSQL via `AGENTICMIND_DATABASE_URL`. Projects store append-only revisions; runs snapshot the IR; events, node outputs, checkpoints, waits, stream chunks, run jobs, leases, memories, conversations, datasets, evaluations, deployments, settings and encrypted secrets are rows. Files live in a project-scoped artifact store on disk.

## Read more

- [The IR](/architecture/ir/)
- [Runtime and execution semantics](/architecture/runtime/)
- [Node SDK](/architecture/node-sdk/)
- [Design decisions](/architecture/decisions/) (all 41 ADRs summarised)
- [Tech stack](/tech-stack/)
