# dark-codex/horizon architecture

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

- Interactive diagram: https://gitdiagram.com/dark-codex/horizon
- Repository: https://github.com/dark-codex/horizon

## Overview

##### Main Components

a) Lexical Analysis Layer
- Lexer component (src/lexer)
- Token handling (src/token and src/token_type)

b) Parsing Layer
- Parser component (src/parser)
- AST (Abstract Syntax Tree) representation (src/parser/ast)
- Reference the grammar file (src/parser/grammar.gr)

c) Error Handling System
- Error management component (src/errors)

d) Core Infrastructure
- Entry point system (src/entry)
- System (src/defines)
- Colorization support (src/colorize)

e) Utility Layer
- File handling (src/misc/file)
- Memory management
- Support utilities

##### Component Relationships

**Input Source (.hr files)**
- ↓
**[Lexical Analysis]**
- Token Generation
- Token Classification
- ↓
**[Parsing]**
- AST Construction
- Grammar Rules
- ↓
**[Semantic Analysis]**
- Type Checking
- ↓
**[Code Generation/Execution]**

##### Important Architectural Elements to Highlight

- The dependency management system (deps/ directory)
- Custom implementations of core data structures (pair, sptr, string, vector)
- The error handling system's integration points
- The colorization system for output formatting
- File handling and management system

##### Technical Details

- Build system integration (CMake)
- Development tools configuration (.clang-format, .clang-tidy)
- CI/CD pipeline (.github/workflows)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        SRC[Source Code]:::input
    end

    subgraph "Lexical Analysis"
        LEX[Lexer]:::core
        TOK[Token Handler]:::core
        TOKTYPE[Token Types]:::core
        
        LEX --> TOK
        TOK --> TOKTYPE
    end

    subgraph "Parsing"
        PAR[Parser]:::core
        AST[AST Builder]:::core
        GRAM[Grammar Rules]:::core
        
        PAR --> AST
        PAR --> GRAM
    end

    subgraph "Core Infrastructure"
        ENTRY[Entry Point]:::core
        DEF[Define System]:::core
        DTYPE[Data Types]:::core
        COLOR[Colorization]:::core
        
        ENTRY --> DEF
        ENTRY --> DTYPE
        ENTRY --> COLOR
    end

    subgraph "Error Handling"
        ERR[Error Manager]:::error
    end

    subgraph "Utility Layer"
        FILE[File Handler]:::util
        MEM[Memory Manager]:::util
    end

    subgraph "Core Data Structures"
        SPTR[Smart Pointer]:::data
        STR[String]:::data
        VEC[Vector]:::data
        PAIR[Pair]:::data
    end

    subgraph "Build & Development"
        CMAKE[CMake]:::build
        CICD[CI/CD Pipeline]:::build
        FORMAT[Code Formatting]:::build
        LINT[Code Analysis]:::build
    end

    SRC --> LEX
    LEX --> PAR
    PAR --> ENTRY

    ERR -.-> LEX
    ERR -.-> PAR
    ERR -.-> ENTRY

    FILE -.-> LEX
    FILE -.-> PAR

    %% Component Mappings
    click LEX "https://github.com/Dark-CodeX/horizon/blob/main/src/lexer/lexer.hh"
    click TOK "https://github.com/Dark-CodeX/horizon/blob/main/src/token/token.hh"
    click TOKTYPE "https://github.com/Dark-CodeX/horizon/blob/main/src/token_type/token_type.hh"
    click PAR "https://github.com/Dark-CodeX/horizon/blob/main/src/parser/parser.hh"
    click AST "https://github.com/Dark-CodeX/horizon/blob/main/src/parser/ast/ast.hh"
    click GRAM "https://github.com/Dark-CodeX/horizon/blob/main/src/parser/grammar.gr"
    click ERR "https://github.com/Dark-CodeX/horizon/blob/main/src/errors/errors.hh"
    click ENTRY "https://github.com/Dark-CodeX/horizon/blob/main/src/entry/horizon.cc"
    click DEF "https://github.com/Dark-CodeX/horizon/blob/main/src/defines/defines.h"
    click DTYPE "https://github.com/Dark-CodeX/horizon/blob/main/src/defines/keywords_primary_data_types.h"
    click COLOR "https://github.com/Dark-CodeX/horizon/blob/main/src/colorize/colorize.h"
    click FILE "https://github.com/Dark-CodeX/horizon/blob/main/src/misc/file/file.hh"
    click MEM "https://github.com/Dark-CodeX/horizon/blob/main/src/misc/exit_heap_fail.hh"
    click SPTR "https://github.com/Dark-CodeX/horizon/blob/main/deps/sptr/sptr.hh"
    click STR "https://github.com/Dark-CodeX/horizon/blob/main/deps/string/string.hh"
    click VEC "https://github.com/Dark-CodeX/horizon/blob/main/deps/vector/vector.hh"
    click PAIR "https://github.com/Dark-CodeX/horizon/blob/main/deps/pair/pair.hh"
    click CMAKE "https://github.com/Dark-CodeX/horizon/blob/main/CMakeLists.txt"
    click CICD "https://github.com/Dark-CodeX/horizon/blob/main/.github/workflows/cmake-single-platform.yml"
    click FORMAT "https://github.com/Dark-CodeX/horizon/blob/main/.clang-format"
    click LINT "https://github.com/Dark-CodeX/horizon/blob/main/.clang-tidy"

    %% Styling
    classDef core fill:#2374ab
    classDef error fill:#ff4d4d
    classDef util fill:#95c623
    classDef data fill:#e9c46a
    classDef build fill:#ccc
    classDef input fill:#2a9d8f

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Error Handling]:::error
        L3[Utilities]:::util
        L4[Data Structures]:::data
        L5[Build Tools]:::build
        L6[Input]:::input
    end
```
