# maaz2022/reseller-portall architecture

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

- Interactive diagram: https://gitdiagram.com/maaz2022/reseller-portall
- Repository: https://github.com/maaz2022/reseller-portall

## Overview

##### Project type and purpose
- This is a full-stack, serverless web application (“Reseller Portal”) built on Next.js 14 with React and TypeScript.
- It provides free and premium user dashboards, product listing, shopping cart, payment flows via Stripe, and user authentication via Firebase.

##### File-structure analysis
Top-level folders and files reveal:
- app/
- app/api/... → Next.js API routes (serverless functions) for payments and products
- app/components/ → shared React UI components (Navbar, ProductGallery, StripePaymentForm, etc.)
- app/dashboard, premium-dashboard, signup, login, payment pages → routing structure
- app/context/ → React Context providers (AuthContext, CartContext)
- lib/ → Firebase client (lib/firebase.ts), Firebase Admin (lib/firebase-admin.ts), utility helpers
- public/ → static assets
- next.config.js, middleware.ts → build/deployment config and custom routing/auth middleware
- tailwind.config.js, postcss.config.mjs → styling engine setup

##### README insights
- Tech stack: Next.js, React, TypeScript, Tailwind, shadcn/ui, Firebase Auth & Firestore, Zod for validation, Stripe payment.
- High-level flow: user sign-up → dashboard (free/premium) → product browsing → cart → checkout → payment intent → payment confirmation → success page.

##### Main components
a. Client (Browser)
- Next.js pages (React UI)
- shadcn/ui + Tailwind CSS for styling
- Stripe.js for payment UI
- React Contexts for Auth & Cart state
b. Next.js Serverless Layer
- API route: /api/create-payment-intent
- API route: /api/verify-payment
- API route: /api/verify-payment-status
- API route: /api/products (list, details)
- Middleware.ts for auth-guard / route protection
- Zod validation on incoming requests
c. Firebase
- Firebase Authentication (client + admin SDK)
- Firestore database (users, products, orders/payments)
d. Stripe (external payment service)
- PaymentIntents, webhooks (if used)—Next.js functions call Stripe SDK
e. Hosting/Deployment
- Vercel or equivalent (serverless function hosting + static content)

##### Relationships and data-flow
- Browser → Next.js pages → fetch(“/api/products”) → Next.js API → Firestore read → returns product data
- Browser (cart/checkout) → POST “/api/create-payment-intent” → API → Stripe SDK → returns client secret → Browser + Stripe.js → confirmCardPayment → Stripe → webhook or direct confirm → Browser calls “/api/verify-payment-status” → API → update Firestore order status
- Browser registration/login → Firebase Auth client SDK → Next.js AuthContext → on success writes user record to Firestore via Admin SDK in protected API route if needed
- Protected pages (dashboard, premium-dashboard) guarded by middleware.ts checking Firebase token via Admin SDK

