# parth3105/dosv architecture

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

- Interactive diagram: https://gitdiagram.com/parth3105/dosv
- Repository: https://github.com/parth3105/dosv

## Overview

##### Main Components
- Client Program:
- Contains the user-facing client interface (Client.java).
- Includes task handling modules (DownloadHandler, UploadHandler, RequestHandler, TaskHandler) for handling file operations.
- Load Balancer Program:
- A dedicated component (LoadBalancer.java) that manages incoming requests and distributes load, potentially to multiple meta servers.
- Meta Server Program:
- Acts as the central coordinator for metadata management.
- Communicates directly with a PostgreSQL database (see lib/postgresql-42.7.5.jar used here) for persistent meta information.
- Contains key modules such as DAO (MetaDAO), service layer (MetaService), configuration for database connections, and even a distribution module implementing consistent hashing to balance meta information.
- Also handles task events with its DownloadHandler, UploadHandler, and TaskHandler.
- Storage Server Program:
- Manages the actual file or object storage backend.
- Uses SQLite (sqlite-jdbc jar provided) for local data persistence.
- Features its own service and DAO layers to interact with stored objects.

##### Relationships and Interactions
- The Client sends requests (upload/download/other file operations) to the Load Balancer.
- The Load Balancer forwards these requests to the appropriate Meta Server.
- The Meta Server acts as the orchestrator; it:
- Communicates with the PostgreSQL backend for metadata operations.
- Uses consistent hashing (as seen in ConsistentHashing.java) to determine which Storage Node to interact with.
- Manages flow both internally (between modules such as request handling and service logic) and externally (across multiple meta servers and with storage nodes).
- Following decision-making by the Meta Server, the Storage Server receives event-triggered interactions (data storage, retrieval, etc.) and uses its built-in SQLite for local persistence.
- There’s a bi-directional flow since Storage Servers might need to return data or confirmations back to Meta Servers, which then relay responses back through the Load Balancer to the Client.

##### Architectural Patterns and Design Principles
- Separation of Concerns – Each component (client, load balancer, meta server, storage server) encapsulates its responsibilities.
- Modular Design – The presence of task handlers, service layers, and DAO layers indicate that the code base is decomposed into well-separated modules.
- Distributed System Concepts – Use of consistent hashing for distributing load and multiple instances of Meta Servers.
- Event-driven Communication – As per the additional instructions, internal flows within Meta Servers and Storage Nodes are managed along with each other when events occur.

##### Incorporating the Multiple Meta Server and Storage Node Interaction
- Clearly denote that multiple Meta Servers exist; illustrate them either as several parallel components or as a cluster.
- That each Meta Server communicates not only with its dedicated PostgreSQL but also with a group of Storage Nodes. Use a “cloud” symbol or grouping for Storage Servers to indicate redundancy and distributed nature.

