# slowfound/next-prisma-tailwind-ecommerce architecture

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

- Interactive diagram: https://gitdiagram.com/slowfound/next-prisma-tailwind-ecommerce
- Repository: https://github.com/slowfound/next-prisma-tailwind-ecommerce

## Overview

##### Project Type and Purpose
- This is a monorepo full-stack e-commerce platform composed of two separate Next.js 14 apps:
- Admin Panel (apps/admin) – for managing products, orders, users, payments.
- Storefront (apps/storefront) – customer-facing shopping experience with blog, cart, checkout, profile.
- Shared code lives under packages/* (mail, oauth, regex, rng, slugify, sms, zarinpal) and is consumed by both apps.
- Both apps use TypeScript, Prisma ORM (PostgreSQL), TailwindCSS, shadcn/ui (Radix), Zod for validation, and Next.js App Router with React Server Components.

##### File Structure
- Top-level: linting/config files, apps/, packages/, bun.lockb, package.json.
- apps/admin & apps/storefront: each has Next.js source (src/app, src/components, src/lib, src/api routes), Prisma schema, Dockerfiles, .env.example.
- packages/*: lightweight utility modules (email templates & sending, OAuth helpers, regex/rng/slugify utilities, SMS gateway, Zarinpal payment).
- Authentication handled via middleware.ts in each app (verifies JWT in httpOnly cookie, injects X-USER-ID header).
- External services: Cloudinary (file uploads), email transporter (packages/mail), SMS (packages/sms), OAuth providers (Google, Apple via packages/oauth), Payment (Zarinpal via packages/zarinpal).

##### README Insights
- Two separate deployments (admin vs storefront).
- Uses dynamic API routes for CRUD (brands, categories, products, orders, payments, cart, profile, wishlist, subscription).
- Uses React Email Tailwind Templates for email; MDX for blog.
- Environment stored in .env, DB URL (Postgres/Supabase).

a. Main Components
- Admin Next.js App (apps/admin)
- Storefront Next.js App (apps/storefront)
- Shared Packages (mail, oauth, sms, zarinpal, etc.)
- Prisma ORM Layer
- PostgreSQL Database
- External Services:
– Cloudinary (file storage)
– SMTP/email provider
– SMS gateway
– OAuth providers (Google, Apple)
– Payment gateway (Zarinpal)
b. Relationships & Data Flow
- User → Next.js App (browser HTTP/HTTPS)
- Next.js API routes ↔ Prisma ORM ↔ PostgreSQL
- Next.js App Server (middleware.ts) injects auth context via JWT cookie
- Server Actions / API endpoints call Shared Packages → External Services
- Client-side state (app/providers, React Server Components)
c. Architectural Patterns
- Monorepo with two deployable Next.js services
- App Router pattern (folder-based routing for UI and API routes)
- Middleware for authentication (JWT in cookies)
- Shared library modules for reusability
- React Server Components & Server Actions for data fetching
d. Key Technologies
- Next.js 14 App Router, React Server Components
- Prisma ORM (PostgreSQL)
- TailwindCSS, shadcn/ui (Radix)
- Zod for schema validation
- Bun as the runtime and package manager
- Docker for containerization

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser["Client (Browser)"]:::client

    %% Next.js Apps
    subgraph "Admin Next.js App" 
        direction TB
        Admin_Middleware["middleware.ts"]:::nextjs
        Admin_API["API Routes"]:::nextjs
        Admin_UI["UI Components"]:::nextjs
        Admin_Providers["State & Providers"]:::nextjs
        Admin_Emails["Email Templates"]:::nextjs
        Admin_Lib["Library Utilities"]:::nextjs
        Admin_Prisma["Prisma Schema"]:::nextjs
    end

    subgraph "Storefront Next.js App"
        direction TB
        Store_Middleware["middleware.ts"]:::nextjs
        Store_API["API Routes"]:::nextjs
        Store_UI["UI Components"]:::nextjs
        Store_Providers["State & Providers"]:::nextjs
        Store_Emails["Email Templates"]:::nextjs
        Store_Lib["Library Utilities"]:::nextjs
        Store_ReactEmail["React Email Templates"]:::nextjs
        Store_Prisma["Prisma Schema"]:::nextjs
    end

    %% Shared Packages
    subgraph "Shared Packages"
        direction TB
        Mail["packages/mail"]:::shared
        OAuth["packages/oauth"]:::shared
        Regex["packages/regex"]:::shared
        RNG["packages/rng"]:::shared
        Slugify["packages/slugify"]:::shared
        SMS["packages/sms"]:::shared
        Zarinpal["packages/zarinpal"]:::shared
    end

    %% Database and ORM
    Database["PostgreSQL Database"]:::database

    %% External Services
    subgraph "External Services"
        direction TB
        Cloudinary["Cloudinary"]:::external
        SMTP["Email Provider (SMTP)"]:::external
        SMSGateway["SMS Gateway"]:::external
        OAuthProviders["OAuth Providers"]:::external
        PaymentGateway["Zarinpal Payment Gateway"]:::external
    end

    %% Relationships
    Browser -->|"HTTP/HTTPS"| Admin_Middleware
    Browser -->|"HTTP/HTTPS"| Store_Middleware
    Admin_Middleware --> Admin_API
    Store_Middleware --> Store_API
    Admin_API -->|"SQL (via Prisma)"| Database
    Store_API -->|"SQL (via Prisma)"| Database
    Admin_API --> Mail
    Admin_API --> SMS
    Admin_API --> OAuth
    Admin_API --> Zarinpal
    Store_API --> Mail
    Store_API --> SMS
    Store_API --> OAuth
    Store_API --> Zarinpal
    Admin_API --> Cloudinary
    Store_API --> Cloudinary
    Mail --> SMTP
    SMS --> SMSGateway
    OAuth --> OAuthProviders
    Zarinpal --> PaymentGateway

    %% Click Events for mapping
    click Admin_Middleware "https://github.com/slowfound/next-prisma-tailwind-ecommerce/blob/main/apps/admin/src/middleware.ts"
    click Store_Middleware "https://github.com/slowfound/next-prisma-tailwind-ecommerce/blob/main/apps/storefront/src/middleware.ts"
    click Admin_API "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/apps/admin/src/app/api"
    click Store_API "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/apps/storefront/src/app/api"
    click Admin_UI "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/apps/admin/src/components"
    click Store_UI "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/apps/storefront/src/components"
    click Admin_Providers "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/apps/admin/src/providers"
    click Store_Providers "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/apps/storefront/src/providers"
    click Admin_Emails "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/apps/admin/src/emails"
    click Store_Emails "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/apps/storefront/src/emails"
    click Store_ReactEmail "https://github.com/slowfound/next-prisma-tailwind-ecommerce/blob/main/apps/storefront/.react-email"
    click Admin_Lib "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/apps/admin/src/lib"
    click Store_Lib "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/apps/storefront/src/lib"
    click Admin_Prisma "https://github.com/slowfound/next-prisma-tailwind-ecommerce/blob/main/apps/admin/prisma/schema.prisma"
    click Store_Prisma "https://github.com/slowfound/next-prisma-tailwind-ecommerce/blob/main/apps/storefront/prisma/schema.prisma"
    click Mail "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/packages/mail"
    click OAuth "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/packages/oauth"
    click Regex "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/packages/regex"
    click RNG "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/packages/rng"
    click Slugify "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/packages/slugify"
    click SMS "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/packages/sms"
    click Zarinpal "https://github.com/slowfound/next-prisma-tailwind-ecommerce/tree/main/packages/zarinpal"

    %% Styles
    classDef client fill:#dde2e6,stroke:#333,stroke-width:1px
    classDef nextjs fill:#bdd7f3,stroke:#1f77b4,stroke-width:1px
    classDef shared fill:#d0f0c0,stroke:#2ca02c,stroke-width:1px
    classDef database fill:#ffdd99,stroke:#ff7f0e,stroke-width:1px
    classDef external fill:#e8daef,stroke:#9467bd,stroke-width:1px
```
