# bradtraversy/prostore architecture

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

## Overview

##### Main System Components

a) Frontend Layer:
- Client-Side Components (app directory structure)
- Public Routes (root)
- Protected Routes (auth, admin, user)
- Shared Components
- UI Components Library

b) API Layer:
- Next.js API Routes
- Authentication System (NextAuth.js)
- External API Integrations:
- Stripe Payment Gateway
- PayPal Integration
- Uploadthing (File Upload)
- Resend (Email Service)

c) Backend Layer:
- Database (PostgreSQL)
- Prisma ORM
- Business Logic (lib/actions)

##### Component Relationships

a) Client-Server Flow:
- How the frontend components interact with API routes
- Server-side rendering paths
- Client-side navigation patterns

b) Data Flow:
- Database interactions through Prisma
- Authentication flow with NextAuth.js
- Payment processing sequences
- File upload handling

##### Specific Implementation Details

Architectural patterns:

a) Next.js App Router Structure:
- Routes by (auth), (root), admin, and user
- Layout hierarchy
- Server vs client components

b) State Management:
- Server actions flow
- Form handling
- Cart management

##### Key Subsystems to Highlight

a) E-commerce Features:
- Product management
- Cart system
- Order processing
- Payment integration
- Review system

b) Admin Dashboard:
- Analytics and charts
- User management
- Product management
- Order management

c) User Features:
- Authentication
- Profile management
- Order history
- Shopping cart

##### Technical Stack Indicators

Technology badges for:
- Next.js 14
- TypeScript
- PostgreSQL
- Prisma
- Stripe/PayPal
- TailwindCSS

##### Security Layer

Highlight:
- Authentication boundaries
- Protected routes
- API security
- Payment data handling

Remember to emphasize:
- The app router architecture
- Server component usage
- API route organization
- Database schema relationships
- External service integrations
- Authentication flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FC[Frontend Components]
        UI[UI Library]:::ui
        SC[Shared Components]:::shared
    end

    subgraph "Route Groups"
        RootRoutes["(root) Routes"]:::root
        AuthRoutes["(auth) Routes"]:::auth
        AdminRoutes["Admin Routes"]:::admin
        UserRoutes["User Routes"]:::user
    end

    subgraph "Feature Systems"
        Auth[Authentication System]:::auth
        Products[Product Management]:::products
        Cart[Cart System]:::cart
        Orders[Order Processing]:::orders
        Reviews[Review System]:::reviews
        Upload[File Upload System]:::upload
        Email[Email Service]:::email
    end

    subgraph "Payment Systems"
        Stripe["Stripe Gateway"]
        PayPal["PayPal Integration"]
        PM[Payment Methods]:::payment
    end

    subgraph "Data Layer"
        Actions[Business Logic]:::actions
        Prisma[Prisma ORM]:::db
        DB[(PostgreSQL)]:::db
        Types[Type Definitions]:::types
    end

    FC --> RootRoutes
    FC --> AuthRoutes
    FC --> AdminRoutes
    FC --> UserRoutes
    
    RootRoutes --> Products
    RootRoutes --> Cart
    RootRoutes --> Orders
    RootRoutes --> Reviews
    
    AdminRoutes --> Products
    AdminRoutes --> Orders
    
    Auth --> Actions
    Products --> Actions
    Cart --> Actions
    Orders --> Actions
    Reviews --> Actions
    
    Actions --> Prisma
    Prisma --> DB
    
    PM --> Stripe
    PM --> PayPal
    Orders --> PM
    
    Products --> Upload
    Orders --> Email

    %% Click Events
    click Auth "https://github.com/bradtraversy/prostore/tree/main/app/(auth)"
    click AdminRoutes "https://github.com/bradtraversy/prostore/tree/main/app/admin"
    click UserRoutes "https://github.com/bradtraversy/prostore/tree/main/app/user"
    click Products "https://github.com/bradtraversy/prostore/tree/main/app/(root)/product"
    click Cart "https://github.com/bradtraversy/prostore/tree/main/app/(root)/cart"
    click Orders "https://github.com/bradtraversy/prostore/tree/main/app/(root)/order"
    click PM "https://github.com/bradtraversy/prostore/tree/main/app/(root)/payment-method"
    click Reviews "https://github.com/bradtraversy/prostore/blob/main/app/(root)/product/[slug]/review-form.tsx"
    click UI "https://github.com/bradtraversy/prostore/tree/main/components/ui"
    click Prisma "https://github.com/bradtraversy/prostore/tree/main/prisma"
    click Upload "https://github.com/bradtraversy/prostore/tree/main/app/api/uploadthing"
    click Email "https://github.com/bradtraversy/prostore/tree/main/email"
    click SC "https://github.com/bradtraversy/prostore/tree/main/components/shared"
    click Actions "https://github.com/bradtraversy/prostore/tree/main/lib/actions"
    click Types "https://github.com/bradtraversy/prostore/tree/main/types"

    %% Styling
    classDef root fill:#e1f5fe
    classDef auth fill:#ffcdd2
    classDef admin fill:#c8e6c9
    classDef user fill:#fff9c4
    classDef products fill:#f8bbd0
    classDef cart fill:#b2dfdb
    classDef orders fill:#d1c4e9
    classDef payment fill:#ffe0b2
    classDef reviews fill:#f0f4c3
    classDef upload fill:#b3e5fc
    classDef email fill:#ffccbc
    classDef db fill:#e1bee7
    classDef ui fill:#cfd8dc
    classDef shared fill:#bbdefb
    classDef actions fill:#c5cae9
    classDef types fill:#f5f5f5
```
