# kaweees/kiwigl architecture

> Architecture diagram of the GitHub repository kaweees/kiwigl, 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/kaweees/kiwigl
- Repository: https://github.com/kaweees/kiwigl

## Overview

##### Main Components Identification

a) API Layer
- Entry point through kiwigl.hpp
- Public interfaces for users

b) Core Components
- Geometry System
- Graphics System
- Texture System

c) Hardware Acceleration Layer
- CUDA Implementation
- Metal Implementation
- CPU Fallback

##### Component Relationships

**[Application Layer]**
- ↓
**[KiwiGL Public API]**
- ↓
**┌─────────────────────────┐**
- Core Components       │
- ┬──────┬───────┤
- Geometry │Graph-│Texture│
- System   │ics   │System │
- System│       │
- ┴──────┴───────┘
- ↓
**[Hardware Acceleration Layer]**
- ┬─────────┬──────┐
- CUDA    │Metal    │CPU   │
- Backend │Backend  │Back- │
- end   │
- ┴─────────┴──────┘

##### Detailed Component Breakdown

For each major component, show:

Geometry System:
- Vector
- Face
- Mesh
- Triangle

Graphics System:
- Display
- FrameBuffer

Texture System:
- Texture management

##### Implementation Details

Notes for:
- Left-handed coordinate system
- Counter-clockwise winding order
- GPU acceleration paths
- Memory management flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        APP[Client Application]
    end

    subgraph "API Layer"
        API[KiwiGL Public API]:::api
    end

    subgraph "Core Components"
        direction TB
        subgraph "Geometry System"
            direction TB
            Vector[Vector]:::geometry
            Face[Face]:::geometry
            Mesh[Mesh]:::geometry
            Triangle[Triangle]:::geometry
        end

        subgraph "Graphics System"
            direction TB
            Display[Display]:::graphics
            FrameBuffer[FrameBuffer]:::graphics
            Color[Color]:::graphics
        end

        subgraph "Texture System"
            direction TB
            Texture[Texture Management]:::texture
        end
    end

    subgraph "Hardware Acceleration Layer"
        direction TB
        CUDA[CUDA Backend]:::gpu
        Metal[Metal Backend]:::gpu
        CPU[CPU Backend]:::cpu
    end

    subgraph "External Dependencies"
        SDL2[SDL2]:::external
    end

    %% Relationships
    APP --> API
    API --> Vector & Face & Mesh & Triangle
    API --> Display & FrameBuffer & Color
    API --> Texture
    Display --> CUDA & Metal & CPU
    Display --> SDL2

    %% Click Events
    click API "https://github.com/kaweees/kiwiGL/blob/main/include/kiwigl/kiwigl.hpp"
    click Vector "https://github.com/kaweees/kiwiGL/blob/main/include/kiwigl/geometry/vector.hpp"
    click Face "https://github.com/kaweees/kiwiGL/blob/main/include/kiwigl/geometry/face.hpp"
    click Mesh "https://github.com/kaweees/kiwiGL/blob/main/include/kiwigl/geometry/mesh.hpp"
    click Triangle "https://github.com/kaweees/kiwiGL/blob/main/include/kiwigl/geometry/triangle.hpp"
    click Display "https://github.com/kaweees/kiwiGL/blob/main/include/kiwigl/graphics/display.hpp"
    click FrameBuffer "https://github.com/kaweees/kiwiGL/blob/main/include/kiwigl/graphics/frame_buffer.hpp"
    click Color "https://github.com/kaweees/kiwiGL/blob/main/include/kiwigl/graphics/color.hpp"
    click Texture "https://github.com/kaweees/kiwiGL/blob/main/include/kiwigl/texture/texture.hpp"
    click CUDA "https://github.com/kaweees/kiwiGL/blob/main/include/kiwigl/graphics/display.cuh"
    click Metal "https://github.com/kaweees/kiwiGL/blob/main/include/kiwigl/graphics/display.metal"
    click CPU "https://github.com/kaweees/kiwiGL/blob/main/include/kiwigl/graphics/display.hpp"

    %% Styles
    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef geometry fill:#4CAF50,stroke:#388E3C,color:white
    classDef graphics fill:#4CAF50,stroke:#388E3C,color:white
    classDef texture fill:#4CAF50,stroke:#388E3C,color:white
    classDef gpu fill:#FF9800,stroke:#F57C00,color:white
    classDef cpu fill:#9E9E9E,stroke:#616161,color:white
    classDef external fill:#9E9E9E,stroke:#616161,color:white

    %% Legend
    subgraph Legend
        L1[API Layer]:::api
        L2[Core Components]:::geometry
        L3[GPU Acceleration]:::gpu
        L4[CPU/External]:::cpu
    end
```
