# marieai/marie-ai architecture

> Architecture diagram of the GitHub repository marieai/marie-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/marieai/marie-ai
- Repository: https://github.com/marieai/marie-ai

## Overview

#### Purpose and Entry Points
Marie-AI is a Python-first, agentic document-intelligence runtime: it accepts document/workflow requests, executes OCR, classification, extraction, NER, LLM/RAG, and transformation agents, and manages them as durable DAG jobs. Primary CLI/package entry points are `marie/__main__.py` and `marie_server/__main__.py`; service configurations define gateway and executor deployments in `config/service/marie-gateway-4.0.0.yml` and `config/service/extract/marie-extract-4.0.0.yml`.

#### Request Gateway and Distributed Serving
The gateway is the external control/data-plane boundary, exposing HTTP/FastAPI, gRPC, WebSocket, and streaming request paths before routing to executors. It constructs topology-aware request dispatch and supports load balancing and service discovery. Core paths: `marie/serve/runtimes/gateway/gateway.py`, `marie/serve/runtimes/gateway/http_fastapi_app.py`, `marie/serve/runtimes/gateway/graph/topology_graph.py`. Clients use corresponding protocol abstractions under `marie/clients/`.

#### Durable DAG Scheduling and Job Control
Workflow submissions become DAGs and jobs persisted in PostgreSQL. Scheduler services admit DAGs, resolve dependencies, prioritize by SLA, lease attempts, dispatch work, reconcile terminal state, and retain operational history. The primary boundary is scheduler logic versus SQL-enforced state transitions: `marie/scheduler/job_scheduler.py`, `marie/scheduler/services/dag_submission_service.py`, `marie/scheduler/services/attempt_lifecycle_service.py`. Database schema and lease operations are material runtime contracts in `config/psql/schema/007_dag.sql`, `config/psql/schema/065_job_attempt.sql`, and `config/psql/schema/lease/001_lease_jobs_by_id.sql`.

#### Executors and Document Processing
Executors are independently deployable processing agents invoked by the gateway/scheduler. Document extraction combines OCR/layout-derived content with configured annotators, parsers, table processors, LLM passes, validation, and result conversion. Key implementations: `marie/executor/extract/document_extractor_executor.py`, `marie/executor/extract/document_annotator_llm_executor.py`, `marie/extract/engine/engine.py`. Traditional pipeline composition remains available through `marie/pipe/extract_pipeline.py` and `marie/pipe/llm_pipeline.py`.

#### Planning, Agents, and Knowledge Workloads
Query planners map higher-level requests into executable plans, including OCR, branching, guardrail, HITL, knowledge-base indexing, and RAG flows: `marie/query_planner/planner.py`, `marie/query_planner/branching.py`, `marie/query_planner/kb_indexing_planner.py`. The embedded AI framework provides agents, retrieval/index abstractions, tools, memory, and LLM integration under `marie/core/agent/`, `marie/core/ingestion/pipeline.py`, and `marie/core/query_engine/`. The separately packaged agent SDK adds A2A coordination, skills, guardrails, and tool runtime at `packages/marie-agent/src/marie/agent/coordination/workflow.py`.

#### State, Messaging, and External Services
PostgreSQL is the system of record for scheduler state, job history, assets, agent memory, and tracking. Etcd provides service discovery; RabbitMQ and gRPC/SSE/webhook handlers support event distribution; Valkey/Redis supports caching/LLM queueing; S3-compatible storage holds documents/artifacts; pgvector supports vector search. Integration boundaries are represented by `marie/storage/database/postgres.py`, `marie/serve/discovery/etcd_client.py`, and `marie/messaging/publisher.py`. LLM dispatch can target OpenAI-compatible services through `packages/marie-engine/src/marie/engine/llm_queue/dispatcher.py`.

#### Deployment and Extensibility
The system runs locally or in containers, Kubernetes/Helm, and via a Kubernetes operator. Docker composition provisions dependencies and service variants in `Dockerfiles/docker-compose.yml`; Helm packages server, executor, PostgreSQL, etcd, RabbitMQ, MinIO, and Valkey under `deploy/helm/charts/marie/`. Extensions are manifest-validated and may run through the Go plugin daemon: `packages/marie-extension/src/marie/extension/loader.py`, `packages/marie-plugin-daemon/cmd/server/main.go`, `marie/executor/extensions/plugin_daemon_executor.py`.

