# roatt-tilma/mentorsoft-engage21 architecture

> Architecture diagram of the GitHub repository roatt-tilma/mentorsoft-engage21, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/roatt-tilma/mentorsoft-engage21
- Repository: https://github.com/roatt-tilma/mentorsoft-engage21

## Overview

##### Main Components
- Client/Frontend:
- EJS Views: The views folder (with index.ejs, joinroomform.ejs, createroomform.ejs, room.ejs, and partials) represents the HTML templates.
- Static Assets: The public directory (CSS, JS, images, and .well-known) which serve styles, client-side JavaScript (like room.js), and media.
- Server/Backend:
- Application Entry Points: Files like app.js and server.js that initialize the server.
- Controllers: The controllers folder (e.g., roomController.js) to handle business logic and request routing.
- Routes: The routes folder (e.g., roomRoutes.js) that maps HTTP endpoints to controllers.
- Models: The models folder (model.js) which likely holds data representations.
- Communication & Real-Time Layers:
- Use of socket.io (as mentioned in the README) to facilitate real-time messaging and signaling.
- WebRTC integration with the help of standard JavaScript APIs used on the client side.
- External Services:
- Azure Communication Services: Used as a TURN relay for secure WebRTC connections.
- Heroku Deployment: The Procfile and hosting URL indicate deployment on Heroku.
- A separate “relay-token-quickstart” folder indicates a script (relay-token.js) related to generating or handling relay tokens.

##### Relationships and Interactions
- The client (browser) loads HTML generated via EJS and static assets from the public folder.
- The web server (Node.js) handles HTTP requests, manages room creation/joining via routes, and invokes the appropriate controller logic.
- Controllers interact with models (if any data storage or transient state management is needed) and then render views.
- Real-time interactions (chat messages, video call events, and UI updates) are managed via socket.io, interfacing between the client and the server.
- WebRTC configurations are used on the client side, with the server (and Azure Communication Services) providing TURN relay tokens needed for establishing secure connections.
- External tokens or authentication for TURN might be generated by the relay-token.js script.

##### Architectural Patterns and Design Principles
- MVC (Model-View-Controller): The separation of concerns is evident through the controllers (business logic), views (UI templates), and models (data structures).
- Layered Architecture: There’s a clear separation between the presentation layer (views/public assets), the application layer (controllers/routes), and the external interaction layer (real-time communication via socket.io and WebRTC, plus external services like Azure).
- Microservice or Module Isolation: The “relay-token-quickstart” could be seen as a specialized module handling external token generation.
- Emphasis on Asynchronous, Event-Driven Communication: Use of socket.io and WebRTC highlights the importance of real-time, asynchronous operations.

##### Relevant Technologies and Frameworks
- Node.js for the backend server.
- Express (implied through the structure) for routing and middleware management.
- EJS for templating.
- socket.io for real-time communication.
- WebRTC for video/audio signaling.
- Azure Communication Services for TURN relay.
- Heroku for deployment.
- Standard client-side technologies (HTML, CSS, JavaScript) for the frontend.

- Clear Labels: Each component (Client, Server, Real-Time Communication, External Services) should be clearly labeled.
- Detailed Interactions:
- That every component involved in signaling (WebRTC is used on the client side and socket.io on the server side) is shown.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side Subgraph
    subgraph "Client Side"
        CV1("EJS Views"):::frontend
        CV2("Static Assets"):::frontend
        RTClient("Real-Time Logic (room.js)"):::frontend
    end

    %% Server Side Subgraph
    subgraph "Server Side"
        SE1("App Entry Point: app.js"):::backend
        SE2("App Entry Point: server.js"):::backend
        ROUTE("Route: roomRoutes.js"):::backend
        CONT("Controller: roomController.js"):::backend
        MODEL("Model: model.js"):::backend
        RTServer("Real-Time Server (socket.io)"):::backend
    end

    %% External Services Subgraph
    subgraph "External Services"
        AZURE("Azure Communication Services (TURN Relay)"):::external
        RELAY("Relay Token Service (relay-token.js)"):::external
    end

    %% Deployment Subgraph
    subgraph "Deployment"
        HEROKU("Heroku Deployment (Procfile)"):::deployment
    end

    %% Interactions between Client and Server (HTTP Flow)
    CV1 -- "HTTP_Request" --> ROUTE
    CV2 -- "Static_File_Request" --> SE1
    ROUTE -- "invoke" --> CONT
    CONT -- "data_access" --> MODEL
    CONT -- "render" --> CV1

    %% App Entry Points routing to HTTP processing
    SE1 -- "initialize" --> ROUTE
    SE2 -- "initialize" --> ROUTE

    %% Real-Time Communication between Client and Server
    RTClient -- "socket_connection" --- RTServer

    %% Integration for TURN relay token generation
    SE1 -- "generate_token" --> RELAY
    RELAY -- "fetch_token" --> AZURE

    %% Deployment connection
    SE1 --- HEROKU
    SE2 --- HEROKU

    %% Click Events
    click CV1 "https://github.com/roatt-tilma/mentorsoft-engage21/blob/master/views/index.ejs"
    click CV2 "https://github.com/roatt-tilma/mentorsoft-engage21/tree/master/public"
    click SE1 "https://github.com/roatt-tilma/mentorsoft-engage21/blob/master/app.js"
    click SE2 "https://github.com/roatt-tilma/mentorsoft-engage21/blob/master/server.js"
    click CONT "https://github.com/roatt-tilma/mentorsoft-engage21/blob/master/controllers/roomController.js"
    click ROUTE "https://github.com/roatt-tilma/mentorsoft-engage21/blob/master/routes/roomRoutes.js"
    click MODEL "https://github.com/roatt-tilma/mentorsoft-engage21/blob/master/models/model.js"
    click RTClient "https://github.com/roatt-tilma/mentorsoft-engage21/blob/master/public/JS/room.js"
    click RELAY "https://github.com/roatt-tilma/mentorsoft-engage21/blob/master/relay-token-quickstart/relay-token.js"
    click HEROKU "https://github.com/roatt-tilma/mentorsoft-engage21/tree/master/Procfile"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#B71C1C,stroke-width:2px;
    classDef deployment fill:#FFF9C4,stroke:#F57F17,stroke-width:2px;
```
