# notesjor/tfres-tinyfastrestendpointserver architecture

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

- Interactive diagram: https://gitdiagram.com/notesjor/tfres-tinyfastrestendpointserver
- Repository: https://github.com/notesjor/tfres-tinyfastrestendpointserver

## Overview

##### Project Type & Purpose
- This is a C# library/framework (“TFRES–Tiny Fast REST Endpoint Server”) built on top of WatsonWebserver to let consumers quickly spin up async REST endpoints (and WebSockets).
- It isn’t a full-stack web application, but an embeddable HTTP server library with multi-target builds (NET Standard, .NET5/6/8).

##### File‐Structure Analysis
- Top‐level:
– TFRES.Core (core abstractions & shared logic)
– TFRES.DotNetStandard / .Net5 / .Net6 / .Net8 (platform-specific builds)
– TefresWebserver (the server runtime: Server.cs, EndpointManager, HttpContext/HttpRequest/HttpResponse, WebSocketHelper, OpenApiHelper, streaming support)
– Tests (a “TFRES.Test.SimpleServer” console app illustrating usage; also an HTML WebSocket demo)
- NuGet packaging: package.nuspec in TefresWebserver
- Configuration & metadata: .suo, .csproj, .xml docs, README, CHANGELOG, LICENSE, CONTRIBUTING, CODE_OF_CONDUCT

##### Key README Insights
- The Server class exposes AddEndpoint(HttpMethod, route, handler)
- Handlers receive an HttpContext, respond with Send(…) / SendFile(…) / WebSocketEasy()
- JSON serialization via Newtonsoft.Json is built-in
- Mono support & routing signatures changed from WatsonWebserver v2 → v3

##### Main Components
a. Client(s)
- HTTP clients (Postman, browser) or WebSocket clients (JS in browser, .NET clients)
b. TFRES Server Runtime (TefresWebserver Project)
- HTTP Listener (WatsonWebserver under the hood)
- EndpointManager (route → handler dispatch)
- HttpContext (wraps HttpRequest & HttpResponse)
- Handlers (user code registered via AddEndpoint)
- Serializer (Newtonsoft.Json)
- File/Chunk streaming (Chunk.cs)
- WebSocketHelper / EasyWebSocket
- OpenApiHelper (optional)
c. Library Modules
- TFRES.Core (shared interfaces, abstractions)
- TFRES.DotNetStandard / DotNet5 / DotNet6 / DotNet8 (assembly variations)
d. Example App (Tests/TFRES.Test.SimpleServer)
- References TFRES package, configures routes, hosts Server

##### Interactions & Data Flows
- Inside Handler: ctx.Request → business logic → ctx.Response.Send(…)
- For WebSocket: Initial HTTP “upgrade” request → WebSocketHelper creates EasyWebSocket → bidirectional message events
- For file streaming: Handler calls ctx.Response.SendFile → chunks via Chunk.cs

##### Architectural Patterns & Principles
- Modular multi-target library (Separation of Core vs Platform-specific)
- Pipeline dispatch (HTTP listener → routing → handler → response)
- Async/await throughout for non-blocking I/O
- Pluggable serialization (Newtonsoft.Json by default)
- Extension points via EndpointManager, OpenApiHelper, WebSocketHelper

## Diagram (Mermaid)

```mermaid
graph TB
    %% External World
    subgraph "External World"
        direction TB
        HTTP_Client["HTTP Client"]:::external
        WS_Client["WebSocket Client"]:::external
    end

    %% TFRES Library
    subgraph "TFRES Library"
        direction TB
        %% Core and Platform Modules
        subgraph "Modules"
            direction TB
            Core["TFRES.Core.dll"]:::core
            Standard["TFRES.DotNetStandard.dll"]:::platform
            DotNet5["TFRES.DotNet5.dll"]:::platform
            DotNet6["TFRES.DotNet6.dll"]:::platform
            DotNet8["TFRES.DotNet8.dll"]:::platform
        end
        %% Runtime Components
        subgraph "Runtime"
            direction TB
            Server["Server"]:::runtime
            Manager["EndpointManager"]:::runtime
            Context["HttpContext"]:::runtime
            Request["HttpRequest"]:::runtime
            RequestFile["HttpRequestFile"]:::runtime
            Response["HttpResponse"]:::runtime
            Chunk["Chunk"]:::helper
            WSHelper["WebSocketHelper"]:::helper
            OpenAPI["OpenApiHelper"]:::helper
            JSON["Newtonsoft.Json"]:::external
            Watson["WatsonWebserver"]:::external
        end
    end

    %% Example App
    subgraph "Example App / Host"
        direction TB
        AppProgram["Program (SimpleServer)"]:::example
        AppProj["TFRES.Test.SimpleServer.csproj"]:::example
        AppConfig["App.config"]:::example
        DemoPage["Text_WebSocket_JS.html"]:::example
    end

    %% Request/Response Flows
    HTTP_Client -->|"HTTP Request"| Server
    Server -->|"route lookup"| Manager
    Manager -->|"invoke handler"| AppProgram
    AppProgram -->|"ctx:Object"| Context
    Context --> Request
    Context --> Response
    AppProgram --> Response
    Response -->|"HTTP Response"| HTTP_Client

    WS_Client -->|"WS Upgrade"| Server
    Server --> WSHelper
    WSHelper <-->|"WS Messages"| WS_Client
    AppProgram --> WSHelper

    %% Dependencies
    Server --> Watson
    Server --> Core
    Manager --> Core
    Context --> Core
    Request --> Core
    Response --> Core
    Chunk --> Core
    WSHelper --> Core
    OpenAPI --> Core
    JSON --> Response

    %% Click Events
    click Core "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TFRES.Core/TFRES.Core.csproj"
    click Standard "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TFRES.DotNetStandard/TFRES.DotNetStandard.csproj"
    click DotNet5 "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TFRES.DotNet5/TFRES.DotNet5.csproj"
    click DotNet6 "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TFRES.DotNet6/TFRES.DotNet6.csproj"
    click DotNet8 "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TFRES.DotNet8/TFRES.DotNet8.csproj"
    click Server "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TefresWebserver/Server.cs"
    click Manager "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TefresWebserver/EndpointManager.cs"
    click Context "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TefresWebserver/HttpContext.cs"
    click Request "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TefresWebserver/HttpRequest.cs"
    click RequestFile "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TefresWebserver/HttpRequestFile.cs"
    click Response "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TefresWebserver/HttpResponse.cs"
    click Chunk "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TefresWebserver/Chunk.cs"
    click WSHelper "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TefresWebserver/WebSocketHelper.cs"
    click OpenAPI "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TefresWebserver/OpenApiHelper.cs"
    click AppProgram "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/Tests/TFRES.Test.SimpleServer/Program.cs"
    click AppProj "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/Tests/TFRES.Test.SimpleServer/TFRES.Test.SimpleServer.csproj"
    click AppConfig "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/Tests/TFRES.Test.SimpleServer/App.config"
    click DemoPage "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/Tests/Text_WebSocket_JS.html"
    click JSON "https://github.com/notesjor/tfres-tinyfastrestendpointserver/blob/master/TefresWebserver/package.nuspec"

    %% Styles
    classDef external fill:#d5e8d4,stroke:#82b366;
    classDef core fill:#dae8fc,stroke:#6c8ebf;
    classDef platform fill:#e1d5e7,stroke:#9673a6;
    classDef runtime fill:#f8cecc,stroke:#b85450;
    classDef helper fill:#fff2cc,stroke:#d6b656;
    classDef example fill:#fef1ec,stroke:#e6b8af;
```
