# russfeld/officehours-node architecture

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

- Interactive diagram: https://gitdiagram.com/russfeld/officehours-node
- Repository: https://github.com/russfeld/officehours-node

## Overview

##### Main Components

A. Frontend Layer:
- Vue.js Application (indicated by /vue directory and public/assets)
- Static Assets (public directory)
- Client-side Socket.IO Connection

B. Backend Layer:
- Express.js Server (app.js)
- Authentication System (CAS integration, routes/auth.js)
- API Routes (routes/api/*)
- WebSocket Server (socket.js)
- Middleware Layer (middlewares/*)

C. Data Layer:
- Database (configured in configs/db.js)
- Knex.js ORM (indicated by knexfile.js)
- Models Layer (models/*)

##### Component Relationships

- Frontend → Backend: HTTP/REST APIs
- Frontend ↔ Backend: WebSocket connections
- Backend → Database: Data persistence
- Authentication Flow: Client → CAS → Backend

##### Architectural Patterns to Highlight

- MVC Pattern:
- Models: /models directory
- Views: /views directory (Pug templates)
- Controllers: /routes directory

- Real-time Communication:
- Socket.io implementation (/sockets directory)
- Queue management system
- Presence tracking

##### Specific Implementation Details

A. Authentication & Authorization:
- CAS Integration
- Token-based middleware
- Role-based access control

B. Real-time Features:
- Queue management
- Presence tracking
- Status updates

C. Data Models:
- User
- Queue
- Event
- Period
- Presence
- Request
- Role

##### Infrastructure Components

Docker-related components:
- Docker container
- Docker Compose services
- Environment configurations

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:white
    classDef auth fill:#e74c3c,stroke:#c0392b,color:white
    classDef websocket fill:#9b59b6,stroke:#8e44ad,color:white
    classDef api fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Frontend Layer
    subgraph Frontend
        VueApp["Vue.js Application"]:::frontend
        StaticAssets["Static Assets"]:::frontend
        WSClient["WebSocket Client"]:::websocket
    end

    %% Backend Layer
    subgraph Backend
        Express["Express.js Server"]:::backend
        AuthMiddleware["Authentication Middleware"]:::auth
        WSServer["WebSocket Server"]:::websocket

        subgraph "API Routes"
            ApiRouter["Main API Router"]:::api
            PeriodsAPI["/api/periods"]:::api
            ProfileAPI["/api/profile"]:::api
            QueuesAPI["/api/queues"]:::api
            RolesAPI["/api/roles"]:::api
            UsersAPI["/api/users"]:::api
            AuthAPI["/auth"]:::api
        end

        subgraph "Middleware Stack"
            AdminAccess["Admin Access Control"]:::backend
            ReqLogger["Request Logger"]:::backend
            SocketQueue["Socket Queue Manager"]:::backend
            TokenValid["Token Validator"]:::backend
            SocketToken["Socket Token Handler"]:::backend
        end

        subgraph "WebSocket Handlers"
            PresenceSocket["Presence Socket"]:::websocket
            QueuesSocket["Queues Socket"]:::websocket
            StatusSocket["Status Socket"]:::websocket
        end
    end

    %% Database Layer
    subgraph Database
        DBConfig["Database Config"]:::database
        
        subgraph "Models"
            BaseModel["Base Model"]:::database
            EventModel["Event Model"]:::database
            PeriodModel["Period Model"]:::database
            PresenceModel["Presence Model"]:::database
            QueueModel["Queue Model"]:::database
            RequestModel["Request Model"]:::database
            RoleModel["Role Model"]:::database
            UserModel["User Model"]:::database
        end
    end

    %% Connections
    VueApp --> Express
    WSClient --> WSServer
    Express --> AuthMiddleware
    Express --> ApiRouter
    ApiRouter --> PeriodsAPI & ProfileAPI & QueuesAPI & RolesAPI & UsersAPI & AuthAPI
    WSServer --> PresenceSocket & QueuesSocket & StatusSocket
    Express --> DBConfig

    %% Click Events
    click VueApp "https://github.com/russfeld/officehours-node/tree/main/vue"
    click StaticAssets "https://github.com/russfeld/officehours-node/tree/main/public/assets"
    click Express "https://github.com/russfeld/officehours-node/blob/main/app.js"
    click ApiRouter "https://github.com/russfeld/officehours-node/blob/main/routes/api.js"
    click PeriodsAPI "https://github.com/russfeld/officehours-node/blob/main/routes/api/periods.js"
    click ProfileAPI "https://github.com/russfeld/officehours-node/blob/main/routes/api/profile.js"
    click QueuesAPI "https://github.com/russfeld/officehours-node/blob/main/routes/api/queues.js"
    click RolesAPI "https://github.com/russfeld/officehours-node/blob/main/routes/api/roles.js"
    click UsersAPI "https://github.com/russfeld/officehours-node/blob/main/routes/api/users.js"
    click AuthAPI "https://github.com/russfeld/officehours-node/blob/main/routes/auth.js"
    click AdminAccess "https://github.com/russfeld/officehours-node/blob/main/middlewares/admin-only.js"
    click ReqLogger "https://github.com/russfeld/officehours-node/blob/main/middlewares/request-logger.js"
    click SocketQueue "https://github.com/russfeld/officehours-node/blob/main/middlewares/socket-queue.js"
    click TokenValid "https://github.com/russfeld/officehours-node/blob/main/middlewares/token.js"
    click SocketToken "https://github.com/russfeld/officehours-node/blob/main/middlewares/socket-token.js"
    click DBConfig "https://github.com/russfeld/officehours-node/blob/main/configs/db.js"
    click BaseModel "https://github.com/russfeld/officehours-node/blob/main/models/base.js"
    click EventModel "https://github.com/russfeld/officehours-node/blob/main/models/event.js"
    click PeriodModel "https://github.com/russfeld/officehours-node/blob/main/models/period.js"
    click PresenceModel "https://github.com/russfeld/officehours-node/blob/main/models/presence.js"
    click QueueModel "https://github.com/russfeld/officehours-node/blob/main/models/queue.js"
    click RequestModel "https://github.com/russfeld/officehours-node/blob/main/models/request.js"
    click RoleModel "https://github.com/russfeld/officehours-node/blob/main/models/role.js"
    click UserModel "https://github.com/russfeld/officehours-node/blob/main/models/user.js"
    click WSServer "https://github.com/russfeld/officehours-node/blob/main/socket.js"
    click PresenceSocket "https://github.com/russfeld/officehours-node/blob/main/sockets/presence.js"
    click QueuesSocket "https://github.com/russfeld/officehours-node/blob/main/sockets/queues.js"
    click StatusSocket "https://github.com/russfeld/officehours-node/blob/main/sockets/status.js"
    click AuthMiddleware "https://github.com/russfeld/officehours-node/blob/main/configs/cas.js"
```
