# andresd1az/molly-lang architecture

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

- Interactive diagram: https://gitdiagram.com/andresd1az/molly-lang
- Repository: https://github.com/andresd1az/molly-lang

## Overview

Molly is a small policy-enforcing language for AI-agent plans: trusted application code fixes the context and available tools, then the engine checks a plan before permitting any effects. The main workflow is plan submission, lexical and syntax analysis, labeled execution and authorization, then a dry-run result or an allowed delivery. The CLI and MCP server expose that workflow; a synthetic demo illustrates it. The engine is a single file, so several distinct language stages share its path. Relationships are limited to calls shown in excerpts or capabilities explicitly documented in the README.

Main entry points: [`molly.py`](https://github.com/andresd1az/molly-lang/blob/main/molly.py) (Execution engine), [`molly_cli.py`](https://github.com/andresd1az/molly-lang/blob/main/molly_cli.py) (CLI and policy), [`molly_mcp.py`](https://github.com/andresd1az/molly-lang/blob/main/molly_mcp.py) (MCP server), [`demo.py`](https://github.com/andresd1az/molly-lang/blob/main/demo.py) (Synthetic demo)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_language["Language engine"]
  node_lexer["DFA lexer<br/>[molly.py]"]
  node_parser["LL&#40;1&#41; parser<br/>[molly.py]"]
  node_analysis["Static checks<br/>[molly.py]"]
  node_labels["Labeled values<br/>[molly.py]"]
  node_engine["Execution engine<br/>[molly.py]"]
end

subgraph group_interfaces["User interfaces"]
  node_cli["CLI and policy<br/>[molly_cli.py]"]
  node_mcp["MCP server<br/>[molly_mcp.py]"]
  node_result["Run result"]
end

subgraph group_integration["Trusted integrations"]
  node_adapters["Trusted adapters"]
end

subgraph group_demo["Demonstration"]
  node_demo["Synthetic demo<br/>[demo.py]"]
  node_demo_adapters["Fake adapters<br/>[demo.py]"]
end

node_developer(("Plan author"))
node_agent(("AI agent"))

node_developer -->|"submits plan"| node_cli
node_cli -->|"checks input"| node_lexer
node_lexer -->|"provides tokens"| node_parser
node_parser -->|"builds syntax tree"| node_analysis
node_analysis -->|"validates plan"| node_engine
node_engine -->|"tracks permissions"| node_labels
node_engine -->|"invokes allowed tools"| node_adapters
node_engine -->|"returns trace"| node_result
node_cli -->|"runs plan"| node_engine
node_cli -->|"formats dry run"| node_result
node_agent -->|"calls tools"| node_mcp
node_mcp -->|"delegates checks"| node_cli
node_mcp -->|"returns redacted result"| node_result
node_demo -->|"executes cases"| node_engine
node_demo -->|"registers adapters"| node_demo_adapters
node_engine -->|"calls fake tools"| node_demo_adapters

click node_lexer "https://github.com/andresd1az/molly-lang/blob/main/molly.py"
click node_parser "https://github.com/andresd1az/molly-lang/blob/main/molly.py"
click node_analysis "https://github.com/andresd1az/molly-lang/blob/main/molly.py"
click node_labels "https://github.com/andresd1az/molly-lang/blob/main/molly.py"
click node_engine "https://github.com/andresd1az/molly-lang/blob/main/molly.py"
click node_cli "https://github.com/andresd1az/molly-lang/blob/main/molly_cli.py"
click node_mcp "https://github.com/andresd1az/molly-lang/blob/main/molly_mcp.py"
click node_demo "https://github.com/andresd1az/molly-lang/blob/main/demo.py"
click node_demo_adapters "https://github.com/andresd1az/molly-lang/blob/main/demo.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_lexer,node_parser,node_analysis,node_labels,node_engine toneBlue
class node_cli,node_mcp,node_result toneAmber
class node_adapters toneMint
class node_demo,node_demo_adapters toneRose
class node_developer,node_agent toneIndigo
```

## Components

### Language engine

- [DFA lexer](https://github.com/andresd1az/molly-lang/blob/main/molly.py): `molly.py`
- [LL(1) parser](https://github.com/andresd1az/molly-lang/blob/main/molly.py): `molly.py`
- [Static checks](https://github.com/andresd1az/molly-lang/blob/main/molly.py): `molly.py`
- [Labeled values](https://github.com/andresd1az/molly-lang/blob/main/molly.py): `molly.py`
- [Execution engine](https://github.com/andresd1az/molly-lang/blob/main/molly.py): `molly.py`

### User interfaces

- [CLI and policy](https://github.com/andresd1az/molly-lang/blob/main/molly_cli.py): `molly_cli.py`
- [MCP server](https://github.com/andresd1az/molly-lang/blob/main/molly_mcp.py): `molly_mcp.py`
- **Run result**

### Trusted integrations

- **Trusted adapters**

### Demonstration

- [Synthetic demo](https://github.com/andresd1az/molly-lang/blob/main/demo.py): `demo.py`
- [Fake adapters](https://github.com/andresd1az/molly-lang/blob/main/demo.py): `demo.py`

### Other components

- **Plan author**
- **AI agent**

## Connections

- Plan author → CLI and policy: submits plan (evidence: `README.md`)
- CLI and policy → DFA lexer: checks input (evidence: `molly_cli.py`)
- DFA lexer → LL(1) parser: provides tokens (evidence: `README.md`)
- LL(1) parser → Static checks: builds syntax tree (evidence: `README.md`)
- Static checks → Execution engine: validates plan (evidence: `README.md`)
- Execution engine → Labeled values: tracks permissions (evidence: `README.md`)
- Execution engine → Trusted adapters: invokes allowed tools (evidence: `README.md`)
- Execution engine → Run result: returns trace (evidence: `molly.py`)
- CLI and policy → Execution engine: runs plan (evidence: `molly_cli.py`)
- CLI and policy → Run result: formats dry run (evidence: `molly_cli.py`)
- AI agent → MCP server: calls tools (evidence: `README.md`)
- MCP server → CLI and policy: delegates checks (evidence: `molly_mcp.py`)
- MCP server → Run result: returns redacted result (evidence: `molly_mcp.py`)
- Synthetic demo → Execution engine: executes cases (evidence: `demo.py`)
- Synthetic demo → Fake adapters: registers adapters (evidence: `demo.py`)
- Execution engine → Fake adapters: calls fake tools (evidence: `demo.py`)
