# mdazfar2/ezyshop architecture

> Architecture diagram of the GitHub repository mdazfar2/ezyshop, 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/mdazfar2/ezyshop
- Repository: https://github.com/mdazfar2/ezyshop

## Overview

##### Project Type and Purpose
- EzyShop is a full-stack, multi-tenant e-commerce platform built on Next.js (App Router).
- It serves three user roles—Shopper (Customer), Store Manager (Seller), and Admin—each with its own UI, routes, and permissions.
- Key features include role-based auth (NextAuth), product/catalog management, cart/checkout with Razorpay, real-time updates, and media uploads via Cloudinary.

##### File Structure
- Top-level “app/” directory uses Next.js App Router to organize pages by role:
- app/(Customer)/…
- app/(Seller)/…
- app/admin/…
- app/api/… (serverless functions for REST endpoints)
- “components/” houses shared React UI components (Blog, Navbar, Modals, UI primitives).
- “actions/” contains client-side functions (e.g., fetch products, chat).
- “lib/” holds database configuration (Prisma → MongoDB), auth helpers, email utilities.
- “context/” and “providers/” implement React Context for theme, cart, flash alerts, sessions.
- “prisma/” defines schema.prisma and seed scripts.
- Config & infra: Dockerfile, docker-compose.yml, GitHub workflows, .env.example.

##### Extract Architecture Insights from README
- Tech Stack:
- Next.js + React (SSR + Client Components)
- TypeScript, Tailwind CSS
- Prisma ORM backed by MongoDB
- NextAuth for auth
- Razorpay for payments
- Cloudinary for image hosting
- Nodemailer for transactional emails
- Deployment target: Vercel (serverless functions) or Docker containers.

##### Main Components & Their Relationships
a. Frontend (Next.js)
– App Router pages (Customer/Seller/Admin layouts & pages)
– React Contexts & Hooks manage local UI state
– “actions/” functions invoked from UI to call API routes
b. API Layer (Next.js serverless under app/api/…)
– REST endpoints for auth, products, categories, chat, FAQ, orders, webhooks
– Uses NextAuth handlers for signup/login flows
c. Business Logic & Data Access
– “lib/prismadb.ts” exports Prisma client
– CRUD operations on MongoDB collections (stores, products, users, chats, orders)
d. External Services
– Razorpay: payment intent creation & verification
– Cloudinary: upload and serve product/store images
– Email (Nodemailer): newsletters, contact form, OTP emails
e. Database
– MongoDB collections accessed via Prisma
– Seed data lives in prisma/seed.ts and public/data/ JSON files

