# nickolaj-jepsen/fnug architecture

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

- Interactive diagram: https://gitdiagram.com/nickolaj-jepsen/fnug
- Repository: https://github.com/nickolaj-jepsen/fnug

## Overview

##### Main Components

a) Core Components:
- Python Frontend (TUI Layer)
- Rust Backend (Core Engine)
- Configuration Handler
- Command Runner System
- File System Watcher
- Git Integration

b) Key Subsystems:
- PTY (Pseudo Terminal) Management
- Command Selection System
- User Interface Components

**┌─ Python Frontend (TUI) ─────────────────────┐**
- Terminal UI (Textual-based)               │
- Components:                               │
- * Context Menu                            │
- * Lint Tree                               │
- * Terminal Display                        │
- ┬───────────────────────┘
- ↕ (IPC)

**┌─ Rust Backend Engine ──────────────────────┐**
- ┌─ Command Management ─┐ ┌─ PTY System ──┐ │
- Auto Command      │ │ - Terminal     │ │
- Group Command     │ │ - Python Int.  │ │
- Inherit Command   │ │ - Messages     │ │
- ┘ └───────────────┘ │
- ┌─ Selectors ─────────┐ ┌─ Config ─────┐ │
- Git Integration   │ │ - YAML/JSON   │ │
- File Watcher      │ │ - Validation  │ │
- Always Selector   │ └───────────────┘ │
- ┘                    │
- ┘

**┌─ File System ─┐ ┌─ Git Repository ─┐**
- Watching    │ │ - Change Status  │
- Config Files│ │ - File Tracking  │
- ┘ └─────────────────┘

##### Important Relationships to Highlight

- Bidirectional communication between Python Frontend and Rust Backend
- How the Selector system interacts with both Git and File System
- Demonstrate the flow from configuration to command execution
- How PTY system manages command output to the UI

##### Implementation Details

- That Python 3.10+ is required
- Supported config formats (YAML/JSON)
- Command selection mechanisms (git-based, file-watch, manual)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Frontend["Python Frontend (TUI)"]
        UI["Terminal UI (Textual)"]:::python
        CM["Context Menu"]:::python
        LT["Lint Tree"]:::python
        TD["Terminal Display"]:::python
        UI --> CM
        UI --> LT
        UI --> TD
    end

    subgraph Core["Rust Backend Engine"]
        direction TB
        subgraph CommandMgmt["Command Management"]
            direction TB
            AC["Auto Command"]:::rust
            GC["Group Command"]:::rust
            IC["Inherit Command"]:::rust
            BC["Base Command"]:::rust
        end

        subgraph PTY["PTY System"]
            direction TB
            TH["Terminal Handler"]:::rust
            PI["Python Integration"]:::rust
            MS["Message System"]:::rust
            CI["Command Interface"]:::rust
        end

        subgraph Selectors["Selector System"]
            direction TB
            GI["Git Integration"]:::rust
            FW["File Watcher"]:::rust
            AS["Always Selector"]:::rust
        end

        CF["Configuration Handler"]:::rust
        CoreIF["Core Engine Interface"]:::rust
        UIS["UI System"]:::rust
    end

    subgraph External["External Systems"]
        FS["File System"]:::external
        GR["Git Repository"]:::external
        Config[".fnug.yaml"]:::config
    end

    Frontend <--> |IPC| Core
    Selectors --> FS
    Selectors --> GR
    CF --> Config
    PTY --> Frontend

    classDef python fill:#3776AB,color:white
    classDef rust fill:#F74C00,color:white
    classDef external fill:#90EE90,color:black
    classDef config fill:#808080,color:white

    %% Click events for component mapping
    click UI "https://github.com/nickolaj-jepsen/fnug/blob/main/src/fnug/ui/app.py"
    click CM "https://github.com/nickolaj-jepsen/fnug/blob/main/src/fnug/ui/components/context_menu.py"
    click LT "https://github.com/nickolaj-jepsen/fnug/blob/main/src/fnug/ui/components/lint_tree.py"
    click TD "https://github.com/nickolaj-jepsen/fnug/blob/main/src/fnug/ui/components/terminal.py"
    click AC "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/commands/auto.rs"
    click GC "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/commands/group.rs"
    click IC "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/commands/inherit.rs"
    click BC "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/commands/command.rs"
    click TH "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/pty/terminal.rs"
    click PI "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/pty/python.rs"
    click MS "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/pty/messages.rs"
    click CI "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/pty/command.rs"
    click GI "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/selectors/git.rs"
    click FW "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/selectors/watch.rs"
    click AS "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/selectors/always.rs"
    click CF "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/config_file.rs"
    click CoreIF "https://github.com/nickolaj-jepsen/fnug/blob/main/src/fnug/core.pyi"
    click UIS "https://github.com/nickolaj-jepsen/fnug/blob/main/rust/src/ui.rs"
    click Config "https://github.com/nickolaj-jepsen/fnug/blob/main/.fnug.yaml"
```
