# mntone/inknit architecture

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

- Interactive diagram: https://gitdiagram.com/mntone/inknit
- Repository: https://github.com/mntone/inknit

## Overview

##### Project type and purpose
- This is an open-source, portable C library (“inknit”) providing high-performance 2D graphics (1bpp–4bpp) for embedded systems.
- It offers a consistent drawing API, template-based code generation, cross-platform abstraction, desktop testing, and benchmarks.

##### File structure
- Top-level directories and files
- CMakeLists.txt & cmake/: Build logic, toolchain definitions, scripts for generating code and configuring compilers.
- scripts/: Shell helpers (copying DLLs, debug wrappers).
- benchmarks/: C++20 benchmark executables, measurement utilities, platform simulators.
- src/inknit/: Core C implementation
– inc/inknit/: Public headers
– shared/: Common helpers (draw_line, helpers.h)
– templates/: .c.in/.h.in templates for code‐generation of drawing routines
– x1, x1lsb, x2, x2lsb, x4, x4lsb/: Bit-depth specific optimized backends in C/assembly
- src/inknit_cxx/: C++ wrapper API (drawable classes, format implementations)
- tests/inknit/: Unit tests using doctest, linking core C library and C++ wrapper
- Patterns
- Template‐driven generation → specialized .c/.h
- Modular backends per bit depth
- Platform abstraction under utils (platform-*.cpp/h)

##### README for additional insights
- Core library is built as a static C lib, optional C++ test & benchmark tools.
- Platform-agnostic: clients supply framebuffer.
- Configured via CMake options (LUT, unroll, target, benchmarks).

##### Main components
a. Build System Layer
- CMake core & cmake/ scripts
- Code‐generation stage (process *.in templates → .c/.h)
b. Core Graphics Library (“inknit”)
- Public headers (inc/)
- Shared utilities (shared/)
- Bit-depth modules (x1, x2, x4 variants)
- Platform abstraction (utils/platform-*.cpp)
c. C++ Wrapper Layer (inknit_cxx)
- Drawable API, format implementations
d. Unit Tests
- tests/inknit linking core + C++ wrapper
e. Benchmark Suite
- benchmarks/inknit and utility monitors/executors
f. External Client Integration
- User’s embedded project → add_subdirectory(inknit) → link libinknit.a → supply framebuffer
g. Target Environments
- Embedded: RP2040/RP2350, ARM, x86
- Host: Linux/WSL for tests & benchmarks

##### Relationships & interactions
- Build System → (1) Template code‐generation → (2) Compiled into Core Library
- Core Library → linked by
- C++ Wrapper → Unit Tests & Benchmarks
- External Client → runs on embedded targets
- Platform Abstraction module mediates between core calls and target‐specific implementations

##### Architectural patterns & design principles
- Template‐based code‐generation for algorithm specialization
- Modular backends for each bit depth
- Platform‐agnostic design via abstraction layer
- Build‐time configurability with CMake options
- Static library + header inclusion model