Main entry points: [`marie/serve/runtimes/gateway/gateway.py`](https://github.com/marieai/marie-ai/blob/main/marie/serve/runtimes/gateway/gateway.py) (Request gateway), [`marie/scheduler/job_scheduler.py`](https://github.com/marieai/marie-ai/blob/main/marie/scheduler/job_scheduler.py) (Job scheduler), [`marie/executor/extract/document_extractor_executor.py`](https://github.com/marieai/marie-ai/blob/main/marie/executor/extract/document_extractor_executor.py) (Document extractor), [`marie/query_planner/planner.py`](https://github.com/marieai/marie-ai/blob/main/marie/query_planner/planner.py) (Query planner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry &amp; Serving"]
  node_cli["CLI entry points<br/>Python CLI<br/>[__main__.py]"]
  node_gateway["Request gateway<br/>distributed gateway<br/>[gateway.py]"]
  node_fastapi["HTTP API<br/>FastAPI app"]
  node_topology["Topology dispatch<br/>routing graph<br/>[topology_graph.py]"]
  node_clients["Protocol clients<br/>client abstractions"]
end

subgraph group_orchestration["Workflow Control"]
  node_planner["Query planner<br/>plan compiler<br/>[planner.py]"]
  node_branching["Branching plans<br/>workflow branching<br/>[branching.py]"]
  node_scheduler["Job scheduler<br/>durable DAG scheduler<br/>[job_scheduler.py]"]
  node_submission["DAG submission<br/>scheduler service"]
  node_attempts["Attempt lifecycle<br/>scheduler service"]
end

subgraph group_processing["Processing &amp; AI"]
  node_extract_executor["Document extractor<br/>executor"]
  node_extract_engine["Extraction engine<br/>document engine<br/>[engine.py]"]
  node_llm_annotator["LLM annotator<br/>executor"]
  node_ai_framework["AI framework<br/>agent and RAG runtime"]
  node_agent_sdk["Agent SDK<br/>agent coordination SDK<br/>[workflow.py]"]
end

subgraph group_state["State &amp; Integrations"]
  node_postgres[("PostgreSQL<br/>system of record<br/>[postgres.py]")]
  node_lease_sql["SQL state contracts<br/>schema and lease SQL"]
  node_discovery[("Etcd discovery<br/>service discovery<br/>[etcd_client.py]")]
  node_messaging["Event publisher<br/>messaging boundary<br/>[publisher.py]"]
  node_llm_dispatch["LLM dispatcher<br/>LLM queue dispatcher<br/>[dispatcher.py]"]
end

subgraph group_extensibility["Extensions &amp; Deployment"]
  node_extensions["Extension loader<br/>extension runtime<br/>[loader.py]"]
  node_plugin_executor["Plugin daemon executor<br/>executor adapter"]
  node_deployment{{"Container &amp; Helm deployment<br/>deployment packaging"}}
end

node_cli -->|"starts"| node_gateway
node_clients -->|"invoke"| node_gateway
node_fastapi -->|"HTTP ingress"| node_gateway
node_gateway -->|"selects route"| node_topology
node_gateway -.->|"discovers services"| node_discovery
node_gateway -->|"submits request"| node_planner
node_planner -->|"composes branches"| node_branching
node_planner -->|"creates DAG"| node_submission
node_submission -->|"admits"| node_scheduler
node_scheduler -->|"manages attempts"| node_attempts
node_scheduler -->|"persists state"| node_postgres
node_scheduler -->|"uses leases"| node_lease_sql
node_scheduler -->|"dispatches work"| node_extract_executor
node_extract_executor -->|"executes"| node_extract_engine
node_extract_engine -->|"uses LLM annotation"| node_llm_annotator
node_extract_engine -->|"uses agents and RAG"| node_ai_framework
node_llm_annotator -->|"queues LLM work"| node_llm_dispatch
node_scheduler -.->|"publishes lifecycle events"| node_messaging
node_agent_sdk -->|"extends runtime"| node_ai_framework
node_extensions -->|"loads into"| node_plugin_executor
node_plugin_executor -.->|"extends processing"| node_extract_executor
node_deployment -.->|"deploys"| node_gateway
node_deployment -.->|"deploys"| node_extract_executor

click node_cli "https://github.com/marieai/marie-ai/blob/main/marie/__main__.py"
click node_gateway "https://github.com/marieai/marie-ai/blob/main/marie/serve/runtimes/gateway/gateway.py"
click node_fastapi "https://github.com/marieai/marie-ai/blob/main/marie/serve/runtimes/gateway/http_fastapi_app.py"
click node_topology "https://github.com/marieai/marie-ai/blob/main/marie/serve/runtimes/gateway/graph/topology_graph.py"
click node_planner "https://github.com/marieai/marie-ai/blob/main/marie/query_planner/planner.py"
click node_branching "https://github.com/marieai/marie-ai/blob/main/marie/query_planner/branching.py"
click node_scheduler "https://github.com/marieai/marie-ai/blob/main/marie/scheduler/job_scheduler.py"
click node_submission "https://github.com/marieai/marie-ai/blob/main/marie/scheduler/services/dag_submission_service.py"
click node_attempts "https://github.com/marieai/marie-ai/blob/main/marie/scheduler/services/attempt_lifecycle_service.py"
click node_extract_executor "https://github.com/marieai/marie-ai/blob/main/marie/executor/extract/document_extractor_executor.py"
click node_extract_engine "https://github.com/marieai/marie-ai/blob/main/marie/extract/engine/engine.py"
click node_llm_annotator "https://github.com/marieai/marie-ai/blob/main/marie/executor/extract/document_annotator_llm_executor.py"
click node_agent_sdk "https://github.com/marieai/marie-ai/blob/main/packages/marie-agent/src/marie/agent/coordination/workflow.py"
click node_postgres "https://github.com/marieai/marie-ai/blob/main/marie/storage/database/postgres.py"
click node_lease_sql "https://github.com/marieai/marie-ai/blob/main/config/psql/schema/lease/001_lease_jobs_by_id.sql"
click node_discovery "https://github.com/marieai/marie-ai/blob/main/marie/serve/discovery/etcd_client.py"
click node_messaging "https://github.com/marieai/marie-ai/blob/main/marie/messaging/publisher.py"
click node_llm_dispatch "https://github.com/marieai/marie-ai/blob/main/packages/marie-engine/src/marie/engine/llm_queue/dispatcher.py"
click node_extensions "https://github.com/marieai/marie-ai/blob/main/packages/marie-extension/src/marie/extension/loader.py"
click node_plugin_executor "https://github.com/marieai/marie-ai/blob/main/marie/executor/extensions/plugin_daemon_executor.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_gateway,node_fastapi,node_topology,node_clients toneBlue
class node_planner,node_branching,node_scheduler,node_submission,node_attempts toneAmber
class node_extract_executor,node_extract_engine,node_llm_annotator,node_ai_framework,node_agent_sdk toneMint
class node_postgres,node_lease_sql,node_discovery,node_messaging,node_llm_dispatch toneRose
class node_extensions,node_plugin_executor,node_deployment toneIndigo
```

## Components

### Entry & Serving

- [CLI entry points](https://github.com/marieai/marie-ai/blob/main/marie/__main__.py): Python CLI · Starts package and server runtimes. · `marie/__main__.py`
- [Request gateway](https://github.com/marieai/marie-ai/blob/main/marie/serve/runtimes/gateway/gateway.py): distributed gateway · External HTTP, gRPC, WebSocket, and streaming boundary. · `marie/serve/runtimes/gateway/gateway.py`
- [HTTP API](https://github.com/marieai/marie-ai/blob/main/marie/serve/runtimes/gateway/http_fastapi_app.py): FastAPI app · `marie/serve/runtimes/gateway/http_fastapi_app.py`
- [Topology dispatch](https://github.com/marieai/marie-ai/blob/main/marie/serve/runtimes/gateway/graph/topology_graph.py): routing graph · Routes requests across executor topology. · `marie/serve/runtimes/gateway/graph/topology_graph.py`
- **Protocol clients**: client abstractions

### Workflow Control

- [Query planner](https://github.com/marieai/marie-ai/blob/main/marie/query_planner/planner.py): plan compiler · Builds executable OCR, RAG, guardrail, and HITL plans. · `marie/query_planner/planner.py`
- [Branching plans](https://github.com/marieai/marie-ai/blob/main/marie/query_planner/branching.py): workflow branching · `marie/query_planner/branching.py`
- [Job scheduler](https://github.com/marieai/marie-ai/blob/main/marie/scheduler/job_scheduler.py): durable DAG scheduler · Admits, prioritizes, leases, dispatches, and reconciles jobs. · `marie/scheduler/job_scheduler.py`
- [DAG submission](https://github.com/marieai/marie-ai/blob/main/marie/scheduler/services/dag_submission_service.py): scheduler service · `marie/scheduler/services/dag_submission_service.py`
- [Attempt lifecycle](https://github.com/marieai/marie-ai/blob/main/marie/scheduler/services/attempt_lifecycle_service.py): scheduler service · Controls leased execution attempts and terminal state. · `marie/scheduler/services/attempt_lifecycle_service.py`

### Processing & AI

- [Document extractor](https://github.com/marieai/marie-ai/blob/main/marie/executor/extract/document_extractor_executor.py): executor · Independently deployable extraction agent. · `marie/executor/extract/document_extractor_executor.py`
- [Extraction engine](https://github.com/marieai/marie-ai/blob/main/marie/extract/engine/engine.py): document engine · Runs OCR/layout, annotators, parsers, LLM passes, validation, and conversion. · `marie/extract/engine/engine.py`
- [LLM annotator](https://github.com/marieai/marie-ai/blob/main/marie/executor/extract/document_annotator_llm_executor.py): executor · `marie/executor/extract/document_annotator_llm_executor.py`
- **AI framework**: agent and RAG runtime · Provides agents, retrieval, tools, memory, and query engines.
- [Agent SDK](https://github.com/marieai/marie-ai/blob/main/packages/marie-agent/src/marie/agent/coordination/workflow.py): agent coordination SDK · Adds A2A workflows, skills, guardrails, and tool runtime. · `packages/marie-agent/src/marie/agent/coordination/workflow.py`

### State & Integrations

- [PostgreSQL](https://github.com/marieai/marie-ai/blob/main/marie/storage/database/postgres.py): system of record · Persists DAGs, jobs, history, assets, memory, and tracking. · `marie/storage/database/postgres.py`
- [SQL state contracts](https://github.com/marieai/marie-ai/blob/main/config/psql/schema/lease/001_lease_jobs_by_id.sql): schema and lease SQL · Database-enforced DAG, attempt, and lease transitions. · `config/psql/schema/lease/001_lease_jobs_by_id.sql`
- [Etcd discovery](https://github.com/marieai/marie-ai/blob/main/marie/serve/discovery/etcd_client.py): service discovery · `marie/serve/discovery/etcd_client.py`
- [Event publisher](https://github.com/marieai/marie-ai/blob/main/marie/messaging/publisher.py): messaging boundary · Distributes events through RabbitMQ and external handlers. · `marie/messaging/publisher.py`
- [LLM dispatcher](https://github.com/marieai/marie-ai/blob/main/packages/marie-engine/src/marie/engine/llm_queue/dispatcher.py): LLM queue dispatcher · Dispatches work to OpenAI-compatible services. · `packages/marie-engine/src/marie/engine/llm_queue/dispatcher.py`

### Extensions & Deployment

- [Extension loader](https://github.com/marieai/marie-ai/blob/main/packages/marie-extension/src/marie/extension/loader.py): extension runtime · Loads manifest-validated extensions. · `packages/marie-extension/src/marie/extension/loader.py`
- [Plugin daemon executor](https://github.com/marieai/marie-ai/blob/main/marie/executor/extensions/plugin_daemon_executor.py): executor adapter · Runs extensions through the Go plugin daemon. · `marie/executor/extensions/plugin_daemon_executor.py`
- **Container & Helm deployment**: deployment packaging · Provisions service variants and infrastructure dependencies.

## Connections

- CLI entry points → Request gateway: starts
- Protocol clients → Request gateway: invoke
- HTTP API → Request gateway: HTTP ingress
- Request gateway → Topology dispatch: selects route
- Request gateway → Etcd discovery: discovers services
- Request gateway → Query planner: submits request
- Query planner → Branching plans: composes branches
- Query planner → DAG submission: creates DAG
- DAG submission → Job scheduler: admits
- Job scheduler → Attempt lifecycle: manages attempts
- Job scheduler → PostgreSQL: persists state
- Job scheduler → SQL state contracts: uses leases
- Job scheduler → Document extractor: dispatches work
- Document extractor → Extraction engine: executes
- Extraction engine → LLM annotator: uses LLM annotation
- Extraction engine → AI framework: uses agents and RAG
- LLM annotator → LLM dispatcher: queues LLM work
- Job scheduler → Event publisher: publishes lifecycle events
- Agent SDK → AI framework: extends runtime
- Extension loader → Plugin daemon executor: loads into
- Plugin daemon executor → Document extractor: extends processing
- Container & Helm deployment → Request gateway: deploys
- Container & Helm deployment → Document extractor: deploys
