# lamgianggg/tklls architecture

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

- Interactive diagram: https://gitdiagram.com/lamgianggg/tklls
- Repository: https://github.com/lamgianggg/tklls

## Overview

Spec2RTL & Prompt2Silicon turns a natural-language hardware specification into synthesizable Verilog, a self-checking testbench, verified simulation results, and Quartus design artifacts. The online workflow is orchestrated by `run_spec2rtl.py`: it analyzes and guards the spec, retrieves reference designs, generates RTL and a testbench, applies static checks, simulates, and may repair failures before packaging outputs. The repository also documents offline model distillation and Quartus waveform/project generation. Edges reflect the README and indexed caller references; unsampled implementations are represented by their supported paths, not assumed internal behavior.

Main entry points: [`agent/run_spec2rtl.py`](https://github.com/lamgianggg/tklls/blob/main/agent/run_spec2rtl.py) (Workflow orchestrator), [`agent/simulator.py`](https://github.com/lamgianggg/tklls/blob/main/agent/simulator.py) (EDA simulator), [`training/distill_teacher_cot.py`](https://github.com/lamgianggg/tklls/blob/main/training/distill_teacher_cot.py) (Teacher distillation), [`models/run_inference.py`](https://github.com/lamgianggg/tklls/blob/main/models/run_inference.py) (Local model inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_analysis["Spec Analysis"]
  node_orchestrator["Workflow orchestrator<br/>[run_spec2rtl.py]"]
  node_analyzer["Spec analyzer<br/>[spec_analyzer.py]"]
  node_retrieval["Hybrid design retrieval"]
  node_knowledge[("Reference designs")]
end

subgraph group_generation["RTL Generation"]
  node_inference["Local model inference<br/>[run_inference.py]"]
  node_rtl["RTL generation<br/>[rtl_generator.py]"]
  node_testbench["Self-checking testbench<br/>[tb_generator.py]"]
  node_rtl_output["Generated Verilog"]
  node_tb_output["Generated testbench"]
end

subgraph group_verification["Verification Loop"]
  node_linter["Hardware AST linter<br/>[verilog_linter.py]"]
  node_port_auditor["Port auditor<br/>[port_auditor.py]"]
  node_simulator["EDA simulator<br/>[simulator.py]"]
  node_reflection["Repair loop<br/>[reflection_loop.py]"]
  node_eda_finder["EDA tool discovery<br/>[eda_finder.py]"]
  node_synthesis["Synthesis profiler"]
  node_simulation_result["Simulation result and VCD"]
end

subgraph group_eda["EDA Artifacts"]
  node_bdf["Quartus project and BDF<br/>[bdf_generator.py]"]
  node_waveform["VWF waveform generator<br/>[vwf_generator.py]"]
  node_quartus_output["Quartus design files"]
end

subgraph group_training["Offline Learning"]
  node_training_distill["Teacher distillation"]
  node_training_sampler["VerilogDB sampler"]
  node_trained_data[("Distilled datasets")]
end

node_engineer(("Hardware designer"))
node_eda_tools["ModelSim / Quartus"]

node_engineer -->|"submits spec"| node_orchestrator
node_orchestrator -->|"analyzes spec"| node_analyzer
node_orchestrator -->|"retrieves examples"| node_retrieval
node_retrieval -->|"searches"| node_knowledge
node_orchestrator -->|"selects model"| node_inference
node_inference -->|"adds RAG context"| node_retrieval
node_inference -->|"falls back to"| node_rtl
node_orchestrator -->|"generates RTL"| node_rtl
node_rtl -.->|"writes RTL"| node_rtl_output
node_orchestrator -->|"generates tests"| node_testbench
node_testbench -.->|"writes testbench"| node_tb_output
node_orchestrator -->|"checks RTL"| node_linter
node_orchestrator -->|"audits ports"| node_port_auditor
node_orchestrator -->|"runs simulation"| node_simulator
node_simulator -->|"locates tools"| node_eda_finder
node_simulator -.->|"invokes simulator"| node_eda_tools
node_simulator -.->|"produces log / VCD"| node_simulation_result
node_orchestrator -->|"repairs failures"| node_reflection
node_reflection -->|"reruns flow"| node_simulator
node_orchestrator -->|"profiles synthesis"| node_synthesis
node_orchestrator -->|"packages project"| node_bdf
node_orchestrator -->|"generates waveform"| node_waveform
node_waveform -->|"reads VCD"| node_simulation_result
node_bdf -.->|"writes artifacts"| node_quartus_output
node_orchestrator -->|"creates project files"| node_quartus_output
node_eda_tools -.->|"provides tool results"| node_orchestrator
node_training_sampler -.->|"curates samples"| node_trained_data
node_training_distill -.->|"exports distilled data"| node_trained_data
node_training_distill -->|"validates specs"| node_analyzer
node_training_distill -->|"uses testbench checks"| node_testbench
node_training_distill -->|"uses lint checks"| node_linter
node_training_sampler -->|"checks port contract"| node_analyzer

click node_orchestrator "https://github.com/lamgianggg/tklls/blob/main/agent/run_spec2rtl.py"
click node_analyzer "https://github.com/lamgianggg/tklls/blob/main/agent/spec_analyzer.py"
click node_retrieval "https://github.com/lamgianggg/tklls/blob/main/agent/knowledge_matcher.py"
click node_knowledge "https://github.com/lamgianggg/tklls/tree/main/knowledge_base"
click node_inference "https://github.com/lamgianggg/tklls/blob/main/models/run_inference.py"
click node_rtl "https://github.com/lamgianggg/tklls/blob/main/agent/rtl_generator.py"
click node_testbench "https://github.com/lamgianggg/tklls/blob/main/agent/tb_generator.py"
click node_linter "https://github.com/lamgianggg/tklls/blob/main/agent/verilog_linter.py"
click node_port_auditor "https://github.com/lamgianggg/tklls/blob/main/agent/port_auditor.py"
click node_simulator "https://github.com/lamgianggg/tklls/blob/main/agent/simulator.py"
click node_reflection "https://github.com/lamgianggg/tklls/blob/main/agent/reflection_loop.py"
click node_eda_finder "https://github.com/lamgianggg/tklls/blob/main/agent/eda_finder.py"
click node_synthesis "https://github.com/lamgianggg/tklls/blob/main/agent/synthesis_profiler.py"
click node_bdf "https://github.com/lamgianggg/tklls/blob/main/agent/bdf_generator.py"
click node_waveform "https://github.com/lamgianggg/tklls/blob/main/agent/vwf_generator.py"
click node_training_distill "https://github.com/lamgianggg/tklls/blob/main/training/distill_teacher_cot.py"
click node_training_sampler "https://github.com/lamgianggg/tklls/blob/main/training/verilogdb_sampler.py"
click node_trained_data "https://github.com/lamgianggg/tklls/tree/main/training"
click node_rtl_output "https://github.com/lamgianggg/tklls/tree/main/src"
click node_tb_output "https://github.com/lamgianggg/tklls/tree/main/sim"
click node_quartus_output "https://github.com/lamgianggg/tklls/tree/main/quartus"
click node_simulation_result "https://github.com/lamgianggg/tklls/tree/main/sim"

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_orchestrator,node_analyzer,node_retrieval,node_knowledge toneBlue
class node_inference,node_rtl,node_testbench,node_rtl_output,node_tb_output toneAmber
class node_linter,node_port_auditor,node_simulator,node_reflection,node_eda_finder,node_synthesis,node_simulation_result toneMint
class node_bdf,node_waveform,node_quartus_output toneRose
class node_training_distill,node_training_sampler,node_trained_data,node_engineer,node_eda_tools toneIndigo
```

## Components

### Spec Analysis

- [Workflow orchestrator](https://github.com/lamgianggg/tklls/blob/main/agent/run_spec2rtl.py): `agent/run_spec2rtl.py`
- [Spec analyzer](https://github.com/lamgianggg/tklls/blob/main/agent/spec_analyzer.py): `agent/spec_analyzer.py`
- [Hybrid design retrieval](https://github.com/lamgianggg/tklls/blob/main/agent/knowledge_matcher.py): `agent/knowledge_matcher.py`
- [Reference designs](https://github.com/lamgianggg/tklls/tree/main/knowledge_base): `knowledge_base`

### RTL Generation

- [Local model inference](https://github.com/lamgianggg/tklls/blob/main/models/run_inference.py): `models/run_inference.py`
- [RTL generation](https://github.com/lamgianggg/tklls/blob/main/agent/rtl_generator.py): `agent/rtl_generator.py`
- [Self-checking testbench](https://github.com/lamgianggg/tklls/blob/main/agent/tb_generator.py): `agent/tb_generator.py`
- [Generated Verilog](https://github.com/lamgianggg/tklls/tree/main/src): `src`
- [Generated testbench](https://github.com/lamgianggg/tklls/tree/main/sim): `sim`

### Verification Loop

- [Hardware AST linter](https://github.com/lamgianggg/tklls/blob/main/agent/verilog_linter.py): `agent/verilog_linter.py`
- [Port auditor](https://github.com/lamgianggg/tklls/blob/main/agent/port_auditor.py): `agent/port_auditor.py`
- [EDA simulator](https://github.com/lamgianggg/tklls/blob/main/agent/simulator.py): `agent/simulator.py`
- [Repair loop](https://github.com/lamgianggg/tklls/blob/main/agent/reflection_loop.py): `agent/reflection_loop.py`
- [EDA tool discovery](https://github.com/lamgianggg/tklls/blob/main/agent/eda_finder.py): `agent/eda_finder.py`
- [Synthesis profiler](https://github.com/lamgianggg/tklls/blob/main/agent/synthesis_profiler.py): `agent/synthesis_profiler.py`
- [Simulation result and VCD](https://github.com/lamgianggg/tklls/tree/main/sim): `sim`

### EDA Artifacts

- [Quartus project and BDF](https://github.com/lamgianggg/tklls/blob/main/agent/bdf_generator.py): `agent/bdf_generator.py`
- [VWF waveform generator](https://github.com/lamgianggg/tklls/blob/main/agent/vwf_generator.py): `agent/vwf_generator.py`
- [Quartus design files](https://github.com/lamgianggg/tklls/tree/main/quartus): `quartus`

### Offline Learning

- [Teacher distillation](https://github.com/lamgianggg/tklls/blob/main/training/distill_teacher_cot.py): `training/distill_teacher_cot.py`
- [VerilogDB sampler](https://github.com/lamgianggg/tklls/blob/main/training/verilogdb_sampler.py): `training/verilogdb_sampler.py`
- [Distilled datasets](https://github.com/lamgianggg/tklls/tree/main/training): `training`

### Other components

- **Hardware designer**
- **ModelSim / Quartus**

## Connections

- Hardware designer → Workflow orchestrator: submits spec (evidence: `README.md`)
- Workflow orchestrator → Spec analyzer: analyzes spec (evidence: `agent/run_spec2rtl.py`)
- Workflow orchestrator → Hybrid design retrieval: retrieves examples (evidence: `agent/run_spec2rtl.py`)
- Hybrid design retrieval → Reference designs: searches (evidence: `agent/knowledge_matcher.py`)
- Workflow orchestrator → Local model inference: selects model (evidence: `agent/run_spec2rtl.py`)
- Local model inference → Hybrid design retrieval: adds RAG context (evidence: `models/run_inference.py`)
- Local model inference → RTL generation: falls back to (evidence: `models/run_inference.py`)
- Workflow orchestrator → RTL generation: generates RTL (evidence: `agent/run_spec2rtl.py`)
- RTL generation → Generated Verilog: writes RTL
- Workflow orchestrator → Self-checking testbench: generates tests (evidence: `agent/run_spec2rtl.py`)
- Self-checking testbench → Generated testbench: writes testbench
- Workflow orchestrator → Hardware AST linter: checks RTL (evidence: `agent/run_spec2rtl.py`)
- Workflow orchestrator → Port auditor: audits ports (evidence: `agent/run_spec2rtl.py`)
- Workflow orchestrator → EDA simulator: runs simulation (evidence: `agent/run_spec2rtl.py`)
- EDA simulator → EDA tool discovery: locates tools (evidence: `agent/simulator.py`)
- EDA simulator → ModelSim / Quartus: invokes simulator
- EDA simulator → Simulation result and VCD: produces log / VCD
- Workflow orchestrator → Repair loop: repairs failures (evidence: `agent/run_spec2rtl.py`)
- Repair loop → EDA simulator: reruns flow (evidence: `agent/reflection_loop.py`)
- Workflow orchestrator → Synthesis profiler: profiles synthesis (evidence: `agent/run_spec2rtl.py`)
- Workflow orchestrator → Quartus project and BDF: packages project (evidence: `agent/run_spec2rtl.py`)
- Workflow orchestrator → VWF waveform generator: generates waveform (evidence: `agent/run_spec2rtl.py`)
- VWF waveform generator → Simulation result and VCD: reads VCD (evidence: `agent/vwf_generator.py`)
- Quartus project and BDF → Quartus design files: writes artifacts
- Workflow orchestrator → Quartus design files: creates project files (evidence: `agent/run_spec2rtl.py`)
- ModelSim / Quartus → Workflow orchestrator: provides tool results
- VerilogDB sampler → Distilled datasets: curates samples (evidence: `training/distill_teacher_cot.py`)
- Teacher distillation → Distilled datasets: exports distilled data (evidence: `training/distill_teacher_cot.py`)
- Teacher distillation → Spec analyzer: validates specs (evidence: `training/distill_teacher_cot.py`)
- Teacher distillation → Self-checking testbench: uses testbench checks (evidence: `training/distill_teacher_cot.py`)
- Teacher distillation → Hardware AST linter: uses lint checks (evidence: `training/distill_teacher_cot.py`)
- VerilogDB sampler → Spec analyzer: checks port contract (evidence: `training/verilogdb_sampler.py`)
