# exaloop/codon architecture

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

- Interactive diagram: https://gitdiagram.com/exaloop/codon
- Repository: https://github.com/exaloop/codon

## Overview

Codon is a statically compiled Python implementation targeting native performance, with parallel and GPU execution plus Python interoperability. The principal workflow starts with a source file or code, parses and checks it, translates it into compiler IR, applies IR passes, emits LLVM, and produces or runs native code. The graph includes documented NumPy, JIT, Python-extension, and Jupyter capabilities. Some parser and backend links are inferred from the documented compiler workflow rather than inspected call sites, so those links are dashed and unevidenced.

Main entry points: [`codon/compiler/compiler.cpp`](https://github.com/exaloop/codon/blob/develop/codon/compiler/compiler.cpp) (Compiler orchestration), [`codon/cir/transform/manager.cpp`](https://github.com/exaloop/codon/blob/develop/codon/cir/transform/manager.cpp) (Pass manager), [`codon/app/main.cpp`](https://github.com/exaloop/codon/blob/develop/codon/app/main.cpp) (Codon CLI), [`codon/compiler/engine.cpp`](https://github.com/exaloop/codon/blob/develop/codon/compiler/engine.cpp) (JIT engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entry points"]
  node_cli["Codon CLI<br/>[main.cpp]"]
  node_jupyter["Jupyter interface<br/>[jupyter.cpp]"]
end

subgraph group_frontend["Language frontend"]
  node_compiler["Compiler orchestration<br/>[compiler.cpp]"]
  node_parse["Parsing and AST<br/>[expr.cpp]"]
  node_scope["Scoping<br/>[scoping.cpp]"]
  node_typecheck["Type checking"]
  node_translate["IR translation"]
end

subgraph group_ir["IR and optimization"]
  node_cir["Codon IR<br/>[module.cpp]"]
  node_passes["Pass manager<br/>[manager.cpp]"]
  node_analysis["IR analyses"]
  node_lowering["IR lowering"]
  node_numpy["NumPy transforms"]
  node_parallel["Parallel transforms"]
end

subgraph group_backend["Native execution"]
  node_llvm["LLVM code generation<br/>[llvisitor.cpp]"]
  node_engine["JIT engine<br/>[engine.cpp]"]
  node_runtime["Codon runtime<br/>[lib.cpp]"]
  node_gpu["GPU backend<br/>[gpu.cpp]"]
end

subgraph group_interop["Integrations"]
  node_python["Python interoperability<br/>[jit.cpp]"]
  node_jitdecorator["Python JIT decorator<br/>[decorator.py]"]
  node_extension["Python extensions<br/>[pyextension.h]"]
end

node_user(("Program author"))
node_externalpython(("Python ecosystem"))

node_user -->|"invokes"| node_cli
node_cli -->|"compiles source"| node_compiler
node_compiler -.->|"parses source"| node_parse
node_parse -.->|"builds AST"| node_scope
node_scope -.->|"resolves names"| node_typecheck
node_typecheck -.->|"checks types"| node_translate
node_translate -.->|"creates IR"| node_cir
node_compiler -->|"owns pass manager"| node_passes
node_passes -->|"runs analyses"| node_analysis
node_passes -->|"registers passes"| node_lowering
node_passes -->|"registers passes"| node_numpy
node_passes -->|"registers passes"| node_parallel
node_compiler -->|"owns code generator"| node_llvm
node_llvm -.->|"emits executable code"| node_engine
node_engine -.->|"resolves runtime symbols"| node_runtime
node_cli -.->|"runs compiled code"| node_engine
node_jupyter -->|"uses compiler"| node_compiler
node_jupyter -.->|"serves notebook use"| node_externalpython
node_compiler -.->|"supports Python interop"| node_python
node_jitdecorator -.->|"uses JIT"| node_python
node_compiler -.->|"builds extensions"| node_extension
node_compiler -.->|"supports GPU targets"| node_gpu
node_parallel -.->|"targets GPU"| node_gpu
node_externalpython -.->|"calls Codon"| node_python

click node_cli "https://github.com/exaloop/codon/blob/develop/codon/app/main.cpp"
click node_jupyter "https://github.com/exaloop/codon/blob/develop/jupyter/jupyter.cpp"
click node_compiler "https://github.com/exaloop/codon/blob/develop/codon/compiler/compiler.cpp"
click node_parse "https://github.com/exaloop/codon/blob/develop/codon/parser/ast/expr.cpp"
click node_scope "https://github.com/exaloop/codon/blob/develop/codon/parser/visitors/scoping/scoping.cpp"
click node_typecheck "https://github.com/exaloop/codon/tree/develop/codon/parser/visitors/typecheck"
click node_translate "https://github.com/exaloop/codon/tree/develop/codon/parser/visitors/translate"
click node_cir "https://github.com/exaloop/codon/blob/develop/codon/cir/module.cpp"
click node_passes "https://github.com/exaloop/codon/blob/develop/codon/cir/transform/manager.cpp"
click node_analysis "https://github.com/exaloop/codon/tree/develop/codon/cir/analyze"
click node_lowering "https://github.com/exaloop/codon/tree/develop/codon/cir/transform/lowering"
click node_numpy "https://github.com/exaloop/codon/tree/develop/codon/cir/transform/numpy"
click node_parallel "https://github.com/exaloop/codon/tree/develop/codon/cir/transform/parallel"
click node_llvm "https://github.com/exaloop/codon/blob/develop/codon/cir/llvm/llvisitor.cpp"
click node_engine "https://github.com/exaloop/codon/blob/develop/codon/compiler/engine.cpp"
click node_runtime "https://github.com/exaloop/codon/blob/develop/codon/runtime/lib.cpp"
click node_python "https://github.com/exaloop/codon/blob/develop/codon/compiler/jit.cpp"
click node_jitdecorator "https://github.com/exaloop/codon/blob/develop/jit/codon/decorator.py"
click node_extension "https://github.com/exaloop/codon/blob/develop/codon/cir/pyextension.h"
click node_gpu "https://github.com/exaloop/codon/blob/develop/codon/cir/llvm/gpu.cpp"

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_jupyter toneBlue
class node_compiler,node_parse,node_scope,node_typecheck,node_translate toneAmber
class node_cir,node_passes,node_analysis,node_lowering,node_numpy,node_parallel toneMint
class node_llvm,node_engine,node_runtime,node_gpu toneRose
class node_python,node_jitdecorator,node_extension,node_user,node_externalpython toneIndigo
```

## Components

### User entry points

- [Codon CLI](https://github.com/exaloop/codon/blob/develop/codon/app/main.cpp): `codon/app/main.cpp`
- [Jupyter interface](https://github.com/exaloop/codon/blob/develop/jupyter/jupyter.cpp): `jupyter/jupyter.cpp`

### Language frontend

- [Compiler orchestration](https://github.com/exaloop/codon/blob/develop/codon/compiler/compiler.cpp): `codon/compiler/compiler.cpp`
- [Parsing and AST](https://github.com/exaloop/codon/blob/develop/codon/parser/ast/expr.cpp): `codon/parser/ast/expr.cpp`
- [Scoping](https://github.com/exaloop/codon/blob/develop/codon/parser/visitors/scoping/scoping.cpp): `codon/parser/visitors/scoping/scoping.cpp`
- [Type checking](https://github.com/exaloop/codon/tree/develop/codon/parser/visitors/typecheck): `codon/parser/visitors/typecheck`
- [IR translation](https://github.com/exaloop/codon/tree/develop/codon/parser/visitors/translate): `codon/parser/visitors/translate`

### IR and optimization

- [Codon IR](https://github.com/exaloop/codon/blob/develop/codon/cir/module.cpp): `codon/cir/module.cpp`
- [Pass manager](https://github.com/exaloop/codon/blob/develop/codon/cir/transform/manager.cpp): `codon/cir/transform/manager.cpp`
- [IR analyses](https://github.com/exaloop/codon/tree/develop/codon/cir/analyze): `codon/cir/analyze`
- [IR lowering](https://github.com/exaloop/codon/tree/develop/codon/cir/transform/lowering): `codon/cir/transform/lowering`
- [NumPy transforms](https://github.com/exaloop/codon/tree/develop/codon/cir/transform/numpy): `codon/cir/transform/numpy`
- [Parallel transforms](https://github.com/exaloop/codon/tree/develop/codon/cir/transform/parallel): `codon/cir/transform/parallel`

### Native execution

- [LLVM code generation](https://github.com/exaloop/codon/blob/develop/codon/cir/llvm/llvisitor.cpp): `codon/cir/llvm/llvisitor.cpp`
- [JIT engine](https://github.com/exaloop/codon/blob/develop/codon/compiler/engine.cpp): `codon/compiler/engine.cpp`
- [Codon runtime](https://github.com/exaloop/codon/blob/develop/codon/runtime/lib.cpp): `codon/runtime/lib.cpp`
- [GPU backend](https://github.com/exaloop/codon/blob/develop/codon/cir/llvm/gpu.cpp): `codon/cir/llvm/gpu.cpp`

### Integrations

- [Python interoperability](https://github.com/exaloop/codon/blob/develop/codon/compiler/jit.cpp): `codon/compiler/jit.cpp`
- [Python JIT decorator](https://github.com/exaloop/codon/blob/develop/jit/codon/decorator.py): `jit/codon/decorator.py`
- [Python extensions](https://github.com/exaloop/codon/blob/develop/codon/cir/pyextension.h): `codon/cir/pyextension.h`

### Other components

- **Program author**
- **Python ecosystem**

## Connections

- Program author → Codon CLI: invokes (evidence: `README.md`)
- Codon CLI → Compiler orchestration: compiles source (evidence: `codon/app/main.cpp`)
- Compiler orchestration → Parsing and AST: parses source
- Parsing and AST → Scoping: builds AST
- Scoping → Type checking: resolves names
- Type checking → IR translation: checks types
- IR translation → Codon IR: creates IR
- Compiler orchestration → Pass manager: owns pass manager
- Pass manager → IR analyses: runs analyses (evidence: `codon/cir/transform/manager.cpp`)
- Pass manager → IR lowering: registers passes (evidence: `codon/cir/transform/manager.cpp`)
- Pass manager → NumPy transforms: registers passes (evidence: `codon/cir/transform/manager.cpp`)
- Pass manager → Parallel transforms: registers passes (evidence: `codon/cir/transform/manager.cpp`)
- Compiler orchestration → LLVM code generation: owns code generator
- LLVM code generation → JIT engine: emits executable code
- JIT engine → Codon runtime: resolves runtime symbols
- Codon CLI → JIT engine: runs compiled code
- Jupyter interface → Compiler orchestration: uses compiler (evidence: `jupyter/jupyter.cpp`)
- Jupyter interface → Python ecosystem: serves notebook use
- Compiler orchestration → Python interoperability: supports Python interop
- Python JIT decorator → Python interoperability: uses JIT
- Compiler orchestration → Python extensions: builds extensions
- Compiler orchestration → GPU backend: supports GPU targets
- Parallel transforms → GPU backend: targets GPU
- Python ecosystem → Python interoperability: calls Codon
