# credmp/hed architecture

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

- Interactive diagram: https://gitdiagram.com/credmp/hed
- Repository: https://github.com/credmp/hed

## Overview

##### Main Components Identification

a. Core Components:
- Command Line Interface (main.rs)
- Host Entry Manager (hostentry.rs)
- Host File Handler (hostfile.rs)
- Application Logic (app.rs)
- Error Handling (errors.rs)
- Utility Functions (utils.rs)

**┌─────────────────────────────────────────────┐**
- User Interface                │
- (Command Line Interface)           │
- ┤
- Application Layer                │
- ┌──────────┐    ┌──────────────────┐    │
- App     │◄───┤   Error Handler  │    │
- ┘    └──────────────────┘    │
- ┤
- Domain Layer                     │
- ┌──────────┐    ┌──────────────────┐    │
- HostEntry │◄───┤    Host File     │    │
- ┘    └──────────────────┘    │
- ┤
- System Layer                     │
- ┌──────────┐    ┌──────────────────┐    │
- Utils    │    │  File System     │    │
- ┘    └──────────────────┘    │
- ┘

##### Key Interactions to Highlight

a. Command Flow:
- User input → CLI
- CLI → App Logic
- App Logic → Host Entry Manager
- Host Entry Manager → Host File Handler
- Host File Handler → File System

b. Error Handling Flow:
- Each component → Error Handler
- Error Handler → CLI (for user feedback)

##### Technical Details

- File system permissions handling
- Host file format parsing/writing
- Command-line argument processing

##### Notes for Implementation

- The simple, focused nature of the tool
- The security considerations (privilege handling)
- The separation of concerns between components
- The error handling pathways

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#B3E5FC,stroke:#0288D1
    classDef app fill:#C8E6C9,stroke:#388E3C
    classDef domain fill:#FFE0B2,stroke:#F57C00
    classDef system fill:#F5F5F5,stroke:#616161
    classDef error fill:#FFCDD2,stroke:#D32F2F

    %% User Interface Layer
    subgraph UI
        CLI["Command Line Interface"]
    end

    %% Application Layer
    subgraph AppLayer
        AppLogic["Application Logic"]
        ErrorHandler["Error Handler"]
    end

    %% Domain Layer
    subgraph DomainLayer
        HostEntry["Host Entry Manager"]
        HostFile["Host File Handler"]
    end

    %% System Layer
    subgraph SystemLayer
        Utils["Utility Functions"]
        FileSystem["File System"]
        SudoElevation["Privilege Elevation"]
        Config["Project Configuration"]
        Docs["Documentation"]
        Pipeline["CI/CD Pipeline"]
    end

    %% Relationships
    CLI --> AppLogic
    AppLogic --> HostEntry
    HostEntry --> HostFile
    HostFile --> FileSystem
    AppLogic --> ErrorHandler
    HostEntry --> ErrorHandler
    HostFile --> ErrorHandler
    ErrorHandler --> CLI
    Utils --> FileSystem
    HostFile --> SudoElevation
    SudoElevation --> FileSystem

    %% Click Events
    click CLI "https://github.com/credmp/hed/blob/main/src/main.rs"
    click HostEntry "https://github.com/credmp/hed/blob/main/src/hostentry.rs"
    click HostFile "https://github.com/credmp/hed/blob/main/src/hostfile.rs"
    click AppLogic "https://github.com/credmp/hed/blob/main/src/app.rs"
    click ErrorHandler "https://github.com/credmp/hed/blob/main/src/errors.rs"
    click Utils "https://github.com/credmp/hed/blob/main/src/utils.rs"
    click Config "https://github.com/credmp/hed/blob/main/Cargo.toml"
    click Docs "https://github.com/credmp/hed/blob/main/hed.1.gz"
    click Pipeline "https://github.com/credmp/hed/blob/main/.github/workflows/rust.yml"

    %% Styling Classes
    class CLI ui
    class AppLogic,ErrorHandler app
    class HostEntry,HostFile domain
    class Utils,FileSystem,SudoElevation,Config,Docs,Pipeline system
    class ErrorHandler error

    %% Legend
    subgraph Legend
        UI_L["UI Component"]:::ui
        App_L["Application Component"]:::app
        Domain_L["Domain Component"]:::domain
        System_L["System Component"]:::system
        Error_L["Error Handler"]:::error
    end
```
