# 9front/drawterm architecture

> Architecture diagram of the GitHub repository 9front/drawterm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/9front/drawterm
- Repository: https://github.com/9front/drawterm

## Overview

##### Main Components Identification

The system should be represented with these primary components:

a) Core Components:
- Authentication System (libauth, libauthsrv)
- Kernel Emulation Layer (kern/)
- GUI Implementations (multiple gui-* directories)
- Security Services (libsec)
- Drawing Systems (libdraw, libmemdraw)

b) Platform-Specific Components:
- Android Implementation
- Windows Implementation
- Unix/Linux Implementation
- macOS Implementation (Cocoa and X11)

**┌─ User Interface Layer ─────────────────────┐**
- GUI Implementations:                       │
- Cocoa (gui-cocoa)                       │
- X11 (gui-x11)                           │
- Android (gui-android)                   │
- Windows (gui-win32)                     │
- ┬───────────────────────┘
- ↓
**┌─ Core Services Layer ──────────────────────┐**
- ┌─────────────┐ ┌──────────┐ ┌──────────┐ │
- Authentication│ │ Drawing  │ │ Security │ │
- Services   │ │ System   │ │ Services │ │
- ┘ └──────────┘ └──────────┘ │
- ┬───────────────────────┘
- ↓
**┌─ Kernel Emulation Layer ──────────────────┐**
- Device Emulation                        │
- Process Management                      │
- File System Interface                   │
- ┬───────────────────────┘
- ↓
**┌─ Platform Abstraction Layer ──────────────┐**
- POSIX Implementation                    │
- Windows Implementation                  │
- ┬───────────────────────┘
- ↓
**┌─ Host System Layer ────────────────────────┐**
- Operating System (Android/Unix/Windows/Mac)│
- ┘

##### Important Details

- Authentication flows (DP9IK authentication support)
- TLS-based rcpu protocol connections
- Device emulation paths (devfs, devip, devaudio)
- Platform-specific GUI implementations
- Security service integrations

##### Component Relationships

Following key interactions:
- GUI layers → Drawing System
- Authentication Services → Security Services
- Kernel Emulation → Platform Abstraction
- Device Emulation → Host System Services

##### Implementation Notes

- A note about Android-specific limitations (plaintext login storage)
- Build configuration paths
- Platform-specific compilation requirements

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#a8d1f0,stroke:#333
    classDef core fill:#90EE90,stroke:#333
    classDef kernel fill:#FFE5B4,stroke:#333
    classDef platform fill:#D3D3D3,stroke:#333
    classDef host fill:#E6E6FA,stroke:#333
    classDef device fill:#FFA07A,stroke:#333

    %% User Interface Layer
    subgraph UI["User Interface Layer"]
        Cocoa["GUI Cocoa"]
        X11["GUI X11"]
        Android["GUI Android"]
        Windows["GUI Win32"]
        Wayland["GUI Wayland"]
    end

    %% Core Services Layer
    subgraph Core["Core Services Layer"]
        Auth["Authentication Services"]
        Draw["Drawing System"]
        Sec["Security Services"]
        CoreLibs["Core Libraries"]
    end

    %% Drawing System Components
    subgraph DrawingSystem["Drawing Components"]
        LibDraw["LibDraw"]
        LibMemDraw["LibMemDraw"]
        LibMemLayer["LibMemLayer"]
    end

    %% Kernel Emulation Layer
    subgraph Kernel["Kernel Emulation Layer"]
        KernelCore["Kernel Core"]
        DevEmulation["Device Emulation"]
    end

    %% Device Emulation Components
    subgraph Devices["Device Components"]
        DevAudio["DevAudio"]
        DevFS["DevFS"]
        DevIP["DevIP"]
    end

    %% Platform Abstraction Layer
    subgraph Platform["Platform Abstraction Layer"]
        PosixPort["POSIX Implementation"]
        WinPort["Windows Implementation"]
    end

    %% Authentication Components
    subgraph AuthComponents["Authentication Components"]
        LibAuth["LibAuth"]
        LibAuthSrv["LibAuthSrv"]
        PosixFact["POSIX Factotum"]
        WinFact["Windows Factotum"]
    end

    %% Host System Layer
    HostOS["Host Operating System"]

    %% Relationships
    UI --> Draw
    Draw --> DrawingSystem
    Core --> Kernel
    Kernel --> Platform
    Platform --> HostOS
    Auth --> AuthComponents
    DevEmulation --> Devices
    
    %% Click Events
    click Cocoa "https://github.com/9front/drawterm/tree/front/gui-cocoa"
    click X11 "https://github.com/9front/drawterm/tree/front/gui-x11"
    click Android "https://github.com/9front/drawterm/tree/front/gui-android"
    click Windows "https://github.com/9front/drawterm/tree/front/gui-win32"
    click Wayland "https://github.com/9front/drawterm/tree/front/gui-wl"
    click LibAuth "https://github.com/9front/drawterm/tree/front/libauth"
    click LibAuthSrv "https://github.com/9front/drawterm/tree/front/libauthsrv"
    click Sec "https://github.com/9front/drawterm/tree/front/libsec"
    click LibDraw "https://github.com/9front/drawterm/tree/front/libdraw"
    click LibMemDraw "https://github.com/9front/drawterm/tree/front/libmemdraw"
    click LibMemLayer "https://github.com/9front/drawterm/tree/front/libmemlayer"
    click KernelCore "https://github.com/9front/drawterm/tree/front/kern"
    click DevAudio "https://github.com/9front/drawterm/blob/front/kern/devaudio.c"
    click DevFS "https://github.com/9front/drawterm/blob/front/kern/devfs-posix.c"
    click DevIP "https://github.com/9front/drawterm/blob/front/kern/devip.c"
    click PosixPort "https://github.com/9front/drawterm/tree/front/posix-port"
    click WinPort "https://github.com/9front/drawterm/blob/front/kern/win32.c"
    click PosixFact "https://github.com/9front/drawterm/blob/front/posix-factotum.c"
    click WinFact "https://github.com/9front/drawterm/blob/front/win32-factotum.c"

    %% Style Applications
    class Cocoa,X11,Android,Windows,Wayland ui
    class Auth,Draw,Sec,CoreLibs core
    class KernelCore,DevEmulation kernel
    class PosixPort,WinPort platform
    class HostOS host
    class DevAudio,DevFS,DevIP device
```
