# khairul-2000/flowmazon architecture

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

- Interactive diagram: https://gitdiagram.com/khairul-2000/flowmazon
- Repository: https://github.com/khairul-2000/flowmazon

## Overview

##### Project type and purpose
- Flowmazon is a full-stack e-commerce website built on Next.js (App Router) with TypeScript, TailwindCSS/DaisyUI for the UI, Prisma ORM for database access, and deployed on Vercel.
- Key features: product listings, search, filtering, shopping cart, checkout flow, user authentication via NextAuth.

##### File structure
- app/ – Next.js App Router code: page.tsx, layout.tsx, global components, API routes under app/api.
- components/ – reusable React UI components (ProductCard, PaginationBar, CheckoutPage, etc.).
- lib/ – utility functions (currency conversion, formatting, env variables) and Prisma database client at lib/db/prisma.ts.
- prisma/ – Prisma schema for data models.
- config files – next.config.mjs, tailwind.config.ts, postcss.config.mjs, tsconfig.json.
- assets/fonts and globals.css for styling.

##### README for additional insights
- Confirms Next.js App Router, TailwindCSS & DaisyUI, Prisma ORM, Vercel deployment.
- Mentions MongoDB or any Prisma-supported database.
- Features: responsive design, search, filter, cart & checkout, user auth.

##### Main components
a. Frontend (Next.js App Router)
- Pages & UI components (app/page.tsx, app/products, components/…)
- Styling layer (TailwindCSS & DaisyUI)
b. Backend/API Layer (Next.js server-side code under app/api)
- Auth routes ([...nextauth])
- Product CRUD routes (app/api/products)
- Counts endpoint (app/api/counts)
c. Database
- Prisma client connecting to database (PostgreSQL / MongoDB) defined in prisma/schema.prisma
d. External/Third-party services
- NextAuth providers (Google, GitHub, etc.)
- Vercel (CI/CD, hosting)

##### Relationships and data flow
- User browser ⇄ Next.js front end (HTTP GET/POST)
- Front end calls API routes for products, counts, cart actions, authentication.
- API layer invokes Prisma client → database.
- NextAuth middleware ↔ external OAuth providers.
- Database responses flow back up to API → front end.

##### Architectural patterns and design principles
- “App Router” folder-based routing in Next.js for pages & serverless functions.
- Separation of concerns: UI components vs. data-access layer (lib/db, lib/utils).
- Serverless Function pattern: each file under app/api is its own lambda.
- ORM abstraction via Prisma.

##### Capturing essential architectural elements
- Presentation layer (Next.js pages & components)
- API / Business logic layer (Next.js serverless functions + NextAuth)
- Data layer (Prisma client + database)
- External dependencies (OAuth, Vercel hosting)
- Utility modules (env config, currency conversion) can be shown as internal libraries.

