# karmveershubham/trustify architecture

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

- Interactive diagram: https://gitdiagram.com/karmveershubham/trustify
- Repository: https://github.com/karmveershubham/trustify

## Overview

##### Project Type and Purpose
- Trustify is a full-stack trust-based e-commerce platform.
- Frontend: Next.js app with SSR/CSR, TailwindCSS, Redux state management.
- Backend: Express.js REST API with Google OAuth, Passport.js authentication.
- Database: Neo4j graph database representing users and “contacts of contacts.”
- Additional services: Cloudinary for image uploads, Socket.io for real-time notifications.

##### File Structure
- Top-level “client” directory holds the Next.js application.
- `src/app` – page routes and dynamic segments for auth, product, user flows
- `src/components` – UI components, feature modules, layout, magic UI elements
- `src/services` – Redux slices (auth, cart) and store/provider setup
- `src/lib` & `src/validations` – shared utilities, API clients, input schemas
- Top-level “server” directory holds the Express API.
- `config` – Cloudinary, Socket.io, constant values
- `neo4j` – driver setup for the graph database
- `middlewares` – auth checks, image upload handling
- `controllers` – request handlers for auth, contacts, listings, notifications, tests
- `routes` – REST endpoints mapped to controllers
- `models` – Neo4j node definitions and queries

##### Extract Insights from the README
- Emphasizes trust graph built on Neo4j, RESTful design, Google OAuth.
- Highlights key user flows: registration/login → building trust connections → listing/purchasing products → real-time notifications.

