# dr-programmer/qbit architecture

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

- Interactive diagram: https://gitdiagram.com/dr-programmer/qbit
- Repository: https://github.com/dr-programmer/qbit

## Overview

Q-bit combines a C quantum simulator, the Q Assembly language toolchain, and SMART scope-based memory management. The main workflow parses a .qsm program, resolves names and checks dimensions, then either runs it on the simulator or generates Q-SET C code. The graph preserves the documented scanner-to-parser and compiler stages, alongside simulator math, quantum operations, algorithms, and optional CUDA support. Some connections are supported by the README rather than sampled implementation excerpts; unsampled internals are not expanded.

Main entry points: [`main.c`](https://github.com/dr-programmer/qbit/blob/main/main.c) (CLI entry), [`simulator/linear_algebra/linear_algebra.c`](https://github.com/dr-programmer/qbit/blob/main/simulator/linear_algebra/linear_algebra.c) (Linear algebra), [`q_assembly/structures/structures.c`](https://github.com/dr-programmer/qbit/blob/main/q_assembly/structures/structures.c) (Q-SET runner), [`q_assembly/parser/parser.y.c`](https://github.com/dr-programmer/qbit/blob/main/q_assembly/parser/parser.y.c) (Parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_assembly["Q Assembly"]
  node_cli["CLI entry<br/>[main.c]"]
  node_scanner["Scanner<br/>[scanner.l.c]"]
  node_parser["Parser<br/>[parser.y.c]"]
  node_ast["AST structures<br/>[structures.c]"]
  node_scope["Symbol scopes<br/>[scope.c]"]
  node_analysis["Semantic analysis<br/>[structures.c]"]
  node_runner["Q-SET runner<br/>[structures.c]"]
  node_generator["Q-SET generator<br/>[structures.c]"]
end

subgraph group_math["Simulator Math"]
  node_complex["Complex numbers<br/>[complex_numbers.c]"]
  node_linear["Linear algebra<br/>[linear_algebra.c]"]
end

subgraph group_quantum["Quantum Simulator"]
  node_states["Quantum states<br/>[qubits.c]"]
  node_operators["Quantum operators<br/>[operators.c]"]
  node_algorithms["Quantum algorithms<br/>[algorithms.c]"]
  node_cuda["CUDA backend<br/>[linear_algebra.cu]"]
end

subgraph group_memory["Memory Management"]
  node_smart["SMART allocator<br/>[smart_allocation.c]"]
end

node_user(("Program author"))
node_qset["Generated Q-SET C"]

node_user -->|"runs program"| node_cli
node_cli -->|"invokes parse"| node_parser
node_scanner -->|"supplies tokens"| node_parser
node_parser -->|"builds AST"| node_ast
node_cli -->|"opens scope"| node_scope
node_cli -->|"resolves and checks"| node_analysis
node_analysis -->|"resolves names"| node_scope
node_cli -->|"runs program"| node_runner
node_cli -->|"generates code"| node_generator
node_runner -->|"executes operations"| node_linear
node_runner -->|"runs quantum logic"| node_states
node_runner -->|"runs quantum logic"| node_operators
node_generator -->|"writes C code"| node_qset
node_complex -->|"supports arithmetic"| node_linear
node_linear -->|"represents states"| node_states
node_linear -->|"represents operators"| node_operators
node_states -->|"used by algorithms"| node_algorithms
node_operators -->|"used by algorithms"| node_algorithms
node_linear -.->|"selects backend"| node_cuda
node_cli -->|"enables backend"| node_cuda
node_cli -->|"allocates memory"| node_smart
node_ast -->|"allocates structures"| node_smart
node_scope -->|"allocates tables"| node_smart

click node_cli "https://github.com/dr-programmer/qbit/blob/main/main.c"
click node_scanner "https://github.com/dr-programmer/qbit/blob/main/q_assembly/scanner/scanner.l.c"
click node_parser "https://github.com/dr-programmer/qbit/blob/main/q_assembly/parser/parser.y.c"
click node_ast "https://github.com/dr-programmer/qbit/blob/main/q_assembly/structures/structures.c"
click node_scope "https://github.com/dr-programmer/qbit/blob/main/q_assembly/structures/scope/scope.c"
click node_analysis "https://github.com/dr-programmer/qbit/blob/main/q_assembly/structures/structures.c"
click node_runner "https://github.com/dr-programmer/qbit/blob/main/q_assembly/structures/structures.c"
click node_generator "https://github.com/dr-programmer/qbit/blob/main/q_assembly/structures/structures.c"
click node_complex "https://github.com/dr-programmer/qbit/blob/main/simulator/complex_numbers/complex_numbers.c"
click node_linear "https://github.com/dr-programmer/qbit/blob/main/simulator/linear_algebra/linear_algebra.c"
click node_states "https://github.com/dr-programmer/qbit/blob/main/simulator/quantum/qubits.c"
click node_operators "https://github.com/dr-programmer/qbit/blob/main/simulator/quantum/operators.c"
click node_algorithms "https://github.com/dr-programmer/qbit/blob/main/simulator/quantum/algorithms/algorithms.c"
click node_cuda "https://github.com/dr-programmer/qbit/blob/main/simulator/linear_algebra/linear_algebra.cu"
click node_smart "https://github.com/dr-programmer/qbit/blob/main/smart_allocation/smart_allocation.c"

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_cli,node_scanner,node_parser,node_ast,node_scope,node_analysis,node_runner,node_generator toneBlue
class node_complex,node_linear toneAmber
class node_states,node_operators,node_algorithms,node_cuda toneMint
class node_smart toneRose
class node_user,node_qset toneIndigo
```

## Components

### Q Assembly

- [CLI entry](https://github.com/dr-programmer/qbit/blob/main/main.c): `main.c`
- [Scanner](https://github.com/dr-programmer/qbit/blob/main/q_assembly/scanner/scanner.l.c): `q_assembly/scanner/scanner.l.c`
- [Parser](https://github.com/dr-programmer/qbit/blob/main/q_assembly/parser/parser.y.c): `q_assembly/parser/parser.y.c`
- [AST structures](https://github.com/dr-programmer/qbit/blob/main/q_assembly/structures/structures.c): `q_assembly/structures/structures.c`
- [Symbol scopes](https://github.com/dr-programmer/qbit/blob/main/q_assembly/structures/scope/scope.c): `q_assembly/structures/scope/scope.c`
- [Semantic analysis](https://github.com/dr-programmer/qbit/blob/main/q_assembly/structures/structures.c): `q_assembly/structures/structures.c`
- [Q-SET runner](https://github.com/dr-programmer/qbit/blob/main/q_assembly/structures/structures.c): `q_assembly/structures/structures.c`
- [Q-SET generator](https://github.com/dr-programmer/qbit/blob/main/q_assembly/structures/structures.c): `q_assembly/structures/structures.c`

### Simulator Math

- [Complex numbers](https://github.com/dr-programmer/qbit/blob/main/simulator/complex_numbers/complex_numbers.c): `simulator/complex_numbers/complex_numbers.c`
- [Linear algebra](https://github.com/dr-programmer/qbit/blob/main/simulator/linear_algebra/linear_algebra.c): `simulator/linear_algebra/linear_algebra.c`

### Quantum Simulator

- [Quantum states](https://github.com/dr-programmer/qbit/blob/main/simulator/quantum/qubits.c): `simulator/quantum/qubits.c`
- [Quantum operators](https://github.com/dr-programmer/qbit/blob/main/simulator/quantum/operators.c): `simulator/quantum/operators.c`
- [Quantum algorithms](https://github.com/dr-programmer/qbit/blob/main/simulator/quantum/algorithms/algorithms.c): `simulator/quantum/algorithms/algorithms.c`
- [CUDA backend](https://github.com/dr-programmer/qbit/blob/main/simulator/linear_algebra/linear_algebra.cu): `simulator/linear_algebra/linear_algebra.cu`

### Memory Management

- [SMART allocator](https://github.com/dr-programmer/qbit/blob/main/smart_allocation/smart_allocation.c): `smart_allocation/smart_allocation.c`

### Other components

- **Program author**
- **Generated Q-SET C**

## Connections

- Program author → CLI entry: runs program (evidence: `README.md`)
- CLI entry → Parser: invokes parse (evidence: `main.c`)
- Scanner → Parser: supplies tokens (evidence: `README.md`)
- Parser → AST structures: builds AST (evidence: `README.md`)
- CLI entry → Symbol scopes: opens scope (evidence: `main.c`)
- CLI entry → Semantic analysis: resolves and checks (evidence: `main.c`)
- Semantic analysis → Symbol scopes: resolves names (evidence: `q_assembly/structures/structures.c`)
- CLI entry → Q-SET runner: runs program (evidence: `main.c`)
- CLI entry → Q-SET generator: generates code (evidence: `main.c`)
- Q-SET runner → Linear algebra: executes operations (evidence: `q_assembly/structures/structures.c`)
- Q-SET runner → Quantum states: runs quantum logic (evidence: `README.md`)
- Q-SET runner → Quantum operators: runs quantum logic (evidence: `README.md`)
- Q-SET generator → Generated Q-SET C: writes C code
- Complex numbers → Linear algebra: supports arithmetic
- Linear algebra → Quantum states: represents states
- Linear algebra → Quantum operators: represents operators
- Quantum states → Quantum algorithms: used by algorithms (evidence: `simulator/quantum/algorithms/algorithms.c`)
- Quantum operators → Quantum algorithms: used by algorithms
- Linear algebra → CUDA backend: selects backend (evidence: `simulator/linear_algebra/linear_algebra.c`)
- CLI entry → CUDA backend: enables backend (evidence: `main.c`)
- CLI entry → SMART allocator: allocates memory (evidence: `main.c`)
- AST structures → SMART allocator: allocates structures (evidence: `q_assembly/structures/structures.c`)
- Symbol scopes → SMART allocator: allocates tables (evidence: `q_assembly/structures/scope/scope.c`)
