# abhishek9525-max/design3d architecture

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

- Interactive diagram: https://gitdiagram.com/abhishek9525-max/design3d
- Repository: https://github.com/abhishek9525-max/design3d

## Overview

##### Project Type & Purpose
- This is a full-stack web application that serves interactive 3D product models with secure user authentication.
- Frontend: React + Tailwind + @react-three/fiber for 3D viewing.
- Backend: Node/Express REST API + MongoDB + JWT.

##### File Structure & Key Components
- Frontend (frontend/):
– Public static assets: 3D models under public/ABeautifulGame, AnimatedCube, AntiqueCamera, Lantern.
– React SPA: src/ (App.jsx, pages, context/AuthContext.jsx, ThreeDViewer.jsx)
– Routing: React Router in pages/*.jsx.
– Styling & build: tailwind.config.js, postcss.config.js, vite.config.js.
– Deployment: vercel.json.
- Backend (backend/):
– server.js: Express app entry.
– Routes: routes/authRoutes.js, productRoutes.js
– Controllers: controller/authUser.js, product.js
– Middleware: authMiddleware.js (JWT guard)
– Models: User.js, Product.js (Mongoose schemas)
– Config: db.js (Mongo connection)
– Deployment: vercel.json

##### README Insights
- REST API endpoints for products & auth.
- JWT for stateless authentication.
- MongoDB via Mongoose.
- 3D viewer uses model URLs returned by backend or served via static public folder.

##### Main System Components
A. Client Layer
1. Browser / SPA (React)
- UI pages (Home, Login, Register, ThreeDViewer)
- AuthContext: holds JWT, user state, injects Authorization header
- Three.js Viewer: @react-three/fiber, @react-three/drei fetches and renders .gltf/.glb assets
B. API Layer
2. API Gateway (Express server)
- Authentication Routes (/api/auth/*): login, register
- Product Routes (/api/products/*): CRUD operations
- Middleware: authMiddleware verifies JWT
C. Data Layer
3. Database (MongoDB)
- Collections: users, products
- Mongoose models handle schema & queries
D. Static Asset Store
4. Static Hosting (Vercel static for 3D models in frontend/public)

##### Interactions & Data Flows
1. User → Browser → React Router →
a. If unauthenticated: Login/Register pages → POST /api/auth → Express → MongoDB → JWT → back to client.
b. If authenticated: Home page → GET /api/products → Express → MongoDB → product list (incl. asset URLs).
c. 3D Viewer: fetch glTF from static URLs on Vercel → WebGL render.
2. ProtectedRoute wrapper in React checks AuthContext before allowing access to ThreeDViewer or product management.

##### Architectural Patterns & Design Principles
- Layered architecture: Presentation (React), Application (Express), Data (MongoDB).
- RESTful design for APIs.
- Stateless JWT auth for horizontal scalability.
- Controller-Service-Model separation in backend.
- Component-based UI with context for cross-cutting concerns (auth).
- Static asset hosting separate from dynamic API.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Browser / SPA"]:::frontend
        AuthCtx["AuthContext"]:::frontend
        Home["Home Page"]:::frontend
        Login["Login Page"]:::frontend
        Register["Register Page"]:::frontend
        ViewerPage["ThreeDViewer Page"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        Express["Express API Gateway"]:::backend
        AuthRoutes["Auth Routes (/api/auth)"]:::backend
        ProdRoutes["Product Routes (/api/products)"]:::backend
        AuthCtrl["Auth Controller"]:::backend
        ProdCtrl["Product Controller"]:::backend
        JWTMid["authMiddleware (JWT Guard)"]:::backend
        DBConfig["MongoDB Config"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Mongo["MongoDB"]:::db
    end

    %% Static Asset Store
    subgraph "Static Asset Store"
        direction TB
        Static["Vercel Static Hosting (3D Models)"]:::static
    end

    %% Client interactions
    Browser --> AuthCtx
    AuthCtx --> Home
    AuthCtx --> Login
    AuthCtx --> Register
    AuthCtx --> ViewerPage

    Login -->|"POST /api/auth/login"| Express
    Register -->|"POST /api/auth/register"| Express
    Home -->|"GET /api/products"| Express
    ViewerPage -->|"Fetch .gltf/.glb"| Static

    %% API internals
    Express --> AuthRoutes
    Express --> ProdRoutes
    AuthRoutes --> AuthCtrl
    ProdRoutes --> ProdCtrl
    AuthRoutes --> JWTMid
    ProdRoutes --> JWTMid
    Express --> DBConfig
    AuthCtrl --> Mongo
    ProdCtrl --> Mongo
    DBConfig --> Mongo

    %% Click Events
    click AuthCtx "https://github.com/abhishek9525-max/design3d/blob/main/frontend/src/context/AuthContext.jsx"
    click Home "https://github.com/abhishek9525-max/design3d/blob/main/frontend/src/pages/Home.jsx"
    click Login "https://github.com/abhishek9525-max/design3d/blob/main/frontend/src/pages/Login.jsx"
    click Register "https://github.com/abhishek9525-max/design3d/blob/main/frontend/src/pages/Register.jsx"
    click ViewerPage "https://github.com/abhishek9525-max/design3d/blob/main/frontend/src/pages/ThreeDViewer.jsx"
    click Express "https://github.com/abhishek9525-max/design3d/blob/main/backend/server.js"
    click AuthRoutes "https://github.com/abhishek9525-max/design3d/blob/main/backend/routes/authRoutes.js"
    click ProdRoutes "https://github.com/abhishek9525-max/design3d/blob/main/backend/routes/productRoutes.js"
    click AuthCtrl "https://github.com/abhishek9525-max/design3d/blob/main/backend/controller/authUser.js"
    click ProdCtrl "https://github.com/abhishek9525-max/design3d/blob/main/backend/controller/product.js"
    click JWTMid "https://github.com/abhishek9525-max/design3d/blob/main/backend/middleware/authMiddleware.js"
    click DBConfig "https://github.com/abhishek9525-max/design3d/blob/main/backend/config/db.js"

    %% Styles
    classDef frontend fill:#E8F0FE,stroke:#4267B2,color:#333
    classDef backend fill:#FEF1E6,stroke:#D35400,color:#333
    classDef db fill:#E8F6F3,stroke:#1ABC9C,color:#333
    classDef static fill:#F6E8FE,stroke:#8E44AD,color:#333
```
