# rajand2510/roomcraft architecture

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

- Interactive diagram: https://gitdiagram.com/rajand2510/roomcraft
- Repository: https://github.com/rajand2510/roomcraft

## Overview

##### Project Type and Purpose
- This is a full-stack e-commerce web application named “Roomcraft” that allows users to browse 3D home-decor models and preview them in AR before purchase.
- The frontend is built with React, Tailwind CSS, Three.js, React-xr, and Spline for 3D/AR experiences. The backend is a Node.js/Express REST API with MongoDB as the database and JWT for authentication. Razorpay handles payments.

##### File Structure Analysis
- Top-level directories:
- client/ – React app, with src/ (components, pages, contexts), public/ (static 3D models, images, draco decoder)
- server/ – Node/Express code (routes, models, config, auth, JWT, DB connection)
- Configuration: vite.config.js, tailwind.config.js, .env variables in server/config.js, vercel.json for deployment.
- Models: dozens of .gltf/.glb files under client/public/models served as static assets.
- API service in client/components/api/apiService.jsx calls server endpoints in server/routes.

##### README Insights
- Lists core features: 3D view, AR integration, secure checkout via Razorpay, JWT-based auth.
- Technology stack summary for frontend, backend, database, and payment gateway.

a. Main Components
- Client Browser / React App
– 3D Renderer (Three.js)
– AR Module (React-xr / WebXR)
– UI Components (Tailwind)
– Auth Context (JWT)
– Cart & Checkout Flows
- Static Asset Store
– 3D Models & Textures hosted under public/
– Draco decoder scripts for model compression
- Backend API (Node.js + Express)
– Authentication & Authorization (JWT)
– Product, Cart, Order REST endpoints
– Payment integration endpoint for Razorpay
- Database (MongoDB Atlas or local)
– Collections: Users, Products, CartOrders, UserOrders, OrderDone
- External Service
– Razorpay Payment Gateway

b. Relationships & Interactions
1. User opens browser → React App served via CDN or Node static files.
2. React App fetches product metadata from REST API.
3. 3D Models loaded directly from static asset store (/public/models).
4. AR module invokes device WebXR to render model in real environment.
5. On login/signup, credentials posted to Auth API → JWT returned → stored in client context.
6. Cart operations call CartOrderRoutes, updating CartOrders in MongoDB.
7. Checkout calls backend payment endpoint → backend communicates with Razorpay API → payment confirmation.
8. Order is persisted in OrderDone collection.

c. Architectural Patterns & Principles
- Layered architecture: UI layer (React) → API layer (Express) → Data layer (MongoDB).
- Separation of concerns: rendering logic, state management (contexts), and API service centralized.
- RESTful API design with resource-based routes.
- JWT stateless authentication for scalability.
- Static content delivery for heavy assets (3D models).

d. Key Technologies & Libraries
- React + Vite for fast dev and build.
- Tailwind CSS for utility-first styling.
- Three.js + React-XR for 3D and AR.
- Node.js + Express for backend.
- Mongoose models under server/models.
- JWT for tokens.
- Razorpay SDK for payments.

## Diagram (Mermaid)

