# sanjusree09/own-compiler architecture

> Architecture diagram of the GitHub repository sanjusree09/own-compiler, 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/sanjusree09/own-compiler
- Repository: https://github.com/sanjusree09/own-compiler

## Overview

##### Main Components
- Input (Source Code): This represents the user’s source code that needs to be compiled or interpreted.
- Lexer Component (lexer.js): Responsible for reading the input source code and splitting it into tokens.
- Interpreter Component (interpreter.js): Acts on the tokens—either parsing them into a form suitable for execution or directly interpreting/compiling them.
- Entry Point (main.js): The main script that ties everything together by invoking the lexer and interpreter. It orchestrates the compilation/interpreter process.
- The Project Metadata and Package Configuration: Represented by package.json and package-lock.json, indicating dependencies and environmental setup (though not part of runtime flow, they are essential for build/deployment).

##### Relationships and Interactions
- Flow starts at the Entry Point (main.js) which receives the source code.
- main.js then calls the Lexer (lexer.js) to tokenize the source code.
- The tokens output by the Lexer are fed into the Interpreter (interpreter.js) for processing.
- Finally, the Interpreter produces the result (this could be executed output, bytecode, or another intermediate representation).
- Dependencies and runtime configurations from package.json manage the environment.

##### Architectural Patterns
- Modular Component Design: Each file (lexer.js, interpreter.js, main.js) is organized by function, demonstrating separation of concerns.
- Pipeline Data Flow: The design follows a linear data processing pipeline—from source input to tokens to interpretation.
- Emphasis on simplicity: With minimal files and clear responsibility boundaries, the project adheres to a minimalist compiler architecture.

- At the top or left side, mark “User Source Code Input.”
- Optionally, include a note that package.json and package-lock.json support the necessary dependencies for running this system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Group
    Input["User Source Code Input"] 
    %% Orchestrator
    MainEntry["Main Entry (main.js)"]
    %% Pipeline Components
    Lexer["Lexer (lexer.js)"]
    Interpreter["Interpreter (interpreter.js)"]
    Output["Compilation Result"]
    %% Configuration Components
    Pkg["package.json"]
    PkgLock["package-lock.json"]

    %% Data Flow
    Input -->|"tokenizes"| Lexer
    Lexer -->|"tokens"| Interpreter
    Interpreter -->|"result"| Output

    %% Orchestration Flow
    MainEntry -->|"calls"| Lexer
    MainEntry -->|"calls"| Interpreter

    %% Configuration Dependency
    Pkg -->|"configures"| MainEntry
    PkgLock -->|"configures"| MainEntry

    %% Click Events
    click MainEntry "https://github.com/sanjusree09/own-compiler/blob/main/main.js"
    click Lexer "https://github.com/sanjusree09/own-compiler/blob/main/lexer.js"
    click Interpreter "https://github.com/sanjusree09/own-compiler/blob/main/interpreter.js"
    click Pkg "https://github.com/sanjusree09/own-compiler/blob/main/package.json"
    click PkgLock "https://github.com/sanjusree09/own-compiler/blob/main/package-lock.json"

    %% Styles
    classDef input fill:#F9E79F,stroke:#D68910,stroke-width:2px;
    classDef main fill:#F7DC6F,stroke:#B7950B,stroke-width:2px;
    classDef lexer fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef interpreter fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef output fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef config fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;

    %% Assign Classes
    class Input input;
    class MainEntry main;
    class Lexer lexer;
    class Interpreter interpreter;
    class Output output;
    class Pkg,PkgLock config;
```
