# jaylzhou/nano-ontology architecture

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

- Interactive diagram: https://gitdiagram.com/jaylzhou/nano-ontology
- Repository: https://github.com/jaylzhou/nano-ontology

## Overview

nano-onto is an executable business ontology: a YAML model defines objects, actions, rules, roles, approvals, and effects; an agent or person submits requests through an interface; the engine validates and enforces policy, then reads or changes data and records outcomes. Its major surfaces include MCP over stdio and HTTP, a human console, and CLI/Python use. Read-through tables, reviewed ontology migrations, and webhook delivery extend the core workflow. Some optional wiring is documented rather than shown in the excerpts, so those links are marked accordingly.

Main entry points: [`nano_onto/engine.py`](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/engine.py) (Action Engine), [`nano_onto/cli.py`](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/cli.py) (CLI and Python API), [`nano_onto/mcp_server.py`](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/mcp_server.py) (MCP Server), [`nano_onto/webhooks.py`](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/webhooks.py) (Webhook Delivery)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["Ontology and Rules"]
  node_ontology["Ontology Schema<br/>[schema.py]"]
  node_expressions["Rule Expressions<br/>[expr.py]"]
  node_compiler["Agent Tool Compiler<br/>[compile.py]"]
end

subgraph group_runtime["Policy Runtime"]
  node_engine["Action Engine<br/>[engine.py]"]
end

subgraph group_data["Data and History"]
  node_store[("Object and Audit Store<br/>[store.py]")]
  node_tables["Read-through Tables<br/>[tables.py]"]
end

subgraph group_interfaces["User Interfaces"]
  node_cli["CLI and Python API<br/>[cli.py]"]
  node_mcp["MCP Server<br/>[mcp_server.py]"]
  node_http["MCP HTTP Transport<br/>[http_server.py]"]
  node_console["Web Console<br/>[console.py]"]
end

subgraph group_integrations["Extensions"]
  node_migration["Ontology Migrations<br/>[migrate.py]"]
  node_webhooks["Webhook Delivery<br/>[webhooks.py]"]
end

node_agent(("AI Agent"))
node_person(("Human User"))
node_erp["External Business System"]

node_ontology -.->|"configures"| node_engine
node_engine -->|"evaluates rules"| node_expressions
node_engine -->|"uses definitions"| node_ontology
node_engine -->|"reads and writes"| node_store
node_store -->|"uses helpers"| node_tables
node_agent -->|"requests tools"| node_mcp
node_mcp -->|"builds tool schemas"| node_compiler
node_mcp -->|"dispatches actions"| node_engine
node_agent -->|"sends MCP requests"| node_http
node_http -->|"serves MCP"| node_mcp
node_person -->|"uses console"| node_console
node_console -->|"runs actions and reads"| node_engine
node_person -->|"runs commands"| node_cli
node_cli -->|"executes requests"| node_engine
node_cli -->|"loads schema"| node_ontology
node_cli -->|"runs migrations"| node_migration
node_cli -->|"sweeps deliveries"| node_webhooks
node_migration -->|"updates data"| node_store
node_engine -.->|"queues effects"| node_webhooks
node_webhooks -->|"claims outbox"| node_store
node_webhooks -->|"posts events"| node_erp

click node_ontology "https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/schema.py"
click node_expressions "https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/expr.py"
click node_compiler "https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/compile.py"
click node_engine "https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/engine.py"
click node_store "https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/store.py"
click node_tables "https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/tables.py"
click node_cli "https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/cli.py"
click node_mcp "https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/mcp_server.py"
click node_http "https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/http_server.py"
click node_console "https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/console.py"
click node_migration "https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/migrate.py"
click node_webhooks "https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/webhooks.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_ontology,node_expressions,node_compiler,node_person toneBlue
class node_engine toneAmber
class node_store,node_tables toneMint
class node_cli,node_mcp,node_http,node_console toneRose
class node_migration,node_webhooks,node_agent,node_erp toneIndigo
```

## Components

### Ontology and Rules

- [Ontology Schema](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/schema.py): `nano_onto/schema.py`
- [Rule Expressions](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/expr.py): `nano_onto/expr.py`
- [Agent Tool Compiler](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/compile.py): `nano_onto/compile.py`

### Policy Runtime

- [Action Engine](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/engine.py): `nano_onto/engine.py`

### Data and History

- [Object and Audit Store](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/store.py): `nano_onto/store.py`
- [Read-through Tables](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/tables.py): `nano_onto/tables.py`

### User Interfaces

- [CLI and Python API](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/cli.py): `nano_onto/cli.py`
- [MCP Server](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/mcp_server.py): `nano_onto/mcp_server.py`
- [MCP HTTP Transport](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/http_server.py): `nano_onto/http_server.py`
- [Web Console](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/console.py): `nano_onto/console.py`

### Extensions

- [Ontology Migrations](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/migrate.py): `nano_onto/migrate.py`
- [Webhook Delivery](https://github.com/jaylzhou/nano-ontology/blob/main/nano_onto/webhooks.py): `nano_onto/webhooks.py`

### Other components

- **AI Agent**
- **Human User**
- **External Business System**

## Connections

- Ontology Schema → Action Engine: configures (evidence: `README.md`)
- Action Engine → Rule Expressions: evaluates rules (evidence: `nano_onto/engine.py`)
- Action Engine → Ontology Schema: uses definitions (evidence: `nano_onto/engine.py`)
- Action Engine → Object and Audit Store: reads and writes (evidence: `nano_onto/engine.py`)
- Object and Audit Store → Read-through Tables: uses helpers (evidence: `nano_onto/store.py`)
- AI Agent → MCP Server: requests tools (evidence: `README.md`)
- MCP Server → Agent Tool Compiler: builds tool schemas (evidence: `nano_onto/mcp_server.py`)
- MCP Server → Action Engine: dispatches actions (evidence: `nano_onto/mcp_server.py`)
- AI Agent → MCP HTTP Transport: sends MCP requests (evidence: `README.md`)
- MCP HTTP Transport → MCP Server: serves MCP (evidence: `nano_onto/http_server.py`)
- Human User → Web Console: uses console (evidence: `README.md`)
- Web Console → Action Engine: runs actions and reads (evidence: `nano_onto/console.py`)
- Human User → CLI and Python API: runs commands (evidence: `README.md`)
- CLI and Python API → Action Engine: executes requests (evidence: `nano_onto/cli.py`)
- CLI and Python API → Ontology Schema: loads schema (evidence: `nano_onto/cli.py`)
- CLI and Python API → Ontology Migrations: runs migrations (evidence: `nano_onto/cli.py`)
- CLI and Python API → Webhook Delivery: sweeps deliveries (evidence: `nano_onto/cli.py`)
- Ontology Migrations → Object and Audit Store: updates data (evidence: `nano_onto/migrate.py`)
- Action Engine → Webhook Delivery: queues effects (evidence: `nano_onto/webhooks.py`)
- Webhook Delivery → Object and Audit Store: claims outbox (evidence: `nano_onto/webhooks.py`)
- Webhook Delivery → External Business System: posts events (evidence: `nano_onto/webhooks.py`)
