# doublecouponday/chunkus architecture

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

- Interactive diagram: https://gitdiagram.com/doublecouponday/chunkus
- Repository: https://github.com/doublecouponday/chunkus

## Overview

##### Main Components Structure

a) C Core (Image Processing)
- As the central component
- Submodules:
- Algorithm module (aggregating, pathfinding, splitting)
- Image handling (PNG, JPEG, SVG conversion)
- Utility services (error handling, logging)
- Chunkmap processing

b) Rust Interface (Discord Bot)
- As the top-level interface
- Include:
- Bot communication layer
- Core bindings/trampolines
- Command handling

c) C++ Debugging Interface
- As a separate debugging component
- Include:
- OpenGL visualization
- GUI components
- Texture handling

##### Component Relationships
- Data flow from Discord bot → C Core → SVG output
- Debug visualization path from C Core → C++ Debugger
- Interop/binding connections between languages

##### Specific Elements

- Blue rectangles: Core processing components
- Green rectangles: Interface components
- Yellow diamonds: Entry points
- Red rectangles: Error handling/logging
- Purple rectangles: File I/O operations
- Gray rectangles: Testing components

##### Technical Details to Highlight
- SIMD instruction usage in C core
- Static linking between components
- Environment variable dependencies
- OpenGL debugging visualization
- File format conversions (PNG/JPEG → SVG)

##### Layered Architecture
In layers:
**Top: User Interface Layer (Discord Bot, Debug GUI)**
**↓**
**Middle: Processing Layer (Core Algorithm)**
**↓**
**Bottom: File I/O Layer (Image Processing)**

##### Additional Elements
Notes for:
- Required environment variables
- Hardware requirements (Intel MMX)
- Build system dependencies
- Testing infrastructure

- The modular nature of the three main components
- The clear separation between processing core and interfaces
- The debug visualization capabilities
- The image processing pipeline

- Special symbols
- Environment requirements

Keep the abstraction level focused on the major components while showing the critical interactions between the three main parts (C, C++, and Rust) of the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Legend"
        L1[Interface Components]:::interface
        L2[Core Processing]:::core
        L3[File Operations]:::fileio
        L4[Error/Logging]:::error
        L5[Testing]:::testing
        L6[Entry Points]:::entry
    end

    subgraph "Rust Interface Layer"
        Bot["Bot Communication"]:::interface
        click Bot "https://github.com/doublecouponday/chunkus/blob/master/Rust_part/src/bot.rs"
        CoreBindings["Core Bindings"]:::interface
        click CoreBindings "https://github.com/doublecouponday/chunkus/blob/master/Rust_part/src/core.rs"
        Trampolines["Trampolines"]:::interface
        click Trampolines "https://github.com/doublecouponday/chunkus/blob/master/Rust_part/src/trampoline.rs"
        RustEntry["Rust Entry Point"]:::entry
        click RustEntry "https://github.com/doublecouponday/chunkus/blob/master/Rust_part/src/main.rs"
        RustTests["Rust Tests"]:::testing
        click RustTests "https://github.com/doublecouponday/chunkus/tree/master/Rust_part/tests/"
    end

    subgraph "C Core Layer"
        subgraph "Algorithm Module"
            Aggregating["Aggregating"]:::core
            click Aggregating "https://github.com/doublecouponday/chunkus/blob/master/C_part/src/algorithm/aggregating.c"
            Pathfinding["Pathfinding"]:::core
            click Pathfinding "https://github.com/doublecouponday/chunkus/blob/master/C_part/src/algorithm/pathfinding.c"
            Splitting["Splitting"]:::core
            click Splitting "https://github.com/doublecouponday/chunkus/blob/master/C_part/src/algorithm/splitting.c"
        end

        subgraph "Image Processing"
            ImageCore["Core Image Processing"]:::core
            click ImageCore "https://github.com/doublecouponday/chunkus/blob/master/C_part/src/image.c"
            Chunkmap["Chunkmap Processing"]:::core
            click Chunkmap "https://github.com/doublecouponday/chunkus/blob/master/C_part/src/chunkmap.c"
            
            subgraph "Format Handlers"
                PNG["PNG Handler"]:::fileio
                click PNG "https://github.com/doublecouponday/chunkus/blob/master/C_part/src/imagefile/pngfile.c"
                JPEG["JPEG Handler"]:::fileio
                click JPEG "https://github.com/doublecouponday/chunkus/blob/master/C_part/src/imagefile/jpegfile.c"
                SVG["SVG Output"]:::fileio
                click SVG "https://github.com/doublecouponday/chunkus/blob/master/C_part/src/imagefile/svg.c"
            end
        end

        subgraph "Utility Services"
            ErrorHandler["Error Handling"]:::error
            click ErrorHandler "https://github.com/doublecouponday/chunkus/blob/master/C_part/src/utility/error.c"
            Logger["Logging"]:::error
            click Logger "https://github.com/doublecouponday/chunkus/blob/master/C_part/src/utility/logger.c"
        end

        CEntry["C Entry Point"]:::entry
        click CEntry "https://github.com/doublecouponday/chunkus/blob/master/C_part/src/entrypoint.c"
        CTests["C Tests"]:::testing
        click CTests "https://github.com/doublecouponday/chunkus/tree/master/C_part/test/"
    end

    subgraph "C++ Debug Layer"
        OpenGL["OpenGL Rendering"]:::interface
        click OpenGL "https://github.com/doublecouponday/chunkus/blob/master/Cpp_part/src/gl.cpp"
        GUI["GUI Components"]:::interface
        click GUI "https://github.com/doublecouponday/chunkus/blob/master/Cpp_part/src/gui_data.cpp"
        Texture["Texture Handling"]:::interface
        click Texture "https://github.com/doublecouponday/chunkus/blob/master/Cpp_part/src/texture.cpp"
        Render["Rendering System"]:::interface
        click Render "https://github.com/doublecouponday/chunkus/blob/master/Cpp_part/src/render.cpp"
        CppEntry["C++ Debug Entry"]:::entry
        click CppEntry "https://github.com/doublecouponday/chunkus/blob/master/Cpp_part/src/main.cpp"
    end

    %% Connections
    Bot --> CoreBindings
    CoreBindings --> Trampolines
    Trampolines --> CEntry
    RustEntry --> Bot

    CEntry --> ImageCore
    ImageCore --> Chunkmap
    ImageCore --> Aggregating
    ImageCore --> Pathfinding
    ImageCore --> Splitting

    PNG --> ImageCore
    JPEG --> ImageCore
    ImageCore --> SVG

    ErrorHandler --> Logger
    ImageCore --> ErrorHandler

    ImageCore --> OpenGL
    OpenGL --> GUI
    OpenGL --> Texture
    OpenGL --> Render
    CppEntry --> OpenGL

    classDef interface fill:#90EE90
    classDef core fill:#87CEEB
    classDef fileio fill:#DDA0DD
    classDef error fill:#FFB6C1
    classDef testing fill:#D3D3D3
    classDef entry fill:#FFD700
```
