# dhcgn/iot-ephemeral-value-store architecture

> Architecture diagram of the GitHub repository dhcgn/iot-ephemeral-value-store, 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/dhcgn/iot-ephemeral-value-store
- Repository: https://github.com/dhcgn/iot-ephemeral-value-store

## Overview

##### Main Components

a) Core Components:
- HTTP Server Layer (Main Entry Point)
- HTTP Handlers Layer
- Storage Layer
- Domain Layer
- Statistics Tracking
- Middleware Components

b) External Components:
- IoT Devices (Clients)
- Web Browsers (Clients)
- File System (for persistence)

**┌─────────────────────────────────────────────────────────────┐**
- External Clients                         │
- ┌──────────────┐  ┌──────────────┐   ┌──────────────┐    │
- IoT Device  │  │ Web Browser  │   │ HTTP Client  │    │
- ┘  └──────────────┘   └──────────────┘    │
- ┬─────────────┬────────────────┬─────────────┘

- ▼             ▼                ▼
**┌─────────────────────────────────────────────────────────────┐**
- Middleware Layer                         │
- ┌──────────┐    ┌───────────┐    ┌────────────────┐      │
- CORS   │    │Rate Limit │    │Request Size Limit│     │
- ┘    └───────────┘    └────────────────┘      │
- ┬───────────────────────────────┘

**┌──────────────────────────▼──────────────────────────────┐**
- HTTP Handler Layer                     │
- ┌─────────┐ ┌────────┐ ┌───────┐ ┌────────┐ ┌───────┐ │
- Upload  │ │Download│ │KeyPair│ │ Delete │ │ Patch │ │
- ┘ └────────┘ └───────┘ └────────┘ └───────┘ │
- ┬──────────────────────────────┘

**┌─────────────────────────▼──────────────────────────────┐**
- Domain Layer                         │
- (Business Logic & Data Structures)               │
- ┬──────────────────────────────┘

**┌─────────────────────────▼──────────────────────────────┐**
- Storage Layer                         │
- ┌────────────────┐        ┌─────────────┐           │
- Ephemeral Store │        │   Stats     │           │
- ┘        └─────────────┘           │
- ┬──────────────────────────────┘

**┌─────────────────────────▼──────────────────────────────┐**
- File System                           │
- (Persistent Storage)                       │
- ┘

##### Important Implementation Details to Highlight
- Key pair generation and verification mechanism
- Data merging for patch operations
- Ephemeral storage duration
- Rate limiting configuration
- Request size limitations
- CORS settings

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients Layer
    subgraph Clients
        IoT[IoT Device]:::client
        Web[Web Browser]:::client
        HTTP[HTTP Client]:::client
    end

    %% Middleware Layer
    subgraph Middleware
        CORS["CORS Middleware"]:::middleware
        RateLimit["Rate Limit"]:::middleware
        SizeLimit["Request Size Limit"]:::middleware
    end

    %% HTTP Handler Layer
    subgraph Handlers
        Upload["Upload Handler"]:::handler
        Download["Download Handler"]:::handler
        KeyPair["KeyPair Handler"]:::handler
        Delete["Delete Handler"]:::handler
        Patch["Patch Handler"]:::handler
        Config["Handler Config"]:::config
    end

    %% Domain Layer
    subgraph Domain
        DomainLogic["Business Logic & Data Structures"]:::domain
    end

    %% Storage Layer
    subgraph Storage
        EphemeralStore["Ephemeral Store"]:::storage
        Stats["Statistics Tracking"]:::storage
    end

    %% File System Layer
    FileSystem["File System (Persistent Storage)"]:::filesystem

    %% Static Interface
    StaticUI["Static Web Interface"]:::ui

    %% Relationships
    IoT & Web & HTTP --> CORS
    CORS & RateLimit & SizeLimit --> Upload & Download & KeyPair & Delete & Patch
    Upload & Download & KeyPair & Delete & Patch --> DomainLogic
    DomainLogic --> EphemeralStore
    EphemeralStore --> FileSystem
    DomainLogic --> Stats
    Web --> StaticUI

    %% Click Events
    click CORS "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/middleware/cors.go"
    click RateLimit "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/middleware/ratelimit.go"
    click SizeLimit "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/middleware/limitRequestSize.go"
    click Upload "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/httphandler/uploadHandler.go"
    click Download "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/httphandler/downloadHandler.go"
    click KeyPair "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/httphandler/keyPairHandler.go"
    click Delete "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/httphandler/deleteHandler.go"
    click Patch "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/httphandler/datahandling.go"
    click Config "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/httphandler/config.go"
    click DomainLogic "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/domain/domain.go"
    click EphemeralStore "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/storage/storage.go"
    click Stats "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/stats/stats.go"
    click StaticUI "https://github.com/dhcgn/iot-ephemeral-value-store/blob/main/static/index.html"

    %% Styles
    classDef client fill:#a8d1f0,stroke:#333,stroke-width:2px
    classDef middleware fill:#90EE90,stroke:#333,stroke-width:2px
    classDef handler fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef domain fill:#FFA07A,stroke:#333,stroke-width:2px
    classDef storage fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef filesystem fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef config fill:#F0E68C,stroke:#333,stroke-width:2px
    classDef ui fill:#98FB98,stroke:#333,stroke-width:2px
```
