# 3l0c/wk architecture

> Architecture diagram of the GitHub repository 3l0c/wk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/3l0c/wk
- Repository: https://github.com/3l0c/wk

## Overview

##### Main Components Overview
The system should be divided into these primary components:

a) Core Components:
- Compiler System
- Runtime System
- Common Utilities
- Configuration System

b) Backends:
- X11 Backend
- Wayland Backend

##### Input Processing Layer
- WKS File Parser
- Preprocessor
- Scanner
- Token Handler
- Piece Table Manager

##### Runtime Layer
- Window Management
- Cairo Graphics Engine
- Backend-specific Display Handlers
- Event Processing System

##### Common Utilities Layer
- Memory Management
- Debug System
- String Handling
- Key Chord Processing
- Menu Management

##### Component Relationships

**[Input Sources] -> [Compiler System]**

- v
- [Common Utilities]

- v                    v
**[Configuration] -> [Runtime System]**

- v
- [Display Backends]

##### Specific Implementation Details

Key architectural elements:

**[WKS Parser]**

- v
**[Piece Table] -> [Token Processing] -> [Compiler]**

- v
**[Preprocessor] -> [Include Resolution]**

- v
**[Runtime Manager]**

- > [X11 Backend]

- v
- [X11 Window]

- > [Wayland Backend]

- v
- [Layer Shell]

##### Important Notes

- Separation between the compiler and runtime systems
- Parallel nature of X11 and Wayland backends
- Common utilities shared across components
- Configuration system's influence on all components
- Preprocessor's role in handling includes and macros

##### Technical Details

- Cairo graphics integration points
- Memory management flow
- Debug system connections
- Key chord processing pipeline
- Window management hierarchy

## Diagram (Mermaid)

```mermaid
graph TB
    %% Main Sections
    subgraph Input ["Input Processing Layer"]
        WKSParser["WKS File Parser"]
        Preprocessor["Preprocessor"]:::critical
        Scanner["Scanner"]
        TokenHandler["Token Handler"]
        PieceTable["Piece Table Manager"]
    end

    subgraph Runtime ["Runtime Layer"]
        WindowMgmt["Window Management"]
        CairoEngine["Cairo Graphics Engine"]
        EventSystem["Event Processing"]
        
        subgraph Backends ["Display Backends"]
            X11["X11 Backend"]
            Wayland["Wayland Backend"]
        end
    end

    subgraph Common ["Common Utilities Layer"]
        MemoryMgmt["Memory Management"]
        DebugSys["Debug System"]
        StringHandler["String Handling"]
        KeyChordProc["Key Chord Processing"]
        MenuMgmt["Menu Management"]
    end

    subgraph Config ["Configuration System"]
        ConfigDef["Configuration Definitions"]
        KeyChordDef["Key Chord Definitions"]
    end

    %% Relationships
    WKSParser --> Preprocessor
    Preprocessor --> Scanner
    Scanner --> TokenHandler
    TokenHandler --> PieceTable
    PieceTable --> EventSystem

    ConfigDef --> WindowMgmt
    KeyChordDef --> KeyChordProc

    WindowMgmt --> X11
    WindowMgmt --> Wayland
    CairoEngine --> X11
    CairoEngine --> Wayland

    MemoryMgmt --> EventSystem
    KeyChordProc --> EventSystem
    MenuMgmt --> WindowMgmt
    DebugSys --> EventSystem
    StringHandler --> KeyChordProc

    %% Styling
    classDef core fill:#2374ab
    classDef display fill:#2a9d8f
    classDef config fill:#e9c46a
    classDef utility fill:#95a5a6
    classDef critical fill:#e76f51

    class WKSParser,Scanner,TokenHandler,PieceTable core
    class WindowMgmt,CairoEngine,X11,Wayland display
    class ConfigDef,KeyChordDef config
    class MemoryMgmt,DebugSys,StringHandler,KeyChordProc,MenuMgmt utility
    class Preprocessor critical

    %% Click Events
    click Preprocessor "https://github.com/3L0C/wk/blob/master/src/compiler/preprocessor.h"
    click Scanner "https://github.com/3L0C/wk/blob/master/src/compiler/scanner.h"
    click TokenHandler "https://github.com/3L0C/wk/blob/master/src/compiler/token.h"
    click PieceTable "https://github.com/3L0C/wk/blob/master/src/compiler/piece_table.h"
    click WindowMgmt "https://github.com/3L0C/wk/blob/master/src/runtime/x11/window.h"
    click CairoEngine "https://github.com/3L0C/wk/blob/master/src/runtime/cairo.h"
    click X11 "https://github.com/3L0C/wk/tree/master/src/runtime/x11/"
    click Wayland "https://github.com/3L0C/wk/tree/master/src/runtime/wayland/"
    click MemoryMgmt "https://github.com/3L0C/wk/blob/master/src/common/memory.h"
    click DebugSys "https://github.com/3L0C/wk/blob/master/src/common/debug.h"
    click StringHandler "https://github.com/3L0C/wk/blob/master/src/common/string.h"
    click KeyChordProc "https://github.com/3L0C/wk/blob/master/src/common/key_chord.h"
    click MenuMgmt "https://github.com/3L0C/wk/blob/master/src/common/menu.h"
    click ConfigDef "https://github.com/3L0C/wk/blob/master/config/config.def.h"
    click KeyChordDef "https://github.com/3L0C/wk/blob/master/config/key_chords.def.h"
```
