# bhanu1776/casecanvas architecture

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

- Interactive diagram: https://gitdiagram.com/bhanu1776/casecanvas
- Repository: https://github.com/bhanu1776/casecanvas

## Overview

##### Main Components

Frontend Layer:
- Next.js Application (Client-Side)
- Pages/Routes structure (/dashboard, /configure, /thank-you)
- UI Components (shadcn, HeadlessUI)
- Client-side state management
- Analytics integration

API Layer:
- Next.js API Routes
- Authentication endpoints
- Protected routes
- Public routes
- Webhook handlers
- File upload handling

Backend Services:
- Authentication Service (Kinde Auth)
- Database Layer (PostgreSQL via NeonDB)
- File Storage (Uploadthing)
- Email Service (Resend)
- Payment Processing (Stripe)
- Analytics (Google Analytics)

**┌─────────────────────────────────────────────────────────┐**
- Client Layer (Browser)                  │
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐      │
- Public    │ │  Protected  │ │Configuration │      │
- Pages    │ │    Pages    │ │    Pages    │      │
- ┘ └─────────────┘ └─────────────┘      │
- ┘

**┌───────────────────────▼───────────────▼────────────────┐**
- API Layer                            │
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐      │
- Auth API   │ │ Protected   │ │  Public     │      │
- Routes     │ │   Routes    │ │   Routes    │      │
- ┘ └─────────────┘ └─────────────┘      │
- ┘

**┌───────▼───────────────▼───────────────▼────────────────┐**
- External Services                        │
- ┌──────────┐ ┌─────────┐ ┌────────┐ ┌──────────────┐   │
- Kinde Auth│ │ NeonDB  │ │Stripe  │ │ Uploadthing  │   │
- ┘ └─────────┘ └────────┘ └──────────────┘   │
- ┘

##### Important Flows to Highlight

Authentication Flow:
- Path from client → Kinde Auth → API → Database
- Protected routes and public routes

Data Flow:
- File upload path through Uploadthing
- Payment processing through Stripe
- Email notifications via Resend

##### Technical Details

- Prisma ORM layer between API and Database
- PWA capabilities
- React Query for data fetching
- TailwindCSS for styling
- Zod for validation

##### Infrastructure Notes

- Serverless deployment
- CDN integration
- Static vs dynamic routes
- Development tools integration

- How authentication flows through the system
- Where and how data is stored
- How different services interact
- Security boundaries and protected resources
- The role of each external service

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Layer (Browser)"]
        direction TB
        PublicPages["Public Pages"]:::frontend
        ProtectedPages["Protected Pages"]:::frontend
        ConfigPages["Configuration Pages"]:::frontend
        
        Navigation["Navigation Components"]:::frontend
        UIComponents["UI Components"]:::frontend
        Analytics["Analytics Integration"]:::frontend
    end

    subgraph APILayer["API Layer"]
        direction TB
        AuthAPI["Authentication API"]:::api
        ProtectedRoutes["Protected Routes"]:::api
        PublicRoutes["Public Routes"]:::api
        WebhookHandlers["Webhook Handlers"]:::api
        FileUploadAPI["File Upload API"]:::api
    end

    subgraph Services["External Services"]
        direction TB
        KindeAuth["Kinde Auth"]:::external
        Database[(PostgreSQL/NeonDB)]:::database
        Stripe["Stripe Payment"]:::external
        Uploadthing["Uploadthing Storage"]:::external
        EmailService["Resend Email"]:::external
    end

    subgraph Components["Core Components"]
        direction TB
        DBLayer["Database Layer"]:::core
        PaymentProcessor["Payment Processing"]:::core
        FileStorage["File Storage Config"]:::core
        EmailTemplates["Email Templates"]:::core
        FormValidation["Form Validation"]:::core
        DBSchema["Database Schema"]:::core
    end

    %% Client Layer Relationships
    PublicPages --> AuthAPI
    ProtectedPages --> ProtectedRoutes
    ConfigPages --> FileUploadAPI
    ConfigPages --> PaymentProcessor

    %% API Layer Relationships
    AuthAPI --> KindeAuth
    ProtectedRoutes --> DBLayer
    PublicRoutes --> DBLayer
    WebhookHandlers --> Stripe
    FileUploadAPI --> Uploadthing

    %% Service Layer Relationships
    DBLayer --> Database
    PaymentProcessor --> Stripe
    FileStorage --> Uploadthing
    EmailTemplates --> EmailService

    %% Click Events
    click AuthAPI "https://github.com/Bhanu1776/CaseCanvas/blob/master/src/app/api/auth/[...kindeAuth]/route.ts"
    click ProtectedRoutes "https://github.com/Bhanu1776/CaseCanvas/blob/master/src/app/api/protected/route.ts"
    click PublicRoutes "https://github.com/Bhanu1776/CaseCanvas/blob/master/src/app/api/public/route.ts"
    click FileUploadAPI "https://github.com/Bhanu1776/CaseCanvas/tree/master/src/app/api/uploadthing/"
    click WebhookHandlers "https://github.com/Bhanu1776/CaseCanvas/blob/master/src/app/api/webhooks/route.ts"
    click DBLayer "https://github.com/Bhanu1776/CaseCanvas/blob/master/src/db/index.ts"
    click PaymentProcessor "https://github.com/Bhanu1776/CaseCanvas/blob/master/src/lib/stripe.ts"
    click FileStorage "https://github.com/Bhanu1776/CaseCanvas/blob/master/src/lib/uploadthing.ts"
    click EmailTemplates "https://github.com/Bhanu1776/CaseCanvas/blob/master/src/components/emails/OrderReceivedEmail.tsx"
    click Analytics "https://github.com/Bhanu1776/CaseCanvas/blob/master/src/components/Analytics/GoogleAnalytics.jsx"
    click UIComponents "https://github.com/Bhanu1776/CaseCanvas/tree/master/src/components/ui/"
    click ProtectedPages "https://github.com/Bhanu1776/CaseCanvas/tree/master/src/app/dashboard/"
    click ConfigPages "https://github.com/Bhanu1776/CaseCanvas/tree/master/src/app/configure/"
    click Navigation "https://github.com/Bhanu1776/CaseCanvas/tree/master/src/components/Navigation/"
    click FormValidation "https://github.com/Bhanu1776/CaseCanvas/blob/master/src/validators/option-validator.ts"
    click DBSchema "https://github.com/Bhanu1776/CaseCanvas/blob/master/prisma/schema.prisma"

    %% Styling
    classDef frontend fill:#2563eb,color:#fff
    classDef api fill:#22c55e,color:#fff
    classDef external fill:#eab308,color:#000
    classDef database fill:#9333ea,color:#fff
    classDef core fill:#64748b,color:#fff

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        API["API Component"]:::api
        External["External Service"]:::external
        DB["Database"]:::database
        Core["Core Component"]:::core
    end
```
