# sdetn/hev-task-system architecture

> Architecture diagram of the GitHub repository sdetn/hev-task-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sdetn/hev-task-system
- Repository: https://github.com/sdetn/hev-task-system

## Overview

##### Main Components

a) Task Management Layer
- Task Scheduler (src/kern/core)
- Task Execution Engine (src/kern/task)
- Architecture-specific Context Switching (src/arch/*)

b) Core Services Layer
- I/O Reactor System (src/kern/io)
- Timer Management (src/kern/time)
- Inter-Task Communication (src/kern/itc)
- Synchronization Primitives (src/kern/sync)

c) Memory Management Layer
- Memory Allocator (src/mem)
- Stack Management (src/kern/task/hev-task-stack-*)

d) Library Layer
- I/O Operations (src/lib/io)
- DNS Support (src/lib/dns)
- Buffer Management (src/lib/io/buffer)
- Object System (src/lib/object)

**┌─────────────────────────────────────────────────────┐**
- Application Layer                   │
- ┤
- API Layer                       │
- (Task API, Channel API, I/O API, Memory API, etc.) │
- ┤
- Core Services Layer                    │
- ┌──────────┐ ┌─────────┐ ┌────────┐ ┌─────────┐   │
- Scheduler │ │   I/O   │ │  ITC   │ │  Sync   │   │
- ┘ └─────────┘ └────────┘ └─────────┘   │
- ┤
- Task Execution Layer                   │
- ┌──────────┐ ┌─────────┐ ┌────────────────────┐   │
- Context  │ │  Stack  │ │ Architecture-      │   │
- Switching │ │ Manager │ │ specific Execution │   │
- ┘ └─────────┘ └────────────────────┘   │
- ┤
- Memory Management Layer                │
- ┘

##### Important Elements to Highlight

- Blue: Core task management components
- Green: I/O and communication components
- Yellow: Memory management components
- Purple: Architecture-specific components

- Control flow between components
- Data flow in inter-task communication
- Dependency relationships

##### Additional Details

A separate section showing:
- Memory allocation patterns
- Task state transitions
- I/O reactor implementation differences (epoll/kqueue)
- Inter-task communication channels

##### Notes for Implementation Details

- How tasks are scheduled and switched
- Where context switching occurs
- Demonstrate the relationship between tasks and system resources
- Memory allocation strategy

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef application fill:#f9f,stroke:#333,stroke-width:2px
    classDef api fill:#bbf,stroke:#333,stroke-width:2px
    classDef core fill:#bfb,stroke:#333,stroke-width:2px
    classDef task fill:#fbf,stroke:#333,stroke-width:2px
    classDef memory fill:#ffb,stroke:#333,stroke-width:2px
    classDef arch fill:#fbb,stroke:#333,stroke-width:2px

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        App[User Applications]:::application
    end

    %% API Layer
    subgraph APILayer["API Layer"]
        TaskAPI[Task API]:::api
        ChannelAPI[Channel API]:::api
        IOAPI[I/O API]:::api
        MemAPI[Memory API]:::api
    end

    %% Core Services Layer
    subgraph CoreLayer["Core Services Layer"]
        Scheduler[Task Scheduler]:::core
        IOReactor[I/O Reactor]:::core
        ITC[Inter-Task Communication]:::core
        Timer[Timer Management]:::core
        Sync[Synchronization Primitives]:::core
    end

    %% Task Execution Layer
    subgraph TaskLayer["Task Execution Layer"]
        TaskExec[Task Execution Engine]:::task
        StackMgr[Stack Manager]:::task
        ContextSwitch[Context Switching]:::task
    end

    %% Memory Management Layer
    subgraph MemLayer["Memory Management Layer"]
        MemAlloc[Memory Allocator]:::memory
        HeapStack[Heap Stack]:::memory
        MMapStack[MMap Stack]:::memory
    end

    %% Library Layer
    subgraph LibLayer["Library Layer"]
        IOOps[I/O Operations]:::core
        DNS[DNS Support]:::core
        Buffer[Buffer Management]:::core
        Object[Object System]:::core
    end

    %% Architecture Layer
    subgraph ArchLayer["Architecture Layer"]
        ArchSpec[Architecture-specific Implementation]:::arch
    end

    %% Relationships
    App --> TaskAPI & ChannelAPI & IOAPI & MemAPI
    TaskAPI --> Scheduler
    ChannelAPI --> ITC
    IOAPI --> IOReactor
    MemAPI --> MemAlloc
    Scheduler --> TaskExec
    TaskExec --> ContextSwitch
    ContextSwitch --> ArchSpec
    IOReactor --> TaskExec
    Timer --> Scheduler
    ITC --> TaskExec
    Sync --> TaskExec
    TaskExec --> StackMgr
    StackMgr --> HeapStack & MMapStack
    HeapStack & MMapStack --> MemAlloc
    IOOps --> IOReactor
    DNS --> IOOps
    Buffer --> IOOps
    Object --> ITC

    %% Click Events
    click Scheduler "https://github.com/sdetn/hev-task-system/blob/master/src/kern/core/hev-task-system-schedule.c"
    click TaskExec "https://github.com/sdetn/hev-task-system/blob/master/src/kern/task/hev-task-executer.c"
    click ArchSpec "https://github.com/sdetn/hev-task-system/tree/master/src/arch"
    click IOReactor "https://github.com/sdetn/hev-task-system/blob/master/src/kern/io/hev-task-io-reactor.c"
    click Timer "https://github.com/sdetn/hev-task-system/blob/master/src/kern/time/hev-task-timer.c"
    click ITC "https://github.com/sdetn/hev-task-system/blob/master/src/kern/itc/hev-task-channel.c"
    click Sync "https://github.com/sdetn/hev-task-system/blob/master/src/kern/sync/hev-task-mutex.c"
    click MemAlloc "https://github.com/sdetn/hev-task-system/blob/master/src/mem/base/hev-memory-allocator.c"
    click HeapStack "https://github.com/sdetn/hev-task-system/blob/master/src/kern/task/hev-task-stack-heap.c"
    click MMapStack "https://github.com/sdetn/hev-task-system/blob/master/src/kern/task/hev-task-stack-mmap.c"
    click IOOps "https://github.com/sdetn/hev-task-system/blob/master/src/lib/io/basic/hev-task-io.c"
    click DNS "https://github.com/sdetn/hev-task-system/blob/master/src/lib/dns/hev-task-dns.c"
    click Buffer "https://github.com/sdetn/hev-task-system/blob/master/src/lib/io/buffer/hev-circular-buffer.c"
    click Object "https://github.com/sdetn/hev-task-system/blob/master/src/lib/object/hev-object.c"
```
