# zed201/r_server architecture

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

- Interactive diagram: https://gitdiagram.com/zed201/r_server
- Repository: https://github.com/zed201/r_server

## Overview

##### Main Components

a) Core Server Components:
- HTTP Server Core (Main listener)
- Thread Pool Manager
- WebSocket Handler (for live reload functionality)
- File System Watcher
- Request Handler
- Logger System

b) External Interfaces:
- Client Browsers
- File System
- CLI Interface

**Top Layer: Client Layer**

**Middle Layer: Server Core**

**Bottom Layer: File System Layer**

##### Specific Component Relationships

a) Main Flow:
- HTTP Client → Server Core → File System
- WebSocket Client ↔ WebSocket Handler
- File System Watcher → WebSocket Handler → Connected Clients

b) Internal Components:
- Thread Pool Manager (show connection to request handling)
- Logger (show connections to all major components)

##### Important Elements to Highlight

a) Two Operating Modes:
- Standard HTTP Server Mode
- Live Server Mode (with WebSocket)

b) Thread Pool Architecture:
- Worker thread distribution
- Connection handling flow

##### Technical Details

- WebSocket upgrade path for live reload
- File watching mechanisms
- Memory management considerations

**┌─ Client Layer ─────────────────────┐**
- HTTP Clients │ WebSocket Clients   │
- ┴────────────────────┘

**┌─ Server Layer ────────────────────┐**
- ┌─────────┐  ┌──────────────────┐ │
- HTTP Core│  │WebSocket Handler │ │
- ┘  └──────────────────┘ │
- ┌─────────┐  ┌──────────────────┐ │
- Thread   │  │File System       │ │
- Pool     │  │Watcher          │ │
- ┘  └──────────────────┘ │
- ┘

**┌─ Storage Layer ──────────────────┐**
- File System Interface            │
- ┘

##### Notes for Implementation Details

- Memory leak points (3.87k noted in TODO)
- Optimization points
- Thread pool improvements
- WebSocket integration points

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Clients
        Browser["Browser/HTTP Client"]:::client
        WSClient["WebSocket Client"]:::client
    end

    %% Server Layer
    subgraph ServerCore["Server Core Layer"]
        HTTPCore["HTTP Server Core"]:::core
        WSHandler["WebSocket Handler"]:::core
        ThreadPool["Thread Pool Manager"]:::utility
        FSWatcher["File System Watcher"]:::utility
        RequestHandler["Request Handler"]:::core
        Logger["Logger System"]:::utility
    end

    %% File System Layer
    subgraph Storage["Storage Layer"]
        FSInterface["File System Interface"]:::storage
        TestDir["Test Directory"]:::storage
    end

    %% CLI Layer
    CLInterface["CLI Interface"]:::utility

    %% Relationships
    Browser --> HTTPCore
    WSClient <--> WSHandler
    HTTPCore --> RequestHandler
    RequestHandler --> FSInterface
    FSWatcher --> WSHandler
    WSHandler --> WSClient
    ThreadPool --> RequestHandler
    Logger --> HTTPCore
    Logger --> WSHandler
    Logger --> ThreadPool
    CLInterface --> HTTPCore
    FSInterface --> TestDir
    FSWatcher --> FSInterface

    %% Click Events
    click Logger "https://github.com/Zed201/R_server/blob/master/src/server/log.rs"
    click HTTPCore "https://github.com/Zed201/R_server/blob/master/src/server/mod.rs"
    click CLInterface "https://github.com/Zed201/R_server/blob/master/src/main.rs"
    click TestDir "https://github.com/Zed201/R_server/tree/master/test_source/"
    click ServerCore "https://github.com/Zed201/R_server/tree/master/src/server/"

    %% Styles
    classDef client fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef utility fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef storage fill:#FFE4B5,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        Client["Client Component"]:::client
        CoreComp["Core Component"]:::core
        UtilityComp["Utility Component"]:::utility
        StorageComp["Storage Component"]:::storage
    end
```
