# avanavi/rust_server_project architecture

> Architecture diagram of the GitHub repository avanavi/rust_server_project, 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/avanavi/rust_server_project
- Repository: https://github.com/avanavi/rust_server_project

## Overview

##### Main Components

A. Core Server Components:
- TCP Listener (Entry Point)
- Connection Handler
- Thread Pool Manager
- Worker Threads Pool
- Request Router
- Static File Server

B. Concurrency Components:
- Thread Pool Implementation
- Job Queue System
- Worker Thread Management
- Message Passing System

C. Feature Components:
- Graceful Shutdown Manager
- Connection Throttling System
- Static Content Handler

- Blue Rectangles: Core server components
- Green Circles: Concurrency-related components
- Orange Hexagons: Feature components
- Purple Diamonds: External interfaces

##### Component Relationships

A. Primary Flow:
**Client Request → TCP Listener → Connection Throttling → Thread Pool → Worker Threads → Response Handler → Client Response**

B. Secondary Flows:
- Thread Pool ←→ Job Queue (using mpsc channels)
- Worker Threads ←→ Static File Server
- Graceful Shutdown Manager → Thread Pool

##### Detailed Component Specifications

A. TCP Listener Layer:
- Listening address (127.0.0.1:7878)
- Connection acceptance flow
- Initial request buffering

B. Thread Pool Layer:
- Worker thread pool (show multiple instances)
- Job queue with Arc<Mutex<>> implementation
- Message passing channels

C. Request Processing Layer:
- Route handling (/index.html, /404.html)
- Static file serving
- Response construction

##### Implementation Details to Highlight

A. Thread Safety:
- Arc<Mutex<>> wrapper around shared resources
- Mpsc channel communications

B. Error Handling:
- Error propagation paths
- 404 response routing

## Diagram (Mermaid)

```mermaid
graph TB
    %% Main Components
    Client(("Client"))
    TCPListener["TCP Listener\n(127.0.0.1:7878)"]:::core
    ConnThrottle["Connection\nThrottling"]:::feature
    ThreadPool["Thread Pool\nManager"]:::concurrency
    JobQueue[("Job Queue")]:::concurrency
    Router["Request Router"]:::core
    StaticServer["Static File Server"]:::core
    GracefulShutdown["Graceful Shutdown\nManager"]:::feature

    %% Worker Thread Pool
    subgraph WorkerThreads["Worker Threads Pool"]
        Worker1["Worker 1"]:::worker
        Worker2["Worker 2"]:::worker
        Worker3["Worker 3"]:::worker
        Worker4["Worker 4"]:::worker
    end

    %% Static Content
    subgraph StaticContent["Static Content"]
        Index["index.html"]:::file
        NotFound["404.html"]:::file
    end

    %% Connections
    Client --> TCPListener
    TCPListener --> ConnThrottle
    ConnThrottle --> ThreadPool
    ThreadPool <--> JobQueue
    JobQueue --> WorkerThreads
    WorkerThreads --> Router
    Router --> StaticServer
    StaticServer --> StaticContent
    GracefulShutdown --> ThreadPool

    %% Response Flow
    WorkerThreads --> |Response|Client

    %% Styling
    classDef core fill:#a8d1f0,stroke:#333
    classDef concurrency fill:#90EE90,stroke:#333
    classDef feature fill:#FFB347,stroke:#333
    classDef worker fill:#DDA0DD,stroke:#333
    classDef file fill:#F0E68C,stroke:#333

    %% Click Events
    click TCPListener "https://github.com/AvanAvi/Rust_Server_Project/blob/main/src/bin/main.rs"
    click ThreadPool "https://github.com/AvanAvi/Rust_Server_Project/blob/main/src/lib.rs"
    click Router "https://github.com/AvanAvi/Rust_Server_Project/blob/main/src/lib.rs"
    click Index "https://github.com/AvanAvi/Rust_Server_Project/blob/main/index.html"
    click NotFound "https://github.com/AvanAvi/Rust_Server_Project/blob/main/404.html"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Concurrency Components"]:::concurrency
        L3["Feature Components"]:::feature
        L4["Worker Threads"]:::worker
        L5["Static Files"]:::file
    end
```
