# geocoderdev/siasis-ss01-dev architecture

> Architecture diagram of the GitHub repository geocoderdev/siasis-ss01-dev, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/geocoderdev/siasis-ss01-dev
- Repository: https://github.com/geocoderdev/siasis-ss01-dev

## Overview

##### Project Type and Purpose
- This is a standalone, TypeScript-based real-time socket server (“SS01-SIASIS”) that provides bi-directional WebSocket (Socket.IO) communication for SIASIS attendance and related operations.
- It exposes both HTTP routes (e.g., `authRoutes.ts`) for login/REST operations and WebSocket channels under `src/sockets` for real-time events (e.g., attendance updates).
- It uses Prisma as its ORM to persist and query data.

##### High-Level Architecture Components
a. Clients (Web or Mobile Frontend)
- Initiate HTTP requests (login, profile) via REST
- Open Socket.IO connections for real-time events
b. API Gateway / HTTP Layer (`src/routes`, `src/server/handlers`)
- Express (or minimal HTTP) routes for authentication and basic CRUD
- Middleware for JWT validation (`src/middlewares/socketAuth.ts`)
c. WebSocket Server (`src/server/SocketServer.ts`, `src/sockets`)
- Socket.IO setup, namespace and event definitions
- Event handlers organized by feature (e.g., `AsistenciaDePersonal`)
d. Business Logic & Utilities (`src/lib/utils`, `src/server/utils`, `src/assets`)
- Environment loader, JWT key resolution
- Shared enums, types, and translation texts
- Logging utility (`ServerLogger.ts`)
e. Data Persistence (Prisma + Database)
- `prisma/schema.prisma` defines models
- Prisma Client invoked in route handlers or socket handlers
f. Deployment Pipeline & Infrastructure
- GitHub Actions workflows (`.github/workflows/*`) for CI/CD
- Oracle Cloud target for Dev/Cert/Prod via auto-deploy YAMLs

##### Relationships and Data Flows
- HTTP Request Flow: Client → API Gateway → Middleware → Route Handler → Prisma → Database → Response → Client
- WebSocket Flow: Client → SocketServer handshake → Auth middleware → Event namespaced under `src/sockets/events` → Event handler → Prisma (if needed) → Broadcast/Emit → Client(s)
- CI/CD Flow: GitHub push → GitHub Actions → Build & Test → Deploy to Oracle Cloud

##### Architectural Patterns & Principles
- Separation of Concerns:
- HTTP REST routes vs. WebSocket event handlers
- Utilities (env, logging) isolated from business logic
- Modular Feature Folders: sockets/events grouped by domain
- Typed Interfaces: Rich TypeScript interfaces under `src/interfaces` ensure strict contracts
- Single Responsibility: One file per handler, config, or utility

## Diagram (Mermaid)

