# slacky300/real_time_edify architecture

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

- Interactive diagram: https://gitdiagram.com/slacky300/real_time_edify
- Repository: https://github.com/slacky300/real_time_edify

## Overview

##### Project Type & Purpose
- RealTimeEdify is a real-time collaborative document editing application built with the MERN stack (MongoDB, Express.js, React, Node.js), Socket.IO for real-time updates, and Quill for document editing.
- It allows multiple users to collaborate simultaneously on documents, display real-time collaborator presence, and uses email verification for securing user accounts.

##### File Structure
- The top-level directories include “src” housing both server and client code, along with configuration files (.env.sample, .gitignore) and contributing guidelines.
- Under “src” you find:
- The “client” directory which contains all frontend code (React, Vite configuration, assets, and components like App.jsx, DarkModeButton, etc.).
- Server-side code files like “server.js”, controllers, routes, models, middlewares, and utility modules (dbConnect, email templates).
- The controllers (auth.controller.js, doc.controller.js, socket.controller.js) and routes (user.routes.js, document.routes.js) signal a RESTful API design, with real-time capabilities handled by the Socket.IO integration.
- Additional directories like “models”, “middlewares”, and “utils” clearly segregate concerns, indicating a modular structure well-suited for a layered architecture.

##### Key Components
a. Frontend:
- Client Application (React with Vite) – Represented by the “src/client” folder.
- Components, pages, contexts, and helpers illustrate different UI elements and client-side logic (e.g., Login, Register, Editor, Document pages).
b. Backend:
- Express Server – Initiated in “server.js”, handling API requests.
- Controllers – Manage authentication, document operations, and socket events.
- Middlewares – Particularly the auth middleware ensuring secure routes.
- Database Model – Handling users and documents within the “models” directory.
c. Real-Time Communication:
- Socket.IO – Managed by “socket.controller.js” on the server and corresponding client-side integration within the React app.
d. Database & External Services:
- MongoDB – The database for persistent storage.
- Email Service – Using configuration in “utils/email.js” and “emailTemplate.js” to handle email verification.

##### Relationships and Data Flow
- The frontend communicates with the backend API over HTTP for RESTful operations (user authentication, document CRUD operations).
- Real-time collaboration and presence are enabled through Socket.IO, which maintains a persistent connection for bi-directional messaging between the client and server.
- The backend retrieves and stores data in MongoDB using models and also triggers email operations as needed.
- Client → Backend API (HTTP requests for authentication, document creation/updates).
- Client ↔ Socket Server (bidirectional real-time communication).
- Backend → Database (data persistence) and Backend → Email Service (sending verification emails).

##### Architectural Patterns & Design Principles
- The project follows a layered/multi-tier architecture, separating concerns between the presentation (frontend), business logic (controllers, services), and data access layers.
- The RESTful API design is evident, and the additional use of WebSockets (Socket.IO) introduces a real-time communication layer.
- Modular structure is maintained throughout the project (components for UI, controllers for logic, middlewares for security).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        UI["UI Components"]:::frontend
        CP["Client Pages"]:::frontend
        CC["Client Context"]:::frontend
        CH["Client Helpers"]:::frontend
        FR["React Client"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        ES["Express Server"]:::backend
        CTRL["Controllers"]:::backend
        MW["Middlewares"]:::backend
        DM["Database Models"]:::backend
        DBUtil["DB Connection Utility"]:::backend
        SIO["Socket.IO Module"]:::backend
    end

    %% External Services
    subgraph "External Services"
        MDB[(MongoDB)]:::external
        EMS["Email Service"]:::email
    end

    %% Frontend internal composition
    UI -->|"composes"| FR
    CP -->|"composes"| FR
    CC -->|"composes"| FR
    CH -->|"composes"| FR

    %% Data flows and interactions
    FR -->|"HTTP_API"| ES
    FR <-->|"RealTime"| SIO
    ES -->|"controls"| CTRL
    ES -->|"securedBy"| MW
    ES -->|"uses"| DBUtil
    ES -->|"operatesOn"| DM
    DM -->|"storesData"| MDB
    ES -->|"emailsThrough"| EMS

    %% Click Events
    click FR "https://github.com/slacky300/real_time_edify/tree/master/src/client"
    click UI "https://github.com/slacky300/real_time_edify/tree/master/src/client/src/components"
    click CP "https://github.com/slacky300/real_time_edify/tree/master/src/client/src/pages"
    click CC "https://github.com/slacky300/real_time_edify/tree/master/src/client/src/context"
    click CH "https://github.com/slacky300/real_time_edify/tree/master/src/client/src/helpers"
    click ES "https://github.com/slacky300/real_time_edify/blob/master/src/server.js"
    click CTRL "https://github.com/slacky300/real_time_edify/tree/master/src/controllers"
    click MW "https://github.com/slacky300/real_time_edify/blob/master/src/middlewares/auth.middleware.js"
    click DM "https://github.com/slacky300/real_time_edify/tree/master/src/models"
    click SIO "https://github.com/slacky300/real_time_edify/blob/master/src/controllers/socket.controller.js"
    click DBUtil "https://github.com/slacky300/real_time_edify/blob/master/src/utils/dbConnect.js"
    click EMS "https://github.com/slacky300/real_time_edify/blob/master/src/utils/email.js"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef external fill:#FDD835,stroke:#333,stroke-width:2px,stroke-dasharray: 5,5;
    classDef email fill:#CE93D8,stroke:#333,stroke-width:2px;
```
