# n213s/araiwapl architecture

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

- Interactive diagram: https://gitdiagram.com/n213s/araiwapl
- Repository: https://github.com/n213s/araiwapl

## Overview

Araiwa is a small Thai-language interpreter. The main workflow is a user-provided .arw script and optional command-line arguments flowing through the CLI, tokenizer, parser/AST, and interpreter to terminal output or errors. Runtime responsibilities include lexical scopes, type semantics, input, and numeric/loop traps. The README documents module imports and several language features; the sampled interpreter excerpt only shows import names being recorded, so no external module-loading behavior is inferred.

Main entry points: [`interpreter.py`](https://github.com/n213s/araiwapl/blob/master/interpreter.py) (AST interpreter), [`araiwa.py`](https://github.com/n213s/araiwapl/blob/master/araiwa.py) (CLI runner), [`parser.py`](https://github.com/n213s/araiwapl/blob/master/parser.py) (Parser), [`lexer.py`](https://github.com/n213s/araiwapl/blob/master/lexer.py) (Tokenizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Program entry"]
  node_cli["CLI runner<br/>[araiwa.py]"]
end

subgraph group_frontend["Language frontend"]
  node_lexer["Tokenizer<br/>[lexer.py]"]
  node_tokens["Token model<br/>[tokens.py]"]
  node_parser["Parser<br/>[parser.py]"]
  node_ast["AST nodes<br/>[ast_nodes.py]"]
end

subgraph group_execution["Execution runtime"]
  node_interpreter["AST interpreter<br/>[interpreter.py]"]
  node_io["Interactive I/O<br/>[interpreter.py]"]
  node_imports["Module declarations<br/>[interpreter.py]"]
end

subgraph group_semantics["Runtime semantics"]
  node_scope["Lexical scopes<br/>[runtime.py]"]
  node_value_rules["Value and trap rules<br/>[runtime.py]"]
  node_errors["Language errors<br/>[errors.py]"]
end

node_user(("Script author"))
node_source["Araiwa source"]
node_terminal(("Terminal"))

node_user -->|"writes"| node_source
node_source -->|"provides script"| node_cli
node_cli -->|"tokenizes"| node_lexer
node_lexer -->|"creates tokens"| node_tokens
node_lexer -->|"raises syntax errors"| node_errors
node_cli -->|"parses tokens"| node_parser
node_parser -->|"reads tokens"| node_tokens
node_parser -->|"builds AST"| node_ast
node_parser -->|"raises parse errors"| node_errors
node_cli -->|"executes AST"| node_interpreter
node_interpreter -->|"dispatches AST nodes"| node_ast
node_interpreter -->|"manages bindings"| node_scope
node_interpreter -->|"checks values"| node_value_rules
node_interpreter -->|"reads input and prints"| node_io
node_interpreter -->|"records imports"| node_imports
node_interpreter -->|"raises runtime errors"| node_errors
node_cli -->|"reports results"| node_terminal
node_io -->|"reads and writes"| node_terminal

click node_cli "https://github.com/n213s/araiwapl/blob/master/araiwa.py"
click node_lexer "https://github.com/n213s/araiwapl/blob/master/lexer.py"
click node_tokens "https://github.com/n213s/araiwapl/blob/master/tokens.py"
click node_parser "https://github.com/n213s/araiwapl/blob/master/parser.py"
click node_ast "https://github.com/n213s/araiwapl/blob/master/ast_nodes.py"
click node_interpreter "https://github.com/n213s/araiwapl/blob/master/interpreter.py"
click node_scope "https://github.com/n213s/araiwapl/blob/master/runtime.py"
click node_value_rules "https://github.com/n213s/araiwapl/blob/master/runtime.py"
click node_io "https://github.com/n213s/araiwapl/blob/master/interpreter.py"
click node_imports "https://github.com/n213s/araiwapl/blob/master/interpreter.py"
click node_errors "https://github.com/n213s/araiwapl/blob/master/errors.py"

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 toneBlue
class node_lexer,node_tokens,node_parser,node_ast toneAmber
class node_interpreter,node_io,node_imports toneMint
class node_scope,node_value_rules,node_errors toneRose
class node_user,node_source,node_terminal toneIndigo
```

## Components

### Program entry

- [CLI runner](https://github.com/n213s/araiwapl/blob/master/araiwa.py): `araiwa.py`

### Language frontend

- [Tokenizer](https://github.com/n213s/araiwapl/blob/master/lexer.py): `lexer.py`
- [Token model](https://github.com/n213s/araiwapl/blob/master/tokens.py): `tokens.py`
- [Parser](https://github.com/n213s/araiwapl/blob/master/parser.py): `parser.py`
- [AST nodes](https://github.com/n213s/araiwapl/blob/master/ast_nodes.py): `ast_nodes.py`

### Execution runtime

- [AST interpreter](https://github.com/n213s/araiwapl/blob/master/interpreter.py): `interpreter.py`
- [Interactive I/O](https://github.com/n213s/araiwapl/blob/master/interpreter.py): `interpreter.py`
- [Module declarations](https://github.com/n213s/araiwapl/blob/master/interpreter.py): `interpreter.py`

### Runtime semantics

- [Lexical scopes](https://github.com/n213s/araiwapl/blob/master/runtime.py): `runtime.py`
- [Value and trap rules](https://github.com/n213s/araiwapl/blob/master/runtime.py): `runtime.py`
- [Language errors](https://github.com/n213s/araiwapl/blob/master/errors.py): `errors.py`

### Other components

- **Script author**
- **Araiwa source**
- **Terminal**

## Connections

- Script author → Araiwa source: writes (evidence: `README.md`)
- Araiwa source → CLI runner: provides script (evidence: `araiwa.py`)
- CLI runner → Tokenizer: tokenizes (evidence: `araiwa.py`)
- Tokenizer → Token model: creates tokens (evidence: `lexer.py`)
- Tokenizer → Language errors: raises syntax errors (evidence: `lexer.py`)
- CLI runner → Parser: parses tokens (evidence: `araiwa.py`)
- Parser → Token model: reads tokens (evidence: `parser.py`)
- Parser → AST nodes: builds AST (evidence: `parser.py`)
- Parser → Language errors: raises parse errors (evidence: `parser.py`)
- CLI runner → AST interpreter: executes AST (evidence: `araiwa.py`)
- AST interpreter → AST nodes: dispatches AST nodes (evidence: `interpreter.py`)
- AST interpreter → Lexical scopes: manages bindings (evidence: `interpreter.py`)
- AST interpreter → Value and trap rules: checks values (evidence: `interpreter.py`)
- AST interpreter → Interactive I/O: reads input and prints (evidence: `interpreter.py`)
- AST interpreter → Module declarations: records imports (evidence: `interpreter.py`)
- AST interpreter → Language errors: raises runtime errors (evidence: `interpreter.py`)
- CLI runner → Terminal: reports results (evidence: `araiwa.py`)
- Interactive I/O → Terminal: reads and writes (evidence: `README.md`)
