# mikhailwahib/ra architecture

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

- Interactive diagram: https://gitdiagram.com/mikhailwahib/ra
- Repository: https://github.com/mikhailwahib/ra

## Overview

##### Project Type & Purpose
- The project is an interpreted programming language called “Ra,” built in Go.
- Its purpose is to demonstrate language development by providing components such as a lexer, parser, evaluator, and a REPL. It is intended for learning and experimentation (not production-grade).

##### Analyzing the File Structure
- The top-level organization splits largely into two parts:
- The “docs” directory holds documentation built with Docusaurus, including configuration, static assets, and a full documentation site for the language (e.g., basic syntax, control flow, etc.).
- The “src” directory contains the core language implementation. It includes subfolders for:
▸ ast – Abstract Syntax Tree definitions and tests.
▸ evaluator – The interpreter’s evaluation logic with builtins and test cases.
▸ lexer – Token generation and testing modules.
▸ parser – Parsing logic for converting tokens to AST with associated tests.
▸ object – Representation of language objects and environments.
▸ repl – Implementation of the interactive Read-Eval-Print Loop.
▸ examples – Sample Ra source files.
- Other files like “ra.go” and “go.mod” indicate entry-point code and dependency management.

##### Main Components of the System
a. Input Source Code:
- Examples or interactive input via the REPL.
b. Lexer:
- Tokenizes raw code into tokens.
- Files: src/lexer/lexer.go, lexer_test.go.
c. Parser:
- Converts tokens into an AST.
- Files: src/parser/parser.go, parser_test.go.
d. AST:
- Data structures that model the code’s syntax.
- Files: src/ast/ast.go, ast_test.go.
e. Evaluator:
- Walks through the AST and evaluates expressions.
- Files: src/evaluator/evaluator.go and evaluator tests.
f. Object System & Environment:
- Manages runtime objects and variable bindings.
- Files: src/object/object.go, environment.go.
g. REPL:
- Provides an interactive shell for execution.
- Files: src/repl/repl.go.
h. Documentation:
- Visualization and usage guidelines with Docusaurus (for external viewers).

##### Relationships and Interactions
- Input (via file execution or REPL) → Lexer → Parser → AST creation → Evaluator → Output/Result.
- How tokens flow from the lexer into the parser, and how the AST is used by the evaluator.
- REPL which sits on top of this evaluation pipeline, providing an interactive interface.
- Optionally, show testing components (unit tests for lexer, parser, evaluator, etc.) as verification points.

##### Architectural Design Patterns & Principles
- Modular design: Each component (lexer, parser, AST, evaluator, REPL) is organized in its own package.
- Separation of concerns: The responsibilities of tokenizing, parsing, and evaluating are clearly separated.
- Extensibility & Testing: Several test files (.go tests in ast, lexer, parser, and evaluator) serve as modular checkpoints for each component.
- For the documentation system (Docusaurus), a clear separation between the user documentation and code is maintained.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Methods Subgraph
    subgraph "Input Methods"
        EX["Examples"]:::input
        RE["REPL"]:::input
    end

    %% Main Processing Pipeline
    EX -->|"sends_code"| LEX["Lexer: Tokenization"]:::core
    RE -->|"sends_code"| LEX
    LEX -->|"produces_tokens"| PAR["Parser: Syntax_Tree_Construction"]:::core
    PAR -->|"generates_AST"| AST["AST: Abstract_Syntax_Tree"]:::core
    AST -->|"traversed_by"| EVAL["Evaluator: Evaluation"]:::core
    EVAL -->|"uses"| OS["Object System"]:::core
    OS -.->|"coupled_with"| ENV["Environment"]:::core

    %% Testing Modules (dashed connections)
    LEX ---|"tests" | LTEST["Lexer Tests"]:::test
    PAR ---|"tests" | PTEST["Parser Tests"]:::test
    AST ---|"tests" | ATEST["AST Tests"]:::test
    EVAL ---|"tests" | ETEST["Evaluator Tests"]:::test

    %% Documentation Component (external)
    DOC["Documentation (Docusaurus)"]:::documentation

    %% Styles
    classDef input fill:#D8E8FF,stroke:#0E639C,stroke-width:2px;
    classDef core fill:#C6EFCE,stroke:#006100,stroke-width:2px;
    classDef test fill:#FFF2CC,stroke:#9C6500,stroke-dasharray:5,stroke-width:2px;
    classDef documentation fill:#F4CCCC,stroke:#A61717,stroke-width:2px;

    %% Click Events
    click EX "https://github.com/mikhailwahib/ra/tree/master/src/examples"
    click RE "https://github.com/mikhailwahib/ra/blob/master/src/repl/repl.go"
    click LEX "https://github.com/mikhailwahib/ra/blob/master/src/lexer/lexer.go"
    click LTEST "https://github.com/mikhailwahib/ra/blob/master/src/lexer/lexer_test.go"
    click PAR "https://github.com/mikhailwahib/ra/blob/master/src/parser/parser.go"
    click PTEST "https://github.com/mikhailwahib/ra/blob/master/src/parser/parser_test.go"
    click AST "https://github.com/mikhailwahib/ra/blob/master/src/ast/ast.go"
    click ATEST "https://github.com/mikhailwahib/ra/blob/master/src/ast/ast_test.go"
    click EVAL "https://github.com/mikhailwahib/ra/blob/master/src/evaluator/evaluator.go"
    click ETEST "https://github.com/mikhailwahib/ra/blob/master/src/evaluator/evaluator_test.go"
    click OS "https://github.com/mikhailwahib/ra/blob/master/src/object/object.go"
    click ENV "https://github.com/mikhailwahib/ra/blob/master/src/object/environment.go"
    click DOC "https://github.com/mikhailwahib/ra/tree/master/docs"
```