##### Architectural Patterns & Design Principles
- **Separation of Concerns:** UI components vs. serverless API vs. data layer
- **Role-Based Routing:** Folder conventions in app/ to isolate routes per user type
- **Server/Client Components:** Leverage Next.js App Router’s layouts, loading, error, and server components
- **Context Providers:** Decouple cross-cutting concerns (theme, cart, flash alerts)
- **Infra as Code:** Docker + GitHub Actions automate builds and deployments

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "Client (Browser)"
        direction TB
        Browser["Browser"]:::external
        Browser -->|"renders"| CustomerUI
        Browser -->|"renders"| SellerUI
        Browser -->|"renders"| AdminUI
    end

    subgraph "Frontend (Next.js App Router)" 
        direction TB
        CustomerUI["Customer UI"]:::frontend
        SellerUI["Seller UI"]:::frontend
        AdminUI["Admin UI"]:::frontend
        SharedComponents["Shared React Components"]:::frontend
        UIPrimitives["UI Primitives"]:::frontend
        Actions["Client-side Actions"]:::frontend
        ContextProviders["React Context Providers"]:::frontend
        SessionProvider["Session Provider"]:::frontend

        CustomerUI -->|"uses"| SharedComponents
        CustomerUI -->|"uses"| UIPrimitives
        CustomerUI -->|"invokes"| Actions
        CustomerUI -->|"wrapped by"| ContextProviders
        CustomerUI -->|"wrapped by"| SessionProvider

        SellerUI -->|"uses"| SharedComponents
        SellerUI -->|"uses"| UIPrimitives
        SellerUI -->|"invokes"| Actions
        SellerUI -->|"wrapped by"| ContextProviders
        SellerUI -->|"wrapped by"| SessionProvider

        AdminUI -->|"uses"| SharedComponents
        AdminUI -->|"uses"| UIPrimitives
        AdminUI -->|"invokes"| Actions
        AdminUI -->|"wrapped by"| ContextProviders
        AdminUI -->|"wrapped by"| SessionProvider

        Actions -->|"calls"| API
    end

    subgraph "Backend (Next.js Serverless Functions)" 
        direction TB
        API["Next.js API Layer"]:::api
        Middleware["Middleware"]:::api
        NextAuthHandlers["NextAuth Handlers"]:::api
        UserLogin["Auth Login: User"]:::api
        SellerLogin["Auth Login: Seller"]:::api
        UserSignup["Auth Signup: User"]:::api
        SellerSignup["Auth Signup: Seller"]:::api
        RESTEndpoints["REST API Endpoints"]:::api
        WebhookReceiver["Webhook Receiver"]:::api

        API -->|"secured by"| Middleware
        API -->|"handles auth"| NextAuthHandlers
        NextAuthHandlers --> UserLogin
        NextAuthHandlers --> SellerLogin
        NextAuthHandlers --> UserSignup
        NextAuthHandlers --> SellerSignup
        API -->|"exposes"| RESTEndpoints
        API -->|"receives events"| WebhookReceiver
        RESTEndpoints -->|"queries"| Prismaclient
    end

    subgraph "Data Layer" 
        direction TB
        Prismaclient["Prisma Client"]:::db
        AuthHelpers["Auth Helpers"]:::db
        NodemailerConfig["Email Config"]:::db
        SendEmail["Send Email Utility"]:::db
        DBSchema["Prisma Schema"]:::db
        DBSeed["Seed Scripts"]:::db
        MongoDB["MongoDB Atlas"]:::db

        Prismaclient -->|"accesses"| MongoDB
        DBSchema --> Prismaclient
        DBSeed --> Prismaclient
        AuthHelpers --> NextAuthHandlers
        NodemailerConfig --> SendEmail
        RESTEndpoints --> SendEmail
    end

    subgraph "External Services"
        direction TB
        Razorpay["Razorpay"]:::external
        Cloudinary["Cloudinary"]:::external
        SMTP["SMTP Server"]:::external

        RESTEndpoints -->|"payment intents"| Razorpay
        WebhookReceiver -->|"webhook events"| Razorpay
        RESTEndpoints -->|"upload images"| Cloudinary
        RESTEndpoints -->|"send emails"| SMTP
    end

    %% Inter-layer connections
    Actions --> API
    API --> Prismaclient

    %% Click Events
    click CustomerUI "https://github.com/mdazfar2/ezyshop/tree/main/app/(Customer)/"
    click SellerUI "https://github.com/mdazfar2/ezyshop/tree/main/app/(Seller)/"
    click AdminUI "https://github.com/mdazfar2/ezyshop/tree/main/app/admin/"
    click SharedComponents "https://github.com/mdazfar2/ezyshop/tree/main/components/"
    click UIPrimitives "https://github.com/mdazfar2/ezyshop/tree/main/components/ui/"
    click Actions "https://github.com/mdazfar2/ezyshop/tree/main/actions/"
    click ContextProviders "https://github.com/mdazfar2/ezyshop/tree/main/context/"
    click SessionProvider "https://github.com/mdazfar2/ezyshop/blob/main/providers/sessionProvider.tsx"
    click NextAuthHandlers "https://github.com/mdazfar2/ezyshop/blob/main/app/api/auth/[...nextauth]/route.ts"
    click UserLogin "https://github.com/mdazfar2/ezyshop/blob/main/app/api/auth/login/user/route.ts"
    click SellerLogin "https://github.com/mdazfar2/ezyshop/blob/main/app/api/auth/login/seller/route.ts"
    click UserSignup "https://github.com/mdazfar2/ezyshop/blob/main/app/api/auth/signup/route.ts"
    click SellerSignup "https://github.com/mdazfar2/ezyshop/blob/main/app/api/auth/signup/seller/route.ts"
    click RESTEndpoints "https://github.com/mdazfar2/ezyshop/tree/main/app/api/"
    click WebhookReceiver "https://github.com/mdazfar2/ezyshop/blob/main/app/api/webhook/route.ts"
    click Prismaclient "https://github.com/mdazfar2/ezyshop/blob/main/lib/prismadb.ts"
    click AuthHelpers "https://github.com/mdazfar2/ezyshop/blob/main/lib/auth.ts"
    click NodemailerConfig "https://github.com/mdazfar2/ezyshop/blob/main/lib/nodemailerConfig.ts"
    click SendEmail "https://github.com/mdazfar2/ezyshop/blob/main/lib/sendEmail.ts"
    click DBSchema "https://github.com/mdazfar2/ezyshop/blob/main/prisma/schema.prisma"
    click DBSeed "https://github.com/mdazfar2/ezyshop/blob/main/prisma/seed.ts"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,stroke-width:1px
    classDef api fill:#DFFFE0,stroke:#28A745,stroke-width:1px
    classDef db fill:#FFF4D0,stroke:#F29D21,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#6A737D,stroke-width:1px
```
