# proofrock/ws4sqlite architecture

> Architecture diagram of the GitHub repository proofrock/ws4sqlite, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/proofrock/ws4sqlite
- Repository: https://github.com/proofrock/ws4sqlite

## Overview

##### Main Components

a) Core Server Components:
- HTTP Server Layer (using gofiber)
- Authentication Handler
- Request Parser/Router
- Transaction Manager
- SQLite Connection Pool
- Scheduled Tasks Manager
- Web Server (for static content)

b) External Components:
- SQLite Database Files
- Client Applications
- (Optional) Reverse Proxy

##### Specific Implementation Details

- REST API Endpoints (/database_name)
- Authentication Module (from authentication.go)
- Transaction Handler (from ws4sqlite.go)
- Scheduled Tasks Manager (from sched_tasks.go)
- SQLite Interface Layer
- Static Web Server Component

##### Flow Representation

**[Client] → [HTTP Server] → [Auth Handler] → [Request Router] →**
**[Transaction Manager] → [SQLite Interface] → [Database Files]**

With parallel flows for:
**[Cron Scheduler] → [Task Manager] → [Database Operations]**
**[Web Server] → [Static Content]**

##### Important Elements

a) Security Layer:
- Basic Auth
- Custom Auth Query
- CORS Handler
- Interface Binding

b) Transaction Features:
- Statement Batching
- Error Handling
- Rollback Control

c) Database Operations:
- Read-only Mode
- WAL Mode
- Stored Statements
- Backup/Vacuum Tasks

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client Layer
        CL[Client Applications]
        RC[REST Client]
        WC[Web Client]
    end

    subgraph Server Layer
        HS["HTTP Server (gofiber)"]:::server
        click HS "https://github.com/proofrock/ws4sqlite/blob/main/src/ws4sqlite.go"
        
        subgraph Security Layer
            AH[Authentication Handler]:::security
            click AH "https://github.com/proofrock/ws4sqlite/blob/main/src/authentication.go"
            CORS[CORS Handler]:::security
        end
        
        subgraph Core Processing
            RP[Request Parser]:::core
            TM[Transaction Manager]:::core
            click TM "https://github.com/proofrock/ws4sqlite/blob/main/src/ws4sqlite.go"
            DS[Data Structures]:::core
            click DS "https://github.com/proofrock/ws4sqlite/blob/main/src/structs.go"
            UT[Utility Functions]:::core
            click UT "https://github.com/proofrock/ws4sqlite/blob/main/src/utils.go"
        end
        
        subgraph Task Management
            STM[Scheduled Tasks Manager]:::tasks
            click STM "https://github.com/proofrock/ws4sqlite/blob/main/src/sched_tasks.go"
            CRON[Cron Scheduler]:::tasks
        end
        
        subgraph Web Server
            WS[Web Server Component]:::web
            click WS "https://github.com/proofrock/ws4sqlite/blob/main/src/web_service.go"
            SC[Static Content]:::web
        end
        
        subgraph Configuration
            CF[Config Files]:::config
            click CF "https://github.com/proofrock/ws4sqlite/blob/main/test/test1.yaml"
            RT[Request Templates]:::config
            click RT "https://github.com/proofrock/ws4sqlite/blob/main/profiler/request.json"
        end
    end
    
    subgraph Database Layer
        CP[Connection Pool]:::db
        SQ[SQLite Interface]:::db
        DB[(SQLite Database Files)]:::db
    end

    %% Connections
    CL --> RC & WC
    RC --> HS
    WC --> WS
    
    HS --> AH
    AH --> CORS
    CORS --> RP
    
    RP --> TM
    TM --> DS
    TM --> UT
    
    STM --> CRON
    CRON --> TM
    
    TM --> CP
    CP --> SQ
    SQ --> DB
    
    WS --> SC
    
    CF -.-> HS
    RT -.-> RP

    %% Styles
    classDef server fill:#6495ED
    classDef security fill:#FFD700
    classDef core fill:#90EE90
    classDef tasks fill:#FFA500
    classDef web fill:#DDA0DD
    classDef db fill:#A9A9A9
    classDef config fill:#F0E68C

    %% Legend
    subgraph Legend
        L1[Server Components]:::server
        L2[Security Layer]:::security
        L3[Core Processing]:::core
        L4[Task Management]:::tasks
        L5[Web Components]:::web
        L6[Database Layer]:::db
        L7[Configuration]:::config
    end
```
