# 169398/strathmall architecture

> Architecture diagram of the GitHub repository 169398/strathmall, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/169398/strathmall
- Repository: https://github.com/169398/strathmall

## Overview

##### Main System Components

a) Frontend Layer:
- Client-side application (Next.js App Router structure)
- Authentication interfaces (/(auth) route)
- Admin dashboard (/admin route)
- Seller dashboard (/seller route)
- User dashboard (/user route)
- Delivery interface (/delivery route)

b) Backend Layer:
- API Routes (/api directory)
- Authentication system (NextAuth.js)
- Payment processing (Stripe & M-Pesa integration)
- File upload system (UploadThing)

c) Database Layer:
- PostgreSQL (indicated by Drizzle ORM usage)
- Redis (for caching)

##### Architectural Patterns to Highlight

a) Next.js App Router Architecture:
- Route Groups: (auth), (root)
- Parallel Routes: @modal
- API Routes structure
- Server vs Client Components

b) Service Architecture:
- Authentication flows
- Payment processing services
- Email service system
- File storage system

##### Specific Implementation Details

a) Data Flow:
- Client-to-API interactions
- Authentication flows
- Payment processing flows
- Real-time updates

b) Integration Points:
- Third-party services (Stripe, M-Pesa)
- File upload service
- Email service
- External APIs

##### Component Relationships

Key interactions:

- User authentication flow
- Product management pipeline
- Order processing system
- Payment processing flow
- Seller-buyer interactions
- Admin management capabilities

**[Client Layer]**
- ↕
**[API/Server Layer]**
- ↕
**[Service Layer]**
- ↕
**[Database Layer]**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Layer"]
        direction TB
        Auth["Authentication Interface"]
        Admin["Admin Dashboard"]
        Seller["Seller Dashboard"]
        User["User Dashboard"]
        Delivery["Delivery Interface"]
        Cart["Cart System"]
        Product["Product Management"]
        Referral["Referral System"]
    end

    subgraph API["API/Server Layer"]
        direction TB
        AuthAPI["Authentication API"]
        PaymentAPI["Payment Processing"]
        UploadAPI["File Upload API"]
        CartAPI["Cart API"]
        ProductAPI["Product API"]
        ReferralAPI["Referral API"]
    end

    subgraph Services["Service Layer"]
        direction TB
        NextAuth["NextAuth.js"]
        Stripe["Stripe"]
        MPesa["M-Pesa"]
        UploadThing["UploadThing"]
        EmailService["Email System"]
    end

    subgraph DB["Database Layer"]
        direction TB
        Postgres[(PostgreSQL)]
        Redis[(Redis Cache)]
    end

    %% Client to API Connections
    Auth --> AuthAPI
    Admin --> AuthAPI
    Seller --> AuthAPI
    User --> AuthAPI
    Delivery --> AuthAPI
    Cart --> CartAPI
    Product --> ProductAPI
    Referral --> ReferralAPI

    %% API to Services Connections
    AuthAPI --> NextAuth
    PaymentAPI --> Stripe
    PaymentAPI --> MPesa
    UploadAPI --> UploadThing
    AuthAPI --> EmailService
    ProductAPI --> EmailService

    %% Services to Database Connections
    NextAuth --> Postgres
    NextAuth --> Redis
    Stripe --> Postgres
    MPesa --> Postgres
    UploadThing --> Postgres

    %% Click Events
    click Auth "https://github.com/169398/strathmall/tree/main/app/(auth)"
    click AuthAPI "https://github.com/169398/strathmall/blob/main/app/api/auth/[...nextauth]/route.ts"
    click Admin "https://github.com/169398/strathmall/tree/main/app/admin"
    click Seller "https://github.com/169398/strathmall/tree/main/app/seller"
    click User "https://github.com/169398/strathmall/tree/main/app/user"
    click Delivery "https://github.com/169398/strathmall/tree/main/app/delivery"
    click PaymentAPI "https://github.com/169398/strathmall/tree/main/app/api/mpesa"
    click UploadAPI "https://github.com/169398/strathmall/tree/main/app/api/uploadthing"
    click Cart "https://github.com/169398/strathmall/tree/main/app/(root)/cart"
    click Product "https://github.com/169398/strathmall/tree/main/app/(root)/product"
    click Referral "https://github.com/169398/strathmall/tree/main/app/(root)/referrals"
    click EmailService "https://github.com/169398/strathmall/tree/main/emails"
    click Postgres "https://github.com/169398/strathmall/blob/main/db/schema.ts"
    click Redis "https://github.com/169398/strathmall/blob/main/lib/redis.ts"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#9b59b6,stroke:#8e44ad,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    
    class Auth,Admin,Seller,User,Delivery,Cart,Product,Referral frontend
    class AuthAPI,PaymentAPI,UploadAPI,CartAPI,ProductAPI,ReferralAPI api
    class NextAuth,Stripe,MPesa,UploadThing,EmailService service
    class Postgres,Redis database
```
