# blinksh/blink architecture

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

- Interactive diagram: https://gitdiagram.com/blinksh/blink
- Repository: https://github.com/blinksh/blink

## Overview

##### Main components
- User Interface & Terminal Layer: Represented by the “Blink” folder that contains the AppDelegate, scene and view controllers, UI components (SmartKeys, LayoutManager, StatusBar, etc.), storyboards, and resources (Media.xcassets).
- Command & Shell Processing Engine: This layer abstracts the commands (including cd, ls, curl, ssh, sftp, etc.), which come from the ios_system.framework integrated into the project. These are implemented in many of the source files under directories such as “Commands”, “BlinkCode”, and “NonStdIO”.
- Session & Connection Management: This includes components found in “Sessions”, “SSH”, and “Mosh” sections within the project. They handle establishing secure SSH/Mosh connections, managing session states, and re-establishing connections according to the always-on philosophy.
- Configuration & Customization: Encompassing directories like “BlinkConfig”, “Settings”, and resources for fonts/themes, this layer manages user settings, key management (from the “SSH/” and “Settings/ViewControllers/BKPubKey” directories), and environment variable definitions (as noted in MCPSession.m).
- Testing & Build Infrastructure: Represent test targets (e.g., BlinkTests, BlinkCodeTests, SSHTests, etc.) and the CI/CD pipelines (referenced in the README and the .github directory) to indicate quality control and automated builds.

- Link the Command Engine to the Session Management layer to show that commands related to SSH/Mosh sessions require establishing and maintaining connections.
- Configuration layer with both the UI and Command Processing layers (for theme settings, key management, and environment variable adjustments).
- External libraries as supporting modules that are utilized by the Command engine and session management modules.
- Interactions between the Logging/Telemetry, FileProvider, and Migrator submodules (as seen in directories like BlinkLogging, BlinkFileProvider, and Migrator) to cover troubleshooting and history tracking.

##### Architectural Patterns & Design Principles
- Model-View-Controller (MVC) or similar component separation: UI (Views/Controllers), a processing layer (model/business logic for sessions and commands) and configuration management.
- Dependencies on low-level libraries (C/Swift integration) for performance-critical functionality.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "User Interface Layer"
        UI("Terminal UI"):::ui
    end

    subgraph "Processing & Session Layer"
        Cmd("Command Interpreter"):::backend
        Session("SSH/Mosh Manager"):::backend
    end

    subgraph "Configuration"
        Config("Configuration Manager"):::config
    end

    subgraph "External Services"
        Ext("External Dependencies"):::external
    end

    subgraph "Testing & Build"
        Test("Testing & Build Infrastructure"):::testing
    end

    UI -->|"initiates"| Cmd
    Cmd -->|"requiresSession"| Session
    Config -->|"appliesConfig"| UI
    Config -->|"configures"| Cmd
    Ext -->|"supports"| Cmd
    Ext -->|"supports"| Session
    Test -->|"validates"| UI
    Test -->|"validates"| Cmd
    Test -->|"validates"| Session

    click UI "https://github.com/blinksh/blink/blob/raw/Blink/AppDelegate.*"
    click UI "https://github.com/blinksh/blink/blob/raw/Blink/Base.lproj"
    click UI "https://github.com/blinksh/blink/blob/raw/Blink/SceneDelegate.swift"
    click UI "https://github.com/blinksh/blink/tree/raw/Blink/UIKit"
    click UI "https://github.com/blinksh/blink/tree/raw/Blink"

    click Cmd "https://github.com/blinksh/blink/tree/raw/Blink/Commands"
    click Cmd "https://github.com/blinksh/blink/blob/raw/BlinkCode/BlinkCode.h"
    click Cmd "https://github.com/blinksh/blink/tree/raw/Blink/NonStdIO"

    click Session "https://github.com/blinksh/blink/blob/raw/Sessions/MCPSession.*"
    click Session "https://github.com/blinksh/blink/blob/raw/Sessions/SSHSession.*"
    click Session "https://github.com/blinksh/blink/blob/raw/Sessions/MoshSession.*"
    click Session "https://github.com/blinksh/blink/blob/raw/SSH/SSHClient.swift"

    click Config "https://github.com/blinksh/blink/blob/raw/BlinkConfig/BlinkConfig.h"
    click Config "https://github.com/blinksh/blink/tree/raw/Settings/ViewControllers/BKPubKey"
    click Config "https://github.com/blinksh/blink/tree/raw/Resources/Fonts"
    click Config "https://github.com/blinksh/blink/tree/raw/Resources/Themes"

    click Ext "https://github.com/blinksh/blink/tree/raw/Frameworks/ios_system"
    click Ext "https://github.com/blinksh/blink/tree/raw/Frameworks/SmartKeys"
    click Ext "https://github.com/blinksh/blink/tree/raw/AppKitBridge"

    click Test "https://github.com/blinksh/blink/tree/raw/BlinkTests"
    click Test "https://github.com/blinksh/blink/tree/raw/BlinkCodeTests"
    click Test "https://github.com/blinksh/blink/tree/raw/SSHTests"
    click Test "https://github.com/blinksh/blink/blob/raw/.github"

    classDef ui fill:#cce5ff,stroke:#004085,stroke-width:2px
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px
    classDef config fill:#fff3cd,stroke:#856404,stroke-width:2px
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px
    classDef testing fill:#d1ecf1,stroke:#0c5460,stroke-width:2px
```
