# omwanere/social architecture

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

- Interactive diagram: https://gitdiagram.com/omwanere/social
- Repository: https://github.com/omwanere/social

## Overview

##### Project type and purpose
- This is a modern, full-stack social media application with real-time chat, notifications, posts, comments, user profiles, and theme toggling.
- It uses React/Vite on the frontend and Node.js/Express with MongoDB on the backend, plus Socket.IO for real-time features.

##### File structure
- Top-level directories:
- Backend/ – Express server, controllers, models, routes, middlewares, Socket.IO server, utilities.
- Frontend/ – Vite/React app, components, hooks, Redux slices, Socket context, API helpers, styling configs.
- Patterns:
- Backend follows MVC (models in Backend/models, controllers in Backend/controllers, routes in Backend/routes).
- Frontend uses component-based architecture, Redux for global state, React Router for navigation, custom hooks for data fetching, and a Context for Socket.IO.
- Configuration and deployment hints: .env via dotenv, CORS, cookie-parser, Cloudinary integration, Multer for uploads, Vite config, Tailwind config.

##### README for additional insights
- Features: authentication (JWT), follow/unfollow, edit profile, posts & comments, real-time messaging and notifications, dark/light mode.
- Tech stack confirmation: React, Redux Toolkit, Express, MongoDB/Mongoose, Socket.IO, Cloudinary, Multer, Axios.

##### Main components and interactions
a. Frontend Application
- UI Layer: React components (feed, chat page, profile, etc.)
- State Layer: Redux store (AuthSlice, postSlice, chatSlice, socketSlice)
- Networking:
- REST API (Axios) → Backend HTTP endpoints for auth, users, posts, comments.
- WebSocket (Socket.IO Client) ↔ Real-time server for chat & notifications.
b. Backend API Server
- HTTP Layer (Express routes & controllers)
- Real-time Layer (Socket.IO server in Backend/socket/socket.js)
- Business Logic: controllers, middlewares (isAuthenticated, multer for file uploads)
- Utilities: Cloudinary/image uploads, datauri conversion, DB connection helper.
c. Database
- MongoDB via Mongoose models: User, Post, Comment, Conversation, Message.
d. External Services
- Cloudinary for image storage
- (Optional) Any third-party OAuth or analytics if added later.

##### Relationships and data flows
- Client → Server (HTTP): login/signup, fetch posts, comments, profiles, follow/unfollow.
- Client ↔ Server (WebSocket): real-time chat messages, typing indicators, real-time notifications for likes/follows.
- Server → DB: CRUD operations via Mongoose.
- Server → Cloudinary: upload user images and post media.

##### Architectural patterns and design principles
- Backend: MVC + service/util layering, stateless JWT authentication, middleware pipeline, single monolithic service.
- Frontend: unidirectional data flow via Redux, container/presentational separation, custom hooks for data fetching, Context API for socket.
- Separation of concerns: UI vs. state vs. networking vs. real-time.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layers
    subgraph "Frontend: Presentation Layer"
        UI["React Components"]:::frontend
        click UI "https://github.com/omwanere/social/tree/main/Frontend/src/components"
        App["Main Application Entry Point"]:::frontend
        click App "https://github.com/omwanere/social/blob/main/Frontend/src/main.jsx"
        Styles["Global Styles"]:::frontend
        click Styles "https://github.com/omwanere/social/blob/main/Frontend/src/index.css"
        click Styles "https://github.com/omwanere/social/blob/main/Frontend/src/App.css"
    end

    subgraph "Frontend: State & Context"
        Redux["Redux Store (Auth, Posts, Chat, Notifications, Socket)"]:::state
        click Redux "https://github.com/omwanere/social/tree/main/Frontend/src/redux"
        SocketCtx["WebSocket Client Context"]:::state
        click SocketCtx "https://github.com/omwanere/social/blob/main/Frontend/src/lib/SocketContext.jsx"
        Hooks["WebSocket Client Helpers"]:::state
        click Hooks "https://github.com/omwanere/social/blob/main/Frontend/src/lib/socket.js"
    end

    subgraph "Frontend: Networking"
        APIClient["REST API Client (Axios)"]:::api
        click APIClient "https://github.com/omwanere/social/blob/main/Frontend/src/api/axios.js"
        WSClient["WebSocket Client"]:::api
    end

    %% Backend Layers
    subgraph "Backend: API Server"
        Express["Express Server Entry"]:::backend
        click Express "https://github.com/omwanere/social/blob/main/Backend/index.js"
        Routes["Express Routes (HTTP Endpoints)"]:::backend
        click Routes "https://github.com/omwanere/social/tree/main/Backend/routes"
        Controllers["Express Controllers (Business Logic)"]:::backend
        click Controllers "https://github.com/omwanere/social/tree/main/Backend/controllers"
        AuthMW["Auth Middleware (JWT Protection)"]:::backend
        click AuthMW "https://github.com/omwanere/social/blob/main/Backend/middlewares/isAuthenticated.js"
        UploadMW["File Upload Middleware (Multer)"]:::backend
        click UploadMW "https://github.com/omwanere/social/blob/main/Backend/middlewares/multer.js"
        Utils1["Cloudinary Integration Utility"]:::backend
        click Utils1 "https://github.com/omwanere/social/blob/main/Backend/utils/cloudinary.js"
        Utils2["DataURI Conversion Utility"]:::backend
        click Utils2 "https://github.com/omwanere/social/blob/main/Backend/utils/datauri.js"
        DBUtil["Database Connection Utility"]:::backend
        click DBUtil "https://github.com/omwanere/social/blob/main/Backend/utils/db.js"
        Models["Mongoose Models"]:::backend
        click Models "https://github.com/omwanere/social/tree/main/Backend/models"
    end

    subgraph "Backend: Real-Time Layer"
        SocketServer["Socket.IO Server"]:::realtime
        click SocketServer "https://github.com/omwanere/social/blob/main/Backend/socket/socket.js"
    end

    subgraph "Persistence"
        DB["MongoDB Database"]:::db
    end

    subgraph "External Services"
        Cloudinary["Cloudinary"]:::external
    end

    %% Data Flows
    App --> UI
    UI --> Redux
    UI --> APIClient
    UI --> WSClient

    Redux --> APIClient
    Redux --> WSClient
    SocketCtx --> WSClient

    APIClient -->|"HTTP (GET/POST)"| Express
    WSClient ---|"WebSocket (emit/on)"| SocketServer

    Express -->|"defines"| Routes
    Routes -->|"calls"| Controllers
    Controllers -->|"uses"| Models
    Controllers -->|"uploads to"| Cloudinary
    Controllers -->|"converts via"| Utils2
    Express --> AuthMW
    Express --> UploadMW
    Express --> DBUtil

    DBUtil --> DB
    Models --> DB
    SocketServer --> Controllers
    SocketServer --> AuthMW
    SocketServer --> Models

    %% Styles
    classDef frontend fill:#F6A560,color:#000,stroke:#333,stroke-width:1px
    classDef state fill:#F6F2B5,color:#000,stroke:#333,stroke-width:1px
    classDef api fill:#76C7C0,color:#000,stroke:#333,stroke-width:1px
    classDef backend fill:#6DA3F7,color:#000,stroke:#333,stroke-width:1px
    classDef realtime fill:#C081F1,color:#000,stroke:#333,stroke-width:1px
    classDef db fill:#7AC29A,color:#000,stroke:#333,stroke-width:1px
    classDef external fill:#B0B0B0,color:#000,stroke:#333,stroke-width:1px
```