##### Final Touches
- Remember to include any relevant build and configuration aspects only if they impact the runtime inter-component interactions (for instance, highlighting the use of jar libraries for database connectors which may affect infrastructure setup).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Program Subgraph
    subgraph "Client Program"
        CInterface["Client Interface (Client.java)"]:::client
        CDownload["Download Handler (DownloadHandler.java)"]:::client
        CUpload["Upload Handler (UploadHandler.java)"]:::client
        CRequest["Request Handler (RequestHandler.java)"]:::client
        CTask["Task Handler (TaskHandler.java)"]:::client

        CInterface ---|"initiates"| CTask
        CInterface ---|"handles_download"| CDownload
        CInterface ---|"handles_upload"| CUpload
        CInterface ---|"sends_request"| CRequest
    end

    %% Load Balancer
    LB["Load Balancer (LoadBalancer.java)"]:::lb

    %% Meta Server Subgraph
    subgraph "Meta Server"
        MetaApp["Meta Server Application (Server.java)"]:::meta
        DBConn1["DB Connectivity (DatabaseConnect.java)"]:::meta
        DBConn2["DB Connectivity (DatabaseConnection.java)"]:::meta
        MetaDAO["DAO (MetaDAO.java)"]:::meta
        MetaService["Service Layer (MetaService.java)"]:::meta
        ConsistentHash["Consistent Hashing (ConsistentHashing.java)"]:::meta
        MetaDDownload["Download Handler (DownloadHandler.java)"]:::meta
        MetaUpload["Upload Handler (UploadHandler.java)"]:::meta
        MetaTask["Task Handler (TaskHandler.java)"]:::meta
        MetaHandler["General Handler (Handler.java)"]:::meta
        Postgres["PostgreSQL Connector (postgresql-42.7.5.jar)"]:::db

        MetaApp --> DBConn1
        MetaApp --> DBConn2
        DBConn1 --> Postgres
        DBConn2 --> Postgres
        MetaApp --> MetaDAO
        MetaDAO --> MetaService
        MetaApp --> ConsistentHash
        MetaApp --> MetaDDownload
        MetaApp --> MetaUpload
        MetaApp --> MetaTask
        MetaApp --> MetaHandler
    end

    %% Storage Server Subgraph
    subgraph "Storage Server"
        StorageApp["Storage Server Application (StorageServer.java)"]:::storage
        StorageTask["Task Handler (TaskHandler.java)"]:::storage
        StorageDB["DB Connectivity (DatabaseConnection.java)"]:::storage
        StorageDAO["DAO (ObjectDAO.java)"]:::storage
        StorageService["Service Layer (Service.java)"]:::storage
        StorageModel["Data Model (ObjectStorage.java)"]:::storage
        SQLiteJDBC["SQLite JDBC (sqlite-jdbc-3.49.1.0.jar)"]:::db

        StorageApp --> StorageDB
        StorageDB --> SQLiteJDBC
        StorageApp --> StorageDAO
        StorageDAO --> StorageService
        StorageApp --> StorageTask
        StorageService --> StorageModel
    end

    %% External Communication Flow
    CInterface -->|"request_upload/download"| LB
    LB -->|"forwards_request"| MetaApp
    ConsistentHash -->|"select_storage_node"| StorageApp
    StorageApp -->|"return_confirmation"| MetaApp
    MetaApp -->|"relay_response"| LB
    LB -->|"deliver_response"| CInterface

    %% Event Driven Interactions
    MetaApp <==>|"event_trigger"| StorageApp

    %% Click Events for Client Program
    click CInterface "https://github.com/parth3105/dosv/blob/main/ClientProgram/src/app/Client.java"
    click CDownload "https://github.com/parth3105/dosv/blob/main/ClientProgram/src/taskhandle/DownloadHandler.java"
    click CUpload "https://github.com/parth3105/dosv/blob/main/ClientProgram/src/taskhandle/UploadHandler.java"
    click CRequest "https://github.com/parth3105/dosv/blob/main/ClientProgram/src/taskhandle/RequestHandler.java"
    click CTask "https://github.com/parth3105/dosv/blob/main/ClientProgram/src/taskhandle/TaskHandler.java"

    %% Click Event for Load Balancer
    click LB "https://github.com/parth3105/dosv/blob/main/LoadBalanceProgram/src/LoadBalancer.java"

    %% Click Events for Meta Server
    click MetaApp "https://github.com/parth3105/dosv/blob/main/MetaServerProgram/src/app/Server.java"
    click DBConn1 "https://github.com/parth3105/dosv/blob/main/MetaServerProgram/src/config/DatabaseConnect.java"
    click DBConn2 "https://github.com/parth3105/dosv/blob/main/MetaServerProgram/src/config/DatabaseConnection.java"
    click MetaDAO "https://github.com/parth3105/dosv/blob/main/MetaServerProgram/src/dao/MetaDAO.java"
    click MetaService "https://github.com/parth3105/dosv/blob/main/MetaServerProgram/src/service/MetaService.java"
    click ConsistentHash "https://github.com/parth3105/dosv/blob/main/MetaServerProgram/src/distribution/ConsistentHashing.java"
    click MetaDDownload "https://github.com/parth3105/dosv/blob/main/MetaServerProgram/src/taskhandle/DownloadHandler.java"
    click MetaUpload "https://github.com/parth3105/dosv/blob/main/MetaServerProgram/src/taskhandle/UploadHandler.java"
    click MetaTask "https://github.com/parth3105/dosv/blob/main/MetaServerProgram/src/taskhandle/TaskHandler.java"
    click MetaHandler "https://github.com/parth3105/dosv/blob/main/MetaServerProgram/src/taskhandle/Handler.java"
    click Postgres "https://github.com/parth3105/dosv/blob/main/MetaServerProgram/src/lib/postgresql-42.7.5.jar"

    %% Click Events for Storage Server
    click StorageApp "https://github.com/parth3105/dosv/blob/main/StorageServerProgram/src/StorageServer.java"
    click StorageTask "https://github.com/parth3105/dosv/blob/main/StorageServerProgram/src/TaskHandler.java"
    click StorageDB "https://github.com/parth3105/dosv/blob/main/StorageServerProgram/src/config/DatabaseConnection.java"
    click StorageDAO "https://github.com/parth3105/dosv/blob/main/StorageServerProgram/src/dao/ObjectDAO.java"
    click StorageService "https://github.com/parth3105/dosv/blob/main/StorageServerProgram/src/service/Service.java"
    click StorageModel "https://github.com/parth3105/dosv/blob/main/StorageServerProgram/src/model/ObjectStorage.java"
    click SQLiteJDBC "https://github.com/parth3105/dosv/blob/main/StorageServerProgram/src/lib/sqlite-jdbc-3.49.1.0.jar"

    %% Style Definitions
    classDef client fill:#aed6f1,stroke:#1f618d,stroke-width:2px;
    classDef lb fill:#f9e79f,stroke:#d4ac0d,stroke-width:2px;
    classDef meta fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef storage fill:#fad7a0,stroke:#ca6f1e,stroke-width:2px;
    classDef db fill:#f5b7b1,stroke:#922b21,stroke-width:2px;
```
