# sudokentucky/olc2_proyecto1_202100106 architecture

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

- Interactive diagram: https://gitdiagram.com/sudokentucky/olc2_proyecto1_202100106
- Repository: https://github.com/sudokentucky/olc2_proyecto1_202100106

## Overview

##### Main Components
- Frontend:
- Represents the user interface built in React/TypeScript.
- Contains components like the Code Editor, Error Table, AST Viewer, Symbol Table, Command Execution, and Console.
- Responsible for sending user input (code) to the backend and displaying results (errors, generated AST, and symbols).
- Backend:
- Developed in C# with ASP.NET Core.
- Hosts the API (with controllers such as Compile.cs) that processes user input.
- Contains the core interpretation pipeline using ANTLR: Lexical analysis, Syntax analysis, Semantic analysis, and AST generation.
- Houses the analyzer modules (Environment, SymbolTable, various Visitors, and AST generation via DOTgenerator) which are the heart of the interpreter.
- ANTLR/Grammar Files:
- Represented in the directories “client/.antlr” and “client/grammar” where the Lexer, Parser, and supporting grammar artifacts are generated.
- Play a central role in the translation pipeline.

##### Relationships and Data Flow
- Within the Backend, show the sequence of processing:
- The code input received by the Compile Controller.
- The invocation of the ANTLR-generated Lexers/Parsers.
- Use of the Analyzer components (including ErrorListener, Symbol Table, AST building, Visitor pattern implementations) to perform complete analysis.
- Generation of artifacts (error lists, symbol tables, AST in DOT format) which are then sent back to the frontend.
- From the Lexer/Parser modules to the AST generation component.
- From the AST to the Visitor implementations that traverse or execute the tree.

##### Important Architectural Patterns & Design Principles
- MVC/MVP-Like Separation: The frontend handles user interactions while the backend concentrates on business logic.
- Pipeline for Language Interpretation: Clearly segment the interpreter into stages (Lexical, Syntax, Semantic, AST Generation) and represent these as subcomponents within the backend.
- Use of Visitor Pattern: Emphasize the multiple “Visitor” classes in the Analyzer which systematically handle different elements of the language during tree traversal.

##### Relevant Technologies & Frameworks
- Frontend: React, TypeScript, Vite, TailwindCSS.
- Backend: C#, ASP.NET Core (including Middleware such as CORS and HTTPS redirection), ANTLR for parser generation.
- Communication is over HTTP/REST.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UserApp["User / Frontend Application"]:::frontend

    subgraph "Frontend"
        CodeEditor["Code Editor"]:::frontend
        ErrorTable["Error Table"]:::frontend
        ASTViewer["AST Viewer"]:::frontend
        SymbolTable["Symbol Table"]:::frontend
        CommandExec["Command Execution"]:::frontend
    end

    subgraph "Backend"
        AppEntry["Application Entry (Program.cs)"]:::backend
        CompileAPI["Compile API (Compile.cs)"]:::backend
        subgraph "Interpreter Pipeline"
            subgraph "Parsing Stage"
                ANTLRFiles["ANTLR Files"]:::antlr
                GrammarFiles["Grammar Files"]:::antlr
                LexSyn["Lexical/Syntax Analysis (Lexer/Parser)"]:::backend
            end
            subgraph "Semantic Analysis Stage"
                ErrorListener["Error Listener"]:::backend
                SymbolTableBuilder["Symbol Table"]:::backend
                VisitorHandlers["Visitor Handlers"]:::backend
                EnvironmentManager["Environment Manager"]:::backend
            end
            ASTGeneration["AST Generation (DOTgenerator & AST nodes)"]:::backend
        end
    end

    %% Frontend interactions
    UserApp -->|"interacts_with"| CodeEditor
    CodeEditor -->|"submits_code"| CompileAPI
    CommandExec -->|"triggers_request"| CompileAPI

    %% Backend processing flow
    CompileAPI -->|"invokes"| LexSyn
    ANTLRFiles -->|"provides_tokens"| LexSyn
    GrammarFiles -->|"provides_grammar"| LexSyn
    LexSyn -->|"passes_to"| ErrorListener
    LexSyn -->|"passes_to"| SymbolTableBuilder
    LexSyn -->|"passes_to"| VisitorHandlers
    LexSyn -->|"passes_to"| EnvironmentManager
    ErrorListener -->|"generates_AST"| ASTGeneration
    SymbolTableBuilder -->|"contributes_to"| ASTGeneration
    VisitorHandlers -->|"contributes_to"| ASTGeneration
    EnvironmentManager -->|"contributes_to"| ASTGeneration

    %% Responses sent back to Frontend
    ASTGeneration -->|"displays_AST"| ASTViewer
    ErrorListener -->|"returns_errors"| ErrorTable
    SymbolTableBuilder -->|"returns_symbols"| SymbolTable

    %% Click Events for Frontend Components
    click CodeEditor "https://github.com/sudokentucky/olc2_proyecto1_202100106/blob/main/frontend/src/components/FileInput.tsx"
    click ErrorTable "https://github.com/sudokentucky/olc2_proyecto1_202100106/blob/main/frontend/src/components/ErrorTable.tsx"
    click ASTViewer "https://github.com/sudokentucky/olc2_proyecto1_202100106/blob/main/frontend/src/components/AST.tsx"
    click SymbolTable "https://github.com/sudokentucky/olc2_proyecto1_202100106/blob/main/frontend/src/components/SymbolTable.tsx"
    click CommandExec "https://github.com/sudokentucky/olc2_proyecto1_202100106/blob/main/frontend/src/components/CommandExecution.tsx"

    %% Click Events for Backend Components
    click CompileAPI "https://github.com/sudokentucky/olc2_proyecto1_202100106/blob/main/client/Controllers/Compile.cs"
    click AppEntry "https://github.com/sudokentucky/olc2_proyecto1_202100106/blob/main/client/Program.cs"
    click ASTGeneration "https://github.com/sudokentucky/olc2_proyecto1_202100106/tree/main/client/Analyzer/AST"
    click ErrorListener "https://github.com/sudokentucky/olc2_proyecto1_202100106/blob/main/client/Analyzer/ErrorListener.cs"
    click SymbolTableBuilder "https://github.com/sudokentucky/olc2_proyecto1_202100106/blob/main/client/Analyzer/SymbolTable.cs"
    click VisitorHandlers "https://github.com/sudokentucky/olc2_proyecto1_202100106/tree/main/client/Analyzer/Visitors"
    click EnvironmentManager "https://github.com/sudokentucky/olc2_proyecto1_202100106/blob/main/client/Analyzer/Environment.cs"

    %% Click Events for ANTLR and Grammar Files
    click ANTLRFiles "https://github.com/sudokentucky/olc2_proyecto1_202100106/blob/main/client/.antlr"
    click GrammarFiles "https://github.com/sudokentucky/olc2_proyecto1_202100106/tree/main/client/grammar"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef antlr fill:#e2e3e5,stroke:#383d41,stroke-width:2px;
```
