# sanjay7978/ai-iot-dsl-compiler architecture

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

- Interactive diagram: https://gitdiagram.com/sanjay7978/ai-iot-dsl-compiler
- Repository: https://github.com/sanjay7978/ai-iot-dsl-compiler

## Overview

Kelvin is an IoT-rule compiler with an optional English-to-DSL AI front end and a browser Studio. The main workflow is English or DSL input, compilation and rule checks, optimization, target-code generation, then inspection or simulation in the Studio. The README documents the compiler stages and targets; the excerpts show the UI’s compile requests, AI verification, and simulation calls. Some internal compiler and server wiring is unsampled, so those documented relationships are cited to the README and uncertain links are omitted.

Main entry points: [`web/js/main.js`](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/main.js) (Studio controller), [`ai.py`](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/ai.py) (English draft), [`server.py`](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/server.py) (HTTP API), [`src/semantic.cpp`](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/semantic.cpp) (Semantic and rule analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Input and AI"]
  node_english["English draft<br/>[ai.py]"]
  node_dsl["DSL source<br/>[main.cpp]"]
end

subgraph group_compiler["Compiler"]
  node_compiler["Compile driver<br/>[compiler.cpp]"]
  node_lexer["Lexer<br/>[lexer.cpp]"]
  node_parser["Parser and grammar<br/>[parser.cpp]"]
  node_ast["AST<br/>[ast.cpp]"]
  node_semantics["Semantic and rule analysis<br/>[semantic.cpp]"]
  node_rule_analysis["Rule conflict analysis<br/>[rule_analysis.cpp]"]
  node_ir["Intermediate code<br/>[ir.cpp]"]
  node_cfg["Control-flow graph<br/>[cfg.cpp]"]
  node_optimizer["Optimizer<br/>[optimizer.cpp]"]
  node_codegen["Target code generation<br/>[codegen.cpp]"]
end

subgraph group_service["Server and targets"]
  node_server["HTTP API<br/>[server.py]"]
  node_runtime["Target runtimes"]
end

subgraph group_studio["Studio"]
  node_editor["DSL editor<br/>[editor.js]"]
  node_studio_main["Studio controller<br/>[main.js]"]
  node_panes["Compiler result panes<br/>[panes.js]"]
  node_xray["Compile X-ray<br/>[xray.js]"]
  node_graph["Compiler visualizations<br/>[graph.js]"]
end

subgraph group_simulation["Simulation"]
  node_twin["Digital twin<br/>[twin.js]"]
  node_vm["IR virtual machine<br/>[vm.js]"]
end

node_user(("Rule author"))
node_ai_providers["Model providers"]
node_sensor(("Sensor remote"))

node_user -->|"describes rule"| node_english
node_english -.->|"requests draft"| node_ai_providers
node_ai_providers -.->|"returns DSL"| node_english
node_english -->|"produces DSL"| node_dsl
node_user -->|"writes rule"| node_dsl
node_dsl -->|"submits source"| node_server
node_server -.->|"invokes compile"| node_compiler
node_english -->|"requests verification"| node_server
node_server -->|"checks compiler result"| node_english
node_compiler -->|"lexes"| node_lexer
node_lexer -->|"supplies tokens"| node_parser
node_parser -->|"builds tree"| node_ast
node_ast -->|"checks meaning"| node_semantics
node_semantics -->|"analyzes rules"| node_rule_analysis
node_semantics -->|"lowers to IR"| node_ir
node_ir -->|"forms control flow"| node_cfg
node_cfg -->|"guides passes"| node_optimizer
node_optimizer -->|"emits optimized program"| node_codegen
node_codegen -->|"targets runtime"| node_runtime
node_studio_main -->|"reads source"| node_editor
node_studio_main -->|"requests compile"| node_server
node_studio_main -->|"renders results"| node_panes
node_panes -->|"draws AST and CFG"| node_graph
node_studio_main -->|"opens trace"| node_xray
node_studio_main -->|"executes optimized IR"| node_vm
node_vm -->|"updates device state"| node_twin
node_sensor -.->|"sets sensor values"| node_studio_main

click node_english "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/ai.py"
click node_dsl "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/main.cpp"
click node_server "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/server.py"
click node_compiler "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/compiler.cpp"
click node_lexer "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/lexer.cpp"
click node_parser "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/parser.cpp"
click node_ast "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/ast.cpp"
click node_semantics "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/semantic.cpp"
click node_rule_analysis "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/rule_analysis.cpp"
click node_ir "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/ir.cpp"
click node_cfg "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/cfg.cpp"
click node_optimizer "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/optimizer.cpp"
click node_codegen "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/codegen.cpp"
click node_runtime "https://github.com/sanjay7978/ai-iot-dsl-compiler/tree/main/runtime"
click node_editor "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/editor.js"
click node_studio_main "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/main.js"
click node_panes "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/panes.js"
click node_xray "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/xray.js"
click node_graph "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/graph.js"
click node_twin "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/twin.js"
click node_vm "https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/vm.js"

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_english,node_dsl toneBlue
class node_compiler,node_lexer,node_parser,node_ast,node_semantics,node_rule_analysis,node_ir,node_cfg,node_optimizer,node_codegen toneAmber
class node_server,node_runtime toneMint
class node_editor,node_studio_main,node_panes,node_xray,node_graph toneRose
class node_twin,node_vm,node_user,node_ai_providers,node_sensor toneIndigo
```

## Components

### Input and AI

- [English draft](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/ai.py): `ai.py`
- [DSL source](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/main.cpp): `src/main.cpp`

### Compiler

- [Compile driver](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/compiler.cpp): `src/compiler.cpp`
- [Lexer](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/lexer.cpp): `src/lexer.cpp`
- [Parser and grammar](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/parser.cpp): `src/parser.cpp`
- [AST](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/ast.cpp): `src/ast.cpp`
- [Semantic and rule analysis](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/semantic.cpp): `src/semantic.cpp`
- [Rule conflict analysis](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/rule_analysis.cpp): `src/rule_analysis.cpp`
- [Intermediate code](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/ir.cpp): `src/ir.cpp`
- [Control-flow graph](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/cfg.cpp): `src/cfg.cpp`
- [Optimizer](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/optimizer.cpp): `src/optimizer.cpp`
- [Target code generation](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/src/codegen.cpp): `src/codegen.cpp`

### Server and targets

- [HTTP API](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/server.py): `server.py`
- [Target runtimes](https://github.com/sanjay7978/ai-iot-dsl-compiler/tree/main/runtime): `runtime`

### Studio

- [DSL editor](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/editor.js): `web/js/editor.js`
- [Studio controller](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/main.js): `web/js/main.js`
- [Compiler result panes](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/panes.js): `web/js/panes.js`
- [Compile X-ray](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/xray.js): `web/js/xray.js`
- [Compiler visualizations](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/graph.js): `web/js/graph.js`

### Simulation

- [Digital twin](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/twin.js): `web/js/twin.js`
- [IR virtual machine](https://github.com/sanjay7978/ai-iot-dsl-compiler/blob/main/web/js/vm.js): `web/js/vm.js`

### Other components

- **Rule author**
- **Model providers**
- **Sensor remote**

## Connections

- Rule author → English draft: describes rule (evidence: `README.md`)
- English draft → Model providers: requests draft (evidence: `ai.py`)
- Model providers → English draft: returns DSL (evidence: `ai.py`)
- English draft → DSL source: produces DSL (evidence: `README.md`)
- Rule author → DSL source: writes rule (evidence: `README.md`)
- DSL source → HTTP API: submits source
- HTTP API → Compile driver: invokes compile
- English draft → HTTP API: requests verification (evidence: `server.py`)
- HTTP API → English draft: checks compiler result (evidence: `ai.py`)
- Compile driver → Lexer: lexes (evidence: `README.md`)
- Lexer → Parser and grammar: supplies tokens (evidence: `README.md`)
- Parser and grammar → AST: builds tree (evidence: `README.md`)
- AST → Semantic and rule analysis: checks meaning (evidence: `README.md`)
- Semantic and rule analysis → Rule conflict analysis: analyzes rules (evidence: `src/semantic.cpp`)
- Semantic and rule analysis → Intermediate code: lowers to IR (evidence: `README.md`)
- Intermediate code → Control-flow graph: forms control flow (evidence: `README.md`)
- Control-flow graph → Optimizer: guides passes (evidence: `README.md`)
- Optimizer → Target code generation: emits optimized program (evidence: `README.md`)
- Target code generation → Target runtimes: targets runtime (evidence: `README.md`)
- Studio controller → DSL editor: reads source (evidence: `web/js/main.js`)
- Studio controller → HTTP API: requests compile (evidence: `web/js/main.js`)
- Studio controller → Compiler result panes: renders results (evidence: `web/js/main.js`)
- Compiler result panes → Compiler visualizations: draws AST and CFG (evidence: `web/js/panes.js`)
- Studio controller → Compile X-ray: opens trace (evidence: `web/js/main.js`)
- Studio controller → IR virtual machine: executes optimized IR (evidence: `web/js/main.js`)
- IR virtual machine → Digital twin: updates device state (evidence: `web/js/main.js`)
- Sensor remote → Studio controller: sets sensor values (evidence: `README.md`)
