# htdangkhoa/pure-http architecture

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

- Interactive diagram: https://gitdiagram.com/htdangkhoa/pure-http
- Repository: https://github.com/htdangkhoa/pure-http

## Overview

##### Main Components

a) Core Components:
- HTTP/HTTPS Server (Native Node.js)
- Router System
- Middleware Pipeline
- Request/Response Extensions
- Cache System
- Static File Server
- View Engine System

b) Supporting Components:
- Cookie Handler
- MIME Types Handler
- ETag Generator
- Error Handler

**HTTP/HTTPS Requests**

**Native Node.js HTTP/HTTPS Server**

**Router System <-> Middleware Pipeline**

**Request Extensions | Response Extensions | Cache System**

**Cookie Handler | MIME Types | ETag | View Engine**

##### Component Relationships

- Request flow: Client -> Server -> Router -> Middleware -> Handler
- Response flow: Handler -> Response Extensions -> Client
- Cache flow: Request -> Cache Check -> (Cache Hit/Miss) -> Handler
- Static file serving: Request -> Static Middleware -> File System
- View rendering: Response -> View Engine -> Template Files

##### Implementation Details to Highlight

- Relationship between pure-http and native http module
- How the middleware pattern is implemented
- Extension points for request/response objects
- View engine integration points

##### Technical Specifications

A sidebar showing:
- Supported Node.js versions
- Key dependencies
- Performance metrics
- Memory footprint

- Lightweight nature (small bundle size)
- High performance (benchmarks show superior performance)
- Compatibility with native http module
- Middleware support
- Extensibility

This system design should help developers understand how pure-http achieves its high performance while maintaining a familiar Express-like API surface.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        client[Client]:::client
    end

    subgraph "Server Layer"
        http[HTTP/HTTPS Server]:::server
        https[HTTPS Implementation]:::server
    end

    subgraph "Core Framework"
        pure[pure-http Core]:::core
        router[Router System]:::core
        middleware[Middleware Pipeline]:::core
    end

    subgraph "Extensions Layer"
        reqExt[Request Extensions]:::extension
        resExt[Response Extensions]:::extension
        cache[Cache System]:::extension
    end

    subgraph "Utility Layer"
        cookie[Cookie Handler]:::utility
        mime[MIME Types]:::utility
        etag[ETag Generator]:::utility
        utils[Utilities]:::utility
        settings[Settings Manager]:::utility
    end

    subgraph "Feature Layer"
        static[Static File Server]:::feature
        views[View Engine]:::feature
        error[Error Handler]:::feature
    end

    %% Connections
    client --> http & https
    http & https --> pure
    pure --> router
    router --> middleware
    middleware --> reqExt & resExt
    reqExt & resExt --> cache
    
    cache --> cookie & mime & etag
    cookie & mime & etag --> static & views & error
    utils --> |Supports All Layers| pure
    settings --> |Configures| pure

    %% Click Events
    click pure "https://github.com/htdangkhoa/pure-http/blob/master/lib/pure-http.js"
    click router "https://github.com/htdangkhoa/pure-http/blob/master/lib/router.js"
    click cache "https://github.com/htdangkhoa/pure-http/blob/master/lib/cache.js"
    click reqExt "https://github.com/htdangkhoa/pure-http/blob/master/lib/extend/request.js"
    click resExt "https://github.com/htdangkhoa/pure-http/blob/master/lib/extend/response.js"
    click cookie "https://github.com/htdangkhoa/pure-http/blob/master/lib/cookie.js"
    click mime "https://github.com/htdangkhoa/pure-http/blob/master/lib/mime.js"
    click etag "https://github.com/htdangkhoa/pure-http/blob/master/lib/etag.js"
    click settings "https://github.com/htdangkhoa/pure-http/blob/master/lib/settings.js"
    click views "https://github.com/htdangkhoa/pure-http/tree/master/demos/render/views/"
    click error "https://github.com/htdangkhoa/pure-http/blob/master/tests/error-handling/server.js"
    click static "https://github.com/htdangkhoa/pure-http/tree/master/demos/render/public/"
    click utils "https://github.com/htdangkhoa/pure-http/blob/master/lib/utils.js"
    click https "https://github.com/htdangkhoa/pure-http/blob/master/demos/https/index.js"
    click router "https://github.com/htdangkhoa/pure-http/blob/master/demos/router/router.js"

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:2px
    classDef server fill:#69c,stroke:#333,stroke-width:2px
    classDef core fill:#3c9,stroke:#333,stroke-width:2px
    classDef extension fill:#fc9,stroke:#333,stroke-width:2px
    classDef utility fill:#ccc,stroke:#333,stroke-width:2px
    classDef feature fill:#9cf,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        client_leg[Client]:::client
        server_leg[Server Components]:::server
        core_leg[Core Components]:::core
        ext_leg[Extensions]:::extension
        util_leg[Utilities]:::utility
        feat_leg[Features]:::feature
    end
```