##### Final recommendations
- Be granular: represent main page groups (products listing, product detail, cart, checkout, auth) as sub-components.
- Reusable components (ProductCard, PaginationBar) as part of the UI layer.
- Flow of user actions: browsing ➔ adding to cart ➔ checkout ➔ order persisted in the database.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        FE_Page["Frontend Entry Page<br/>app/page.tsx"]:::frontend
        subgraph "Product Pages"
            direction TB
            All_Products["All Products<br/>app/products/page.tsx"]:::frontend
            Product_Detail["Product Detail<br/>app/products/[id]/page.tsx"]:::frontend
            Category_Filter["Category Filter<br/>app/products/category/[category]/page.tsx"]:::frontend
        end
        subgraph "Cart & Checkout"
            direction TB
            Cart_Page["Shopping Cart Page<br/>app/cart/page.tsx"]:::frontend
            Checkout_UI["Checkout Component<br/>components/CheckoutPage.tsx"]:::frontend
        end
        Search_Page["Search Page<br/>app/search/page.tsx"]:::frontend
        subgraph "Authentication UI"
            direction TB
            SignIn_Page["Sign-In Page<br/>app/sign-in/page.tsx"]:::frontend
            SignIn_Button["Sign-In Button<br/>app/sign-in/SignInButton.tsx"]:::frontend
        end
        Add_Product["Add-Product Page<br/>app/add-product/page.tsx"]:::frontend
        Root_Layout["Root Layout<br/>app/layout.tsx"]:::frontend
        Globals_CSS["Global Styles<br/>app/globals.css"]:::frontend
        Tailwind_Config["Tailwind & PostCSS Config"]:::frontend
        subgraph "Navbar & Footer"
            direction TB
            Navbar["Navbar Container<br/>app/Navbar/Navbar.tsx"]:::frontend
            Cart_Button["Shopping Cart Button<br/>app/Navbar/ShoppingCartButton.tsx"]:::frontend
            UserMenu["User Menu Button<br/>app/Navbar/UserMenuButton.tsx"]:::frontend
            Footer["Footer<br/>app/Footer.tsx"]:::frontend
        end
        Session_Provider["Session Provider<br/>app/SessionProvider.tsx"]:::frontend
        subgraph "Reusable UI Components"
            direction TB
            ProductCard["Product Card<br/>components/ProductCard.tsx"]:::frontend
            PaginationBar["Pagination Bar<br/>components/PaginationBar.tsx"]:::frontend
            PriceTag["Price Tag<br/>components/PriceTag.tsx"]:::frontend
            ImageSlider["Image Slider<br/>components/ImageSlider.tsx"]:::frontend
            JustForYou["Just For You<br/>components/JustForYou.tsx"]:::frontend
            FormSubmit["Form Submit Button<br/>components/FormSubmitButton.tsx"]:::frontend
        end
    end

    %% API Layer
    subgraph "API / Business Logic Layer"
        direction TB
        Auth_Routes["Auth Routes<br/>app/api/auth/[...nextauth]/route.ts"]:::api
        Products_API["Products CRUD<br/>app/api/products/route.ts"]:::api
        Counts_API["Counts Endpoint<br/>app/api/counts/route.ts"]:::api
    end

    %% Internal Utility Modules
    subgraph "Internal Libraries"
        direction TB
        Convert["Currency Conversion<br/>lib/convertToSubcurrency.ts"]:::internal
        EnvUtils["Env Utilities<br/>lib/utils/env.ts"]:::internal
        FormatUtils["Formatting Utilities<br/>lib/utils/format.ts"]:::internal
        CartHelpers["Cart Actions<br/>lib/utils/cart.ts & app/cart/actions.ts"]:::internal
        CategoryUtils["Category Helpers<br/>lib/utils/category.ts"]:::internal
        DisplayUtils["Display Helpers<br/>lib/utils/display.ts"]:::internal
        ActionsUtils["General Actions<br/>lib/utils/actions.ts"]:::internal
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Prisma_Client["Prisma Client<br/>lib/db/prisma.ts"]:::db
        Prisma_Schema["Prisma Schema<br/>prisma/schema.prisma"]:::db
        Database["Database (PostgreSQL/MongoDB)"]:::db
    end

    %% External Services
    subgraph "External Services"
        direction TB
        OAuth["OAuth Providers"]:::external
        Vercel["Vercel Hosting & CI/CD"]:::external
    end

    %% Relationships
    Browser -->|"HTTP GET/POST"| FE_Page
    FE_Page -->|"renders pages"| All_Products
    FE_Page --> Product_Detail
    FE_Page --> Category_Filter
    FE_Page --> Cart_Page
    FE_Page --> Checkout_UI
    FE_Page --> Search_Page
    FE_Page --> SignIn_Page
    FE_Page --> Add_Product
    FE_Page --> Navbar
    FE_Page --> Footer
    FE_Page --> Session_Provider

    %% Frontend to API
    All_Products -->|"GET /api/products"| Products_API
    Product_Detail -->|"GET /api/products/:id"| Products_API
    Category_Filter -->|"GET /api/products?category"| Products_API
    Cart_Page -->|"POST add-to-cart"| Products_API
    Cart_Page -->|"GET /api/counts"| Counts_API
    Checkout_UI -->|"POST /api/orders"| Products_API
    SignIn_Button -->|"CALL auth"| Auth_Routes

    %% API to DB
    Products_API -->|"Prisma query"| Prisma_Client
    Counts_API -->|"Prisma query"| Prisma_Client
    Auth_Routes -->|"Prisma query"| Prisma_Client

    Prisma_Client --> Prisma_Schema
    Prisma_Schema --> Database

    %% Auth to OAuth
    Auth_Routes -->|"OAuth flow"| OAuth

    %% Hosting
    FE_Page --> Vercel
    Auth_Routes --> Vercel
    Products_API --> Vercel

    %% Internal Lib usage
    Products_API --> Convert
    Products_API --> CartHelpers
    FE_Page --> FormatUtils
    FE_Page --> CategoryUtils
    FE_Page --> DisplayUtils
    Cart_Page --> ActionsUtils

    %% Click events
    click FE_Page "https://github.com/khairul-2000/flowmazon/blob/main/app/page.tsx"
    click All_Products "https://github.com/khairul-2000/flowmazon/blob/main/app/products/page.tsx"
    click Product_Detail "https://github.com/khairul-2000/flowmazon/blob/main/app/products/[id]/page.tsx"
    click Category_Filter "https://github.com/khairul-2000/flowmazon/blob/main/app/products/category/[category]/page.tsx"
    click Cart_Page "https://github.com/khairul-2000/flowmazon/blob/main/app/cart/page.tsx"
    click Checkout_UI "https://github.com/khairul-2000/flowmazon/blob/main/components/CheckoutPage.tsx"
    click Search_Page "https://github.com/khairul-2000/flowmazon/blob/main/app/search/page.tsx"
    click SignIn_Page "https://github.com/khairul-2000/flowmazon/blob/main/app/sign-in/page.tsx"
    click SignIn_Button "https://github.com/khairul-2000/flowmazon/blob/main/app/sign-in/SignInButton.tsx"
    click Add_Product "https://github.com/khairul-2000/flowmazon/blob/main/app/add-product/page.tsx"
    click Root_Layout "https://github.com/khairul-2000/flowmazon/blob/main/app/layout.tsx"
    click Globals_CSS "https://github.com/khairul-2000/flowmazon/blob/main/app/globals.css"
    click Tailwind_Config "https://github.com/khairul-2000/flowmazon/blob/main/tailwind.config.ts"
    click Navbar "https://github.com/khairul-2000/flowmazon/blob/main/app/Navbar/Navbar.tsx"
    click Cart_Button "https://github.com/khairul-2000/flowmazon/blob/main/app/Navbar/ShoppingCartButton.tsx"
    click UserMenu "https://github.com/khairul-2000/flowmazon/blob/main/app/Navbar/UserMenuButton.tsx"
    click Footer "https://github.com/khairul-2000/flowmazon/blob/main/app/Footer.tsx"
    click Session_Provider "https://github.com/khairul-2000/flowmazon/blob/main/app/SessionProvider.tsx"
    click Auth_Routes "https://github.com/khairul-2000/flowmazon/blob/main/app/api/auth/[...nextauth]/route.ts"
    click Products_API "https://github.com/khairul-2000/flowmazon/blob/main/app/api/products/route.ts"
    click Counts_API "https://github.com/khairul-2000/flowmazon/blob/main/app/api/counts/route.ts"
    click Prisma_Client "https://github.com/khairul-2000/flowmazon/blob/main/lib/db/prisma.ts"
    click Prisma_Schema "https://github.com/khairul-2000/flowmazon/blob/main/prisma/schema.prisma"

    %% Styles
    classDef frontend fill:#ebf5ff,stroke:#5b9bd5,stroke-width:1px
    classDef api fill:#e8f5e9,stroke:#43a047,stroke-width:1px
    classDef db fill:#fff3e0,stroke:#fb8c00,stroke-width:1px
    classDef external fill:#eceff1,stroke:#546e7a,stroke-width:1px
    classDef internal fill:#fffde7,stroke:#f9a825,stroke-width:1px
```