A. Main Components
- Browser Client (Next.js SSR/CSR)
- API Gateway / Express Server
- Neo4j Graph Database
- Cloudinary Image Service
- External Auth Provider (Google)
- Real-time Layer (Socket.io)
B. Relationships & Data Flow
1. Browser ↔ Next.js App: user visits pages, static assets served.
2. Next.js App → Express API: REST calls for login, listings, contacts, etc.
3. Express API → Neo4j: CRUD operations on User, Listing, Notification nodes/relationships.
4. Express API → Cloudinary: image upload/download via upload middleware.
5. Express API ↔ Google OAuth: token exchange, user profile fetch during auth.
6. Express API ↔ Browser (WebSocket): real-time notifications pushed to authenticated clients.
C. Architectural Patterns & Principles
- Separation of Concerns: Presentation (Next.js) vs. Business Logic (Express controllers) vs. Data (Neo4j).
- Modularization: service layers (e.g., productService, validation), Redux slices.
- Middleware pipeline in Express for auth, file upload, error handling.
- Dynamic routing in Next.js for product/user pages.
D. Key Technologies & Frameworks
- Next.js – routing, SSR/CSR hybrid, API calls
- TailwindCSS – styling utility classes
- Redux – global state (auth, cart)
- Express.js – API framework
- Passport.js & Google OAuth – authentication
- Neo4j Driver – graph database connectivity
- Cloudinary SDK – media storage
- Socket.io – real-time push notifications

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Next.js)" 
        direction TB
        NextJS["Next.js Frontend"]:::frontend
        Pages["Page Routes & Dynamic Segments"]:::frontend
        Components["UI Components (TailwindCSS)"]:::frontend
        GlobalsCSS["Global Styles & Layout"]:::frontend
        Services["Redux State Management"]:::frontend
        AuthSlice["Redux Slices (auth, cart)"]:::frontend
        Store["Redux Store & Provider Setup"]:::frontend
        ApiClient["API Client Services"]:::frontend
        Utils["Shared Utilities & Validations"]:::frontend
        TailwindCfg["TailwindCSS Configuration"]:::frontend

        NextJS --> Pages
        NextJS --> Components
        NextJS --> GlobalsCSS
        NextJS --> Services
        NextJS --> Utils
        NextJS --> TailwindCfg
        Services --> AuthSlice
        Services --> Store
        Services --> ApiClient
    end

    %% Backend Layer
    subgraph "Backend (Express REST API)"
        direction TB
        Index["API Entry Point"]:::backend
        Config["Express Configuration"]:::backend
        CloudinaryCfg["Cloudinary Service Setup"]:::backend
        SocketCfg["Socket.io Initialization"]:::backend
        Constants["Constants & Environment"]:::backend
        Neo4jSetup["Neo4j Driver & Database Setup"]:::backend
        Middlewares["Express Middlewares"]:::backend
        Routes["REST Routes"]:::backend
        Controllers["Controllers"]:::backend
        Models["Neo4j Models & Queries"]:::backend

        Index --> Config
        Config --> CloudinaryCfg
        Config --> SocketCfg
        Config --> Constants
        Index --> Middlewares
        Index --> Routes
        Routes --> Controllers
        Controllers --> Models
        Controllers --> Neo4jSetup
    end

    %% External Services
    Google["Google OAuth"]:::external
    CloudinaryService["Cloudinary"]:::external
    WebSocket["WebSocket (Socket.io)"]:::external
    DB["Neo4j Graph DB"]:::db
    Browser["User's Browser"]:::browser

    %% Data Flows
    Browser -->|HTTP/SSR/CSR| NextJS
    NextJS -->|HTTP/REST API| Index
    Controllers -->|Bolt Driver| DB
    Controllers -->|Upload API| CloudinaryService
    Controllers -->|OAuth Exchange| Google
    SocketCfg -->|WebSocket Init| WebSocket
    WebSocket -->|Push Notifications| Browser

    %% Click Events
    click NextJS "https://github.com/karmveershubham/trustify/tree/main/client/"
    click Pages "https://github.com/karmveershubham/trustify/tree/main/client/src/app"
    click Components "https://github.com/karmveershubham/trustify/tree/main/client/src/components"
    click GlobalsCSS "https://github.com/karmveershubham/trustify/blob/main/client/src/app/globals.css"
    click GlobalsCSS "https://github.com/karmveershubham/trustify/blob/main/client/src/app/layout.tsx"
    click Services "https://github.com/karmveershubham/trustify/tree/main/client/src/services"
    click AuthSlice "https://github.com/karmveershubham/trustify/blob/main/client/src/services/slices/authSlices.ts"
    click AuthSlice "https://github.com/karmveershubham/trustify/blob/main/client/src/services/slices/cartSlices.ts"
    click Store "https://github.com/karmveershubham/trustify/blob/main/client/src/services/store.ts"
    click Store "https://github.com/karmveershubham/trustify/blob/main/client/src/services/Provider.tsx"
    click ApiClient "https://github.com/karmveershubham/trustify/blob/main/client/src/lib/productService.ts"
    click Utils "https://github.com/karmveershubham/trustify/blob/main/client/src/lib/utils.ts"
    click Utils "https://github.com/karmveershubham/trustify/blob/main/client/src/validations/schemas.tsx"
    click TailwindCfg "https://github.com/karmveershubham/trustify/blob/main/client/tailwind.config.ts"
    click Index "https://github.com/karmveershubham/trustify/blob/main/server/index.js"
    click Config "https://github.com/karmveershubham/trustify/tree/main/server/config"
    click CloudinaryCfg "https://github.com/karmveershubham/trustify/blob/main/server/config/cloudinary.js"
    click SocketCfg "https://github.com/karmveershubham/trustify/blob/main/server/config/Socket.js"
    click Constants "https://github.com/karmveershubham/trustify/blob/main/server/config/constant.js"
    click Constants "https://github.com/karmveershubham/trustify/blob/main/server/.env.example"
    click Neo4jSetup "https://github.com/karmveershubham/trustify/blob/main/server/neo4j/neo4j.js"
    click Middlewares "https://github.com/karmveershubham/trustify/blob/main/server/middlewares/authMiddleware.js"
    click Middlewares "https://github.com/karmveershubham/trustify/blob/main/server/middlewares/uploadImage.js"
    click Controllers "https://github.com/karmveershubham/trustify/blob/main/server/controllers/authController.js"
    click Controllers "https://github.com/karmveershubham/trustify/blob/main/server/controllers/contactController.js"
    click Controllers "https://github.com/karmveershubham/trustify/blob/main/server/controllers/listingController.js"
    click Controllers "https://github.com/karmveershubham/trustify/blob/main/server/controllers/notificationController.js"
    click Controllers "https://github.com/karmveershubham/trustify/blob/main/server/controllers/testController.js"
    click Routes "https://github.com/karmveershubham/trustify/blob/main/server/routes/authRoutes.js"
    click Routes "https://github.com/karmveershubham/trustify/blob/main/server/routes/contactsRoute.js"
    click Routes "https://github.com/karmveershubham/trustify/blob/main/server/routes/ListingRoute.js"
    click Routes "https://github.com/karmveershubham/trustify/blob/main/server/routes/notificationRoutes.js"
    click Routes "https://github.com/karmveershubham/trustify/blob/main/server/routes/testRoutes.js"
    click Models "https://github.com/karmveershubham/trustify/blob/main/server/models/User.js"
    click Models "https://github.com/karmveershubham/trustify/blob/main/server/models/Notification.js"
    click Models "https://github.com/karmveershubham/trustify/blob/main/server/models/productAttribute.js"
    click Models "https://github.com/karmveershubham/trustify/blob/main/server/models/productQuery.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,stroke-width:1px
    classDef backend  fill:#E6FFDA,stroke:#22863A,stroke-width:1px
    classDef external fill:#F0F0F0,stroke:#6A737D,stroke-width:1px,stroke-dasharray: 5 5
    classDef db        fill:#FFE4B5,stroke:#D9730D,stroke-width:1px
    classDef browser   fill:#FFF5F0,stroke:#C2410C,stroke-width:1px
```
