# radenrishwan/hfs architecture

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

## Overview

##### Main Components

a) Core Server Components:
- HTTP Server Core (represented by server.go)
- Request Handler System
- WebSocket Manager
- Response Builder

b) Supporting Components:
- Request Parser
- Response Formatter
- WebSocket Protocol Handler
- Broadcasting System

**Top Level (Client Layer):**
- HTTP Clients
- WebSocket Clients

**Middle Level (Server Layer):**
- HTTP Server Core
- Request Router
- WebSocket Manager

**Bottom Level (Processing Layer):**
- Request Handler
- Response Builder
- WebSocket Protocol Handler

##### Specific Implementation Details

a) HTTP Flow:
- Request handling (request.go)
- Response generation (response.go)
- Error handling (error.go)

b) WebSocket Flow:
- Connection upgrade process
- Message broadcasting system (broadcast.go)
- Client management

##### Key Architectural Points to Highlight

- The server's modular design with separate components for HTTP and WebSocket
- The request-response cycle
- WebSocket upgrade mechanism
- Broadcasting capabilities
- Helper utilities integration

##### Technical Details

Following interfaces:
**Server Interface:**
- NewServer()
- Handle()

**WebSocket Interface:**
- Upgrade()
- Read()
- Send()
- Broadcast()

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Clients
        HC[HTTP Clients]
        WC[WebSocket Clients]
    end

    %% Server Layer
    subgraph "Server Components"
        SC["HTTP Server Core"]:::core
        RR["Request Router"]:::http
        WM["WebSocket Manager"]:::websocket
    end

    %% Processing Layer
    subgraph "Request Processing"
        RH["Request Handler"]:::http
        RB["Response Builder"]:::http
        WPH["WebSocket Protocol Handler"]:::websocket
    end

    %% Utility Layer
    subgraph "Utility Components"
        EH["Error Handler"]:::utility
        BS["Broadcasting System"]:::websocket
        HU["Helper Utilities"]:::utility
    end

    %% Implementation Layer
    subgraph "Implementation"
        MI["Main Server Implementation"]:::impl
        WI["WebSocket Implementation"]:::impl
        SWI["Simple WebSocket Example"]:::impl
    end

    %% Interface Layer
    subgraph "Interfaces"
        CI["WebSocket Chat Interface"]:::interface
        SWF["Simple WebSocket Interface"]:::interface
    end

    %% Connections
    HC --> SC
    WC --> WM
    SC --> RR
    RR --> RH
    RH --> RB
    WM --> WPH
    WPH --> BS
    RH -.-> EH
    WPH -.-> EH
    BS -.-> HU
    WPH <--> WI
    WI --> SWI
    SWI --> CI
    SWI --> SWF

    %% Click Events
    click SC "https://github.com/radenrishwan/hfs/blob/master/server.go"
    click RH "https://github.com/radenrishwan/hfs/blob/master/request.go"
    click RB "https://github.com/radenrishwan/hfs/blob/master/response.go"
    click WM "https://github.com/radenrishwan/hfs/blob/master/websocket.go"
    click BS "https://github.com/radenrishwan/hfs/blob/master/broadcast.go"
    click EH "https://github.com/radenrishwan/hfs/blob/master/error.go"
    click HU "https://github.com/radenrishwan/hfs/blob/master/helper.go"
    click MI "https://github.com/radenrishwan/hfs/blob/master/cmd/main.go"
    click WI "https://github.com/radenrishwan/hfs/blob/master/cmd/ws.go"
    click SWI "https://github.com/radenrishwan/hfs/blob/master/cmd/simple_ws.go"
    click CI "https://github.com/radenrishwan/hfs/blob/master/html/chat.html"
    click SWF "https://github.com/radenrishwan/hfs/blob/master/html/simple_ws.html"

    %% Styles
    classDef core fill:#2374ab
    classDef http fill:#57a773
    classDef websocket fill:#845ec2
    classDef utility fill:#gray
    classDef impl fill:#ffd23f
    classDef interface fill:#ff9671

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["HTTP Components"]:::http
        L3["WebSocket Components"]:::websocket
        L4["Utility Components"]:::utility
        L5["Implementation"]:::impl
        L6["Interfaces"]:::interface
    end
```
