# odin-lang/odin architecture

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

- Interactive diagram: https://gitdiagram.com/odin-lang/odin
- Repository: https://github.com/odin-lang/odin

## Overview

##### Main Components Identification
- Compiler Frontend – Includes modules for tokenization, parsing, AST creation, and code formatting (directories such as core/odin/ast, core/odin/parser, core/odin/tokenizer, and core/odin/printer).
- Runtime & Base Libraries – Provided in the “base” and “core/runtime” directories. They include the system’s low-level runtimes, allocator modules, OS-specific entry points, and error-checking routines.
- Standard Library & Utilities – Encapsulated in “core” directories (such as core/mem, core/container, core/crypto, core/os, and core/net). These parts form the language’s built-in libraries and are critical to its low-level functionality and cross-platform support.
- Tools & Build Infrastructure – Includes configuration files (Makefile, build scripts like build_odin.sh, build.bat), CI workflows (.github/workflows), tests (found in tests/), and vendor components.
- External and Third-Party Integrations – The repository contains external toolchains and libraries (such as LLVM and nasm under bin, libtommath in src, and aspects in misc).

##### Relationship & Interactions
- The Compiler Frontend takes source code and processes it through tokenization, parsing, and AST generation.
- The AST is then used by the Backend to perform semantic checks and generate machine code/LLVM intermediate representation.
- Runtime components and OS-specific modules (in base/runtime and core/sys) provide the necessary bridge between generated code and the operating system.
- Core libraries (core/...) offer supporting functionality like memory management, string and math operations, and hardware-specific optimizations (e.g., SIMD support, crypto, and threading).
- Testing and build scripts ensure that the various modules work in harmony and are continuously integrated across multiple platforms.

##### Architectural Patterns & Design Principles
- Modular Design: The separation into modules (frontend, backend, runtime, libraries, tests, and tooling) reflects a highly modular architecture.
- Data-Oriented Design: Emphasis on efficiency, minimal overhead, and direct control over hardware resources.
- Cross-Platform Abstraction: There are dedicated components for abstracting OS-specific behavior (look under core/sys, base/runtime, and parts of core/os).
- Extensibility: The vendor and core libraries facilitate extending the language with additional built-in packages and facilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    Source["Source Code"]:::redStyle

    %% Compiler Frontend Subgraph
    subgraph "Compiler Frontend (Tokenizer, Parser, AST, Printer)"
        T["Tokenizer"]:::redStyle
        P["Parser"]:::redStyle
        A["AST"]:::redStyle
        PR["Printer"]:::redStyle
    end

    %% Code Generation & Backend Subgraph
    subgraph "Code Generation & Backend (LLVM Integration, Tilde Passes)"
        LLVM["LLVM Integration"]:::redStyle
        Tilde["Tilde Passes"]:::redStyle
    end

    %% Runtime & Base Libraries
    R["Runtime & Base Libraries"]:::redStyle

    %% Standard Library & Utilities Subgraph
    subgraph "Standard Library & Utilities (Memory, Container, Crypto, OS, Net)"
        Mem["Memory Module"]:::redStyle
        Cont["Container Module"]:::redStyle
        Crypto["Crypto Module"]:::redStyle
        OS["OS Module"]:::redStyle
        Net["Net Module"]:::redStyle
    end

    %% Tools & Build Infrastructure Subgraph
    subgraph "Tools & Build Infrastructure (Build Scripts, CI, Tests)"
        MF["Makefile"]:::redStyle
        Bash["build_odin.sh"]:::redStyle
        Bat["build.bat"]:::redStyle
        CI["CI Workflows"]:::redStyle
        Tests["Tests"]:::redStyle
    end

    %% External & Third-Party Integrations Subgraph
    subgraph "External & Third-Party Integrations (LLVM, nasm, libtommath, Misc)"
        BinLLVM["LLVM Toolchain"]:::redStyle
        Nasm["nasm"]:::redStyle
        Libtommath["libtommath"]:::redStyle
        Misc["Misc Tools"]:::redStyle
    end

    %% Connections - Main Compiler Pipeline
    Source -->|"processes"| T
    T -->|"feeds"| P
    P -->|"creates"| A
    A -->|"formats"| PR
    PR -->|"generatesIR"| LLVM
    PR -->|"generatesIR"| Tilde
    LLVM -->|"passesCode"| R
    Tilde -->|"passesCode"| R
    R -->|"linksWith"| Mem
    R -->|"linksWith"| Cont
    R -->|"linksWith"| Crypto
    R -->|"linksWith"| OS
    R -->|"linksWith"| Net

    %% Connections - Tools & Build Infrastructure influence
    MF -->|"triggersBuild"| T
    Bash -->|"triggersBuild"| T
    Bat -->|"triggersBuild"| T
    CI -->|"integrates"| T
    Tests -->|"validates"| T

    %% Connections - External Tools Support
    BinLLVM -->|"supports"| LLVM
    Nasm -->|"supports"| Tilde
    Libtommath -->|"integratesWith"| Crypto
    Misc -->|"toolsFor"| T

    %% Click Events for Compiler Frontend
    click T "https://github.com/odin-lang/odin/tree/master/core/odin/tokenizer"
    click P "https://github.com/odin-lang/odin/tree/master/core/odin/parser"
    click A "https://github.com/odin-lang/odin/tree/master/core/odin/ast"
    click PR "https://github.com/odin-lang/odin/tree/master/core/odin/printer"

    %% Click Events for Code Generation & Backend
    click LLVM "https://github.com/odin-lang/odin/blob/master/src/llvm_backend.cpp"
    click Tilde "https://github.com/odin-lang/odin/blob/master/src/tilde.cpp"

    %% Click Event for Runtime & Base Libraries
    click R "https://github.com/odin-lang/odin/tree/master/base/runtime"

    %% Click Events for Standard Library & Utilities
    click Mem "https://github.com/odin-lang/odin/tree/master/core/mem"
    click Cont "https://github.com/odin-lang/odin/tree/master/core/container"
    click Crypto "https://github.com/odin-lang/odin/tree/master/core/crypto"
    click OS "https://github.com/odin-lang/odin/tree/master/core/os"
    click Net "https://github.com/odin-lang/odin/tree/master/core/net"

    %% Click Events for Tools & Build Infrastructure
    click MF "https://github.com/odin-lang/odin/tree/master/Makefile"
    click Bash "https://github.com/odin-lang/odin/blob/master/build_odin.sh"
    click Bat "https://github.com/odin-lang/odin/blob/master/build.bat"
    click CI "https://github.com/odin-lang/odin/tree/master/.github/workflows"
    click Tests "https://github.com/odin-lang/odin/tree/master/tests/"

    %% Click Events for External & Third-Party Integrations
    click BinLLVM "https://github.com/odin-lang/odin/tree/master/bin/llvm"
    click Nasm "https://github.com/odin-lang/odin/tree/master/bin/nasm"
    click Libtommath "https://github.com/odin-lang/odin/tree/master/src/libtommath"
    click Misc "https://github.com/odin-lang/odin/tree/master/misc/"

    %% Styles
    classDef redStyle fill:#ff0000,stroke:#ff0000,color:#ffff00,stroke-width:2px
    linkStyle default stroke:#ff0000,stroke-width:2px,color:#ffff00
```
