# omdxp/fun architecture

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

- Interactive diagram: https://gitdiagram.com/omdxp/fun
- Repository: https://github.com/omdxp/fun

## Overview

Fun is a self-hosted, statically typed language compiler that lowers Fun programs to C, alongside a standard library, language server, editor integrations, and an interactive reference site. The main workflow is a developer invoking the CLI on Fun source, which is compiled through lexical, syntactic, semantic, and code-generation stages before native compilation and execution. The README documents these compiler stages and product capabilities; sampled source confirms the reference playground invokes the compiler and VS Code launches the language server. Internal links beyond the sampled excerpts follow documented structure and are limited to the evident compiler pipeline.

Main entry points: [`src/cli/main.fn`](https://github.com/omdxp/fun/blob/main/src/cli/main.fn) (Fun CLI), [`src/parser/parser.fn`](https://github.com/omdxp/fun/blob/main/src/parser/parser.fn) (Parser), [`src/cli/driver.fn`](https://github.com/omdxp/fun/blob/main/src/cli/driver.fn) (Compile Driver), [`src/lexer/lexer.fn`](https://github.com/omdxp/fun/blob/main/src/lexer/lexer.fn) (Lexer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_compiler["Compiler"]
  node_cli["Fun CLI<br/>[main.fn]"]
  node_driver["Compile Driver<br/>[driver.fn]"]
  node_lexer["Lexer<br/>[lexer.fn]"]
  node_parser["Parser<br/>[parser.fn]"]
  node_imports["Import Resolution<br/>[import_resolver.fn]"]
  node_semantics["Type Checking<br/>[typecheck.fn]"]
  node_codegen["C Code Generation<br/>[codegen.fn]"]
end

subgraph group_tooling["Developer Tooling"]
  node_fls["Fun Language Server<br/>[main.fn]"]
end

subgraph group_stdlib["Standard Library"]
  node_stdlib["Fun Standard Library<br/>[prelude.fn]"]
end

subgraph group_editors["Editor Integrations"]
  node_vscode["VS Code Extension<br/>[extension.ts]"]
  node_other_editors["Other Editor Support"]
end

subgraph group_reference["Reference Site"]
  node_reference_app["Reference App<br/>[App.tsx]"]
  node_markdown["Runnable Docs"]
  node_playground["Code Playground<br/>[RunCodeBlock.tsx]"]
  node_reference_server["Playground Server<br/>[index.ts]"]
end

node_developer(("Developer"))
node_fun_source["Fun Source"]
node_native_compiler["C Compiler"]
node_program["Native Program"]

node_developer -->|"writes"| node_fun_source
node_developer -->|"runs"| node_cli
node_fun_source -->|"provides input"| node_cli
node_cli -->|"dispatches"| node_driver
node_driver -->|"lexes"| node_lexer
node_lexer -->|"tokens"| node_parser
node_parser -->|"resolves imports"| node_imports
node_parser -->|"checks"| node_semantics
node_semantics -->|"typed program"| node_codegen
node_codegen -->|"emits C"| node_native_compiler
node_native_compiler -->|"builds"| node_program
node_program -.->|"uses modules"| node_stdlib
node_developer -->|"edits code"| node_vscode
node_vscode -->|"launches"| node_fls
node_developer -->|"edits code"| node_other_editors
node_developer -->|"browses"| node_reference_app
node_reference_app -->|"renders docs"| node_markdown
node_markdown -->|"renders runnable blocks"| node_playground
node_playground -->|"posts code"| node_reference_server
node_reference_server -->|"runs compiler"| node_cli

click node_cli "https://github.com/omdxp/fun/blob/main/src/cli/main.fn"
click node_driver "https://github.com/omdxp/fun/blob/main/src/cli/driver.fn"
click node_lexer "https://github.com/omdxp/fun/blob/main/src/lexer/lexer.fn"
click node_parser "https://github.com/omdxp/fun/blob/main/src/parser/parser.fn"
click node_imports "https://github.com/omdxp/fun/blob/main/src/parser/import_resolver.fn"
click node_semantics "https://github.com/omdxp/fun/blob/main/src/semantics/typecheck.fn"
click node_codegen "https://github.com/omdxp/fun/blob/main/src/codegen/codegen.fn"
click node_stdlib "https://github.com/omdxp/fun/blob/main/stdlib/std/prelude.fn"
click node_fls "https://github.com/omdxp/fun/blob/main/src/fls/main.fn"
click node_vscode "https://github.com/omdxp/fun/blob/main/editors/vscode/src/extension.ts"
click node_other_editors "https://github.com/omdxp/fun/tree/main/editors"
click node_reference_app "https://github.com/omdxp/fun/blob/main/website/reference/src/App.tsx"
click node_markdown "https://github.com/omdxp/fun/blob/main/website/reference/src/components/MarkdownWithPlayground.tsx"
click node_playground "https://github.com/omdxp/fun/blob/main/website/reference/src/components/RunCodeBlock.tsx"
click node_reference_server "https://github.com/omdxp/fun/blob/main/website/reference/server/index.ts"

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_driver,node_lexer,node_parser,node_imports,node_semantics,node_codegen toneBlue
class node_fls toneAmber
class node_stdlib toneMint
class node_vscode,node_other_editors toneRose
class node_reference_app,node_markdown,node_playground,node_reference_server,node_developer,node_fun_source,node_native_compiler,node_program toneIndigo
```

## Components

### Compiler

- [Fun CLI](https://github.com/omdxp/fun/blob/main/src/cli/main.fn): `src/cli/main.fn`
- [Compile Driver](https://github.com/omdxp/fun/blob/main/src/cli/driver.fn): `src/cli/driver.fn`
- [Lexer](https://github.com/omdxp/fun/blob/main/src/lexer/lexer.fn): `src/lexer/lexer.fn`
- [Parser](https://github.com/omdxp/fun/blob/main/src/parser/parser.fn): `src/parser/parser.fn`
- [Import Resolution](https://github.com/omdxp/fun/blob/main/src/parser/import_resolver.fn): `src/parser/import_resolver.fn`
- [Type Checking](https://github.com/omdxp/fun/blob/main/src/semantics/typecheck.fn): `src/semantics/typecheck.fn`
- [C Code Generation](https://github.com/omdxp/fun/blob/main/src/codegen/codegen.fn): `src/codegen/codegen.fn`

### Developer Tooling

- [Fun Language Server](https://github.com/omdxp/fun/blob/main/src/fls/main.fn): `src/fls/main.fn`

### Standard Library

- [Fun Standard Library](https://github.com/omdxp/fun/blob/main/stdlib/std/prelude.fn): `stdlib/std/prelude.fn`

### Editor Integrations

- [VS Code Extension](https://github.com/omdxp/fun/blob/main/editors/vscode/src/extension.ts): `editors/vscode/src/extension.ts`
- [Other Editor Support](https://github.com/omdxp/fun/tree/main/editors): `editors`

### Reference Site

- [Reference App](https://github.com/omdxp/fun/blob/main/website/reference/src/App.tsx): `website/reference/src/App.tsx`
- [Runnable Docs](https://github.com/omdxp/fun/blob/main/website/reference/src/components/MarkdownWithPlayground.tsx): `website/reference/src/components/MarkdownWithPlayground.tsx`
- [Code Playground](https://github.com/omdxp/fun/blob/main/website/reference/src/components/RunCodeBlock.tsx): `website/reference/src/components/RunCodeBlock.tsx`
- [Playground Server](https://github.com/omdxp/fun/blob/main/website/reference/server/index.ts): `website/reference/server/index.ts`

### Other components

- **Developer**
- **Fun Source**
- **C Compiler**
- **Native Program**

## Connections

- Developer → Fun Source: writes
- Developer → Fun CLI: runs
- Fun Source → Fun CLI: provides input
- Fun CLI → Compile Driver: dispatches
- Compile Driver → Lexer: lexes
- Lexer → Parser: tokens
- Parser → Import Resolution: resolves imports
- Parser → Type Checking: checks
- Type Checking → C Code Generation: typed program
- C Code Generation → C Compiler: emits C
- C Compiler → Native Program: builds
- Native Program → Fun Standard Library: uses modules
- Developer → VS Code Extension: edits code
- VS Code Extension → Fun Language Server: launches
- Developer → Other Editor Support: edits code
- Developer → Reference App: browses
- Reference App → Runnable Docs: renders docs
- Runnable Docs → Code Playground: renders runnable blocks
- Code Playground → Playground Server: posts code
- Playground Server → Fun CLI: runs compiler
