# legmask/hagimule architecture

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

- Interactive diagram: https://gitdiagram.com/legmask/hagimule
- Repository: https://github.com/legmask/hagimule

## Overview

##### Main Components Identification

The system consists of several key components that should be represented:

a) Client Layer:
- Client implementation (Client.java)
- Daemon service (Daemon.java, DaemonImpl.java)
- Download management (Download.java, DownloadImpl.java, Downloader.java)
- TUI (Terminal User Interface) components

b) Shared Components:
- File management (File.java, FileImpl.java)
- Peer management (Peer.java, PeerImpl.java)
- File information handling (FileInfo.java, FileInfoImpl.java)

c) Diary Service:
- Central coordination component (Diary.java, DiaryImpl.java)

**┌─────────────────┐**
- Diary Service  │
- ┬────────┘

- ┌────┴────┐
- Network│
- ┬────┘
- ┌──────┴──────┐
**┌─┴─┐  ┌─┴─┐ ┌─┴─┐**
- CLI│  │CLI│ │CLI│
- ┘  └───┘ └───┘

##### Connection and Flow Representation

- Bidirectional communication between Diary and Clients
- Peer-to-peer connections between Clients
- File transfer flows between Clients

##### Component Details

For each major component, include:
- Interface definitions
- Key methods
- Communication protocols
- State management (especially for downloads: DownloadStatus)

##### Technical Details

- Java-based implementation
- Docker container support (noted by Dockerfile presence)
- AWS deployment capabilities
- Terminal UI interface
- Peer-to-peer communication channels

Remember to maintain a balance between showing the overall architecture and including important implementation details that affect the system's behavior, such as the download status management and peer coordination mechanisms.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Infrastructure
        AWS["AWS Cloud"]:::infra
        TF["Terraform Config"]:::infra
    end

    subgraph DiaryLayer
        DS["Diary Service"]:::diary
        DI["Diary Implementation"]:::diary
    end

    subgraph NetworkLayer
        NET["Network Communication"]:::network
    end

    subgraph ClientLayer
        C1["Client 1"]:::client
        C2["Client 2"]:::client
        C3["Client 3"]:::client

        subgraph ClientComponents
            DM["Download Manager"]:::component
            TUI["Terminal UI"]:::component
            DMN["Daemon Service"]:::component
        end
    end

    subgraph SharedComponents
        FM["File Management"]:::shared
        PM["Peer Management"]:::shared
        FI["File Information"]:::shared
    end

    %% Connections
    DS <--> NET
    NET <--> C1
    NET <--> C2
    NET <--> C3
    C1 <--> C2
    C2 <--> C3
    C1 <--> C3

    C1 --- DM
    C1 --- TUI
    C1 --- DMN

    DM --- FM
    DM --- PM
    DM --- FI

    AWS --- DS
    TF --- AWS

    %% Styles
    classDef diary fill:#3498db,stroke:#2980b9,color:white
    classDef network fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef client fill:#2ecc71,stroke:#27ae60,color:white
    classDef component fill:#e74c3c,stroke:#c0392b,color:white
    classDef shared fill:#f1c40f,stroke:#f39c12,color:black
    classDef infra fill:#9b59b6,stroke:#8e44ad,color:white

    %% Click Events
    click DS "https://github.com/LeGmask/HagiMule/blob/master/app/src/main/java/n7/HagiMule/Diary/Diary.java"
    click DI "https://github.com/LeGmask/HagiMule/blob/master/app/src/main/java/n7/HagiMule/Diary/DiaryImpl.java"
    click C1 "https://github.com/LeGmask/HagiMule/blob/master/app/src/main/java/n7/HagiMule/Client/Client.java"
    click DMN "https://github.com/LeGmask/HagiMule/blob/master/app/src/main/java/n7/HagiMule/Client/Daemon.java"
    click DM "https://github.com/LeGmask/HagiMule/blob/master/app/src/main/java/n7/HagiMule/Client/Download.java"
    click TUI "https://github.com/LeGmask/HagiMule/blob/master/app/src/main/java/n7/HagiMule/Client/Tui/Tui.java"
    click FM "https://github.com/LeGmask/HagiMule/blob/master/app/src/main/java/n7/HagiMule/Shared/File.java"
    click PM "https://github.com/LeGmask/HagiMule/blob/master/app/src/main/java/n7/HagiMule/Shared/Peer.java"
    click FI "https://github.com/LeGmask/HagiMule/blob/master/app/src/main/java/n7/HagiMule/Shared/FileInfo.java"
    click TF "https://github.com/LeGmask/HagiMule/blob/master/infra/main.tf"
    click AWS "https://github.com/LeGmask/HagiMule/tree/master/infra"

    %% Legend
    subgraph Legend
        L1["Diary Service"]:::diary
        L2["Network Layer"]:::network
        L3["Client"]:::client
        L4["Client Component"]:::component
        L5["Shared Component"]:::shared
        L6["Infrastructure"]:::infra
    end
```
