# andrewcharly1/mcum architecture

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

- Interactive diagram: https://gitdiagram.com/andrewcharly1/mcum
- Repository: https://github.com/andrewcharly1/mcum

## Overview

#### Purpose and entry points
MCUM is a local, PostgreSQL-native MCP orchestration, audit, and persistent-memory layer installed per workspace. The primary user entry point is the Node CLI at `bin/mcum.mjs`, published through `package.json`; it installs/configures the Python runtime and agent bridges. Runtime request entry is the Python dispatcher `core/dispatcher.py`, with direct query utilities in `mcum_query.py` and `simple_query.py`.

#### Agent-to-brain boundary
Agents do not access PostgreSQL directly. MCP-capable clients connect through Node/stdio bridges, which invoke the Python brain:
- Local MCP bridge: `integrations/antigravity/mcum_local_mcp_stdio.mjs`
- OpenClaw bridge: `integrations/openclaw/openclaw_bridge.py`
- Agent definitions: `agents/openai.yaml`

This boundary centralizes tool execution, policy enforcement, session context, and audit recording before any persistence operation.

#### Request orchestration and lifecycle
`core/dispatcher.py` is the main tool-routing/control-plane layer. It coordinates task intake, project context, agent execution, and state recording:
- Context assembly/planning: `core/project_context_orchestrator.py`, `core/context_query_planner.py`
- Session lifecycle and playbooks: `core/session_manager.py`, `workspace_session.py`, `db/session_playbooks.py`
- Worker execution/model selection: `core/worker_runner.py`, `core/model_router.py`, `core/multi_agent.py`

The expected flow is agent request → bridge → dispatcher → context/policy/session services → database-backed execution result and memory updates.

#### PostgreSQL memory and graph persistence
PostgreSQL is the system of record; schema and seeds live in `db/schema.sql` and `db/seed_minimal.sql`. Connection/runtime provisioning supports existing databases, Docker/pgvector, or an embedded persistent PostgreSQL:
- Connection/provisioning: `db/connection.py`, `db/embedded_pg.mjs`
- Vector embeddings: `db/embedder.py`, `db/pgvector_util.py`
- Cross-domain graph storage: `db/unified_graph_store.py`, `db/code_graph_store.py`, `db/graph_intelligence_store.py`

Semantic retrieval combines stored records and embeddings; vector acceleration depends on pgvector/HNSW where available.

#### Code and artifact knowledge graph
The graph subsystem indexes workspace code and non-code artifacts into a queryable dependency/intelligence graph:
- Index/sync lifecycle: `core/code_graph_autoindex.py`, `core/code_graph_indexer.py`, `core/code_graph_sync.py`
- Extraction boundary: `core/graph_extractors/tree_sitter_extractor.py`, `core/graph_extractors/artifact_extractor.py`
- Query, impact, analytics, and export surfaces: `core/graph_query_service.py`, `core/graph_impact.py`, `core/graph_analytics.py`

Tree-sitter and media/artifact adapters isolate source-format parsing from graph persistence and planner-facing queries.

#### Knowledge, patterns, and self-improvement
Long-lived organizational knowledge is managed separately from code graph data, with taxonomy/routing and semantic/shadow stores:
`core/knowledge_library_router.py`, `db/knowledge_library_semantic.py`, `db/knowledge_library_shadow.py`.

Pattern discovery materializes reusable execution knowledge through `core/pattern_discovery.py` and `db/pattern_store.py`. SISL then generates, evaluates, and evolves skills: `sisl/autonomous_loop.py`, `sisl/skill_writer.py`, `core/skill_factory.py`.

#### Policy, quality gates, and operations
Policies are data-driven JSON directives, interpreted by enforcement services rather than embedded in agent clients:
`directives/execution_policy.json`, `directives/graph_policy.json`, `core/graph_policy.py`.

Operational safeguards include loop prevention (`anti_loop.py`), memory freshness/governance (`memory_freshness.py`, `memory_governor.py`), specifications/contracts (`core/spec_contract.py`), and connector health (`core/connector_health.py`). A lightweight optional dashboard exposes persisted operational data via `integrations/dashboard/server.py` and `integrations/dashboard/data_service.py`.

