# xomagat/fabsharp architecture

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

- Interactive diagram: https://gitdiagram.com/xomagat/fabsharp
- Repository: https://github.com/xomagat/fabsharp

## Overview

FAB# is a C++ compiler for a compiled language: users submit `.fab` source and receive a standalone executable, optionally running it immediately. The documented flow passes through command-line handling, lexing, parsing, LLVM code generation, object compilation and linking. The parser and AST cover language constructs; manifests describe standard-library symbols, with type methods always available and other libraries loaded on demand. The README and source index establish the main flow, but many implementation details—especially linking and individual AST code generation—were not sampled.

Main entry points: [`Parser/Parser.cpp`](https://github.com/xomagat/fabsharp/blob/main/Parser/Parser.cpp) (Parser), [`main.cpp`](https://github.com/xomagat/fabsharp/blob/main/main.cpp) (Compiler CLI), [`libs/STDLibInfo.h`](https://github.com/xomagat/fabsharp/blob/main/libs/STDLibInfo.h) (Library manifests), [`CodeGen/Compile.cpp`](https://github.com/xomagat/fabsharp/blob/main/CodeGen/Compile.cpp) (Object compilation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Frontend"]
  node_cli["Compiler CLI<br/>[main.cpp]"]
  node_lexer["Lexer<br/>[Lexer.cpp]"]
  node_parser["Parser<br/>[Parser.cpp]"]
end

subgraph group_language["Language AST"]
  node_expressions["Expressions<br/>[Expression.h]"]
  node_statements["Statements<br/>[Statement.h]"]
  node_assignments["Assignments"]
  node_functions["Functions"]
  node_classes["Classes<br/>[ClassStatement.h]"]
end

subgraph group_compile["Code Generation"]
  node_codegen["Codegen context<br/>[CodegenContext.h]"]
  node_compile_obj["Object compilation<br/>[Compile.cpp]"]
end

subgraph group_stdlib["Standard Library"]
  node_stdlib_info["Library manifests<br/>[STDLibInfo.h]"]
  node_type_methods["Type methods"]
  node_collections["List and dict<br/>[list.cpp]"]
  node_optional_libs["Optional libraries"]
  node_runtime["Runtime support<br/>[alloc.cpp]"]
end

subgraph group_output["Build Output"]
  node_linker["Executable linking<br/>[Compile.cpp]"]
  node_program["Standalone program"]
end

node_developer(("Program author"))
node_llvm["LLVM"]

node_developer -->|"provides source"| node_cli
node_cli -->|"starts lexing"| node_lexer
node_cli -->|"starts parsing"| node_parser
node_lexer -.->|"supplies tokens"| node_parser
node_parser -->|"builds expressions"| node_expressions
node_parser -->|"builds statements"| node_statements
node_parser -->|"builds assignments"| node_assignments
node_parser -->|"builds functions"| node_functions
node_parser -->|"builds classes"| node_classes
node_cli -->|"invokes compilation"| node_compile_obj
node_compile_obj -.->|"uses context"| node_codegen
node_codegen -->|"emits LLVM IR"| node_llvm
node_stdlib_info -->|"describes symbols"| node_type_methods
node_stdlib_info -->|"describes symbols"| node_optional_libs
node_stdlib_info -->|"describes symbols"| node_collections
node_cli -->|"loads manifests"| node_stdlib_info
node_compile_obj -->|"links output"| node_linker
node_linker -->|"produces executable"| node_program
node_cli -->|"may run after build"| node_program
node_type_methods -.->|"uses runtime"| node_runtime
node_collections -->|"allocates memory"| node_runtime

click node_cli "https://github.com/xomagat/fabsharp/blob/main/main.cpp"
click node_lexer "https://github.com/xomagat/fabsharp/blob/main/Parser/Lexer.cpp"
click node_parser "https://github.com/xomagat/fabsharp/blob/main/Parser/Parser.cpp"
click node_expressions "https://github.com/xomagat/fabsharp/blob/main/Parser/AST/Expression.h"
click node_statements "https://github.com/xomagat/fabsharp/blob/main/Parser/AST/Statement.h"
click node_assignments "https://github.com/xomagat/fabsharp/blob/main/Parser/AST/AssigementStatement.h"
click node_functions "https://github.com/xomagat/fabsharp/blob/main/Parser/AST/FunctionStatement.h"
click node_classes "https://github.com/xomagat/fabsharp/blob/main/Parser/AST/ClassStatement.h"
click node_codegen "https://github.com/xomagat/fabsharp/blob/main/CodeGen/CodegenContext.h"
click node_compile_obj "https://github.com/xomagat/fabsharp/blob/main/CodeGen/Compile.cpp"
click node_stdlib_info "https://github.com/xomagat/fabsharp/blob/main/libs/STDLibInfo.h"
click node_type_methods "https://github.com/xomagat/fabsharp/tree/main/lib/types"
click node_collections "https://github.com/xomagat/fabsharp/blob/main/lib/types/list.cpp"
click node_optional_libs "https://github.com/xomagat/fabsharp/tree/main/lib/libs"
click node_runtime "https://github.com/xomagat/fabsharp/blob/main/lib/alloc.cpp"
click node_linker "https://github.com/xomagat/fabsharp/blob/main/CodeGen/Compile.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_lexer,node_parser toneBlue
class node_expressions,node_statements,node_assignments,node_functions,node_classes toneAmber
class node_codegen,node_compile_obj toneMint
class node_stdlib_info,node_type_methods,node_collections,node_optional_libs,node_runtime toneRose
class node_linker,node_program,node_developer,node_llvm toneIndigo
```

## Components

### Frontend

- [Compiler CLI](https://github.com/xomagat/fabsharp/blob/main/main.cpp): `main.cpp`
- [Lexer](https://github.com/xomagat/fabsharp/blob/main/Parser/Lexer.cpp): `Parser/Lexer.cpp`
- [Parser](https://github.com/xomagat/fabsharp/blob/main/Parser/Parser.cpp): `Parser/Parser.cpp`

### Language AST

- [Expressions](https://github.com/xomagat/fabsharp/blob/main/Parser/AST/Expression.h): `Parser/AST/Expression.h`
- [Statements](https://github.com/xomagat/fabsharp/blob/main/Parser/AST/Statement.h): `Parser/AST/Statement.h`
- [Assignments](https://github.com/xomagat/fabsharp/blob/main/Parser/AST/AssigementStatement.h): `Parser/AST/AssigementStatement.h`
- [Functions](https://github.com/xomagat/fabsharp/blob/main/Parser/AST/FunctionStatement.h): `Parser/AST/FunctionStatement.h`
- [Classes](https://github.com/xomagat/fabsharp/blob/main/Parser/AST/ClassStatement.h): `Parser/AST/ClassStatement.h`

### Code Generation

- [Codegen context](https://github.com/xomagat/fabsharp/blob/main/CodeGen/CodegenContext.h): `CodeGen/CodegenContext.h`
- [Object compilation](https://github.com/xomagat/fabsharp/blob/main/CodeGen/Compile.cpp): `CodeGen/Compile.cpp`

### Standard Library

- [Library manifests](https://github.com/xomagat/fabsharp/blob/main/libs/STDLibInfo.h): `libs/STDLibInfo.h`
- [Type methods](https://github.com/xomagat/fabsharp/tree/main/lib/types): `lib/types`
- [List and dict](https://github.com/xomagat/fabsharp/blob/main/lib/types/list.cpp): `lib/types/list.cpp`
- [Optional libraries](https://github.com/xomagat/fabsharp/tree/main/lib/libs): `lib/libs`
- [Runtime support](https://github.com/xomagat/fabsharp/blob/main/lib/alloc.cpp): `lib/alloc.cpp`

### Build Output

- [Executable linking](https://github.com/xomagat/fabsharp/blob/main/CodeGen/Compile.cpp): `CodeGen/Compile.cpp`
- **Standalone program**

### Other components

- **Program author**
- **LLVM**

## Connections

- Program author → Compiler CLI: provides source
- Compiler CLI → Lexer: starts lexing (evidence: `main.cpp`)
- Compiler CLI → Parser: starts parsing (evidence: `main.cpp`)
- Lexer → Parser: supplies tokens
- Parser → Expressions: builds expressions
- Parser → Statements: builds statements
- Parser → Assignments: builds assignments
- Parser → Functions: builds functions
- Parser → Classes: builds classes
- Compiler CLI → Object compilation: invokes compilation (evidence: `main.cpp`)
- Object compilation → Codegen context: uses context
- Codegen context → LLVM: emits LLVM IR
- Library manifests → Type methods: describes symbols
- Library manifests → Optional libraries: describes symbols
- Library manifests → List and dict: describes symbols
- Compiler CLI → Library manifests: loads manifests
- Object compilation → Executable linking: links output
- Executable linking → Standalone program: produces executable
- Compiler CLI → Standalone program: may run after build
- Type methods → Runtime support: uses runtime
- List and dict → Runtime support: allocates memory (evidence: `lib/types/list.cpp`)