##### Architectural patterns and principles
- File-based routing (Next.js app directory)
- Serverless functions for backend logic (zero-server management)
- Separation of concerns: UI components, data-access (lib/firebase, lib/firebase-admin), business logic in API routes
- Context API for global state (authentication, shopping cart)
- API layer with input validation (Zod)
- External services (Firebase, Stripe) as pluggable components

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)" 
        direction TB
        subgraph "Pages" 
            direction TB
            P1["app/page.tsx"]:::ui
            P2["app/login/page.tsx"]:::ui
            P3["app/signup/page.tsx"]:::ui
            P4["app/dashboard/page.tsx"]:::ui
            P5["app/premium-dashboard/page.tsx"]:::ui
            P6["app/product/[id]/page.tsx"]:::ui
            P7["app/payment/page.tsx"]:::ui
            P8["app/payment-success/page.tsx"]:::ui
        end
        subgraph "Components" 
            direction TB
            C1["Navbar.tsx"]:::ui
            C2["ProductGallery.tsx"]:::ui
            C3["ProductGrid.tsx"]:::ui
            C4["CartDrawer.tsx"]:::ui
            C5["StripePaymentForm.tsx"]:::ui
            C6["LoginForm.tsx"]:::ui
            C7["SignupForm.tsx"]:::ui
            C8["Benefits.tsx"]:::ui
            C9["app/components/ui/*"]:::ui
        end
        subgraph "Context Providers"
            direction TB
            CT1["AuthContext.tsx"]:::ui
            CT2["CartContext.tsx"]:::ui
        end
    end

    %% Serverless Layer
    subgraph "Next.js Serverless Layer"
        direction TB
        API1["/api/products (GET)"]:::api
        API2["/api/products/[id] (GET)"]:::api
        API3["/api/create-payment-intent (POST)"]:::api
        API4["/api/verify-payment (POST)"]:::api
        API5["/api/verify-payment-status (GET)"]:::api
        MWM["middleware.ts (Auth Guard)"]:::api
    end

    %% Firebase Services
    subgraph "Firebase"
        direction TB
        F1["Firebase Auth (Client SDK)"]:::data
        F2["lib/firebase.ts"]:::data
        F3["lib/firebase-admin.ts"]:::data
        F4["Firestore Database"]:::data
        F5["lib/auth.ts"]:::data
    end

    %% Stripe Service
    subgraph "Stripe (External)"
        direction TB
        S1["Stripe SDK"]:::ext
        S2["PaymentIntents & Webhooks"]:::ext
    end

    %% Hosting Platform
    V["Vercel Hosting"]:::infra

    %% Data Validation & Utils
    U["lib/utils.ts (Zod Schemas)"]:::api

    %% Styling & Config
    SC1["tailwind.config.js"]:::infra
    SC2["postcss.config.mjs"]:::infra
    NX1["next.config.js"]:::infra
    NX2["next.config.ts"]:::infra

    %% Static Assets
    PUB["public/"]:::infra

    %% Relationships
    P1 -->|fetchProducts| API1
    P6 -->|fetchProductDetails| API2
    P7 -->|createPaymentIntent| API3
    P7 -->|confirmCardPayment| S1
    S1 -->|webhook/payment| API4
    P7 -->|verifyPaymentStatus| API5
    API1 -->|read| F4
    API2 -->|read| F4
    API3 -->|createIntent| S1
    API3 -->|validate| U
    API4 -->|verify| U
    API5 -->|updateOrder| F4
    P2 -->|signInWithEmailAndPassword| F1
    P3 -->|createUser| F1
    CT1 -->|providesAuth| P1
    CT2 -->|providesCart| P7
    API1 -->|validate| U
    MWM -->|guardRoutes| API1
    MWM -->|guardRoutes| API3
    MWM -->|guardRoutes| API4
    F1 -->|token| MWM
    API3 -->|adminOperations| F3
    P1 -->|styling| SC1
    P1 -->|styling| SC2
    P1 -->|routing| NX1
    P1 -->|routing| NX2
    V -->|hosts UI & API| P1
    V -->|hosts UI & API| API1
    PUB -->|assets| P1

    %% Click Events
    click P1 "https://github.com/maaz2022/reseller-portall/blob/main/app/page.tsx"
    click P2 "https://github.com/maaz2022/reseller-portall/blob/main/app/login/page.tsx"
    click P3 "https://github.com/maaz2022/reseller-portall/blob/main/app/signup/page.tsx"
    click P4 "https://github.com/maaz2022/reseller-portall/blob/main/app/dashboard/page.tsx"
    click P5 "https://github.com/maaz2022/reseller-portall/blob/main/app/premium-dashboard/page.tsx"
    click P6 "https://github.com/maaz2022/reseller-portall/blob/main/app/product/[id]/page.tsx"
    click P7 "https://github.com/maaz2022/reseller-portall/blob/main/app/payment/page.tsx"
    click P8 "https://github.com/maaz2022/reseller-portall/blob/main/app/payment-success/page.tsx"
    click C1 "https://github.com/maaz2022/reseller-portall/blob/main/app/components/Navbar.tsx"
    click C2 "https://github.com/maaz2022/reseller-portall/blob/main/app/components/ProductGallery.tsx"
    click C3 "https://github.com/maaz2022/reseller-portall/blob/main/app/components/ProductGrid.tsx"
    click C4 "https://github.com/maaz2022/reseller-portall/blob/main/app/components/CartDrawer.tsx"
    click C5 "https://github.com/maaz2022/reseller-portall/blob/main/app/components/StripePaymentForm.tsx"
    click C6 "https://github.com/maaz2022/reseller-portall/blob/main/app/components/LoginForm.tsx"
    click C7 "https://github.com/maaz2022/reseller-portall/blob/main/app/components/SignupForm.tsx"
    click C8 "https://github.com/maaz2022/reseller-portall/blob/main/app/components/Benefits.tsx"
    click C9 "https://github.com/maaz2022/reseller-portall/tree/main/app/components/ui/"
    click CT1 "https://github.com/maaz2022/reseller-portall/blob/main/app/context/AuthContext.tsx"
    click CT2 "https://github.com/maaz2022/reseller-portall/blob/main/app/context/CartContext.tsx"
    click API1 "https://github.com/maaz2022/reseller-portall/blob/main/app/api/products/route.ts"
    click API2 "https://github.com/maaz2022/reseller-portall/blob/main/app/api/products/[id]/route.ts"
    click API3 "https://github.com/maaz2022/reseller-portall/blob/main/app/api/create-payment-intent/route.ts"
    click API4 "https://github.com/maaz2022/reseller-portall/blob/main/app/api/verify-payment/route.ts"
    click API5 "https://github.com/maaz2022/reseller-portall/blob/main/app/api/verify-payment-status/route.ts"
    click MWM "https://github.com/maaz2022/reseller-portall/blob/main/middleware.ts"
    click F2 "https://github.com/maaz2022/reseller-portall/blob/main/lib/firebase.ts"
    click F3 "https://github.com/maaz2022/reseller-portall/blob/main/lib/firebase-admin.ts"
    click F5 "https://github.com/maaz2022/reseller-portall/blob/main/lib/auth.ts"
    click U "https://github.com/maaz2022/reseller-portall/blob/main/lib/utils.ts"
    click SC1 "https://github.com/maaz2022/reseller-portall/blob/main/tailwind.config.js"
    click SC2 "https://github.com/maaz2022/reseller-portall/blob/main/postcss.config.mjs"
    click NX1 "https://github.com/maaz2022/reseller-portall/blob/main/next.config.js"
    click NX2 "https://github.com/maaz2022/reseller-portall/blob/main/next.config.ts"
    click PUB "https://github.com/maaz2022/reseller-portall/tree/main/public/"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#2a6fab
    classDef api fill:#d1ecf1,stroke:#087990
    classDef data fill:#d4edda,stroke:#2d6a4f
    classDef ext fill:#ffe5b4,stroke:#ba4a00
    classDef infra fill:#e2e3e5,stroke:#6c757d
```
