# x7ea/ruc architecture

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

- Interactive diagram: https://gitdiagram.com/x7ea/ruc
- Repository: https://github.com/x7ea/ruc

## Overview

Ruc BASIC is a statically typed language compiler. Its visible workflow reads source from stdin, parses it, compiles it to assembly text, and writes that text to stdout; the repository does not show an assembler or execution step. The parser also loads named `.rc` libraries from `lib/`. The README is minimal, so the library files are shown as available language libraries rather than assigned undocumented capabilities. Type inference is a distinct compiler layer, but the excerpts do not establish its call path from compilation.

Main entry points: [`src/parse.rs`](https://github.com/x7ea/ruc/blob/main/src/parse.rs) (Source Parser), [`src/main.rs`](https://github.com/x7ea/ruc/blob/main/src/main.rs) (Compiler Entry), [`src/emit.rs`](https://github.com/x7ea/ruc/blob/main/src/emit.rs) (Assembly Emitter), [`src/lexer.rs`](https://github.com/x7ea/ruc/blob/main/src/lexer.rs) (Token Lexer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_driver["Compiler Driver"]
  node_driver["Compiler Entry<br/>[main.rs]"]
end

subgraph group_frontend["Source Frontend"]
  node_parser["Source Parser<br/>[parse.rs]"]
  node_lexer["Token Lexer<br/>[lexer.rs]"]
end

subgraph group_semantics["Type Semantics"]
  node_inference["Type Inference<br/>[typ.rs]"]
end

subgraph group_backend["Assembly Backend"]
  node_emitter["Assembly Emitter<br/>[emit.rs]"]
end

subgraph group_libraries["Language Libraries"]
  node_library["Standard Library<br/>[std.rc]"]
  node_gtk["GTK Library<br/>[gtk.rc]"]
  node_web["Web Library<br/>[web.rc]"]
end

node_author(("Source Provider"))
node_stdin(("Standard Input"))
node_stdout(("Standard Output"))

node_author -->|"provides source"| node_stdin
node_stdin -->|"reads source"| node_driver
node_driver -->|"parses source"| node_parser
node_parser -->|"tokenizes input"| node_lexer
node_parser -->|"loads named library"| node_library
node_parser -->|"loads named library"| node_gtk
node_parser -->|"loads named library"| node_web
node_driver -->|"compiles program"| node_emitter
node_emitter -.->|"uses type analysis"| node_inference
node_driver -->|"writes assembly"| node_stdout

click node_driver "https://github.com/x7ea/ruc/blob/main/src/main.rs"
click node_parser "https://github.com/x7ea/ruc/blob/main/src/parse.rs"
click node_lexer "https://github.com/x7ea/ruc/blob/main/src/lexer.rs"
click node_inference "https://github.com/x7ea/ruc/blob/main/src/typ.rs"
click node_emitter "https://github.com/x7ea/ruc/blob/main/src/emit.rs"
click node_library "https://github.com/x7ea/ruc/blob/main/lib/std.rc"
click node_gtk "https://github.com/x7ea/ruc/blob/main/lib/gtk.rc"
click node_web "https://github.com/x7ea/ruc/blob/main/lib/web.rc"

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_driver toneBlue
class node_parser,node_lexer toneAmber
class node_inference toneMint
class node_emitter toneRose
class node_library,node_gtk,node_web,node_author,node_stdin,node_stdout toneIndigo
```

## Components

### Compiler Driver

- [Compiler Entry](https://github.com/x7ea/ruc/blob/main/src/main.rs): `src/main.rs`

### Source Frontend

- [Source Parser](https://github.com/x7ea/ruc/blob/main/src/parse.rs): `src/parse.rs`
- [Token Lexer](https://github.com/x7ea/ruc/blob/main/src/lexer.rs): `src/lexer.rs`

### Type Semantics

- [Type Inference](https://github.com/x7ea/ruc/blob/main/src/typ.rs): `src/typ.rs`

### Assembly Backend

- [Assembly Emitter](https://github.com/x7ea/ruc/blob/main/src/emit.rs): `src/emit.rs`

### Language Libraries

- [Standard Library](https://github.com/x7ea/ruc/blob/main/lib/std.rc): `lib/std.rc`
- [GTK Library](https://github.com/x7ea/ruc/blob/main/lib/gtk.rc): `lib/gtk.rc`
- [Web Library](https://github.com/x7ea/ruc/blob/main/lib/web.rc): `lib/web.rc`

### Other components

- **Source Provider**
- **Standard Input**
- **Standard Output**

## Connections

- Source Provider → Standard Input: provides source
- Standard Input → Compiler Entry: reads source (evidence: `src/main.rs`)
- Compiler Entry → Source Parser: parses source (evidence: `src/main.rs`)
- Source Parser → Token Lexer: tokenizes input (evidence: `src/parse.rs`)
- Source Parser → Standard Library: loads named library (evidence: `src/parse.rs`)
- Source Parser → GTK Library: loads named library (evidence: `src/parse.rs`)
- Source Parser → Web Library: loads named library (evidence: `src/parse.rs`)
- Compiler Entry → Assembly Emitter: compiles program (evidence: `src/main.rs`)
- Assembly Emitter → Type Inference: uses type analysis
- Compiler Entry → Standard Output: writes assembly (evidence: `src/main.rs`)