Main entry points: [`db/schema.sql`](https://github.com/andrewcharly1/mcum/blob/main/db/schema.sql) (PostgreSQL system of record), [`core/dispatcher.py`](https://github.com/andrewcharly1/mcum/blob/main/core/dispatcher.py) (Request dispatcher), [`core/project_context_orchestrator.py`](https://github.com/andrewcharly1/mcum/blob/main/core/project_context_orchestrator.py) (Context planning), [`integrations/antigravity/mcum_local_mcp_stdio.mjs`](https://github.com/andrewcharly1/mcum/blob/main/integrations/antigravity/mcum_local_mcp_stdio.mjs) (MCP agent bridges)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry &amp; Agent Bridges"]
  node_cli["MCUM CLI<br/>Node CLI<br/>[mcum.mjs]"]
  node_bridges["MCP agent bridges<br/>stdio / OpenClaw adapters"]
  node_agents["Agent definitions<br/>agent registry<br/>[openai.yaml]"]
  node_query_tools["Direct query utilities<br/>Python query tools<br/>[mcum_query.py]"]
end

subgraph group_control["Control Plane"]
  node_dispatcher["Request dispatcher<br/>Python control plane<br/>[dispatcher.py]"]
  node_context["Context planning<br/>context orchestrator"]
  node_sessions["Session lifecycle<br/>session manager<br/>[session_manager.py]"]
  node_workers["Worker execution<br/>worker / model routing<br/>[worker_runner.py]"]
end

subgraph group_graph["Code &amp; Artifact Graph"]
  node_graph_index["Graph indexing &amp; sync<br/>index lifecycle"]
  node_extractors["Source &amp; artifact extraction<br/>parser adapters"]
  node_graph_query["Graph query &amp; impact<br/>planner query service"]
end

subgraph group_data["PostgreSQL Memory"]
  node_graph_store[("Unified graph storage<br/>PostgreSQL graph store")]
  node_postgres[("PostgreSQL system of record<br/>persistent database<br/>[schema.sql]")]
  node_provisioning["Database provisioning<br/>connection runtime<br/>[connection.py]"]
  node_embeddings["Embedding retrieval<br/>pgvector service<br/>[embedder.py]"]
end

subgraph group_learning["Knowledge &amp; Improvement"]
  node_knowledge["Knowledge library<br/>semantic knowledge router"]
  node_patterns["Pattern discovery<br/>execution pattern mining"]
  node_sisl["SISL skill evolution<br/>autonomous skill loop<br/>[autonomous_loop.py]"]
end

subgraph group_ops["Policy &amp; Operations"]
  node_policies["Policy enforcement<br/>policy service<br/>[graph_policy.py]"]
  node_safeguards["Operational safeguards<br/>governance services<br/>[memory_governor.py]"]
  node_dashboard["Optional dashboard<br/>operations UI server<br/>[server.py]"]
end

node_cli -->|"configures"| node_bridges
node_agents -.->|"defines clients"| node_bridges
node_bridges -->|"agent requests"| node_dispatcher
node_query_tools -->|"direct queries"| node_dispatcher
node_dispatcher -->|"assembles context"| node_context
node_dispatcher -->|"manages lifecycle"| node_sessions
node_dispatcher -->|"enforces directives"| node_policies
node_dispatcher -->|"dispatches execution"| node_workers
node_context -->|"retrieves code context"| node_graph_query
node_context -->|"retrieves knowledge"| node_knowledge
node_sessions -->|"persists state"| node_postgres
node_workers -->|"records results and audit"| node_postgres
node_policies -.->|"governs graph access"| node_graph_query
node_safeguards -->|"governs memory"| node_postgres
node_graph_index -->|"extracts workspace artifacts"| node_extractors
node_extractors -->|"writes entities and links"| node_graph_store
node_graph_store -->|"persists graph records"| node_postgres
node_graph_query -->|"queries dependencies and impact"| node_graph_store
node_provisioning -->|"connects or provisions"| node_postgres
node_embeddings -->|"stores and searches vectors"| node_postgres
node_knowledge -->|"semantic retrieval"| node_embeddings
node_patterns -->|"materializes patterns"| node_postgres
node_sisl -->|"uses execution knowledge"| node_patterns
node_sisl -->|"creates evolved skills"| node_workers
node_dashboard -->|"reads operational data"| node_postgres

click node_cli "https://github.com/andrewcharly1/mcum/blob/main/bin/mcum.mjs"
click node_bridges "https://github.com/andrewcharly1/mcum/blob/main/integrations/antigravity/mcum_local_mcp_stdio.mjs"
click node_agents "https://github.com/andrewcharly1/mcum/blob/main/agents/openai.yaml"
click node_dispatcher "https://github.com/andrewcharly1/mcum/blob/main/core/dispatcher.py"
click node_context "https://github.com/andrewcharly1/mcum/blob/main/core/project_context_orchestrator.py"
click node_sessions "https://github.com/andrewcharly1/mcum/blob/main/core/session_manager.py"
click node_workers "https://github.com/andrewcharly1/mcum/blob/main/core/worker_runner.py"
click node_policies "https://github.com/andrewcharly1/mcum/blob/main/core/graph_policy.py"
click node_safeguards "https://github.com/andrewcharly1/mcum/blob/main/memory_governor.py"
click node_graph_index "https://github.com/andrewcharly1/mcum/blob/main/core/code_graph_autoindex.py"
click node_extractors "https://github.com/andrewcharly1/mcum/blob/main/core/graph_extractors/tree_sitter_extractor.py"
click node_graph_query "https://github.com/andrewcharly1/mcum/blob/main/core/graph_query_service.py"
click node_graph_store "https://github.com/andrewcharly1/mcum/blob/main/db/unified_graph_store.py"
click node_postgres "https://github.com/andrewcharly1/mcum/blob/main/db/schema.sql"
click node_provisioning "https://github.com/andrewcharly1/mcum/blob/main/db/connection.py"
click node_embeddings "https://github.com/andrewcharly1/mcum/blob/main/db/embedder.py"
click node_knowledge "https://github.com/andrewcharly1/mcum/blob/main/core/knowledge_library_router.py"
click node_patterns "https://github.com/andrewcharly1/mcum/blob/main/core/pattern_discovery.py"
click node_sisl "https://github.com/andrewcharly1/mcum/blob/main/sisl/autonomous_loop.py"
click node_dashboard "https://github.com/andrewcharly1/mcum/blob/main/integrations/dashboard/server.py"
click node_query_tools "https://github.com/andrewcharly1/mcum/blob/main/mcum_query.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_bridges,node_agents,node_query_tools toneBlue
class node_dispatcher,node_context,node_sessions,node_workers toneAmber
class node_graph_index,node_extractors,node_graph_query toneMint
class node_graph_store,node_postgres,node_provisioning,node_embeddings toneRose
class node_knowledge,node_patterns,node_sisl toneIndigo
class node_policies,node_safeguards,node_dashboard toneTeal
```

## Components

### Entry & Agent Bridges

- [MCUM CLI](https://github.com/andrewcharly1/mcum/blob/main/bin/mcum.mjs): Node CLI · Installs and configures the local runtime and bridges. · `bin/mcum.mjs`
- [MCP agent bridges](https://github.com/andrewcharly1/mcum/blob/main/integrations/antigravity/mcum_local_mcp_stdio.mjs): stdio / OpenClaw adapters · Isolate agent clients from direct database access. · `integrations/antigravity/mcum_local_mcp_stdio.mjs`
- [Agent definitions](https://github.com/andrewcharly1/mcum/blob/main/agents/openai.yaml): agent registry · `agents/openai.yaml`
- [Direct query utilities](https://github.com/andrewcharly1/mcum/blob/main/mcum_query.py): Python query tools · `mcum_query.py`

### Control Plane

- [Request dispatcher](https://github.com/andrewcharly1/mcum/blob/main/core/dispatcher.py): Python control plane · Routes tools and records request lifecycle state. · `core/dispatcher.py`
- [Context planning](https://github.com/andrewcharly1/mcum/blob/main/core/project_context_orchestrator.py): context orchestrator · `core/project_context_orchestrator.py`
- [Session lifecycle](https://github.com/andrewcharly1/mcum/blob/main/core/session_manager.py): session manager · `core/session_manager.py`
- [Worker execution](https://github.com/andrewcharly1/mcum/blob/main/core/worker_runner.py): worker / model routing · `core/worker_runner.py`

### Code & Artifact Graph

- [Graph indexing & sync](https://github.com/andrewcharly1/mcum/blob/main/core/code_graph_autoindex.py): index lifecycle · `core/code_graph_autoindex.py`
- [Source & artifact extraction](https://github.com/andrewcharly1/mcum/blob/main/core/graph_extractors/tree_sitter_extractor.py): parser adapters · Tree-sitter and artifact adapters isolate format parsing. · `core/graph_extractors/tree_sitter_extractor.py`
- [Graph query & impact](https://github.com/andrewcharly1/mcum/blob/main/core/graph_query_service.py): planner query service · `core/graph_query_service.py`

### PostgreSQL Memory

- [Unified graph storage](https://github.com/andrewcharly1/mcum/blob/main/db/unified_graph_store.py): PostgreSQL graph store · `db/unified_graph_store.py`
- [PostgreSQL system of record](https://github.com/andrewcharly1/mcum/blob/main/db/schema.sql): persistent database · Stores audit, sessions, memory, vectors, and graph records. · `db/schema.sql`
- [Database provisioning](https://github.com/andrewcharly1/mcum/blob/main/db/connection.py): connection runtime · Supports existing, Docker/pgvector, and embedded PostgreSQL. · `db/connection.py`
- [Embedding retrieval](https://github.com/andrewcharly1/mcum/blob/main/db/embedder.py): pgvector service · Uses pgvector/HNSW acceleration when available. · `db/embedder.py`

### Knowledge & Improvement

- [Knowledge library](https://github.com/andrewcharly1/mcum/blob/main/core/knowledge_library_router.py): semantic knowledge router · Maintains organizational knowledge separate from code graph data. · `core/knowledge_library_router.py`
- [Pattern discovery](https://github.com/andrewcharly1/mcum/blob/main/core/pattern_discovery.py): execution pattern mining · `core/pattern_discovery.py`
- [SISL skill evolution](https://github.com/andrewcharly1/mcum/blob/main/sisl/autonomous_loop.py): autonomous skill loop · Generates, evaluates, and evolves reusable skills. · `sisl/autonomous_loop.py`

### Policy & Operations

- [Policy enforcement](https://github.com/andrewcharly1/mcum/blob/main/core/graph_policy.py): policy service · Interprets data-driven execution and graph directives. · `core/graph_policy.py`
- [Operational safeguards](https://github.com/andrewcharly1/mcum/blob/main/memory_governor.py): governance services · Loop prevention, freshness, contracts, and connector health. · `memory_governor.py`
- [Optional dashboard](https://github.com/andrewcharly1/mcum/blob/main/integrations/dashboard/server.py): operations UI server · Exposes persisted operational data. · `integrations/dashboard/server.py`

## Connections

- MCUM CLI → MCP agent bridges: configures
- Agent definitions → MCP agent bridges: defines clients
- MCP agent bridges → Request dispatcher: agent requests
- Direct query utilities → Request dispatcher: direct queries
- Request dispatcher → Context planning: assembles context
- Request dispatcher → Session lifecycle: manages lifecycle
- Request dispatcher → Policy enforcement: enforces directives
- Request dispatcher → Worker execution: dispatches execution
- Context planning → Graph query & impact: retrieves code context
- Context planning → Knowledge library: retrieves knowledge
- Session lifecycle → PostgreSQL system of record: persists state
- Worker execution → PostgreSQL system of record: records results and audit
- Policy enforcement → Graph query & impact: governs graph access
- Operational safeguards → PostgreSQL system of record: governs memory
- Graph indexing & sync → Source & artifact extraction: extracts workspace artifacts
- Source & artifact extraction → Unified graph storage: writes entities and links
- Unified graph storage → PostgreSQL system of record: persists graph records
- Graph query & impact → Unified graph storage: queries dependencies and impact
- Database provisioning → PostgreSQL system of record: connects or provisions
- Embedding retrieval → PostgreSQL system of record: stores and searches vectors
- Knowledge library → Embedding retrieval: semantic retrieval
- Pattern discovery → PostgreSQL system of record: materializes patterns
- SISL skill evolution → Pattern discovery: uses execution knowledge
- SISL skill evolution → Worker execution: creates evolved skills
- Optional dashboard → PostgreSQL system of record: reads operational data
