# snwfke/orbit architecture

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

- Interactive diagram: https://gitdiagram.com/snwfke/orbit
- Repository: https://github.com/snwfke/orbit

## Overview

#### Purpose and Delivery

Orbit is an alpha Zig-to-Lua microtranspiler aimed at selective, type-safe source translation for Lua-targeted environments such as DCS modding. It can be consumed as a Zig module or built as the `orbit` command-line executable. Build/package wiring is in `build.zig`; executable startup is `src/main.zig`; the library-facing module is likely `src/orbit.zig`.

#### Compilation Pipeline

The core flow is source file input → lexical tokens → parsed AST → Lua emission:
- CLI orchestration and input/output selection: `src/main.zig`
- Tokenization of Zig source: `src/lexer.zig`
- Syntax parsing and AST construction: `src/parser.zig`, `src/ast.zig`
- Lua generation from the internal representation: `src/codegen.zig`

This staged design establishes clear language boundaries: Zig source syntax is handled before code generation, and Lua-specific decisions are concentrated in the backend.

#### Front-End Representation

`src/ast.zig` defines the compiler’s intermediate syntax model shared between parser and generator. `src/lexer.zig` converts raw source text into tokens, while `src/parser.zig` validates supported Zig constructs and maps them into AST nodes. The AST is the principal contract: changes to supported language features generally require coordinated parser and code-generator updates.

#### Lua Backend

`src/codegen.zig` owns lowering supported Zig semantics into efficient Lua operations. The README identifies structs, enums, tables, constants, and imperative logic as important translation targets. Code generation is intentionally selective rather than attempting full Zig compatibility; unsupported compile-time, type-system, or runtime behavior should remain outside this backend’s semantic scope.

#### Public Integration Boundary

`src/orbit.zig` is the likely reusable library entry point exposed through the Zig build dependency/module pattern documented by the project. It should provide the stable API for embedding transpilation without invoking the CLI, while `src/main.zig` adapts command-line arguments such as input source (`-F`) and output Lua file (`-o`) to that library/compiler flow.

#### Runtime and Infrastructure

The implementation and build runtime are Zig 0.14.0, with `build.zig` producing the executable and module artifacts. Generated output targets Lua/Lua VM environments; there is no indicated server, database, or hosted external service dependency. Project language semantics and intended transpilation limits are documented in `THEORY.md`, with theory-oriented validation in `src/test_theory.zig`.

Main entry points: [`src/main.zig`](https://github.com/snwfke/orbit/blob/main/src/main.zig) (orbit CLI), [`src/orbit.zig`](https://github.com/snwfke/orbit/blob/main/src/orbit.zig) (Orbit module API), [`src/lexer.zig`](https://github.com/snwfke/orbit/blob/main/src/lexer.zig) (Lexer), [`src/parser.zig`](https://github.com/snwfke/orbit/blob/main/src/parser.zig) (Parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_delivery["Build & entry points"]
  node_build{{"Zig build wiring<br/>[build.zig]"}}
  node_cli["orbit CLI<br/>executable entry<br/>[main.zig]"]
  node_api["Orbit module API<br/>library entry<br/>[orbit.zig]"]
end

subgraph group_frontend["Zig front end"]
  node_source["Zig source file<br/>input"]
  node_lexer["Lexer<br/>tokenizer<br/>[lexer.zig]"]
  node_parser["Parser<br/>[parser.zig]"]
  node_ast["AST<br/>intermediate representation<br/>[ast.zig]"]
end

subgraph group_backend["Lua backend"]
  node_codegen["Lua generator<br/>code generator<br/>[codegen.zig]"]
  node_lua["Lua output file<br/>generated artifact"]
  node_theory["Language semantics<br/>design documentation<br/>[THEORY.md]"]
end

node_build -->|"builds"| node_cli
node_build -->|"exports"| node_api
node_cli -->|"invokes"| node_api
node_cli -->|"selects with -F"| node_source
node_api -->|"starts compilation"| node_lexer
node_source -->|"source text"| node_lexer
node_lexer -->|"tokens"| node_parser
node_parser -->|"constructs"| node_ast
node_ast -->|"lowers"| node_codegen
node_codegen -->|"emits"| node_lua
node_theory -.->|"defines supported syntax"| node_parser
node_theory -.->|"guides semantics"| node_codegen

click node_build "https://github.com/snwfke/orbit/blob/main/build.zig"
click node_cli "https://github.com/snwfke/orbit/blob/main/src/main.zig"
click node_api "https://github.com/snwfke/orbit/blob/main/src/orbit.zig"
click node_lexer "https://github.com/snwfke/orbit/blob/main/src/lexer.zig"
click node_parser "https://github.com/snwfke/orbit/blob/main/src/parser.zig"
click node_ast "https://github.com/snwfke/orbit/blob/main/src/ast.zig"
click node_codegen "https://github.com/snwfke/orbit/blob/main/src/codegen.zig"
click node_theory "https://github.com/snwfke/orbit/blob/main/THEORY.md"

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_build,node_cli,node_api toneBlue
class node_source,node_lexer,node_parser,node_ast toneAmber
class node_codegen,node_lua,node_theory toneMint
```

## Components

### Build & entry points

- [Zig build wiring](https://github.com/snwfke/orbit/blob/main/build.zig): build · Builds the CLI executable and reusable module. · `build.zig`
- [orbit CLI](https://github.com/snwfke/orbit/blob/main/src/main.zig): executable entry · Selects source input and Lua output from command-line arguments. · `src/main.zig`
- [Orbit module API](https://github.com/snwfke/orbit/blob/main/src/orbit.zig): library entry · Embedding boundary for transpilation without the CLI. · `src/orbit.zig`

### Zig front end

- **Zig source file**: input
- [Lexer](https://github.com/snwfke/orbit/blob/main/src/lexer.zig): tokenizer · Converts Zig source text into lexical tokens. · `src/lexer.zig`
- [Parser](https://github.com/snwfke/orbit/blob/main/src/parser.zig): syntax parser · Validates supported Zig syntax and constructs the AST. · `src/parser.zig`
- [AST](https://github.com/snwfke/orbit/blob/main/src/ast.zig): intermediate representation · Shared contract between parsing and Lua generation. · `src/ast.zig`

### Lua backend

- [Lua generator](https://github.com/snwfke/orbit/blob/main/src/codegen.zig): code generator · Lowers supported Zig constructs into Lua operations. · `src/codegen.zig`
- **Lua output file**: generated artifact · Output consumed by Lua VM environments.
- [Language semantics](https://github.com/snwfke/orbit/blob/main/THEORY.md): design documentation · Defines intended translation limits and semantics. · `THEORY.md`

## Connections

- Zig build wiring → orbit CLI: builds
- Zig build wiring → Orbit module API: exports
- orbit CLI → Orbit module API: invokes
- orbit CLI → Zig source file: selects with -F
- Orbit module API → Lexer: starts compilation
- Zig source file → Lexer: source text
- Lexer → Parser: tokens
- Parser → AST: constructs
- AST → Lua generator: lowers
- Lua generator → Lua output file: emits
- Language semantics → Parser: defines supported syntax
- Language semantics → Lua generator: guides semantics
