# singhutsav5502/hacktivate_socialcalcclone architecture

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

- Interactive diagram: https://gitdiagram.com/singhutsav5502/hacktivate_socialcalcclone
- Repository: https://github.com/singhutsav5502/hacktivate_socialcalcclone

## Overview

##### Project type and purpose
- This is a full-stack, real-time collaborative spreadsheet web application (“SocialCalc Clone”).
- Frontend: React single-page app using Redux Toolkit for state, Material-UI/Emotion for styling, React Router for navigation, axios for REST, and socket.io-client for live collaboration.
- Backend: Node.js/Express server with REST routes for user/session management, Socket.IO for WebSocket communication, Mongoose for MongoDB persistence, and diff-match-patch for merge/patch logic.

##### Main components
a. Frontend (social_calc_clone_frontend)
- Browser / React App
- UI Components: Login, CardComponent, SessionMenu, Toolbar, Spreadsheet
- State Store: Redux slices (userSlice, sessionSlice) + store.js
- Networking: axios (HTTP), socket.io-client (WebSocket)
- Routing: react-router-dom
- Styling: Material-UI, Emotion, CSS modules
b. Backend (social_calc_clone_backend)
- Express HTTP Server (index.js)
- REST Routes: sessionRoutes.js (login, create/join sessions)
- WebSocket Server: socket.io integration in index.js
- Models: Mongoose schemas for User and Session
- Utilities: diff-match-patch for computing/applying patches, async-lock for concurrency
- Security/Config: dotenv (.env), CORS, SSL certificates folder (certificate.crt, private.key, ca_bundle.crt)
c. Database
- MongoDB instance (sessions, users collections)
d. External / Infrastructure
- SSL/TLS termination (certs)
- Environment variables:
– REACT_APP_SERVER_URL (frontend)
– MONGO_DB_URL (backend)

##### Relationships & Data Flow
1. Browser requests React app via HTTP (GET /index.html)
2. User authenticates or creates/join a session through REST API (axios POST/GET → Express routes → MongoDB)
3. Upon entering a sheet, front end opens a WebSocket (socket.io) to the backend
4. User edits spreadsheet cells → diff-match-patch on frontend computes patch → socket.emit(“edit”, patch)
5. Server receives patch → applies diff-match-patch on stored document → saves to MongoDB → broadcasts patch to other clients in same session
6. Other clients receive patch events → apply to local sheet state via Redux

##### Architectural Patterns & Principles
- Client-Server separation with clear REST & WebSocket layers
- Unidirectional state flow on frontend via Redux
- Event-driven, real-time collaboration using operational transforms (diff-match-patch)
- MVC-style on backend (routes → controllers in index.js → models → database)
- Config and secrets externalized via dotenv and SSL certs

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Application"
        direction TB
        Browser["Browser / React SPA"]:::frontend
        Login["Login Component"]:::frontend
        Card["CardComponent"]:::frontend
        SessionMenu["SessionMenu"]:::frontend
        Toolbar["Toolbar"]:::frontend
        Spreadsheet["Spreadsheet"]:::frontend
        Store["Redux Store\n(userSlice, sessionSlice)"]:::frontend
        NetworkingHTTP["axios\n(HTTP)"]:::frontend
        NetworkingWS["socket.io-client\n(WebSocket)"]:::frontend
        Routing["React Router"]:::frontend
        Styling["MUI/Emotion & CSS Modules"]:::frontend
        Theme["theme.js"]:::frontend
    end

    subgraph "Backend Server"
        direction TB
        Server["Express API Server\n(index.js)"]:::backend
        SessionRoutes["sessionRoutes.js"]:::backend
        SocketServer["Socket.IO Server"]:::backend
        UserModel["User Model\n(user.js)"]:::backend
        SessionModel["Session Model\n(session.js)"]:::backend
        DiffPatchServer["diff-match-patch"]:::backend
        Dotenv["dotenv (.env)"]:::backend
    end

    Database["MongoDB\n(sessions, users)"]:::db

    subgraph "SSL/TLS Layer"
        Certs["certs/"]:::ssl
    end

    %% Connections
    Browser -->|GET /index.html| Server
    Browser -->|REST login/join| SessionRoutes
    SessionRoutes -->|read/write| Database
    Browser -->|WebSocket socket.io| SocketServer
    SocketServer -->|read/write| Database
    SocketServer -->|broadcast edit patch| Browser

    Login -->|dispatch actions| Store
    SessionMenu -->|dispatch actions| Store
    Toolbar -->|dispatch actions| Store
    Spreadsheet -->|dispatch actions & subscribe| Store
    Store -->|HTTP calls| NetworkingHTTP
    Store -->|emit/receive| NetworkingWS
    Routing -->|navigates| Browser
    Styling -->|styles| Browser
    Theme -->|provides theme| Styling

    DiffPatchServer -->|merge patches| SessionModel
    SocketServer -->|uses| DiffPatchServer
    Server -->|uses| Dotenv
    Certs -->|SSL termination| Server

    %% Click Events
    click Browser "https://github.com/singhutsav5502/hacktivate_socialcalcclone/tree/main/social_calc_clone_frontend/"
    click Login "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/components/Login.jsx"
    click Card "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/components/CardComponent.jsx"
    click SessionMenu "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/components/SessionMenu.jsx"
    click Toolbar "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/components/Toolbar.jsx"
    click Spreadsheet "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/components/Spreadsheet.jsx"
    click Styling "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/index.css"
    click Styling "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/App.css"
    click Styling "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/components/Login.module.css"
    click Styling "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/components/SessionMenu.module.css"
    click Styling "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/components/Toolbar.css"
    click Styling "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/components/Spreadsheet.css"
    click Theme "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/theme.js"
    click Store "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/store/store.js"
    click Store "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/store/userSlice.js"
    click Store "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/store/sessionSlice.js"
    click Server "https://github.com/singhutsav5502/hacktivate_socialcalcclone/tree/main/social_calc_clone_backend/"
    click Server "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_backend/index.js"
    click SessionRoutes "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_backend/routes/sessionRoutes.js"
    click UserModel "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_backend/models/user.js"
    click SessionModel "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_backend/models/session.js"
    click Certs "https://github.com/singhutsav5502/hacktivate_socialcalcclone/tree/main/social_calc_clone_backend/certs/"
    click Certs "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_backend/certs/certificate.crt"
    click Certs "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_backend/certs/private.key"
    click Certs "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_backend/certs/ca_bundle.crt"
    click Dotenv "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_backend/index.js"
    click Browser "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/index.js"
    click Browser "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/src/App.js"
    click BackendPkg "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_backend/package.json"
    click FrontendPkg "https://github.com/singhutsav5502/hacktivate_socialcalcclone/blob/main/social_calc_clone_frontend/package.json"

    %% Styles
    classDef frontend fill:#B3CDE0,stroke:#333,stroke-width:1px;
    classDef backend fill:#C7E9C0,stroke:#333,stroke-width:1px;
    classDef db fill:#FBB4AE,stroke:#333,stroke-width:1px;
    classDef ssl fill:#D9D9D9,stroke:#333,stroke-width:1px;
```
