# aditya-gupta171/docsphere architecture

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

- Interactive diagram: https://gitdiagram.com/aditya-gupta171/docsphere
- Repository: https://github.com/aditya-gupta171/docsphere

## Overview

##### Main Components
- Frontend: The file tree shows a React-based project using Vite. Components such as src/App.jsx, src/pages (Editor.jsx, JoinDocument.jsx, Signin.jsx, Signup.jsx), src/components (editor & layout folders), and src/routes indicate a well-structured single-page application. The technologies involved include React.js, TailwindCSS, Quill.js for rich text editing, and Socket.IO client for real-time interactions.
- Backend: Although the provided file tree is for the frontend, the README clearly describes a separate Backend directory using Node.js, Express.js, and Socket.IO. This backend handles API requests (authentication, document management), real-time communication, and email invitation functionalities.
- Database: MongoDB is used for persistent storage of documents, user data, and session-related information.
- External Services:
- Email Service: Using Nodemailer along with Gmail (with secure authentication via app passwords) for sending invitations.
- Real-Time Communication: Socket.IO is employed on both the client and server sides for live document editing and cursor tracking.

##### Relationships and Interactions
- The Frontend interacts with the Backend through:
- Regular RESTful API calls (using Axios) for CRUD operations related to user authentication, document creation, and data retrieval.
- WebSocket connections (via Socket.IO) for real-time collaboration such as live editing and cursor position broadcasting.
- The Backend, in turn, communicates with:
- The MongoDB database for storing and retrieving user data and document content.
- The Email Service for sending out document invitation emails.
- A flow should be drawn showing that when a user signs up or logs in, the frontend makes secure API requests—with JWT used to secure these endpoints. When a document is edited, data flows over Socket.IO channels ensuring all connected collaborators receive updates.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The design clearly separates the client (React interface) from the server (Express API and real-time communication handling).
- MVC / Component-Based Design: On the frontend, components (editor, layout, routes) are broken into clear UI and logical segments.
- Real-Time Communication Pattern: Leveraging Socket.IO for push notifications and live document updates.
- Security with JWT: For user authentication and session management.

##### Relevant Technologies
- Frontend: React.js, Vite, TailwindCSS, Quill.js, Axios, Socket.IO Client.
- Backend: Node.js, Express.js, MongoDB, Socket.IO, JWT, Nodemailer.

##### Elements
- Use clear labels for each component with descriptive titles (e.g., “React Client”, “Express API Server”, “MongoDB Database”, “Email Service via Nodemailer”, “Socket.IO Real-Time Server”).
- From the React Client to the API Server for REST calls.
- From the React Client to the Socket.IO Server for real-time communication.
- From the API Server to MongoDB to represent data persistence.
- From the API Server to the Email Service for sending invitations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        ReactClient["React Client"]:::frontend
        UIPages["UI Pages"]:::frontend
        EditorComponents["Editor Components"]:::frontend
        LayoutComponents["Layout Components"]:::frontend
        Routing["Routing"]:::frontend
        DocumentHook["Document Handling Hook"]:::frontend
        APIService["API Service"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        APIServer["Express API Server"]:::backend
        SocketServer["Socket.IO Real-Time Server"]:::backend
        JWT["JWT Authentication"]:::backend
    end

    %% External Services
    subgraph "External Services"
        MongoDB["MongoDB Database"]:::external
        EmailService["Email Service (Nodemailer)"]:::external
    end

    %% Frontend Internal Connections
    ReactClient -->|"uses"| UIPages
    ReactClient -->|"uses"| EditorComponents
    ReactClient -->|"uses"| LayoutComponents
    ReactClient -->|"uses"| Routing
    ReactClient -->|"uses"| DocumentHook
    ReactClient -->|"REST_API"| APIService

    %% Communication Between Frontend and Backend
    APIService -->|"API_Request"| APIServer
    ReactClient -->|"Socket.IO"| SocketServer

    %% Backend Security and Data Flow
    JWT -->|"Secured"| APIServer
    APIServer -->|"Data_Persistence"| MongoDB
    APIServer -->|"Send_Invitations"| EmailService

    %% Click Events
    click ReactClient "https://github.com/aditya-gupta171/docsphere/blob/master/src/App.jsx"
    click UIPages "https://github.com/aditya-gupta171/docsphere/tree/master/src/pages"
    click EditorComponents "https://github.com/aditya-gupta171/docsphere/tree/master/src/components/editor"
    click LayoutComponents "https://github.com/aditya-gupta171/docsphere/tree/master/src/components/layout"
    click APIService "https://github.com/aditya-gupta171/docsphere/blob/master/src/api/axios.jsx"
    click Routing "https://github.com/aditya-gupta171/docsphere/tree/master/src/routes"
    click DocumentHook "https://github.com/aditya-gupta171/docsphere/blob/master/src/hooks/useDocument.js"

    %% Styles
    classDef frontend fill:#b3deff,stroke:#333,stroke-width:2px;
    classDef backend fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef external fill:#d5f5e3,stroke:#333,stroke-width:2px;
```
