# sajjad-amin/socket-server architecture

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

- Interactive diagram: https://gitdiagram.com/sajjad-amin/socket-server
- Repository: https://github.com/sajjad-amin/socket-server

## Overview

##### Main Components

A. Client Layer:
- Web Browsers
- Socket.IO Client

B. Server Layer:
- Express.js Server
- Socket.IO Server
- Authentication System
- MVC Components:
- Controllers (AuthController, DashboardController, etc.)
- Models (EventModel, UserModel, etc.)
- Views (EJS templates)

C. Core Services:
- Database (SQLite - indicated by database.db)
- Email Factory
- Hash Factory
- Validation Factory

##### Component Relationships

**[Client Layer]**
- ↕ HTTP/WebSocket
**[Express + Socket.IO Server Layer]**
- ↕
**[Middleware Layer]**
- ↕
**[Controller Layer]**
- ↕
**[Model Layer]**
- ↕
**[Core Layer]**
- ↕
**[Database]**

##### Specific Elements

A. Request Flow:
- WebSocket event flow
- Middleware checkpoints (AuthMiddleware, VerifiedUserMiddleware)

B. Core Components:
- Factory pattern implementation
- Database connections
- Authentication flow

##### Detailed Component Breakdown

A. Authentication Flow:
**[Login/Register View] → [AuthController] → [UserModel]**
- ↓
- [AuthMiddleware]
- ↓
- [Dashboard View]

B. Event Management:
**[Socket.IO Client] ←→ [EventController] → [EventModel]**
- ↓
- [Database]

##### Important Architectural Notes

- Separation of concerns with the MVC pattern
- Middleware chain for protected routes
- Real-time communication paths via Socket.IO
- Factory pattern implementation in the Core layer
- Database interaction patterns

##### Implementation Details to Highlight

- Authentication system with verification
- Password reset flow
- Real-time event handling
- Database operations
- Email notifications
- Input validation

##### Core Services Layer (Factories, Database)

Use standardized symbols:
- Rectangles: Components
- Diamonds: Decision points

- How real-time events are handled
- The authentication and authorization flow
- Data persistence patterns
- Core service integration
- Security middleware implementation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
        SocketClient["Socket.IO Client"]:::socket
    end

    subgraph Server
        Express["Express.js Server"]:::server
        SocketServer["Socket.IO Server"]:::socket
        click Express "https://github.com/sajjad-amin/socket-server/blob/main/index.js"
    end

    subgraph Routes
        AuthRouter["Auth Router"]:::route
        DashRouter["Dashboard Router"]:::route
        HomeRouter["Home Router"]:::route
        click AuthRouter "https://github.com/sajjad-amin/socket-server/blob/main/App/Routes/AuthRouter.js"
        click DashRouter "https://github.com/sajjad-amin/socket-server/blob/main/App/Routes/DashboardRouter.js"
        click HomeRouter "https://github.com/sajjad-amin/socket-server/blob/main/App/Routes/HomeRouter.js"
    end

    subgraph Middleware
        AuthMW["Auth Middleware"]:::security
        VerifiedMW["Verified User Middleware"]:::security
        click AuthMW "https://github.com/sajjad-amin/socket-server/blob/main/App/Middlewares/AuthMiddleware.js"
        click VerifiedMW "https://github.com/sajjad-amin/socket-server/blob/main/App/Middlewares/VerifiedUserMiddleware.js"
    end

    subgraph Controllers
        AuthCtrl["Auth Controller"]:::controller
        DashCtrl["Dashboard Controller"]:::controller
        EventCtrl["Event Controller"]:::controller
        ProfileCtrl["Profile Controller"]:::controller
        WebsiteCtrl["Website Controller"]:::controller
        click AuthCtrl "https://github.com/sajjad-amin/socket-server/blob/main/App/Controllers/AuthController.js"
        click DashCtrl "https://github.com/sajjad-amin/socket-server/blob/main/App/Controllers/DashboardController.js"
        click EventCtrl "https://github.com/sajjad-amin/socket-server/blob/main/App/Controllers/EventController.js"
        click ProfileCtrl "https://github.com/sajjad-amin/socket-server/blob/main/App/Controllers/ProfileController.js"
        click WebsiteCtrl "https://github.com/sajjad-amin/socket-server/blob/main/App/Controllers/WebsiteController.js"
    end

    subgraph Models
        EventModel["Event Model"]:::model
        UserModel["User Model"]:::model
        ForgotModel["Forgot Model"]:::model
        BaseModel["Base Model"]:::model
        click EventModel "https://github.com/sajjad-amin/socket-server/blob/main/App/Models/EventModel.js"
        click UserModel "https://github.com/sajjad-amin/socket-server/blob/main/App/Models/UserModel.js"
        click ForgotModel "https://github.com/sajjad-amin/socket-server/blob/main/App/Models/ForgotModel.js"
        click BaseModel "https://github.com/sajjad-amin/socket-server/blob/main/Core/Model/Model.js"
    end

    subgraph Views
        AuthViews["Auth Views"]:::view
        DashViews["Dashboard Views"]:::view
        HomeViews["Home Views"]:::view
        ProfileViews["Profile Views"]:::view
        click AuthViews "https://github.com/sajjad-amin/socket-server/tree/main/App/Views/Auth/"
        click DashViews "https://github.com/sajjad-amin/socket-server/tree/main/App/Views/Dashboard/"
        click HomeViews "https://github.com/sajjad-amin/socket-server/tree/main/App/Views/Home/"
        click ProfileViews "https://github.com/sajjad-amin/socket-server/tree/main/App/Views/Profile/"
    end

    subgraph Core
        DB["Database Service"]:::database
        EmailFactory["Email Factory"]:::core
        HashFactory["Hash Factory"]:::core
        ValidationFactory["Validation Factory"]:::core
        click DB "https://github.com/sajjad-amin/socket-server/blob/main/Core/Database/Database.js"
        click EmailFactory "https://github.com/sajjad-amin/socket-server/blob/main/Core/Factory/Email.js"
        click HashFactory "https://github.com/sajjad-amin/socket-server/blob/main/Core/Factory/Hash.js"
        click ValidationFactory "https://github.com/sajjad-amin/socket-server/blob/main/Core/Factory/Validation.js"
    end

    Database[(SQLite DB)]:::database
    click Database "https://github.com/sajjad-amin/socket-server/blob/main/App/Database/database.db"

    %% Connections
    Browser --> Express
    SocketClient <-.-> SocketServer
    Express --> Routes
    Routes --> Middleware
    Middleware --> Controllers
    Controllers --> Models
    Models --> Core
    Core --> Database
    Controllers --> Views
    
    %% Styles
    classDef server fill:#1e88e5,color:white
    classDef socket fill:#673ab7,color:white
    classDef route fill:#43a047,color:white
    classDef security fill:#e53935,color:white
    classDef controller fill:#00acc1,color:white
    classDef model fill:#fb8c00,color:white
    classDef view fill:#8e24aa,color:white
    classDef core fill:#fdd835,color:black
    classDef database fill:#6d4c41,color:white
```