```mermaid
graph TD
  %% Presentation Layer
  subgraph "Presentation (Frontend)" 
    direction TB
    Browser["Client Browser / React App"]:::frontend
    ThreeD["3D Renderer (Three.js)"]:::frontend
    ARContainer["AR Module Container"]:::frontend
    XeHitModel["XeHitModel Component"]:::frontend
    UIComp["UI Components"]:::frontend
    AuthCtx["Auth Context (JWT)"]:::frontend
    CartCtx["Cart Context & Flows"]:::frontend
    Checkout["Checkout Component"]:::frontend
    MyOrder["MyOrder Component"]:::frontend
    APIService["API Service"]:::frontend
    StaticAssets["Static Asset Store"]:::database
    subgraph "Draco Decoder Scripts"
      direction TB
      DracoJS["draco_decoder.js"]:::frontend
      DracoWASM["draco_decoder.wasm"]:::frontend
      DracoWrapper["draco_wasm_wrapper.js"]:::frontend
    end
  end

  %% Backend Layer
  subgraph "Application Services (Backend)"
    direction TB
    ServerEntry["Backend Entry Point & Static Serving"]:::backend
    Config["Application Configuration"]:::backend
    DBConn["Database Connection (MongoDB)"]:::backend
    JWTUtil["JWT Utilities"]:::backend
    AuthMW["Auth Middleware"]:::backend

    subgraph "Routes"
      direction TB
      AuthRoutes["Authentication Routes (/api/auth)"]:::backend
      ProductRoutes["Product Routes (/api/products)"]:::backend
      CartRoutes["Cart Order Routes (/api/cart)"]:::backend
      UserOrderRoutes["User Order Routes (/api/orders)"]:::backend
      OrderDoneRoutes["Completed Orders Routes (/api/orderdone)"]:::backend
    end

    subgraph "Models"
      direction TB
      ModelProduct["ProductList Model"]:::database
      ModelCart["CartOrder Model"]:::database
      ModelUserOrder["UserOrder Model"]:::database
      ModelOrderDone["OrderDone Model"]:::database
      ModelPerson["Person Model"]:::database
    end
  end

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

  %% External Services
  subgraph "External Services"
    direction TB
    Razorpay["Razorpay Payment Gateway"]:::external
  end

  %% Relationships
  Browser -->|"renders via Three.js"| ThreeD
  Browser -->|"invokes WebXR"| ARContainer
  ARContainer -->|"uses component"| XeHitModel
  Browser -->|"renders UI"| UIComp
  Browser -->|"manages auth state"| AuthCtx
  Browser -->|"manages cart state"| CartCtx
  Browser -->|"renders checkout"| Checkout
  Browser -->|"renders orders"| MyOrder
  Browser -->|"calls REST"| APIService
  Browser -->|"loads models"| StaticAssets
  StaticAssets --> DracoJS
  StaticAssets --> DracoWASM
  StaticAssets --> DracoWrapper

  APIService -->|"HTTPS REST"| AuthRoutes
  APIService -->|"HTTPS REST"| ProductRoutes
  APIService -->|"HTTPS REST"| CartRoutes
  APIService -->|"HTTPS REST"| UserOrderRoutes
  APIService -->|"HTTPS REST"| OrderDoneRoutes

  AuthRoutes --> JWTUtil
  AuthRoutes --> AuthMW
  AuthRoutes --> ModelPerson

  ProductRoutes --> ModelProduct
  CartRoutes --> ModelCart
  UserOrderRoutes --> ModelUserOrder
  OrderDoneRoutes --> ModelOrderDone

  DBConn --> MongoDB
  ServerEntry --> Config
  ServerEntry --> DBConn
  ServerEntry --> AuthRoutes
  ServerEntry --> ProductRoutes
  ServerEntry --> CartRoutes
  ServerEntry --> UserOrderRoutes
  ServerEntry --> OrderDoneRoutes

  UserOrderRoutes --> Razorpay
  Razorpay --> UserOrderRoutes
  UserOrderRoutes --> ModelOrderDone

  %% Click events
  click Browser "https://github.com/rajand2510/roomcraft/blob/master/client/src/App.jsx"
  click ThreeD "https://github.com/rajand2510/roomcraft/blob/master/client/src/components/Cube/Cube.jsx"
  click ARContainer "https://github.com/rajand2510/roomcraft/blob/master/client/src/components/xr-hit-model/XrHitModelConatainer.jsx"
  click XeHitModel "https://github.com/rajand2510/roomcraft/blob/master/client/src/components/xr-hit-model/XeHitModel.jsx"
  click UIComp "https://github.com/rajand2510/roomcraft/tree/master/client/src/components/homecontainer"
  click AuthCtx "https://github.com/rajand2510/roomcraft/blob/master/client/src/AuthContext.jsx"
  click CartCtx "https://github.com/rajand2510/roomcraft/blob/master/client/src/CartContext.jsx"
  click Checkout "https://github.com/rajand2510/roomcraft/blob/master/client/src/UserComponents/Checkout.jsx"
  click MyOrder "https://github.com/rajand2510/roomcraft/blob/master/client/src/UserComponents/MyOrder.jsx"
  click StaticAssets "https://github.com/rajand2510/roomcraft/tree/master/client/public/models/"
  click DracoJS "https://github.com/rajand2510/roomcraft/blob/master/client/public/draco/draco_decoder.js"
  click DracoWASM "https://github.com/rajand2510/roomcraft/blob/master/client/public/draco/draco_decoder.wasm"
  click DracoWrapper "https://github.com/rajand2510/roomcraft/blob/master/client/public/draco/draco_wasm_wrapper.js"
  click APIService "https://github.com/rajand2510/roomcraft/blob/master/client/src/components/api/apiService.jsx"
  click ServerEntry "https://github.com/rajand2510/roomcraft/blob/master/server/index.js"
  click Config "https://github.com/rajand2510/roomcraft/blob/master/server/config.js"
  click DBConn "https://github.com/rajand2510/roomcraft/blob/master/server/db.js"
  click JWTUtil "https://github.com/rajand2510/roomcraft/blob/master/server/jwt.js"
  click AuthMW "https://github.com/rajand2510/roomcraft/blob/master/server/auth.js"
  click AuthRoutes "https://github.com/rajand2510/roomcraft/blob/master/server/routes/personRoutes.js"
  click ProductRoutes "https://github.com/rajand2510/roomcraft/blob/master/server/routes/ProductListRoutes.js"
  click CartRoutes "https://github.com/rajand2510/roomcraft/blob/master/server/routes/CartOrderRoutes.js"
  click UserOrderRoutes "https://github.com/rajand2510/roomcraft/blob/master/server/routes/UserOrderRoutes.js"
  click OrderDoneRoutes "https://github.com/rajand2510/roomcraft/blob/master/server/routes/OrderDoneRoutes.js"
  click ModelProduct "https://github.com/rajand2510/roomcraft/blob/master/server/models/ProductList.js"
  click ModelCart "https://github.com/rajand2510/roomcraft/blob/master/server/models/CartOrder.js"
  click ModelUserOrder "https://github.com/rajand2510/roomcraft/blob/master/server/models/UserOrder.js"
  click ModelOrderDone "https://github.com/rajand2510/roomcraft/blob/master/server/models/OrderDone.js"
  click ModelPerson "https://github.com/rajand2510/roomcraft/blob/master/server/models/Person.js"

  %% Styles
  classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
  classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
  classDef database fill:#FFFACD,stroke:#333,stroke-width:1px
  classDef external fill:#FFA500,stroke:#333,stroke-width:1px
```
