# humayun167/swiftcart architecture

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

- Interactive diagram: https://gitdiagram.com/humayun167/swiftcart
- Repository: https://github.com/humayun167/swiftcart

## Overview

##### Project type and purpose
- This is a full-stack, e-commerce web application built with Next.js (App Router).
- It provides storefront pages (all-products, product details, cart, checkout flow) and a seller dashboard (product management, order management).
- It integrates with a MongoDB database, uses Inngest for background jobs, and maintains global state via React Context.

##### File structure
- Top-level “app” directory: Next.js pages and nested layouts for user and seller flows.
- app/layout.js – global layout (header, footer, globals.css).
- app/api/inngest/route.js – serverless API endpoint for Inngest event handling.
- app/[route]/page.jsx – each user-facing page.
- app/seller/layout.jsx & app/seller/** – seller dashboard pages.
- “components” and “components/seller”: React UI components for storefront and seller UI.
- “config”: configuration for database (config/db.js) and Inngest (config/inngest.js).
- “lib/authSeller.js” & “middleware.ts”: authentication logic and route protection.
- “models/User.js”: Mongoose schema for user data.
- “context/AppContext.jsx”: React Context for global cart/user state.
- “assets”: static JS data and images.
- “public”: static assets (served via CDN).
- Root config files: next.config.mjs, tailwind.config.mjs, postcss.config.mjs, jsconfig.json.

##### Extract architecture notes from README
- Uses Next.js App Router for SSR/SSG, serverless functions (API routes).
- Optimizes fonts via next/font.
- Deploys on Vercel (supports edge functions, serverless functions).

##### Main components & interactions
a. Components
1. Client (Browser)
2. Next.js App
- App Router (pages & layouts)
- API Routes (Inngest endpoint)
3. React Context (Cart/User state)
4. MongoDB Database
5. Inngest (Background Job Processor)
6. Public CDN (public/*)
7. Authentication/Middleware
b. Relationships & data flow
- Browser ↔ Next.js App (SSR/SSG for pages; CSR for interactivity).
- Browser → API Routes to trigger server-side logic (e.g., order creation).
- Next.js App → MongoDB via config/db.js (CRUD on User, Orders, Products).
- API Route (/api/inngest) → Inngest service → triggers background jobs (e.g., order confirmation email).
- React Context provides shared client-side state (cart items, user session).
- Public static assets served from CDN.
c. Architectural patterns & design principles
- Hybrid rendering: SSR for SEO pages (all-products, product/[id]), client components for dynamic content.
- Module grouping: “app” for route structure, “components” for UI, “config/lib/models” for data & infra.
- Separation of concerns: storefront vs. seller dashboard via nested layouts.
- API routes as thin serverless functions.
d. Key technologies & frameworks
- Next.js (App Router, serverless API routes)
- React (client components, context)
- MongoDB (Mongoose models)
- Inngest (event gateway / job runner)
- Tailwind CSS (styling)
- Vercel (deployment platform)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Side
    Browser["Browser"]:::client
    ReactContext["React Context"]:::context
    click ReactContext "https://github.com/humayun167/swiftcart/blob/main/context/AppContext.jsx"

    %% Next.js Application
    subgraph "Next.js App" 
        style NextApp fill:#e0ffe0,stroke:#2d8f2d,stroke-width:2px
        NextApp(["App Router"]):::server
        click NextApp "https://github.com/humayun167/swiftcart/tree/main/app/"

        %% User Storefront Pages
        subgraph "User Storefront" 
            layout["Global Layout"]:::server
            click layout "https://github.com/humayun167/swiftcart/blob/main/app/layout.js"
            allProducts["All Products Page"]:::server
            click allProducts "https://github.com/humayun167/swiftcart/blob/main/app/all-products/page.jsx"
            productDetails["Product Details Page"]:::server
            click productDetails "https://github.com/humayun167/swiftcart/blob/main/app/product/[id]/page.jsx"
            cartPage["Cart Page"]:::server
            click cartPage "https://github.com/humayun167/swiftcart/blob/main/app/cart/page.jsx"
            addAddress["Add Address Page"]:::server
            click addAddress "https://github.com/humayun167/swiftcart/blob/main/app/add-address/page.jsx"
            orderPlaced["Order Confirmation Page"]:::server
            click orderPlaced "https://github.com/humayun167/swiftcart/blob/main/app/order-placed/page.jsx"
            myOrders["My Orders Page"]:::server
            click myOrders "https://github.com/humayun167/swiftcart/blob/main/app/my-orders/page.jsx"
        end

        %% Seller Dashboard Pages
        subgraph "Seller Dashboard"
            sellerLayout["Seller Layout"]:::server
            click sellerLayout "https://github.com/humayun167/swiftcart/blob/main/app/seller/layout.jsx"
            sellerHome["Seller Home"]:::server
            click sellerHome "https://github.com/humayun167/swiftcart/blob/main/app/seller/page.jsx"
            sellerOrders["Seller Orders Page"]:::server
            click sellerOrders "https://github.com/humayun167/swiftcart/blob/main/app/seller/orders/page.jsx"
            sellerProducts["Seller Product List"]:::server
            click sellerProducts "https://github.com/humayun167/swiftcart/blob/main/app/seller/product-list/page.jsx"
        end

        %% API Routes
        apiRoutes["API Route: /api/inngest"]:::lambda
        click apiRoutes "https://github.com/humayun167/swiftcart/blob/main/app/api/inngest/route.js"
    end

    %% Configuration & Models
    subgraph "Config & Models"
        dbConfig["DB Config"]:::server
        click dbConfig "https://github.com/humayun167/swiftcart/blob/main/config/db.js"
        inngestConfig["Inngest Config"]:::server
        click inngestConfig "https://github.com/humayun167/swiftcart/blob/main/config/inngest.js"
        authLogic["Seller Auth Logic"]:::server
        click authLogic "https://github.com/humayun167/swiftcart/blob/main/lib/authSeller.js"
        middleware["Route Protection"]:::server
        click middleware "https://github.com/humayun167/swiftcart/blob/main/middleware.ts"
        userModel["User Model"]:::server
        click userModel "https://github.com/humayun167/swiftcart/blob/main/models/User.js"
    end

    %% Assets
    assets["Static JS Data Assets"]:::storage
    click assets "https://github.com/humayun167/swiftcart/blob/main/assets/productData.js"
    publicAssets["Public CDN Assets"]:::storage
    click publicAssets "https://github.com/humayun167/swiftcart/tree/main/public/"

    %% External Services
    db["MongoDB Atlas"]:::db
    inngest["Inngest Service"]:::external

    %% Connections
    Browser --> ReactContext
    Browser --> NextApp
    ReactContext --> layout
    ReactContext --> sellerLayout

    NextApp --> dbConfig
    NextApp --> inngestConfig
    NextApp --> authLogic
    NextApp --> middleware
    NextApp --> userModel

    layout --> allProducts
    layout --> productDetails
    layout --> cartPage
    layout --> addAddress
    layout --> orderPlaced
    layout --> myOrders

    sellerLayout --> sellerHome
    sellerLayout --> sellerOrders
    sellerLayout --> sellerProducts

    Browser --> apiRoutes
    apiRoutes --> inngest
    apiRoutes --> db

    dbConfig --> db
    inngestConfig --> inngest
    inngest --> db

    assets --> allProducts
    assets --> sellerProducts
    publicAssets --> Browser

    %% Styles
    classDef client fill:#cce5ff,stroke:#004085,stroke-width:1px
    classDef server fill:#d4edda,stroke:#155724,stroke-width:1px
    classDef context fill:#fff3cd,stroke:#856404,stroke-width:1px
    classDef db fill:#ffe5b4,stroke:#ff8c00,stroke-width:1px
    classDef external fill:#f5c6cb,stroke:#721c24,stroke-width:1px
    classDef lambda fill:#e2e3e5,stroke:#6c757d,stroke-width:1px,stroke-dasharray: 5 5
    classDef storage fill:#d1ecf1,stroke:#0c5460,stroke-width:1px
```
