# bareca/mini architecture

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

- Interactive diagram: https://gitdiagram.com/bareca/mini
- Repository: https://github.com/bareca/mini

## Overview

Mini is a statically typed, indentation-based language compiler: a programmer supplies a `.mini` program, the compiler parses and checks it, then emits LLVM IR for external tools to turn into a native executable. Its core stages are lexing, parsing/AST construction, semantic analysis, and code generation; the runtime supplies dynamic values and language operations. The README documents these stages and runtime capabilities, while sampled source confirms driver, semantic, codegen, and runtime responsibilities. Lexer and parser implementation details were not sampled, so their links rely on the README’s documented pipeline.

Main entry points: [`src/main.c`](https://github.com/bareca/mini/blob/main/src/main.c) (Compiler driver), [`src/codegen.c`](https://github.com/bareca/mini/blob/main/src/codegen.c) (LLVM codegen), [`src/semantic.c`](https://github.com/bareca/mini/blob/main/src/semantic.c) (Semantic analysis), [`src/mini.y`](https://github.com/bareca/mini/blob/main/src/mini.y) (Parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Front end"]
  node_driver["Compiler driver<br/>[main.c]"]
  node_lexer["Lexer<br/>[mini.l]"]
  node_parser["Parser<br/>[mini.y]"]
  node_ast["AST model<br/>[ast.c]"]
  node_diagnostics["Diagnostics<br/>[diag.c]"]
end

subgraph group_compiler["Analysis and codegen"]
  node_semantic["Semantic analysis<br/>[semantic.c]"]
  node_codegen["LLVM codegen<br/>[codegen.c]"]
end

subgraph group_runtime["Runtime and language services"]
  node_runtime["Runtime support<br/>[rt.c]"]
end

node_programmer(("Programmer"))
node_source["Mini source"]
node_external_tools{{"LLVM native tools"}}
node_executable["Native executable"]

node_programmer -->|"writes"| node_source
node_source -->|"supplies input"| node_driver
node_driver -->|"scans"| node_lexer
node_driver -->|"invokes"| node_parser
node_lexer -->|"provides tokens"| node_parser
node_parser -->|"builds"| node_ast
node_driver -->|"analyzes AST"| node_semantic
node_semantic -->|"reports errors"| node_diagnostics
node_driver -->|"checks errors"| node_diagnostics
node_semantic -->|"annotates AST"| node_codegen
node_driver -->|"emits IR"| node_codegen
node_codegen -->|"calls runtime"| node_runtime
node_codegen -->|"produces LLVM IR"| node_external_tools
node_runtime -->|"links into program"| node_external_tools
node_external_tools -->|"builds"| node_executable

click node_driver "https://github.com/bareca/mini/blob/main/src/main.c"
click node_lexer "https://github.com/bareca/mini/blob/main/src/mini.l"
click node_parser "https://github.com/bareca/mini/blob/main/src/mini.y"
click node_ast "https://github.com/bareca/mini/blob/main/src/ast.c"
click node_diagnostics "https://github.com/bareca/mini/blob/main/src/diag.c"
click node_semantic "https://github.com/bareca/mini/blob/main/src/semantic.c"
click node_codegen "https://github.com/bareca/mini/blob/main/src/codegen.c"
click node_runtime "https://github.com/bareca/mini/blob/main/runtime/rt.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_driver,node_lexer,node_parser,node_ast,node_diagnostics toneBlue
class node_semantic,node_codegen toneAmber
class node_runtime toneMint
class node_programmer,node_source,node_external_tools,node_executable toneIndigo
```

## Components

### Front end

- [Compiler driver](https://github.com/bareca/mini/blob/main/src/main.c): `src/main.c`
- [Lexer](https://github.com/bareca/mini/blob/main/src/mini.l): `src/mini.l`
- [Parser](https://github.com/bareca/mini/blob/main/src/mini.y): `src/mini.y`
- [AST model](https://github.com/bareca/mini/blob/main/src/ast.c): `src/ast.c`
- [Diagnostics](https://github.com/bareca/mini/blob/main/src/diag.c): `src/diag.c`

### Analysis and codegen

- [Semantic analysis](https://github.com/bareca/mini/blob/main/src/semantic.c): `src/semantic.c`
- [LLVM codegen](https://github.com/bareca/mini/blob/main/src/codegen.c): `src/codegen.c`

### Runtime and language services

- [Runtime support](https://github.com/bareca/mini/blob/main/runtime/rt.c): `runtime/rt.c`

### Other components

- **Programmer**
- **Mini source**
- **LLVM native tools**
- **Native executable**

## Connections

- Programmer → Mini source: writes (evidence: `README.md`)
- Mini source → Compiler driver: supplies input (evidence: `README.md`)
- Compiler driver → Lexer: scans (evidence: `src/main.c`)
- Compiler driver → Parser: invokes (evidence: `src/main.c`)
- Lexer → Parser: provides tokens (evidence: `README.md`)
- Parser → AST model: builds (evidence: `README.md`)
- Compiler driver → Semantic analysis: analyzes AST (evidence: `src/main.c`)
- Semantic analysis → Diagnostics: reports errors (evidence: `src/semantic.c`)
- Compiler driver → Diagnostics: checks errors (evidence: `src/main.c`)
- Semantic analysis → LLVM codegen: annotates AST (evidence: `src/codegen.c`)
- Compiler driver → LLVM codegen: emits IR (evidence: `src/main.c`)
- LLVM codegen → Runtime support: calls runtime (evidence: `src/codegen.c`)
- LLVM codegen → LLVM native tools: produces LLVM IR (evidence: `README.md`)
- Runtime support → LLVM native tools: links into program (evidence: `README.md`)
- LLVM native tools → Native executable: builds (evidence: `README.md`)
