# vuhuuquocbao/reverse architecture

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

- Interactive diagram: https://gitdiagram.com/vuhuuquocbao/reverse
- Repository: https://github.com/vuhuuquocbao/reverse

## Overview

##### Project type and purpose
- Looking at the file structure we see two main “Core” areas (Core and Core2) and two “Execute” projects. The “Core” directories contain elements such as parsers, scanners, token management, AST visitors (e.g., AstPrinter, Interpreter), errors, and environment handling. In “Core2” we see implementation files for a Virtual Machine, Chunk management, value arrays, and related enums/utilities. This suggests the project implements some kind of interpreter or a language runtime – likely for a domain-specific language or a reverse-engineering tool – with one branch (Core) handling high-level interpretation via an Abstract Syntax Tree and visitor pattern, and another branch (Core2) providing a lower-level Virtual Machine implementation.
- The “Execute” and “Execute2” directories define entry points (Program.cs), likely offering alternative execution models (direct interpretation versus VM execution).

##### File structure to extract architectural insights
- The “Core” directory is organized by functionality:
- Class, Function, Script, Enums, and Visitor subdirectories. This suggests separation of concerns among class representations, function call abstractions (IReverseCallable, ReverseCallable), script parsing (AstTreeGenerator), and AST or visitor patterns.
- Files like Parser.cs, Scanner.cs, and Token.cs indicate a full lexer-parser front-end for language processing.
- The “Core2” directory has a similar but distinct approach focused on the runtime level:
- VirtualMachine.cs, Chunk.cs, and MemoryUtils.cs clearly point to a bytecode or low-level execution model.
- The separation into “Enums/Common.cs” and “Enums/InterpretResult.cs” implies detailed handling of runtime execution statuses.
- The existence of multiple .csproj files and a solution file (“Reverse.sln”) confirms a multi-project solution, reinforcing discrete modules that interact through defined boundaries.

a. Main Components (nodes):
- Source Code Input / Script: Represents the input being processed.
- Lexical Analysis: Scanner and Token components (Core/Scanner.cs, Core/Token.cs).
- Parsing Layer: Parser.cs and AST Generation (including AstTreeGenerator.cs in the Script folder).
- AST and Visitor Framework: AST nodes, IVisitor interface, AstPrinter and Interpreter in the Visitor folder.
- Runtime Environment: Environment, Exception, Expression, and Extension classes (handling execution context).
- Virtual Machine Layer: Managed under Core2 with components like VirtualMachine, Chunk, ValueArray, and utilities.
- Execution Entry Points: Execute/Program.cs and Execute2/Program.cs that serve as the starting nodes for processing.
- Supporting Components: Enums (both in Core and Core2) for managing token types, common values, and interpretation results.

b. Relationships and interactions:
- One branch should show the Interpreter (visitor mode) processing attached to environment management and runtime exception handling.
- A parallel branch should map the processed AST or compiled bytecode being sent to the Virtual Machine layer in Core2.
- Both branches eventually result in the execution of code and generation of outputs.

c. Architectural patterns and design principles:
- The use of an AST combined with a Visitor pattern (clear in the Visitor directory) indicates modular separation of operations (printing, interpreting) over the language’s syntax tree.
- The presence of a Virtual Machine as a separate module in Core2 suggests a layered approach where the language might support both direct interpretation and bytecode execution.
- Separation into distinct projects (Core, Core2, Execute, Execute2) underscores a modular design, which could support plug-and-play of different execution strategies.

d. Technologies, frameworks, or libraries:
- Specific patterns like the Visitor pattern, environment handling for runtime support, and low-level VM operation should be explicitly noted.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Entry Layer"
        E1["Entry Points"]:::entry
    end

    subgraph "Front-end Parsing"
        LA["Lexical Analyzer"]:::frontend
        PA["Parser & AST Generator"]:::frontend
    end

    subgraph "Interpretation Path"
        AV["AST & Visitor Framework"]:::interpreter
        RE["Runtime Environment"]:::interpreter
    end

    subgraph "Virtual Machine Path"
        VM["Bytecode Engine/ Virtual Machine"]:::vmstyle
    end

    subgraph "Supporting Components"
        SC["Callable & Class Representation"]:::support
        TE["Token & Enum Definitions"]:::support
    end

    %% Relationships
    E1 -->|"triggers"| LA
    LA -->|"generatesTokens"| PA
    PA -->|"createsAST"| AV
    AV -->|"executesUsing"| RE
    PA -->|"compilesTo"| VM
    LA ---|"uses"| TE
    AV ---|"reliesOn"| SC

    %% Click Events for Entry Points
    click E1 "https://github.com/vuhuuquocbao/reverse/blob/main/Execute/Program.cs"
    click E1 "https://github.com/vuhuuquocbao/reverse/blob/main/Execute2/Program.cs"

    %% Click Events for Lexical Analysis
    click LA "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Core/Scanner.cs"
    click LA "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Core/Token.cs"

    %% Click Events for Parsing Layer
    click PA "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Core/Parser.cs"
    click PA "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Script/AstTreeGenerator.cs"

    %% Click Events for AST & Visitor Framework
    click AV "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Core/Visitor/IVisitor.cs"
    click AV "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Core/Visitor/AstPrinter.cs"
    click AV "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Core/Visitor/Interpreter.cs"

    %% Click Events for Runtime Environment
    click RE "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Core/Environment.cs"
    click RE "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Core/Exception.cs"
    click RE "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Core/Expression.cs"
    click RE "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Core/Extension.cs"

    %% Click Events for Virtual Machine Layer
    click VM "https://github.com/vuhuuquocbao/reverse/blob/main/Core2/Core/VirtualMachine.cs"
    click VM "https://github.com/vuhuuquocbao/reverse/blob/main/Core2/Core/Chunk.cs"
    click VM "https://github.com/vuhuuquocbao/reverse/blob/main/Core2/Core/ValueArray.cs"
    click VM "https://github.com/vuhuuquocbao/reverse/blob/main/Core2/Enums/Common.cs"
    click VM "https://github.com/vuhuuquocbao/reverse/blob/main/Core2/Enums/InterpretResult.cs"
    click VM "https://github.com/vuhuuquocbao/reverse/blob/main/Core2/Utils/MemoryUtils.cs"
    click VM "https://github.com/vuhuuquocbao/reverse/blob/main/Core2/Utils/ChunkUtils.cs"

    %% Click Events for Supporting Components
    click SC "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Function/IReverseCallable.cs"
    click SC "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Function/ReverseCallable.cs"
    click SC "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Class/ReverseClass.cs"
    click SC "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Class/ReverseInstance.cs"

    %% Click Events for Token & Enum Definitions
    click TE "https://github.com/vuhuuquocbao/reverse/blob/main/Core/Enums/TokenType.cs"

    %% Styles
    classDef entry fill:#FFD699,stroke:#CC6600,stroke-width:2px;
    classDef frontend fill:#B3D9FF,stroke:#003366,stroke-width:2px;
    classDef interpreter fill:#BFFFC9,stroke:#006600,stroke-width:2px;
    classDef vmstyle fill:#E6CCFF,stroke:#660099,stroke-width:2px;
    classDef support fill:#FFE680,stroke:#CC9900,stroke-width:2px;
```
