# mahdielmi/buy-stuff architecture

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

- Interactive diagram: https://gitdiagram.com/mahdielmi/buy-stuff
- Repository: https://github.com/mahdielmi/buy-stuff

## Overview

##### Main System Components

A. Frontend Layer
- Client-Side Components
- Server Components (Next.js App Router)
- UI Components Library

B. API Layer
- Authentication (NextAuth)
- File Upload Service (UploadThing)
- Server Actions

C. Database Layer
- Prisma ORM
- Database (likely PostgreSQL based on Prisma schema)

##### Detailed Component Breakdown

- Authentication & Authorization
- Product Management
- Shopping Cart
- User Dashboard
- Vendor Management
- Blog System
- Review System

##### Key Relationships to Highlight

- Client Components ↔ Server Actions
- Server Components ↔ Database
- Authentication Flow ↔ Protected Routes
- Upload Service ↔ Storage

##### Specific Implementation Details

Technical elements:
**Frontend:**
- Next.js 13+ App Router
- React Server Components
- Client Components where needed
- Tailwind CSS for styling
- Shadcn UI components

**API Layer:**
- Next.js API Routes
- Server Actions for data mutations
- NextAuth.js for authentication
- UploadThing for file handling

**Data Layer:**
- Prisma ORM
- Database Models (User, Product, Cart, etc.)

##### Important Architectural Patterns

Patterns:
- Server-side rendering paths
- Client-side interactivity points
- Data fetching patterns
- State management flow (using atoms.ts)

**[Client Layer]**
- ↕
**[Server Layer]**
- ↕
**[Data Layer]**

**[Authentication]  →  [Main Application Flow]  ←  [File Upload]**

**[App Router]**
- /products
- /dashboard
- /vendors
- /shopping-cart
- /blog

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        ClientComponents["Client Components"]
        ServerComponents["Server Components"]
        UILib["UI Components Library"]:::ui
        click UILib "https://github.com/mahdiElmi/buy-stuff/tree/main/src/components/ui/"
    end

    subgraph APILayer
        Auth["Authentication System"]:::auth
        click Auth "https://github.com/mahdiElmi/buy-stuff/blob/main/src/app/api/auth/[...nextauth]/route.ts"
        Upload["File Upload Service"]:::upload
        click Upload "https://github.com/mahdiElmi/buy-stuff/tree/main/src/app/api/uploadthing/"
        ServerActions["Server Actions"]:::actions
        click ServerActions "https://github.com/mahdiElmi/buy-stuff/tree/main/src/actions/"
    end

    subgraph DataLayer
        PrismaORM["Prisma ORM"]:::db
        click PrismaORM "https://github.com/mahdiElmi/buy-stuff/blob/main/src/lib/db.ts"
        Database[(Database)]:::db
        click Database "https://github.com/mahdiElmi/buy-stuff/blob/main/prisma/schema.prisma"
    end

    subgraph Features
        Products["Product Management"]:::feature
        click Products "https://github.com/mahdiElmi/buy-stuff/tree/main/src/app/products/"
        Cart["Shopping Cart"]:::feature
        click Cart "https://github.com/mahdiElmi/buy-stuff/tree/main/src/app/shopping-cart/"
        Dashboard["User Dashboard"]:::feature
        click Dashboard "https://github.com/mahdiElmi/buy-stuff/tree/main/src/app/dashboard/"
        Vendors["Vendor Management"]:::feature
        click Vendors "https://github.com/mahdiElmi/buy-stuff/tree/main/src/app/vendors/"
        Blog["Blog System"]:::feature
        click Blog "https://github.com/mahdiElmi/buy-stuff/tree/main/src/app/blog/"
        Reviews["Review System"]:::feature
        click Reviews "https://github.com/mahdiElmi/buy-stuff/blob/main/src/app/product/[productId]/ReviewForm.tsx"
    end

    %% Relationships
    ClientComponents --> ServerActions
    ServerComponents --> PrismaORM
    Auth --> Database
    Upload --> Database
    ServerActions --> Database
    PrismaORM --> Database

    %% Feature Connections
    Products --> ServerActions
    Cart --> ServerActions
    Dashboard --> ServerActions
    Vendors --> ServerActions
    Blog --> ServerActions
    Reviews --> ServerActions

    %% Cross-cutting Concerns
    Auth -.-> Features
    Upload -.-> Features
    UILib -.-> Features

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#e74c3c,stroke:#c0392b,color:white
    classDef db fill:#2ecc71,stroke:#27ae60,color:white
    classDef feature fill:#9b59b6,stroke:#8e44ad,color:white
    classDef auth fill:#f39c12,stroke:#d35400,color:white
    classDef upload fill:#1abc9c,stroke:#16a085,color:white
    classDef actions fill:#e67e22,stroke:#d35400,color:white
    classDef ui fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        Frontend_L["Frontend"]:::frontend
        API_L["API Services"]:::api
        DB_L["Database"]:::db
        Feature_L["Features"]:::feature
        Auth_L["Auth"]:::auth
        Upload_L["Upload"]:::upload
        Actions_L["Actions"]:::actions
        UI_L["UI"]:::ui
    end
```
