# robo-monk/krama architecture

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

- Interactive diagram: https://gitdiagram.com/robo-monk/krama
- Repository: https://github.com/robo-monk/krama

## Overview

##### Project Type Analysis
This is a programming language implementation project that includes both a compiler and interpreter. The project is written in C and appears to be a toy programming language named Krama with its own syntax and features.

##### Main Components

A. Frontend Layer:
- Tokenizer (src/frontend/tokeniser.c)
- Parser (src/frontend/parser.c)
- Keyword and Operator handling (src/frontend/KeywordToken.c, Op.c)

B. Middle Layer:
- Abstract Syntax Tree (src/ast/AbstractSyntaxTree.c)
- AST Evaluator (src/ast/AbstractSyntaxTreeEvaluator.c)
- Type Inference System (src/compiler/inference.c)

C. Backend Layer:
- C Compiler (src/compiler/CCompiler.c)
- Interpreter (src/interpreter/Interpreter.c)

D. Support Systems:
- HashMap Implementation (src/hashmap/hashmap.c)
- Utilities (src/utils.c)

**[Input Krama Code]**
- ↓

- Frontend     |

- Tokenizer | |

- ↓       |

- Parser  | |

- ↓

- Middle Layer  |

- AST    | |

- ↓       |

- Inference | |

- ↓

- Backend      |

- C Compiler| |

- ↓       |

- Interpreter | |

- ↓
**[Output (C Code/Execution)]**

##### Important Details

a. Data Flow Paths:
- How source code flows from tokenization through parsing
- How AST is generated and transformed
- Bifurcation between compilation and interpretation paths

b. Key Processes:
- Type inference system interaction
- AST evaluation steps
- Compilation to C code process
- Interpretation process

c. Component Interactions:
- How the hashmap is used across components
- Where type checking occurs
- Error handling flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        KramaCode[Krama Source Code]
    end

    subgraph Frontend
        Tokenizer["Tokenizer"]:::frontend
        Parser["Parser"]:::frontend
        KeywordHandler["Keyword Handler"]:::frontend
        OpHandler["Operator Handler"]:::frontend
        LiteralHandler["Literal Type Handler"]:::frontend
    end

    subgraph MiddleLayer
        AST["Abstract Syntax Tree"]:::middle
        ASTEval["AST Evaluator"]:::middle
        TypeInference["Type Inference System"]:::middle
    end

    subgraph Backend
        CCompiler["C Compiler"]:::backend
        Interpreter["Interpreter"]:::backend
        CompilerInterface["Main Compiler Interface"]:::backend
    end

    subgraph Support
        HashMap["HashMap Implementation"]:::support
        Utils["Utilities"]:::support
    end

    subgraph Output
        CompiledCode["Compiled C Code"]
        ExecutionResult["Execution Result"]
    end

    %% Connections
    KramaCode --> Tokenizer
    Tokenizer --> Parser
    Parser --> AST
    AST --> TypeInference
    TypeInference --> CCompiler
    TypeInference --> Interpreter
    CCompiler --> CompiledCode
    Interpreter --> ExecutionResult
    
    %% Support System Connections
    HashMap -.-> AST
    HashMap -.-> Interpreter
    Utils -.-> Parser
    Utils -.-> CCompiler
    
    %% Frontend Interconnections
    Parser --- KeywordHandler
    Parser --- OpHandler
    Parser --- LiteralHandler
    
    %% Middle Layer Interconnections
    AST --- ASTEval
    
    %% Backend Interconnections
    CCompiler --- CompilerInterface

    %% Styling
    classDef frontend fill:#a8d1f0
    classDef middle fill:#90EE90
    classDef backend fill:#FFB347
    classDef support fill:#DDA0DD
    
    %% Click Events
    click Tokenizer "https://github.com/robo-monk/krama/blob/main/src/frontend/tokeniser.c"
    click Parser "https://github.com/robo-monk/krama/blob/main/src/frontend/parser.c"
    click KeywordHandler "https://github.com/robo-monk/krama/blob/main/src/frontend/KeywordToken.c"
    click OpHandler "https://github.com/robo-monk/krama/blob/main/src/frontend/Op.c"
    click AST "https://github.com/robo-monk/krama/blob/main/src/ast/AbstractSyntaxTree.c"
    click ASTEval "https://github.com/robo-monk/krama/blob/main/src/ast/AbstractSyntaxTreeEvaluator.c"
    click TypeInference "https://github.com/robo-monk/krama/blob/main/src/compiler/inference.c"
    click CCompiler "https://github.com/robo-monk/krama/blob/main/src/compiler/CCompiler.c"
    click Interpreter "https://github.com/robo-monk/krama/blob/main/src/interpreter/Interpreter.c"
    click HashMap "https://github.com/robo-monk/krama/blob/main/src/hashmap/hashmap.c"
    click Utils "https://github.com/robo-monk/krama/blob/main/src/utils.c"
    click LiteralHandler "https://github.com/robo-monk/krama/blob/main/src/frontend/LiteralType.c"
    click CompilerInterface "https://github.com/robo-monk/krama/blob/main/src/compiler/compiler.c"
```
