# prostgles/prostgles-server-js architecture

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

- Interactive diagram: https://gitdiagram.com/prostgles/prostgles-server-js
- Repository: https://github.com/prostgles/prostgles-server-js

## Overview

##### Main Components Identification

a) Core Components:
- Database Layer (PostgreSQL)
- Server-Side Handler (Prostgles Server)
- Client-Side Interface
- WebSocket Communication Layer (Socket.io)

b) Key Functional Modules (represented as subsystems):
- Auth Handler (/lib/Auth)
- DBO Builder (/lib/DboBuilder)
- File Manager (/lib/FileManager)
- PubSub Manager (/lib/PubSubManager)
- Schema Watch (/lib/SchemaWatch)
- REST API Handler (/lib/RestApi.ts)

**[Database Layer]**
- ↑↓
**[Prostgles Server Core]**
- ↑↓
**[Communication Layer]**
- ↑↓
**[Client Applications]**

##### Detailed Component Breakdown

DBO Builder Section:
**[Query Builder] → [Table Handler] → [View Handler]**
- ↓               ↓              ↓
- [SQL Generation] [Data Validation] [Filtering]

Auth Handler Section:
**[Auth Providers] → [Auth Handler] → [Email/OAuth]**
- ↓              ↓
**[Session Management] [User Validation]**

##### Special Features to Highlight

Create dedicated sections showing:
- TypeScript Definition Generation
- JSONB Schema Validation
- Real-time Subscriptions
- Access Control Flow

##### Integration Points

External integration points:
- Socket.io WebSocket connection
- Express.js integration
- File storage system
- Email service connections

##### Technical Details

Small annotations showing:
- TypeScript integration points
- WebSocket channels
- Database connection pools
- Cache layers (if any)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Database
        PG[PostgreSQL Database]
    end

    subgraph "Server Core"
        PS[Prostgles Server]:::core
        click PS "https://github.com/prostgles/prostgles-server-js/blob/master/lib/Prostgles.ts"
        ST[Server Types]:::core
        click ST "https://github.com/prostgles/prostgles-server-js/blob/master/lib/ProstglesTypes.ts"
        SI[Server Init]:::core
        click SI "https://github.com/prostgles/prostgles-server-js/blob/master/lib/initProstgles.ts"
    end

    subgraph "Core Handlers"
        direction TB
        AH[Auth Handler]:::auth
        click AH "https://github.com/prostgles/prostgles-server-js/blob/master/lib/Auth/AuthHandler.ts"
        DB[DBO Builder]:::data
        click DB "https://github.com/prostgles/prostgles-server-js/blob/master/lib/DboBuilder/DboBuilder.ts"
        FM[File Manager]:::file
        click FM "https://github.com/prostgles/prostgles-server-js/blob/master/lib/FileManager/FileManager.ts"
        PM[PubSub Manager]:::pubsub
        click PM "https://github.com/prostgles/prostgles-server-js/blob/master/lib/PubSubManager/PubSubManager.ts"
        SW[Schema Watch]:::schema
        click SW "https://github.com/prostgles/prostgles-server-js/blob/master/lib/SchemaWatch/SchemaWatch.ts"
        RA[REST API]:::api
        click RA "https://github.com/prostgles/prostgles-server-js/blob/master/lib/RestApi.ts"
    end

    subgraph "Auth Components"
        direction TB
        OP[OAuth Providers]:::auth
        click OP "https://github.com/prostgles/prostgles-server-js/blob/master/lib/Auth/authProviders/setOAuthProviders.ts"
        EP[Email Provider]:::auth
        click EP "https://github.com/prostgles/prostgles-server-js/blob/master/lib/Auth/authProviders/setEmailProvider.ts"
    end

    subgraph "DBO Components"
        direction TB
        QB[Query Builder]:::data
        click QB "https://github.com/prostgles/prostgles-server-js/blob/master/lib/DboBuilder/QueryBuilder/QueryBuilder.ts"
        TH[Table Handler]:::data
        click TH "https://github.com/prostgles/prostgles-server-js/blob/master/lib/DboBuilder/TableHandler/TableHandler.ts"
        VH[View Handler]:::data
        click VH "https://github.com/prostgles/prostgles-server-js/blob/master/lib/DboBuilder/ViewHandler/ViewHandler.ts"
    end

    subgraph "File Components"
        direction TB
        FU[File Upload]:::file
        click FU "https://github.com/prostgles/prostgles-server-js/blob/master/lib/FileManager/upload.ts"
        SU[Stream Upload]:::file
        click SU "https://github.com/prostgles/prostgles-server-js/blob/master/lib/FileManager/uploadStream.ts"
    end

    subgraph "PubSub Components"
        direction TB
        SH[Subscription Handler]:::pubsub
        click SH "https://github.com/prostgles/prostgles-server-js/blob/master/lib/PubSubManager/addSub.ts"
        NL[Notification Listener]:::pubsub
        click NL "https://github.com/prostgles/prostgles-server-js/blob/master/lib/PubSubManager/notifListener.ts"
    end

    subgraph "Communication Layer"
        WS[WebSocket Handler]:::comm
        click WS "https://github.com/prostgles/prostgles-server-js/blob/master/lib/onSocketConnected.ts"
        CR[Client Request Handler]:::comm
        click CR "https://github.com/prostgles/prostgles-server-js/blob/master/lib/runClientRequest.ts"
    end

    subgraph "Schema & Validation"
        direction TB
        DE[DB Events Manager]:::schema
        click DE "https://github.com/prostgles/prostgles-server-js/blob/master/lib/DBEventsManager.ts"
        SB[Schema Builder]:::schema
        click SB "https://github.com/prostgles/prostgles-server-js/blob/master/lib/DBSchemaBuilder.ts"
        JV[JSON Validation]:::validation
        click JV "https://github.com/prostgles/prostgles-server-js/blob/master/lib/JSONBValidation/validation.ts"
    end

    %% Connections
    PG --> PS
    PS --> ST
    PS --> SI
    
    PS --> AH
    PS --> DB
    PS --> FM
    PS --> PM
    PS --> SW
    PS --> RA

    AH --> OP
    AH --> EP

    DB --> QB
    DB --> TH
    DB --> VH

    FM --> FU
    FM --> SU

    PM --> SH
    PM --> NL

    WS --> CR
    CR --> PS

    classDef core fill:#3498db
    classDef auth fill:#f1c40f
    classDef data fill:#2ecc71
    classDef file fill:#e67e22
    classDef pubsub fill:#9b59b6
    classDef schema fill:#1abc9c
    classDef api fill:#e74c3c
    classDef comm fill:#34495e
    classDef validation fill:#95a5a6

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Auth Components]:::auth
        L3[Data Components]:::data
        L4[File Components]:::file
        L5[PubSub Components]:::pubsub
        L6[Schema Components]:::schema
        L7[API Components]:::api
        L8[Communication]:::comm
        L9[Validation]:::validation
    end
```
