# yixiaojiu/kimika architecture

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

- Interactive diagram: https://gitdiagram.com/yixiaojiu/kimika
- Repository: https://github.com/yixiaojiu/kimika

## Overview

##### Main Components
- CLI Client (kimika): This crate handles parsing user input, configuration (see the config directory), and the initiation of sending, receiving, and requesting file transfers. It comprises submodules like:
– send (local and remote sending logic)
– receive (handling local and remote receipt of data)
– request (managing the handshake and initiation of transfers, including over UDP)
– server (acting as a coordinator for incoming file requests or notifications)
– utils (helper functions for command-line parsing with clap, terminal UI with crossterm, etc.)
- Server (kimika-server): This is the backend service that manages transfer operations via gRPC. Its components include:
– service layer modules for various API endpoints (e.g., get_metadata, post_upload, post_download, post_register, etc.)
– utilities to support HTTP/hyper integration and type definitions.
- Infrastructure/External Services:
– gRPC: Used as the communication protocol between the CLI and the server.

##### Relationships and Interactions
- Interaction for local network transfers: indicate the path where the CLI directly communicates with local receivers.
- In the server component, display the different service functions (get_metadata, post_upload, etc.) as submodules that process incoming gRPC messages.

##### Architectural Patterns and Design Principles
- Modularity: Both main crates are organized into clear submodules. The services in kimika-server are decomposed into several components, which aids testing and maintainability.
- Separation of Concerns: The client handles command line interaction and file/request management while the server focuses on processing transfers and coordinating metadata.
- gRPC as a Core Communication Mechanism: Show this as a central conduit between the CLI and the server.
- Use of Rust’s Cargo workspaces: Although not explicitly a workspace, the project uses multiple Cargo.toml files indicating separation into independent but related crates.

##### Relevant Technologies and Libraries
- Rust: The language overall.
- tonic (based on gRPC): Mention this as the library facilitating remote procedure calls.
- clap: For CLI and command-line argument processing.
- crossterm: For enhancing terminal UI interactions.
- Other standard libraries for networking and file operations in Rust.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User Input"]:::user

    subgraph "Kimika CLI"
        direction TB
        CLI_Main["CLI Main"]:::cli
        CLI_Config["Configuration Module"]:::cli
        CLI_Send["Send Module"]:::cli
        CLI_Receive["Receive Module"]:::cli
        CLI_Request["Request Module"]:::cli
        CLI_Server["Server Handling"]:::cli
        CLI_Utils["Utility Functions"]:::cli
    end

    subgraph "Kimika Server"
        direction TB
        Server_Main["Server Main"]:::server
        Server_Service["Service Endpoints"]:::server
        Server_Utils["Utility Functions (Server)"]:::server
    end

    gRPC["gRPC Communication"]:::external
    Local_Net["Local Network Transfer"]:::external

    %% User initiates CLI actions
    User -->|"initiates"| CLI_Main

    %% CLI internal module interactions
    CLI_Main -->|"uses"| CLI_Config
    CLI_Main -->|"uses"| CLI_Send
    CLI_Main -->|"uses"| CLI_Receive
    CLI_Main -->|"uses"| CLI_Request
    CLI_Main -->|"notifies"| CLI_Server
    CLI_Main -->|"utilizes"| CLI_Utils

    %% External transfer paths from CLI modules
    CLI_Send -->|"local_transfer"| Local_Net
    CLI_Send -->|"remote_transfer"| gRPC
    CLI_Request -->|"handshake"| gRPC
    CLI_Server -->|"notification"| gRPC

    %% gRPC communication to Server
    gRPC -->|"request"| Server_Main
    Server_Main -->|"response"| gRPC
    gRPC -->|"dispatch"| Server_Service

    %% Server internal module interactions
    Server_Main -->|"invokes"| Server_Service
    Server_Main -->|"uses"| Server_Utils

    %% Bidirectional callback from gRPC to CLI Server
    gRPC -->|"callback"| CLI_Server

    %% Styles
    classDef cli fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef server fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#7D6608,stroke-width:2px;
    classDef user fill:#F5B7B1,stroke:#922B21,stroke-width:2px;

    %% Click Events for CLI Client components
    click CLI_Main "https://github.com/yixiaojiu/kimika/blob/main/kimika/src/main.rs"
    click CLI_Config "https://github.com/yixiaojiu/kimika/tree/main/kimika/src/config"
    click CLI_Send "https://github.com/yixiaojiu/kimika/tree/main/kimika/src/send"
    click CLI_Receive "https://github.com/yixiaojiu/kimika/tree/main/kimika/src/receive"
    click CLI_Request "https://github.com/yixiaojiu/kimika/tree/main/kimika/src/request"
    click CLI_Server "https://github.com/yixiaojiu/kimika/tree/main/kimika/src/server"
    click CLI_Utils "https://github.com/yixiaojiu/kimika/tree/main/kimika/src/utils"

    %% Click Events for Server Component
    click Server_Main "https://github.com/yixiaojiu/kimika/blob/main/kimika-server/src/main.rs"
    click Server_Service "https://github.com/yixiaojiu/kimika/tree/main/kimika-server/src/service"
    click Server_Utils "https://github.com/yixiaojiu/kimika/tree/main/kimika-server/src/utils"
```
