# braidpay/code-sample-consultation architecture

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

- Interactive diagram: https://gitdiagram.com/braidpay/code-sample-consultation
- Repository: https://github.com/braidpay/code-sample-consultation

## Overview

##### Project type and purpose
- This is a monolithic full-stack web application built with Next.js’s App Router.
- Purpose: a consultation-booking front end with integrated payment processing via BraidPay.
- Key functionality: UI pages for browsing and booking consultations, client-side polling of payment status, serverless API routes for checking payment status and receiving BraidPay webhooks.

##### File structure
- Top-level:
- app/                         ← Next.js App Router
– page.tsx                   ← main booking page (React Server/Client components)
– layout.tsx                 ← global layout
– globals.css                ← global styles
– api/                       ← serverless endpoints
· check-payment-status/route.ts
· webhook/route.ts
- components/ui/                ← Shadcn UI primitives organized by component
- hooks/                        ← custom React Hooks (use-mobile, use-toast)
- lib/utils.ts                  ← shared utilities
- config files: next.config.js/ts, tailwind.config.js/ts, postcss.config.mjs, tsconfig.json
- package.json + lockfile
- public/                       ← static assets

##### README
- Confirms Next.js + Shadcn UI + Tailwind CSS + BraidPay integration.
- Describes serverless webhook and polling for real-time payment updates.
- Deployment target: Vercel (serverless functions).

a. Main components:
- Client (Browser / Mobile)
- Next.js application (deployed on Vercel or similar)
- Frontend (React + Shadcn UI + Tailwind)
- Serverless API routes
· /api/check-payment-status
· /api/webhook
- External service: BraidPay
- (Optional) CDN / Edge network

b. Relationships & interactions:
1. User → Browser → Next.js Frontend (SSR/Client)
2. Frontend → BraidPay Checkout (redirect to hosted payment page)
3. BraidPay → Browser (checkout page) → User completes payment
4. BraidPay → Next.js `/api/webhook` (POST webhook)
5. Frontend polls `/api/check-payment-status` → Next.js reads stored status (in-memory or persistent store)

c. Architectural patterns & principles:
- Monolithic front+back but logically separated layers
- Serverless functions for event-driven webhook handling
- Client polling pattern for real-time updates
- Component-based UI with Shadcn primitives
- CSS utility framework (Tailwind) for styling consistency

d. Key technologies:
- Next.js (App Router, React Server/Client components)
- Shadcn UI (components/ui/)
- Tailwind CSS (tailwind.config.ts)
- Vercel or any serverless platform
- BraidPay API & Webhooks
- TypeScript

##### Elements
- Browser (Client)
- Next.js Frontend (SSR/CSR)
- API Routes (`check-payment-status`, `webhook`)
- BraidPay Service
- Blue for UI components
- Green for serverless/API
- Orange for external services

##### Detailed capture of essential elements
- Storage or in-memory state if payment status is cached (you may note “Redis” or “in-memory”).
- If using Vercel, illustrate “Vercel Edge CDN → Next.js Functions → BraidPay”.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client/UI Layer
    subgraph "Client/UI Layer"
        direction TB
        User["User"]:::external
        Browser["Browser"]:::frontend
        AppRouter["Next.js App Router"]:::infra
        Page["Booking Page"]:::frontend
        Layout["Global Layout"]:::frontend
        GlobalsCSS["Global Styles"]:::frontend
        UIComp["Shadcn UI Library"]:::ui
        HookMobile["use-mobile Hook"]:::ui
        HookToast["use-toast Hook"]:::ui
        UtilsFile["Shared Utils"]:::ui
    end

    %% Server/API Layer
    subgraph "Server/API Layer"
        direction TB
        Vercel["Vercel Edge CDN & Functions"]:::infra
        subgraph "API Routes"
            direction TB
            Check["/api/check-payment-status"]:::api
            Webhook["/api/webhook"]:::api
        end
        EnvVars["Environment Variables\n(WEBHOOK_SECRET, PAYMENT_LINK_ID)"]:::infra
        StateStore["Payment Status Store\n(In-memory/Redis)"]:::infra
    end

    %% External Services
    BraidPay["BraidPay Service"]:::external

    %% Connections
    User --> Browser
    Browser --> AppRouter
    AppRouter --> Page
    AppRouter --> Layout
    AppRouter --> GlobalsCSS
    AppRouter --> UIComp
    AppRouter --> HookMobile
    AppRouter --> HookToast
    AppRouter --> UtilsFile

    Browser -->|"GET /"| Page
    Page -->|"Render UI"| Browser

    Page -->|"Redirect to Checkout"| BraidPay
    BraidPay -->|"Hosted Checkout"| Browser
    BraidPay -->|"POST Webhook"| Webhook

    Browser -->|"Polling GET"| Check
    Check -->|"Read/Write"| StateStore
    Webhook -->|"Update Status"| StateStore
    Check -->|"Return Status"| Browser

    Page --> Vercel
    Check --> Vercel
    Webhook --> Vercel

    %% Click Events
    click AppRouter "https://github.com/braidpay/code-sample-consultation/tree/main/app/"
    click Page "https://github.com/braidpay/code-sample-consultation/blob/main/app/page.tsx"
    click Layout "https://github.com/braidpay/code-sample-consultation/blob/main/app/layout.tsx"
    click GlobalsCSS "https://github.com/braidpay/code-sample-consultation/blob/main/app/globals.css"
    click Check "https://github.com/braidpay/code-sample-consultation/blob/main/app/api/check-payment-status/route.ts"
    click Webhook "https://github.com/braidpay/code-sample-consultation/blob/main/app/api/webhook/route.ts"
    click UIComp "https://github.com/braidpay/code-sample-consultation/tree/main/components/ui/"
    click HookMobile "https://github.com/braidpay/code-sample-consultation/blob/main/hooks/use-mobile.tsx"
    click HookToast "https://github.com/braidpay/code-sample-consultation/blob/main/hooks/use-toast.ts"
    click UtilsFile "https://github.com/braidpay/code-sample-consultation/blob/main/lib/utils.ts"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#2B6CB0,color:#2B6CB0
    classDef api fill:#DBF4FF,stroke:#3182CE,color:#3182CE
    classDef ui fill:#E6FFFA,stroke:#2C7A7B,color:#2C7A7B
    classDef infra fill:#F0FFF4,stroke:#2F855A,color:#2F855A
    classDef external fill:#FFF4E6,stroke:#DD6B20,color:#DD6B20
```