##### Essential elements to capture
- Build pipeline (generate, compile, link)
- Core library internals (inc/, shared/, xN modules)
- C++ wrapper, test harness, benchmark suite
- Client integration flow into embedded deployments
- Platform abstraction and supported targets

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build System Layer
    subgraph "Build System Layer"
        direction TB
        CMakeLists["CMakeLists.txt"]:::build
        cmakeDir["cmake/"]:::build
        scriptsDir["scripts/"]:::build
        GenerateTemplate["GenerateTemplate.cmake"]:::build
    end

    %% Code Generation
    CodeGen["Template Code-Generation"]:::build

    %% Core Graphics Library
    subgraph "Core Graphics Library (inknit)"
        direction TB
        inc["Public Headers (inc/)"]:::core
        shared["Shared Utilities (shared/)"]:::core
        templates["Template Definitions"]:::core
        subgraph "Bit-Depth Backends"
            direction TB
            x1["x1/"]:::core
            x1lsb["x1lsb/"]:::core
            x2["x2/"]:::core
            x2lsb["x2lsb/"]:::core
            x4["x4/"]:::core
            x4lsb["x4lsb/"]:::core
        end
        platformAbst["Platform Abstraction (utils/)"]:::core
    end

    %% C++ Wrapper Layer
    subgraph "C++ Wrapper Layer (inknit_cxx)"
        direction TB
        cxxCMake["CMakeLists.txt"]:::wrapper
        cxxInc["Public C++ Headers"]:::wrapper
        formatDir["Format Implementations"]:::wrapper
        cxxUtils["Utility Helpers"]:::wrapper
    end

    %% Unit Tests
    subgraph "Unit Tests"
        direction TB
        testsCMake["tests/CMakeLists.txt"]:::test
        testsDir["tests/inknit/"]:::test
    end

    %% Benchmark Suite
    subgraph "Benchmark Suite"
        direction TB
        benchRootCMake["benchmarks/CMakeLists.txt"]:::benchmark
        benchInkCMake["benchmarks/inknit/CMakeLists.txt"]:::benchmark
        benchDrivers["Benchmark Drivers & Cases"]:::benchmark
        benchUtils["Bench Utils & Platform Simulators"]:::benchmark
    end

    %% External Client Integration
    external["External Client Integration"]:::external

    %% Target Environments
    subgraph "Target Environments"
        direction TB
        embedded["Embedded Targets"]:::target
        host["Host (Linux/WSL)"]:::target
    end

    %% Connections
    CMakeLists -->|includes| cmakeDir
    CMakeLists -->|includes| scriptsDir
    cmakeDir -->|runs| GenerateTemplate
    GenerateTemplate -->|generates code| CodeGen
    CodeGen -->|produces| inc
    CodeGen --> shared
    CodeGen --> templates
    CodeGen --> platformAbst
    CodeGen --> x1
    CodeGen --> x1lsb
    CodeGen --> x2
    CodeGen --> x2lsb
    CodeGen --> x4
    CodeGen --> x4lsb

    inc -->|"compiled into"| platformAbst
    shared -->|"compiled into"| platformAbst
    templates -->|"compiled into"| platformAbst
    x1 & x1lsb & x2 & x2lsb & x4 & x4lsb -->|"compiled into"| platformAbst

    platformAbst -->|"core library"| cxxCMake
    inc --> cxxCMake
    shared --> cxxCMake

    cxxCMake --> cxxInc
    cxxCMake --> formatDir
    cxxCMake --> cxxUtils

    cxxCMake --> testsCMake
    inc --> testsCMake
    cxxInc --> testsCMake
    testsCMake --> testsDir

    cxxCMake --> benchRootCMake
    benchRootCMake --> benchInkCMake
    benchInkCMake --> benchDrivers
    benchInkCMake --> benchUtils

    inc --> external
    shared --> external
    templates --> external
    x1 & x1lsb & x2 & x2lsb & x4 & x4lsb --> external
    external --> embedded
    external --> host

    %% Click Events
    click CMakeLists "https://github.com/mntone/inknit/blob/main/CMakeLists.txt"
    click cmakeDir "https://github.com/mntone/inknit/tree/main/cmake/"
    click scriptsDir "https://github.com/mntone/inknit/tree/main/scripts/"
    click GenerateTemplate "https://github.com/mntone/inknit/blob/main/cmake/scripts/GenerateTemplate.cmake"
    click inc "https://github.com/mntone/inknit/tree/main/src/inknit/inc/inknit/"
    click shared "https://github.com/mntone/inknit/tree/main/src/inknit/shared/"
    click templates "https://github.com/mntone/inknit/tree/main/src/inknit/templates/"
    click x1 "https://github.com/mntone/inknit/tree/main/src/inknit/x1/"
    click x1lsb "https://github.com/mntone/inknit/tree/main/src/inknit/x1lsb/"
    click x2 "https://github.com/mntone/inknit/tree/main/src/inknit/x2/"
    click x2lsb "https://github.com/mntone/inknit/tree/main/src/inknit/x2lsb/"
    click x4 "https://github.com/mntone/inknit/tree/main/src/inknit/x4/"
    click x4lsb "https://github.com/mntone/inknit/tree/main/src/inknit/x4lsb/"
    click platformAbst "https://github.com/mntone/inknit/tree/main/cmake/Platform/"
    click cxxCMake "https://github.com/mntone/inknit/blob/main/src/inknit_cxx/CMakeLists.txt"
    click cxxInc "https://github.com/mntone/inknit/tree/main/src/inknit_cxx/inc/inknit/"
    click formatDir "https://github.com/mntone/inknit/tree/main/src/inknit_cxx/format/"
    click cxxUtils "https://github.com/mntone/inknit/tree/main/src/inknit_cxx/utils/"
    click testsCMake "https://github.com/mntone/inknit/blob/main/tests/CMakeLists.txt"
    click testsDir "https://github.com/mntone/inknit/tree/main/tests/inknit/"
    click benchRootCMake "https://github.com/mntone/inknit/blob/main/benchmarks/CMakeLists.txt"
    click benchInkCMake "https://github.com/mntone/inknit/blob/main/benchmarks/inknit/CMakeLists.txt"

    %% Styles
    classDef build fill:#D0E6FF,stroke:#0066CC
    classDef core fill:#FFE4B2,stroke:#CC6600
    classDef wrapper fill:#E6D0FF,stroke:#6600CC
    classDef test fill:#F0F0F0,stroke:#999999
    classDef benchmark fill:#EFE6FF,stroke:#9966CC
    classDef external fill:#D9D9D9,stroke:#666666
    classDef target fill:#FFF2CC,stroke:#CC9900
```
