# ct-team-spring-2024/project-1 architecture

> Architecture diagram of the GitHub repository ct-team-spring-2024/project-1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ct-team-spring-2024/project-1
- Repository: https://github.com/ct-team-spring-2024/project-1

## Overview

##### Main Components
- UI Module: Represented by the ui/ directory. Include the main UI file (ui/main_ui.go) and its sub-components (tab1, tab2, tab3) that handle functions such as adding downloads, displaying download lists, and managing queues.
- Core Business Logic: The internal/ package holds the core operations such as state management, persistence, queue management, and overall business rules (files like state.go, queue.go, etc.).
- Network Functionality: The pkg/network/ directory contains the downloader logic (downloader.go) which abstracts external file downloads and network communications.
- Command/Testing Entry Points: The cmd/ directory (especially cmd/idm/main.go and cmd/testing_servers/main.go) is used for running test scenarios and possibly serving as entry points to demonstrate how the application interacts with the core logic.
- Data Types/Models: The types/ directory defines essential data types (download_types.go, queue_types.go, state_types.go) used across the application, ensuring consistent data structures.

##### Relationships and Interactions
- The UI interacts with the Core Business Logic: The UI components call functions within the internal/ package to initiate downloads, update state, and display download/queue information.
- The Business Logic uses the Network Module: When downloads are required, the internal logic is responsible for invoking functions in the pkg/network/downloader module to perform network operations.
- The Command Modules set up test scenarios that exercise both the UI (or a simulation of it) and the internal/network layers, ensuring the complete system is integrated.
- Data flows between these components using the types defined in the types/ directory, providing consistent data models across network, business logic, and UI interactions.

##### Architectural Patterns and Important Details
- Clear separation of concerns: UI presentation is decoupled from business rules and network operations.
- Testing/Command Modules: Indicate that cmd/idm and cmd/testing_servers serve as various entry points (and possibly orchestration modules) which validate and trigger interactions between the modules.

##### Elements
- “UI Module” (with sub-labels Tab1, Tab2, Tab3).
- “Internal Business Logic” (including elements like state, persistence, and queue management).
- “Network Downloader” (highlighting the module in pkg/network).
- “Command/Testing Modules” (representing cmd/idm and cmd/testing_servers).
- “Data Models/Types” (centraling models shared across components).
- Data flow from UI → Internal Logic.
- Command/testing modules invoking or simulating internal logic.
- Internal logic communicating with the Network Downloader.
- Bidirectional or mediated interactions through shared data types.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Module"
        UI_Main["Main UI"]:::uiStyle
        Tab1["Tab1"]:::uiStyle
        Tab2["Tab2"]:::uiStyle
        Tab3["Tab3"]:::uiStyle
        UI_Main --> Tab1
        UI_Main --> Tab2
        UI_Main --> Tab3
    end

    subgraph "Internal Business Logic"
        SM["State Management"]:::internalStyle
        DC["Download Controller"]:::internalStyle
        P["Persistence"]:::internalStyle
        QM["Queue Management"]:::internalStyle
        SM --> DC
        SM --> P
        DC --> QM
    end

    subgraph "Network Downloader"
        DL["Downloader Module"]:::networkStyle
    end

    subgraph "Command/Testing Modules"
        IDM["IDM Entrypoint"]:::commandStyle
        TS["Testing Servers Entrypoint"]:::commandStyle
    end

    subgraph "Data Models/Types"
        DT["Download Types"]:::dataStyle
        QT["Queue Types"]:::dataStyle
        ST["State Types"]:::dataStyle
    end

    %% Inter-module connections
    UI_Main -->|"calls"| SM
    IDM -->|"triggers"| SM
    TS -->|"triggers"| SM
    SM ---|"uses"| DT
    DC ---|"uses"| QT
    P ---|"uses"| ST
    DC -->|"invokes"| DL

    %% Click Events
    click UI_Main "https://github.com/ct-team-spring-2024/project-1/blob/master/ui/main_ui.go"
    click Tab1 "https://github.com/ct-team-spring-2024/project-1/tree/master/ui/tab1"
    click Tab2 "https://github.com/ct-team-spring-2024/project-1/tree/master/ui/tab2"
    click Tab3 "https://github.com/ct-team-spring-2024/project-1/tree/master/ui/tab3"
    click SM "https://github.com/ct-team-spring-2024/project-1/blob/master/internal/state.go"
    click DC "https://github.com/ct-team-spring-2024/project-1/blob/master/internal/download.go"
    click P "https://github.com/ct-team-spring-2024/project-1/blob/master/internal/persistance.go"
    click QM "https://github.com/ct-team-spring-2024/project-1/blob/master/internal/queue.go"
    click DL "https://github.com/ct-team-spring-2024/project-1/blob/master/pkg/network/downloader.go"
    click IDM "https://github.com/ct-team-spring-2024/project-1/blob/master/cmd/idm/main.go"
    click TS "https://github.com/ct-team-spring-2024/project-1/blob/master/cmd/testing_servers/main.go"
    click DT "https://github.com/ct-team-spring-2024/project-1/blob/master/types/download_types.go"
    click QT "https://github.com/ct-team-spring-2024/project-1/blob/master/types/queue_types.go"
    click ST "https://github.com/ct-team-spring-2024/project-1/blob/master/types/state_types.go"

    %% Styles
    classDef uiStyle fill:#c0e8f7,stroke:#333,stroke-width:2px;
    classDef internalStyle fill:#f7d6c1,stroke:#333,stroke-width:2px;
    classDef networkStyle fill:#d0f7c1,stroke:#333,stroke-width:2px;
    classDef commandStyle fill:#f7c1d0,stroke:#333,stroke-width:2px;
    classDef dataStyle fill:#e8f7c1,stroke:#333,stroke-width:2px;
```
