# bahaamohamed98/terminalplusplus architecture

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

- Interactive diagram: https://gitdiagram.com/bahaamohamed98/terminalplusplus
- Repository: https://github.com/bahaamohamed98/terminalplusplus

## Overview

##### Project type and purpose
- Terminal++ is an open‐source, header‐only C++ library for building rich terminal UIs on Windows and UNIX‐like systems.
- Its purpose is to expose a unified, chainable API for styling text, controlling cursor, handling input, performing async tasks, and abstracting away platform differences.

##### File structure
- Top‐level files:
- CMakeLists.txt – build entry point
- README.md, LICENSE – documentation and license
- assets/ – images used in docs (logo, charts)
- src/Terminal++.hpp – main header containing all API classes
- src/examples/ – sample consumer code demonstrating usage

##### Key components
a. Public API Facade
b. Core Subsystems
- Cursor & Screen Control
- Input Handling
- Asynchronous Task Manager (thread pool or background thread abstraction)
c. Platform Abstraction Layer
- ANSI escape sequence emitter (UNIX)
- Win32 Console API adapter (Windows)
d. Standard Library Dependencies
- std::thread, std::mutex, std::chrono, std::string, etc.
e. Consumer Applications
- Example programs in src/examples that link against Terminal++

##### Relationships and data flow
- Consumer code → invokes Public API methods (Printer.println, Cursor.moveTo, etc.)
- Public API → delegates to Core Subsystems for formatting, queuing commands
- Core Subsystems → call Platform Abstraction Layer to emit appropriate OS‐specific sequences
- Asynchronous calls spawn threads via std::thread in Task Manager → callback into Printer/Core
- All commands eventually reach the OS terminal device

##### Architectural patterns & design principles
- Facade pattern: Terminal++ façade unifies all operations under a simple chainable interface.
- Adapter pattern: Platform Abstraction Layer adapts a single API to ANSI codes or Win32 calls.
- Single‐header distribution: simplifies integration; no external dependencies beyond STL.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Consumer Applications
    subgraph "Consumer Applications"
        CountDown["countDown.cpp"]:::consumer
        Example["example.cpp"]:::consumer
    end

    %% Public API Facade
    subgraph "Public API Facade"
        Terminal["Terminal, Printer, Cursor, Input, Color, TextStyle, ClearType"]:::api
    end

    %% Core Subsystems
    subgraph "Core Subsystems"
        Styling["Styling & Color Engine"]:::core
        CursorCtrl["Cursor & Screen Control"]:::core
        Input["Input Handling"]:::core
        Async["Asynchronous Task Manager"]:::core
    end

    %% Platform Abstraction Layer
    subgraph "Platform Abstraction Layer"
        ANSI["ANSI Escape Sequence Emitter"]:::adapter
        Win32["Win32 Console API Adapter"]:::adapter
    end

    %% Standard Library Dependencies
    StdLib["std::thread, std::mutex, std::chrono, std::string..."]:::stdlib

    %% OS Terminal Device
    OSTerm["OS Terminal Device"]:::external

    %% Documentation & Build
    CMake["Build Entry Point (CMakeLists.txt)"]:::doc
    Readme["README.md"]:::doc
    License["LICENSE"]:::doc
    Assets["assets/"]:::doc

    %% Relationships
    CountDown -->|"calls API"| Terminal
    Example -->|"calls API"| Terminal

    Terminal -->|"format, queue commands"| Styling
    Terminal -->|"format, queue commands"| CursorCtrl
    Terminal -->|"format, queue commands"| Input
    Terminal -->|"spawn tasks"| Async

    Styling -->|"emit sequence"| ANSI
    CursorCtrl -->|"emit sequence"| ANSI
    CursorCtrl -->|"WinAPI call"| Win32
    Input -->|"read key event"| ANSI
    Async -->|"spawn thread"| StdLib

    ANSI -->|"ANSI sequence"| OSTerm
    Win32 -->|"WinAPI call"| OSTerm

    CMake -->|"builds header"| Terminal
    Readme -->|"docs"| Terminal
    License -->|"license"| Terminal
    Assets -->|"resources"| Readme

    %% Click Events
    click Terminal "https://github.com/bahaamohamed98/terminalplusplus/blob/master/src/Terminal++.hpp"
    click Styling "https://github.com/bahaamohamed98/terminalplusplus/blob/master/src/Terminal++.hpp"
    click CursorCtrl "https://github.com/bahaamohamed98/terminalplusplus/blob/master/src/Terminal++.hpp"
    click Input "https://github.com/bahaamohamed98/terminalplusplus/blob/master/src/Terminal++.hpp"
    click Async "https://github.com/bahaamohamed98/terminalplusplus/blob/master/src/Terminal++.hpp"
    click ANSI "https://github.com/bahaamohamed98/terminalplusplus/blob/master/src/Terminal++.hpp"
    click Win32 "https://github.com/bahaamohamed98/terminalplusplus/blob/master/src/Terminal++.hpp"
    click CountDown "https://github.com/bahaamohamed98/terminalplusplus/blob/master/src/examples/countDown.cpp"
    click Example "https://github.com/bahaamohamed98/terminalplusplus/blob/master/src/examples/example.cpp"
    click CMake "https://github.com/bahaamohamed98/terminalplusplus/blob/master/CMakeLists.txt"
    click Readme "https://github.com/bahaamohamed98/terminalplusplus/blob/master/README.md"
    click License "https://github.com/bahaamohamed98/terminalplusplus/tree/master/LICENSE"
    click Assets "https://github.com/bahaamohamed98/terminalplusplus/tree/master/assets/"

    %% Styles
    classDef api fill:#87CEEB,stroke:#333,stroke-width:1px
    classDef core fill:#90EE90,stroke:#333,stroke-width:1px
    classDef adapter fill:#FFA500,stroke:#333,stroke-width:1px
    classDef stdlib fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke-dasharray:5 5
    classDef consumer fill:#DA70D6,stroke:#333,stroke-width:1px
    classDef doc fill:#F5DEB3,stroke:#333,stroke-width:1px
```