```mermaid
flowchart TD
    Clients["Clients (Web & Mobile)"]:::client

    subgraph "Socket Server (SS01-SIASIS)"
        subgraph "HTTP Layer"
            APIRoutes["authRoutes.ts"]:::internal
            RouteHandler["RouteHandler.ts"]:::internal
        end
        Middleware["socketAuth.ts"]:::internal
        subgraph "WebSocket Layer"
            SocketServer["SocketServer.ts"]:::internal
            SocketsCore["Sockets.ts"]:::internal
            subgraph "Events: AsistenciaDePersonal"
                EventIndex["index.ts"]:::internal
                BackendEvents["TomaAsistenciaPersonalSS01Events.ts"]:::internal
                FrontendEvents["TomaAsistenciaPersonalSIU01Events.ts"]:::internal
                Interfaces1["NombresEventosAsistenciaDePersonal.ts"]:::internal
                Interfaces2["PayloadEventosAsisteciaDePersonal.ts"]:::internal
            end
            UtilsSocket["SocketsUnitario.ts"]:::internal
        end
        subgraph "Config & Utils"
            ServerConfig["ServerConfig.ts"]:::internal
            JWTEnv["getJWTKeyForRole.ts"]:::internal
            ServerLogger["ServerLogger.ts"]:::internal
            Assets1["Entornos.ts"]:::internal
            Assets2["RolesTextos.ts"]:::internal
            InterfacesUSR["UserData.ts"]:::internal
            InterfacesShared["shared interfaces"]:::internal
        end
    end

    DB["Prisma + Database\n(schema.prisma)"]:::db
    CI["GitHub Actions CI/CD"]:::cicd
    subgraph "Oracle Cloud"
        Oracle["Oracle Cloud"]:::infra
    end

    Clients -->|"REST API calls / JWT"| APIRoutes
    APIRoutes -->|"REST request"| Middleware
    Middleware -->|"validated"| RouteHandler
    RouteHandler -->|"Prisma ORM queries"| DB
    Clients -->|"Socket.IO connect & events"| SocketServer
    SocketServer -->|"handshake"| Middleware
    Middleware -->|"auth"| EventIndex
    EventIndex -->|"invoke"| BackendEvents
    BackendEvents -->|"query"| DB
    DB -->|"results"| BackendEvents
    BackendEvents -->|"emit"| Clients
    JWTEnv -.->|"provides"| ServerConfig
    ServerConfig -.->|"configures"| SocketServer
    Assets1 -.-> APIRoutes
    InterfacesUSR -.-> RouteHandler
    InterfacesShared -.-> EventIndex
    CI -->|"deploy"| Oracle

    classDef client fill:#fdfd96,stroke:#333,stroke-width:1px
    classDef internal fill:#aec6cf,stroke:#333,stroke-width:1px
    classDef db fill:#b2fab4,stroke:#333,stroke-width:1px
    classDef infra fill:#ffb347,stroke:#333,stroke-width:1px
    classDef cicd fill:#d3d3d3,stroke:#333,stroke-width:1px

    click APIRoutes "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/routes/authRoutes.ts"
    click RouteHandler "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/server/handlers/RouteHandler.ts"
    click Middleware "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/middlewares/socketAuth.ts"
    click SocketServer "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/server/SocketServer.ts"
    click SocketsCore "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/sockets/Sockets.ts"
    click EventIndex "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/sockets/events/AsistenciaDePersonal/index.ts"
    click BackendEvents "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/sockets/events/AsistenciaDePersonal/backend/TomaAsistenciaPersonalSS01Events.ts"
    click FrontendEvents "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/sockets/events/AsistenciaDePersonal/frontend/TomaAsistenciaPersonalSIU01Events.ts"
    click Interfaces1 "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/sockets/events/AsistenciaDePersonal/interfaces/NombresEventosAsistenciaDePersonal.ts"
    click Interfaces2 "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/sockets/events/AsistenciaDePersonal/interfaces/PayloadEventosAsisteciaDePersonal.ts"
    click UtilsSocket "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/sockets/utils/SocketsUnitario.ts"
    click ServerConfig "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/server/config/ServerConfig.ts"
    click JWTEnv "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/lib/utils/env/getJWTKeyForRole.ts"
    click ServerLogger "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/server/utils/ServerLogger.ts"
    click Assets1 "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/assets/Entornos.ts"
    click Assets2 "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/assets/RolesTextos.ts"
    click InterfacesUSR "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/src/interfaces/UserData.ts"
    click InterfacesShared "https://github.com/geocoderdev/siasis-ss01-dev/tree/master/src/interfaces/shared"
    click DB "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/prisma/schema.prisma"
    click CI "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/.github/workflows/autoDeployToOracleCloudDev.yml"
    click CI "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/.github/workflows/autoDeployToOracleCloudCert.yml"
    click CI "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/.github/workflows/autoDeployToOracleCloudProd.yml"
    click CI "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/.github/workflows/haciaDesarrollo.yml"
    click CI "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/.github/workflows/haciaCertificacion.yml"
    click CI "https://github.com/geocoderdev/siasis-ss01-dev/blob/master/.github/workflows/haciaProduccionIE20935.yml"
```
