> ## Documentation Index
> Fetch the complete documentation index at: https://docs.loom.teamecho.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture

> How Loom is organized — from interface layer to memory layer.

Loom is structured in three layers: **Interface**, **Core**, and **Memory**.

```mermaid theme={null}
graph TD
    User(("User / App"))
    LLM(("LLM Provider\n(OpenAI-compatible)"))

    subgraph Interface["Interface Layer"]
        CLI["CLI · loom"]
        API["REST API · FastAPI"]
        WebUI["Web UI"]
    end

    subgraph Core["Loom Core"]
        Engine["Loom Engine"]
        CM["CM Agent\n(Cognitive Memory)"]
        SCP["Schema Call Protocol\nrecall · update · create · register"]
        Chatbot["Chatbot"]
    end

    subgraph Memory["Memory Layer"]
        Registry["Schema Registry"]
        Files[("Schema Files\n(cross-session shared)")]
        Templates["Schema Templates"]
    end

    Plugins{{"Plugins\n(RAG · Logging · Safety Filters · …)"}}

    User --> Interface --> Engine
    Engine -->|"build() / chat()"| CM
    CM <-->|"inference"| LLM
    CM <-->|"SCP tools"| SCP
    SCP <--> Registry <--> Files
    Templates -.->|"init schema"| Registry
    CM -->|"recalled schema"| Chatbot -->|"response"| User
    Plugins -.->|"lifecycle hooks"| Engine
```

## Interface Layer

Multiple ways to interact with Loom:

| Interface              | Description                                |
| ---------------------- | ------------------------------------------ |
| **CLI** (`loom`)       | Command-line for init, build, chat, serve  |
| **REST API** (FastAPI) | Full HTTP API for programmatic integration |
| **Web UI**             | Browser-based chat with schema inspection  |

## Core Layer

The engine orchestrates two main components:

* **CM Agent (Cognitive Memory)** — An LLM-powered agent that reads user input and decides which schema operations to perform. It uses the Schema Call Protocol tools to read/write structured memory.
* **Chatbot** — Generates responses grounded in recalled schema data.

## Memory Layer

* **Schema Registry** — In-memory registry of all schema domains and their fields.
* **Schema Files** — Standalone JSON files on disk, shared across sessions.
* **Schema Templates** — Pre-defined field structures that bootstrap new schemas.

## Plugins

Optional plugins hook into the engine lifecycle (before/after build and chat) without modifying core code. Common uses include RAG retrieval, logging, and safety filters.

## Project Structure

```
Loom/
├── src/loom/                     # Package root
│   ├── __init__.py               # Loom class & public API
│   ├── config.py                 # LoomConfig (env + YAML)
│   ├── converters.py             # Input format converters
│   ├── helpers.py                # Forget / sensitive-field utilities
│   ├── plugins.py                # Plugin system (LoomPlugin protocol)
│   ├── prompts.py                # Default prompts
│   ├── templates.py              # Schema templates & TemplateRegistry
│   ├── core/                     # Core cognitive memory system
│   │   ├── agent.py              # CogAgent — LLM ↔ SCP tool loop
│   │   ├── llm.py                # Async LLM client
│   │   ├── protocol.py           # Schema Call Protocol (SCP)
│   │   ├── schema.py             # UniversalSchemaDomain & SchemaRegistry
│   │   └── state.py              # State, StateManager & SchemaFileManager
│   └── server/                   # User-facing interfaces
│       ├── api.py                # FastAPI REST service
│       ├── cli.py                # Click-based CLI
│       └── web/static/           # Web UI
├── loom-openclaw-plugin/        # OpenClaw Context Engine plugin
├── templates/                    # Schema templates (JSON)
│   └── custom/                  # User custom templates (git-ignored)
├── schemas/                      # Standalone schema files (cross-session)
├── configs/                      # Configuration files
├── tests/                        # Unit tests
└── examples/                     # Example code
```
