# shubhamore/connect-verse architecture

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

- Interactive diagram: https://gitdiagram.com/shubhamore/connect-verse
- Repository: https://github.com/shubhamore/connect-verse

## Overview

##### Project Type and Purpose
- -Verse is a full-stack MERN application: a social media platform enabling user registration, authentication (including Google OAuth), profile management, posting, commenting, liking, connecting with other users, and image handling via Cloudinary.

##### Main Architectural Components
a. Frontend (React.js SPA)
- React (components under client/src/*)
- Redux Toolkit for state management (client/src/state)
- React Router for navigation (scenes folder)
- Material-UI for UI
- Formik & Yup for forms
- Assets & static files (client/public)
b. Backend (Node.js + Express)
- Express server (server/index.js)
- Controllers (server/controllers/*) implement business logic (auth, user, post, comment)
- Routes (server/routes/*) define RESTful endpoints (/auth, /user, /post)
- Middleware (server/middleware/auth.js) handles JWT verification
- Config (server/config/cloudinary.js) sets up image upload service
c. Database
- MongoDB with Mongoose ODM (server/models/User.js, Post.js)
d. External Services
- Cloudinary for image storage
- Google OAuth (via passport or custom OAuth flow)
e. Authentication & Security
- JSON Web Tokens (JWT) for session management
- Protected routes middleware
f. Deployment
- Render.com hosting for both client and server

##### Relationships & Data Flow
- User actions in the React UI dispatch Redux actions → async thunks call the Express API → Express routes invoke controllers → controllers interact with MongoDB (via Mongoose models) → responses flow back through Express → Redux state updates → React re-renders.
- Image uploads in the UI → sent to Express → forwarded to Cloudinary → secure URL stored in MongoDB → returned to client.
- Google OAuth: user redirected to Google → OAuth callback to Express → create/validate user in MongoDB → issue JWT.

##### Architectural Patterns & Design Principles
- Separation of concerns: clear layers (UI, client-side state, API, business logic, data layer)
- RESTful API design for backend
- MVC–like organization on server (routes → controllers → models)
- Component-based design on frontend
- Single Page Application (SPA) pattern
- Use of middleware for cross-cutting concerns (auth, error handling)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (React.js + Redux Toolkit)" 
        direction TB
        Browser["User Browser"]:::frontend
        subgraph "Source Code (client/src)"
            direction TB
            App["App.js"]:::frontend
            click App "https://github.com/shubhamore/connect-verse/blob/main/client/src/App.js"
            Components["components"]:::frontend
            click Components "https://github.com/shubhamore/connect-verse/tree/main/client/src/components"
            Scenes["scenes"]:::frontend
            click Scenes "https://github.com/shubhamore/connect-verse/tree/main/client/src/scenes"
            Redux["state (Redux Toolkit)"]:::frontend
            click Redux "https://github.com/shubhamore/connect-verse/blob/main/client/src/state/index.js"
            Theme["theme.js"]:::frontend
            click Theme "https://github.com/shubhamore/connect-verse/blob/main/client/src/theme.js"
        end
        Public["Public Files (client/public)"]:::frontend
        click Public "https://github.com/shubhamore/connect-verse/tree/main/client/public"
        %% Scenes subnodes
        subgraph "Pages & Widgets"
            direction TB
            HomePage["HomePage.jsx"]:::frontend
            click HomePage "https://github.com/shubhamore/connect-verse/blob/main/client/src/scenes/homePage/HomePage.jsx"
            LoginPage["LoginPage.jsx"]:::frontend
            click LoginPage "https://github.com/shubhamore/connect-verse/blob/main/client/src/scenes/loginPage/LoginPage.jsx"
            LoginForm["Form.jsx"]:::frontend
            click LoginForm "https://github.com/shubhamore/connect-verse/blob/main/client/src/scenes/loginPage/Form.jsx"
            MyProfile["MyProfile.jsx"]:::frontend
            click MyProfile "https://github.com/shubhamore/connect-verse/blob/main/client/src/scenes/myProfile/MyProfile.jsx"
            ProfilePage["ProfilePage.jsx"]:::frontend
            click ProfilePage "https://github.com/shubhamore/connect-verse/blob/main/client/src/scenes/profilePage/ProfilePage.jsx"
            PostShare["PostSharePage.jsx"]:::frontend
            click PostShare "https://github.com/shubhamore/connect-verse/blob/main/client/src/scenes/postSharePage/PostSharePage.jsx"
            Navbar["Navbar.jsx"]:::frontend
            click Navbar "https://github.com/shubhamore/connect-verse/blob/main/client/src/scenes/navbar/Navbar.jsx"
            Widgets["widgets"]:::frontend
            click Widgets "https://github.com/shubhamore/connect-verse/tree/main/client/src/scenes/widgets"
        end
    end

    %% Backend Layer
    subgraph "Backend (Node.js + Express)" 
        direction TB
        Server["server/index.js"]:::backend
        click Server "https://github.com/shubhamore/connect-verse/blob/main/server/index.js"
        subgraph "Routes"
            direction TB
            AuthRoute["auth.js"]:::backend
            click AuthRoute "https://github.com/shubhamore/connect-verse/blob/main/server/routes/auth.js"
            UserRoute["user.js"]:::backend
            click UserRoute "https://github.com/shubhamore/connect-verse/blob/main/server/routes/user.js"
            PostRoute["post.js"]:::backend
            click PostRoute "https://github.com/shubhamore/connect-verse/blob/main/server/routes/post.js"
        end
        subgraph "Controllers"
            direction TB
            AuthCtrl["auth.js"]:::backend
            click AuthCtrl "https://github.com/shubhamore/connect-verse/blob/main/server/controllers/auth.js"
            UserCtrl["user.js"]:::backend
            click UserCtrl "https://github.com/shubhamore/connect-verse/blob/main/server/controllers/user.js"
            PostCtrl["post.js"]:::backend
            click PostCtrl "https://github.com/shubhamore/connect-verse/blob/main/server/controllers/post.js"
        end
        Middleware["auth.js (JWT Middleware)"]:::backend
        click Middleware "https://github.com/shubhamore/connect-verse/blob/main/server/middleware/auth.js"
        Config["cloudinary.js"]:::backend
        click Config "https://github.com/shubhamore/connect-verse/blob/main/server/config/cloudinary.js"
        DataScript["seed data (index.js)"]:::backend
        click DataScript "https://github.com/shubhamore/connect-verse/blob/main/server/data/index.js"
    end

    %% Database Layer
    subgraph "Database (MongoDB + Mongoose)" 
        direction TB
        MongoDB[(MongoDB)]:::db
        subgraph "Models"
            direction TB
            UserModel["User.js"]:::db
            click UserModel "https://github.com/shubhamore/connect-verse/blob/main/server/models/User.js"
            PostModel["Post.js"]:::db
            click PostModel "https://github.com/shubhamore/connect-verse/blob/main/server/models/Post.js"
        end
    end

    %% External Services
    subgraph "External Services" 
        direction TB
        Cloudinary[(Cloudinary)]:::external
        GoogleOAuth[(Google OAuth)]:::external
    end

    %% Data Flows
    Browser -->|"HTTP REST (JSON)"| Server
    Server -->|"Mongoose Queries"| MongoDB
    Server -->|"Image Upload API"| Cloudinary
    Browser -->|"OAuth Flow"| GoogleOAuth
    GoogleOAuth -->|"OAuth Callback"| Server

    %% Style Definitions
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef backend fill:#E6FFD0,stroke:#3C8031,color:#3C8031;
    classDef db fill:#FFE5B4,stroke:#DA8C16,color:#DA8C16;
    classDef external fill:#F0D0FF,stroke:#7D3C98,color:#7D3C98;
```
