# kataklinger/forque architecture

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

## Overview

##### Main Components

a) Core Components:
- Tag System
- Static Tags Handler
- Dynamic Tags Handler
- Queue Management System
- Reservation System
- Population System
- Consumer Management
- Item Processing Controller
- Release Management

b) Supporting Components:
- Synchronization Layer
- Task Management System
- Utility Services

**┌─ Application Layer ─────────────────────┐**
- (Sample Applications/Client Code)       │
- ┤
- Public API Layer              │
- (forque.hpp - Main Interface)          │
- ┤
- Core Processing Layer           │
- ┬─────────────┬──────────┤
- Tag System   │Queue System │Task Mgmt │
- ┴─────────────┴──────────┘

##### Component Relationships

- Tag System → Queue System (hierarchical tag processing)
- Queue System → Task Management (item scheduling)
- Synchronization Layer ↔ All Components (thread safety)

##### Specific Implementation Details

- mutex.hpp/cpp: Synchronization mechanisms
- runque.hpp: Queue implementation
- tag.hpp: Tag system implementation
- task.hpp: Task management
- sync_wait.hpp: Synchronization utilities

##### Flow Representation

a) Production Flow (Green):
**Reserve → Populate → Queue**

b) Consumption Flow (Blue):
**Obtain → Process → Release**

##### Additional Notes

A small section showing the tag hierarchy example:
**Tag Hierarchy Example:**
**1/2   ←→ 1/2/3    (Related)**
**1/2/1 ↹  1/2/3    (Unrelated)**

Remember to emphasize the coroutine-based nature of the implementation and the thread-safety mechanisms, as these are crucial aspects of the library's architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef core fill:#a8d1f0,stroke:#333
    classDef api fill:#90EE90,stroke:#333
    classDef sync fill:#FFB6C1,stroke:#333
    classDef client fill:#D3D3D3,stroke:#333
    classDef util fill:#FFE4B5,stroke:#333

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        Client["Sample Applications"]:::client
        SamplePool["Thread Pool Implementation"]:::client
    end
    click Client "https://github.com/kataklinger/forque/blob/master/sample/app.cpp"
    click SamplePool "https://github.com/kataklinger/forque/blob/master/sample/pool.hpp"

    %% Public API Layer
    subgraph APILayer["Public API Layer"]
        ForqueAPI["Forque API Interface"]:::api
    end
    click ForqueAPI "https://github.com/kataklinger/forque/blob/master/src/inc/forque.hpp"

    %% Core Processing Layer
    subgraph CoreLayer["Core Processing Layer"]
        %% Tag System
        subgraph TagSystem["Tag System"]
            StaticTags["Static Tags Handler"]:::core
            DynamicTags["Dynamic Tags Handler"]:::core
            TagStream["Tag Stream Processor"]:::core
        end
        click StaticTags "https://github.com/kataklinger/forque/blob/master/src/inc/tag.hpp"
        click DynamicTags "https://github.com/kataklinger/forque/blob/master/src/inc/tag.hpp"
        click TagStream "https://github.com/kataklinger/forque/blob/master/src/inc/tag_stream.hpp"

        %% Queue System
        subgraph QueueSystem["Queue Management System"]
            ReservationSys["Reservation System"]:::core
            PopulationSys["Population System"]:::core
            RunQueue["Run Queue Implementation"]:::core
        end
        click RunQueue "https://github.com/kataklinger/forque/blob/master/src/inc/runque.hpp"

        %% Task Management
        subgraph TaskSystem["Task Management"]
            TaskController["Task Controller"]:::core
            TaskProcessor["Task Processor"]:::core
        end
        click TaskController "https://github.com/kataklinger/forque/blob/master/src/inc/task.hpp"
        click TaskProcessor "https://github.com/kataklinger/forque/blob/master/src/inc/task.hpp"
    end

    %% Synchronization Layer
    subgraph SyncLayer["Synchronization Layer"]
        Mutex["Mutex Handler"]:::sync
        SyncWait["Sync Wait Utilities"]:::sync
    end
    click Mutex "https://github.com/kataklinger/forque/blob/master/src/inc/mutex.hpp"
    click SyncWait "https://github.com/kataklinger/forque/blob/master/src/inc/sync_wait.hpp"

    %% Utility Layer
    subgraph UtilLayer["Utility Services"]
        Utils["Utility Functions"]:::util
    end
    click Utils "https://github.com/kataklinger/forque/blob/master/src/inc/utility.hpp"

    %% Test Suite
    subgraph TestSuite["Test Suite"]
        ForqueTests["Forque Tests"]
        MutexTests["Mutex Tests"]
        RunQueTests["RunQue Tests"]
        TagTests["Tag Tests"]
        TaskTests["Task Tests"]
    end
    click ForqueTests "https://github.com/kataklinger/forque/blob/master/test/forque_tests.cpp"
    click MutexTests "https://github.com/kataklinger/forque/blob/master/test/mutex_tests.cpp"
    click RunQueTests "https://github.com/kataklinger/forque/blob/master/test/runque_tests.cpp"
    click TagTests "https://github.com/kataklinger/forque/blob/master/test/tag_tests.cpp"
    click TaskTests "https://github.com/kataklinger/forque/blob/master/test/task_tests.cpp"

    %% Relationships
    Client --> ForqueAPI
    SamplePool --> ForqueAPI
    ForqueAPI --> TagSystem
    ForqueAPI --> QueueSystem
    ForqueAPI --> TaskSystem
    TagSystem --> QueueSystem
    QueueSystem --> TaskSystem
    SyncLayer -.-> TagSystem
    SyncLayer -.-> QueueSystem
    SyncLayer -.-> TaskSystem
    Utils -.-> CoreLayer

    %% Legend
    subgraph Legend["Legend"]
        CoreComp["Core Component"]:::core
        APIComp["API Component"]:::api
        SyncComp["Sync Component"]:::sync
        ClientComp["Client Component"]:::client
        UtilComp["Utility Component"]:::util
    end
```
