# sebastienlaurentt/escape-game architecture

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

- Interactive diagram: https://gitdiagram.com/sebastienlaurentt/escape-game
- Repository: https://github.com/sebastienlaurentt/escape-game

## Overview

##### Main architectural layers/components
- Frontend (User Interface):
- Next.js “app” directory contains all page components arranged by user context: Public (in "(root)") versus authenticated sections (in "(auth)").
- Components are modularized into shared UI components (e.g., Header, Footer, ExperienceCard, BookingForm) and specialized components (account management, booking flows).
- Styling is handled via Tailwind CSS (see tailwind.config.ts & globals.css).

- Backend/API Layer:
- API routes are defined in “app/api” for authentication (using Kinde) and webhooks.
- This layer handles secure interactions (e.g., sign-in via kindeAuth) and processes events from external services (e.g., Stripe payments).

- Business Logic & Services:
- “lib” contains utility functions and service abstractions (like handling Prisma database interactions, Stripe, Supabase, and custom actions).
- The separation of logic into discrete files supports MVC-like separation within the Next.js framework.

- Data Persistence:
- Prisma is used to manage database schemas and migrations. The “prisma” folder houses all migration scripts along with the main Prisma schema.
- This layer represents the core of data storage (reservations, experiences, account data, etc.).

- External Integrations:
- Stripe integration for payments.
- Supabase for additional backend support (authentication or database operations).
- Kinde for sophisticated authentication.
- Email components for booking confirmation notifications.

##### Relationships and Data Flow
- The client (frontend pages and components) interacts with the backend by making API calls to the “app/api” endpoints.
- API routes process requests, utilize business logic (via functions in lib/), and interact with the database layer through Prisma.
- External services like Stripe and Supabase get invoked from these business logic modules, ensuring payments and user management work seamlessly.
- Static assets (CSS, images) in “public” support client-side rendering.

##### Architectural Patterns/Design Principles
- File-Based Routing in Next.js: The structure of the “app” folder shows clear segregation of routes and contexts (authenticated vs. public).
- Separation of Concerns: Note that API routes, business logic, and UI code are separated into distinct folder hierarchies.
- Database Abstraction via Prisma: The migrations and schema management highlight a clear DB abstraction that decouples business logic from direct DB calls.

- Client / Browser
- Next.js Pages (public: home, contact, FAQ, reservation, thank-you)
- Authenticated pages (account management & sub-pages: experiences, insights, opening, prices, reservations)
- Navigation (Header, MobileNav, BurgerMenu)
- API Endpoints
- /api/auth/[kindeAuth] for authentication
- /api/webhooks for external callbacks
- Business Logic / Services (lib)
- Prisma Integration (lib/prisma.ts)
- Payment Processing (lib/stripe.ts)
- External Data/Authentication (lib/supabase.ts)
- Utility functions (lib/utils.ts)
- Database
- Managed by Prisma (schema.prisma and migrations)
- External Services
- Stripe, Supabase, Kinde, Email Services (via components/emails)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend (Next.js UI)
    Browser("Browser/Client"):::frontend

    subgraph "Frontend (Next.js UI)"
        FP1["Public Pages (/app/(root))"]:::frontend
        FP2["Authenticated Pages (/app/(auth))"]:::frontend
        FP3["Shared UI Components"]:::frontend
        NS1["Header"]:::frontend
        NS2["BurgerMenu"]:::frontend
        NS3["MobileNav"]:::frontend
        SC1["Tailwind Config"]:::styling
        SC2["Globals CSS"]:::styling
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        API1["Auth Endpoint (/api/auth/[kindeAuth])"]:::api
        API2["Webhook Endpoint (/api/webhooks)"]:::api
    end

    %% Business Logic & Services
    subgraph "Business Logic & Services (lib)"
        BL1["Prisma Integration"]:::service
        BL2["Payment Processing"]:::service
        BL3["Supabase Integration"]:::service
        BL4["Utility Functions"]:::service
        BL5["Custom Actions"]:::service
    end

    %% Data Persistence Layer
    subgraph "Data Persistence (Prisma)"
        DB1["Prisma Database"]:::database
    end

    %% External Integrations
    subgraph "External Integrations"
        EX1["Stripe"]:::external
        EX2["Supabase"]:::external
        EX3["Kinde"]:::external
        EX4["Email Service"]:::external
    end

    %% Connections
    Browser --> FP1
    Browser --> FP2
    Browser --> FP3
    Browser --> NS1
    Browser --> NS2
    Browser --> NS3
    Browser --> SC1
    Browser --> SC2

    FP1 -->|"API_call"| API1
    FP1 -->|"API_call"| API2
    FP2 -->|"API_call"| API1
    FP2 -->|"API_call"| API2

    API1 -->|"processes"| BL5
    API2 -->|"triggers"| BL4
    API1 -->|"auth_via"| EX3

    BL1 -->|"data_ops"| DB1
    BL2 -->|"process_payment"| EX1
    BL3 -->|"data_auth"| EX2
    BL5 -->|"send_email"| EX4

    %% Click Events for Frontend
    click FP1 "https://github.com/sebastienlaurentt/escape-game/tree/master/app/(root)"
    click FP2 "https://github.com/sebastienlaurentt/escape-game/tree/master/app/(auth)"
    click FP3 "https://github.com/sebastienlaurentt/escape-game/tree/master/components/shared"
    click NS1 "https://github.com/sebastienlaurentt/escape-game/blob/master/components/shared/Header.tsx"
    click NS2 "https://github.com/sebastienlaurentt/escape-game/blob/master/components/shared/BurgerMenu.tsx"
    click NS3 "https://github.com/sebastienlaurentt/escape-game/blob/master/components/shared/Account/MobileNav.tsx"
    click SC1 "https://github.com/sebastienlaurentt/escape-game/blob/master/tailwind.config.ts"
    click SC2 "https://github.com/sebastienlaurentt/escape-game/blob/master/app/globals.css"

    %% Click Events for Backend/API Layer
    click API1 "https://github.com/sebastienlaurentt/escape-game/blob/master/app/api/auth/[kindeAuth]/route.ts"
    click API2 "https://github.com/sebastienlaurentt/escape-game/blob/master/app/api/webhooks/route.ts"

    %% Click Events for Business Logic & Services
    click BL1 "https://github.com/sebastienlaurentt/escape-game/blob/master/lib/prisma.ts"
    click BL2 "https://github.com/sebastienlaurentt/escape-game/blob/master/lib/stripe.ts"
    click BL3 "https://github.com/sebastienlaurentt/escape-game/blob/master/lib/supabase.ts"
    click BL4 "https://github.com/sebastienlaurentt/escape-game/blob/master/lib/utils.ts"
    click BL5 "https://github.com/sebastienlaurentt/escape-game/blob/master/lib/action.ts"

    %% Click Events for Data Persistence
    click DB1 "https://github.com/sebastienlaurentt/escape-game/tree/master/prisma/"

    %% Click Event for External Email Service
    click EX4 "https://github.com/sebastienlaurentt/escape-game/blob/master/components/emails/BookingReceveidEmail.tsx"

    %% Styles
    classDef frontend fill:#FAD7A0,stroke:#333,stroke-width:2px;
    classDef api fill:#D5F5E3,stroke:#333,stroke-width:2px;
    classDef service fill:#D6EAF8,stroke:#333,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef external fill:#FADBD8,stroke:#333,stroke-width:2px;
    classDef styling fill:#FDEDEC,stroke:#333,stroke-width:2px;
```
