# snowmerak/lux architecture

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

- Interactive diagram: https://gitdiagram.com/snowmerak/lux
- Repository: https://github.com/snowmerak/lux

## Overview

##### Main Components

a) Core Framework Components:
- Lux Server Core
- Context Handler
- Controller Layer
- Middleware System
- Provider System
- Signal Handler

b) Request/Response Flow Components:
- REST Controllers
- WebSocket Controllers
- Middleware Chain
- Context Management

**┌─────────────────────────────────────────────┐**
- Client Layer                │
- ┘
- ↕️
**┌─────────────────────────────────────────────┐**
- Lux Server Core                │
- ┌─────────────┐    ┌─────────────────┐    │
- Router    │←→│  Context Handler  │    │
- ┘    └─────────────────┘    │
- ┘
- ↕️
**┌─────────────────────────────────────────────┐**
- Controller Layer                 │
- ┌─────────────┐    ┌─────────────────┐    │
- REST     │    │    WebSocket    │    │
- Controllers │    │   Controllers   │    │
- ┘    └─────────────────┘    │
- ┘
- ↕️
**┌─────────────────────────────────────────────┐**
- Middleware Chain                 │
- ┌─────────────┐    ┌─────────────────┐    │
- Request   │→│   Response      │    │
- Middlewares │    │  Middlewares    │    │
- ┘    └─────────────────┘    │
- ┘
- ↕️
**┌─────────────────────────────────────────────┐**
- Service Layer                    │
- ┌─────────────┐    ┌─────────────────┐    │
- Services   │    │    Providers    │    │
- ┘    └─────────────────┘    │
- ┘

##### Important Relationships

a) Request Flow:
- Client → Lux Server → Context Handler → Middleware Chain → Controller → Service → Response

b) Dependency Injection:
- Provider System → Services → Controllers

c) Middleware Integration:
- How middleware can be inserted at different points in the request lifecycle

##### Special Components to Highlight

a) Provider System:
- How it manages dependency injection
- Constructor and updater patterns

b) Context Management:
- Demonstrate how it handles request/response lifecycle
- JWT and WebSocket integration

##### Additional Elements

- Component types
- Special symbols used

##### Implementation Details

- The modular nature of the framework
- How controllers can be generated and customized
- The middleware chain's flexibility
- The service layer's integration

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CL[Client]
    end

    subgraph Core
        LUX["Lux Server Core"]:::core
        CH["Context Handler"]:::core
        RT["Router"]:::core
        SH["Signal Handler"]:::core
    end

    subgraph Controllers
        REST["REST Controllers"]:::controller
        WS["WebSocket Controllers"]:::controller
    end

    subgraph Middleware
        direction TB
        MW["Middleware System"]:::middleware
        CORS["CORS Handler"]:::middleware
        COMP["Compression"]:::middleware
        ACL["ACL Implementation"]:::middleware
        AUTH["Authorization"]:::middleware
    end

    subgraph Context
        CTX_RESP["Response Handler"]:::context
        CTX_STAT["Status Handler"]:::context
        JWT["JWT Management"]:::context
        WS_SUP["WebSocket Support"]:::context
    end

    subgraph Services
        PS["Provider System"]:::service
        PA["Provider Analyzer"]:::service
        LOG["Logging System"]:::service
    end

    %% Relationships
    CL --> LUX
    LUX --> CH
    LUX --> RT
    LUX --> SH

    RT --> REST
    RT --> WS

    CH --> MW
    MW --> CORS
    MW --> COMP
    MW --> ACL
    MW --> AUTH

    CH --> CTX_RESP
    CH --> CTX_STAT
    CH --> JWT
    CH --> WS_SUP

    REST --> PS
    WS --> PS
    PS --> PA
    PS --> LOG

    %% Click Events
    click LUX "https://github.com/snowmerak/lux/blob/v3/lux/lux.go"
    click CH "https://github.com/snowmerak/lux/blob/v3/context/context.go"
    click REST "https://github.com/snowmerak/lux/blob/v3/controller/rest.go"
    click WS "https://github.com/snowmerak/lux/blob/v3/controller/ws.go"
    click MW "https://github.com/snowmerak/lux/blob/v3/middleware/middleware.go"
    click PS "https://github.com/snowmerak/lux/blob/v3/provider/provider.go"
    click SH "https://github.com/snowmerak/lux/blob/v3/signal/signal.go"
    click JWT "https://github.com/snowmerak/lux/blob/v3/context/jwt.go"
    click WS_SUP "https://github.com/snowmerak/lux/blob/v3/context/websocket.go"
    click CORS "https://github.com/snowmerak/lux/blob/v3/middleware/cors.go"
    click COMP "https://github.com/snowmerak/lux/blob/v3/middleware/compress.go"
    click ACL "https://github.com/snowmerak/lux/blob/v3/middleware/acl.go"
    click AUTH "https://github.com/snowmerak/lux/blob/v3/middleware/authorize.go"
    click CTX_RESP "https://github.com/snowmerak/lux/blob/v3/context/reply.go"
    click CTX_STAT "https://github.com/snowmerak/lux/blob/v3/context/status.go"
    click PA "https://github.com/snowmerak/lux/blob/v3/provider/analyzer.go"
    click LOG "https://github.com/snowmerak/lux/blob/v3/logext/zerolog.go"

    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef controller fill:#4CAF50,stroke:#2E7D32,color:white
    classDef middleware fill:#FF9800,stroke:#EF6C00,color:white
    classDef context fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef service fill:#673AB7,stroke:#4527A0,color:white

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Controllers]:::controller
        L3[Middleware]:::middleware
        L4[Context Handlers]:::context
        L5[Services]:::service
    end
```
