# ayushrai7/parkmate architecture

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

- Interactive diagram: https://gitdiagram.com/ayushrai7/parkmate
- Repository: https://github.com/ayushrai7/parkmate

## Overview

1. **Overall shape**
   - ParkMate is a **single Next.js 14 monolith**: the same app serves the UI, API routes, authentication, booking logic, invoice handling, and owner/admin workflows.
   - The main architectural boundary is between the **browser-facing App Router pages/components** and the **server-side route handlers** under `src/app/api`.

2. **Client-facing application layers**
   - The app uses the Next.js App Router with page entrypoints for the main experiences: **homepage**, **login**, **booking**, **invoice**, **owner dashboard**, and **auth callback**.
   - Most screens are composed from feature-specific React components in `src/components/*`, with a shared UI kit in `src/components/ui` built around Shadcn-style primitives.

3. **Authentication and session management**
   - Authentication is centralized in **NextAuth.js** (`src/app/api/auth/[...nextauth]/route.ts`) with **Google OAuth** and **Credentials** sign-in flows.
   - Sessions are JWT-based, and there is app-level protection via `middleware.ts`, which likely gates authenticated routes and role-specific access.
   - Supporting auth utilities live in `src/lib/auth.ts` and `src/lib/auth-utils.ts`, with NextAuth type extensions in `src/types/next-auth.d.ts`.

4. **Role-based architecture**
   - The system explicitly separates **Users** and **Venue Owners**.
   - There are dedicated server endpoints for role assignment and onboarding, including `api/auth/set-role`, `api/auth/signup/user`, and `api/owner`.
   - The UI mirrors this split with distinct flows and pages for login, booking, and owner management, so role is a first-class part of the navigation and authorization model.

5. **Core booking flow**
   - Booking is handled through `src/app/api/booking` and `src/app/api/booking/[bookingId]`, suggesting both creation and booking-level retrieval/update operations.
   - The user-facing booking page uses dedicated components for **searching venues**, **viewing venue cards**, **fare summary**, and **booking form submission**.
   - The backend likely coordinates slot selection, persistence, and status transitions such as **Pending → Confirmed → Expired**.

6. **Payments and confirmation**
   - Payment processing is separated into `src/app/api/payment`, with **Stripe** as the external payment gateway.
   - A dedicated webhook endpoint at `src/app/api/webhook/stripe` is used to confirm payment events server-side, which is important for reliable booking confirmation.
   - This webhook boundary is the key integration point where external payment state is translated into internal booking state.

7. **Invoice generation and storage**
   - After successful payment, the app exposes invoice functionality through `src/app/api/invoice/upload`, and a dedicated invoice page in the UI.
   - The README indicates invoices are generated as **PDFs** and stored in **AWS S3**, with download access controlled through **pre-signed URLs**.
   - The invoice UI is split into header, details, footer, layout, and download controls, indicating a document-centric rendering flow rather than a generic page.

8. **Owner operations and venue management**
   - Owners have a separate dashboard under `src/app/owner` and APIs such as `src/app/api/owner` and `src/app/api/venues`.
   - The owner interface includes venue creation, search/filtering, and booking tables, which suggests it is the administrative control plane for supply-side management.
   - This is the main place where venue inventory and booking oversight are exposed to non-end-user operators.

9. **Data layer and persistence**
   - The app uses **Prisma ORM** with a PostgreSQL database, likely hosted on **Supabase** as described in the README.
   - The `prisma/migrations` history shows the schema evolved around NextAuth integration and a later merge of user/owner tables, reinforcing that identity and role data are tightly coupled in the DB model.
   - `src/lib/prisma.ts` is the shared database client boundary used by route handlers and server-side logic.

10. **Infrastructure and deployment boundaries**
   - The repository is containerized with a **Dockerfile**, and GitHub Actions (`.github/workflows/deploy.yml`) handles CI/CD deployment.
   - The README indicates deployment to **AWS EC2**, with **AWS S3** as an external storage dependency and **UptimeRobot** for availability monitoring.
   - In architectural terms, the app is deployed as one web service container backed by managed external services: Postgres, Stripe, S3, and OAuth providers.

11. **Shared app utilities**
   - `src/lib/s3.ts` encapsulates S3 integration, while `src/lib/utils.ts` and `src/hooks/*` support reusable client behavior.
   - Global providers and UI helpers (`src/components/Providers.tsx`, toast hooks, mobile hooks) indicate the app is designed around a shared client runtime with server-rendered pages plus interactive client components.

12. **Diagramming takeaway**
   - A good architecture diagram should show:
     - **Browser/UI** → Next.js App Router pages/components
     - **Middleware/Auth** guarding role-based access
     - **Next.js API routes** for booking, payment, invoice, venues, and owner operations
     - **NextAuth + Google/Credentials** for identity
     - **Prisma → PostgreSQL** for persistence
     - **Stripe webhooks** as an external event ingress
     - **S3** for invoice PDFs
     - **Docker/GitHub Actions/EC2** as the deployment path

Main entry points: [`src/app/layout.tsx`](https://github.com/ayushrai7/parkmate/blob/main/src/app/layout.tsx) (App Router), [`src/lib/prisma.ts`](https://github.com/ayushrai7/parkmate/blob/main/src/lib/prisma.ts) (Prisma DB), [`src/app/api/auth/[...nextauth]/route.ts`](https://github.com/ayushrai7/parkmate/blob/main/src/app/api/auth/[...nextauth]/route.ts) (NextAuth), [`src/app/api/booking/route.ts`](https://github.com/ayushrai7/parkmate/blob/main/src/app/api/booking/route.ts) (Booking API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client App"]
  node_app_root["App Router<br/>nextjs shell<br/>[layout.tsx]"]
  node_home_page["Homepage<br/>landing page<br/>[page.tsx]"]
  node_login_page["Login<br/>auth page<br/>[page.tsx]"]
  node_booking_page["Booking<br/>[page.tsx]"]
  node_invoice_page["Invoice<br/>[page.tsx]"]
  node_owner_page["Owner Dashboard<br/>admin page<br/>[page.tsx]"]
  node_ui_kit["UI Kit<br/>shared components<br/>[button.tsx]"]
  node_auth_ui["Auth UI<br/>feature components<br/>[Form.tsx]"]
  node_booking_ui["Booking UI<br/>feature components<br/>[Form.tsx]"]
  node_invoice_ui["Invoice UI<br/>document components<br/>[InvoiceLayout.tsx]"]
  node_owner_ui["Owner UI<br/>admin components<br/>[BookingsTable.tsx]"]
end

subgraph group_server["Server Core"]
  node_middleware{{"Middleware<br/>route guard<br/>[middleware.ts]"}}
  node_nextauth{{"NextAuth<br/>auth service<br/>[route.ts]"}}
  node_auth_routes{{"Auth Routes<br/>auth endpoints<br/>[route.ts]"}}
  node_booking_api{{"Booking API<br/>booking endpoints<br/>[route.ts]"}}
  node_payment_api{{"Payment API<br/>payment endpoint<br/>[route.ts]"}}
  node_webhook{{"Stripe Webhook<br/>event ingress<br/>[route.ts]"}}
  node_invoice_api{{"Invoice API<br/>document endpoint<br/>[route.ts]"}}
  node_owner_api{{"Owner API<br/>owner endpoint<br/>[route.ts]"}}
  node_venues_api{{"Venues API<br/>inventory endpoint<br/>[route.ts]"}}
  node_db[("Prisma DB<br/>persistence layer<br/>[prisma.ts]")]
end

subgraph group_infra["Delivery"]
  node_s3[("S3 Storage<br/>object storage<br/>[s3.ts]")]
  node_deployment["CI/CD<br/>docker + actions"]
end

node_app_root -->|"routes to"| node_home_page
node_app_root -->|"routes to"| node_login_page
node_app_root -->|"routes to"| node_booking_page
node_app_root -->|"routes to"| node_invoice_page
node_app_root -->|"routes to"| node_owner_page
node_home_page -->|"composes"| node_ui_kit
node_login_page -->|"composes"| node_auth_ui
node_booking_page -->|"composes"| node_booking_ui
node_invoice_page -->|"composes"| node_invoice_ui
node_owner_page -->|"composes"| node_owner_ui
node_middleware -->|"protects"| node_nextauth
node_auth_ui -->|"signs in via"| node_nextauth
node_nextauth -->|"reads/writes"| node_db
node_auth_routes -->|"extends"| node_nextauth
node_booking_api -->|"persists"| node_db
node_booking_api -->|"hands off to"| node_payment_api
node_payment_api -->|"confirms via"| node_webhook
node_webhook -->|"updates"| node_db
node_invoice_api -->|"stores"| node_s3
node_invoice_api -->|"records"| node_db
node_owner_api -->|"manages"| node_db
node_venues_api -->|"queries"| node_db
node_deployment -->|"delivers"| node_app_root

click node_app_root "https://github.com/ayushrai7/parkmate/blob/main/src/app/layout.tsx"
click node_home_page "https://github.com/ayushrai7/parkmate/blob/main/src/app/homepage/page.tsx"
click node_login_page "https://github.com/ayushrai7/parkmate/blob/main/src/app/login/page.tsx"
click node_booking_page "https://github.com/ayushrai7/parkmate/blob/main/src/app/booking/page.tsx"
click node_invoice_page "https://github.com/ayushrai7/parkmate/blob/main/src/app/invoice/page.tsx"
click node_owner_page "https://github.com/ayushrai7/parkmate/blob/main/src/app/owner/page.tsx"
click node_ui_kit "https://github.com/ayushrai7/parkmate/blob/main/src/components/ui/button.tsx"
click node_auth_ui "https://github.com/ayushrai7/parkmate/blob/main/src/components/login/Form.tsx"
click node_booking_ui "https://github.com/ayushrai7/parkmate/blob/main/src/components/booking/Form.tsx"
click node_invoice_ui "https://github.com/ayushrai7/parkmate/blob/main/src/components/invoice/InvoiceLayout.tsx"
click node_owner_ui "https://github.com/ayushrai7/parkmate/blob/main/src/components/owner/BookingsTable.tsx"
click node_middleware "https://github.com/ayushrai7/parkmate/blob/main/middleware.ts"
click node_nextauth "https://github.com/ayushrai7/parkmate/blob/main/src/app/api/auth/[...nextauth]/route.ts"
click node_auth_routes "https://github.com/ayushrai7/parkmate/blob/main/src/app/api/auth/set-role/route.ts"
click node_booking_api "https://github.com/ayushrai7/parkmate/blob/main/src/app/api/booking/route.ts"
click node_payment_api "https://github.com/ayushrai7/parkmate/blob/main/src/app/api/payment/route.ts"
click node_webhook "https://github.com/ayushrai7/parkmate/blob/main/src/app/api/webhook/stripe/route.ts"
click node_invoice_api "https://github.com/ayushrai7/parkmate/blob/main/src/app/api/invoice/upload/route.ts"
click node_owner_api "https://github.com/ayushrai7/parkmate/blob/main/src/app/api/owner/route.ts"
click node_venues_api "https://github.com/ayushrai7/parkmate/blob/main/src/app/api/venues/route.ts"
click node_db "https://github.com/ayushrai7/parkmate/blob/main/src/lib/prisma.ts"
click node_s3 "https://github.com/ayushrai7/parkmate/blob/main/src/lib/s3.ts"
click node_deployment "https://github.com/ayushrai7/parkmate/tree/main/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_root,node_home_page,node_login_page,node_booking_page,node_invoice_page,node_owner_page,node_ui_kit,node_auth_ui,node_booking_ui,node_invoice_ui,node_owner_ui toneBlue
class node_middleware,node_nextauth,node_auth_routes,node_booking_api,node_payment_api,node_webhook,node_invoice_api,node_owner_api,node_venues_api,node_db toneAmber
class node_s3,node_deployment toneMint
```

## Components

### Client App

Browser-facing App Router pages and shared React components.

- [App Router](https://github.com/ayushrai7/parkmate/blob/main/src/app/layout.tsx): nextjs shell · Top-level Next.js 14 application shell and route composition. · `src/app/layout.tsx`
- [Homepage](https://github.com/ayushrai7/parkmate/blob/main/src/app/homepage/page.tsx): landing page · Public entry experience and marketing content. · `src/app/homepage/page.tsx`
- [Login](https://github.com/ayushrai7/parkmate/blob/main/src/app/login/page.tsx): auth page · Authentication entrypoint with role and sign-in switching. · `src/app/login/page.tsx`
- [Booking](https://github.com/ayushrai7/parkmate/blob/main/src/app/booking/page.tsx): booking page · User booking flow for venue search, selection, and submission. · `src/app/booking/page.tsx`
- [Invoice](https://github.com/ayushrai7/parkmate/blob/main/src/app/invoice/page.tsx): invoice page · Invoice viewing and download experience. · `src/app/invoice/page.tsx`
- [Owner Dashboard](https://github.com/ayushrai7/parkmate/blob/main/src/app/owner/page.tsx): admin page · Venue-owner control plane for inventory and bookings. · `src/app/owner/page.tsx`
- [UI Kit](https://github.com/ayushrai7/parkmate/blob/main/src/components/ui/button.tsx): shared components · Reusable Shadcn-style primitives shared across screens. · `src/components/ui/button.tsx`
- [Auth UI](https://github.com/ayushrai7/parkmate/blob/main/src/components/login/Form.tsx): feature components · Login form, Google sign-in, and role selection UI. · `src/components/login/Form.tsx`
- [Booking UI](https://github.com/ayushrai7/parkmate/blob/main/src/components/booking/Form.tsx): feature components · Venue search, cards, fare summary, and booking form. · `src/components/booking/Form.tsx`
- [Invoice UI](https://github.com/ayushrai7/parkmate/blob/main/src/components/invoice/InvoiceLayout.tsx): document components · Invoice layout, metadata, and download controls. · `src/components/invoice/InvoiceLayout.tsx`
- [Owner UI](https://github.com/ayushrai7/parkmate/blob/main/src/components/owner/BookingsTable.tsx): admin components · Owner dashboard controls for venues and booking tables. · `src/components/owner/BookingsTable.tsx`

### Server Core

Next.js route handlers, auth, persistence, and integrations.

- [Middleware](https://github.com/ayushrai7/parkmate/blob/main/middleware.ts): route guard · App-level protection for authenticated and role-based access. · `middleware.ts`
- [NextAuth](https://github.com/ayushrai7/parkmate/blob/main/src/app/api/auth/[...nextauth]/route.ts): auth service · Central authentication route with Google and credentials flows. · `src/app/api/auth/[...nextauth]/route.ts`
- [Auth Routes](https://github.com/ayushrai7/parkmate/blob/main/src/app/api/auth/set-role/route.ts): auth endpoints · Session refresh, role setting, and user signup endpoints. · `src/app/api/auth/set-role/route.ts`
- [Booking API](https://github.com/ayushrai7/parkmate/blob/main/src/app/api/booking/route.ts): booking endpoints · Create and manage bookings by booking ID. · `src/app/api/booking/route.ts`
- [Payment API](https://github.com/ayushrai7/parkmate/blob/main/src/app/api/payment/route.ts): payment endpoint · Stripe-backed payment initiation and coordination. · `src/app/api/payment/route.ts`
- [Stripe Webhook](https://github.com/ayushrai7/parkmate/blob/main/src/app/api/webhook/stripe/route.ts): event ingress · External payment confirmation events translated into booking state. · `src/app/api/webhook/stripe/route.ts`
- [Invoice API](https://github.com/ayushrai7/parkmate/blob/main/src/app/api/invoice/upload/route.ts): document endpoint · Invoice generation and upload workflow. · `src/app/api/invoice/upload/route.ts`
- [Owner API](https://github.com/ayushrai7/parkmate/blob/main/src/app/api/owner/route.ts): owner endpoint · Owner onboarding and supply-side management endpoints. · `src/app/api/owner/route.ts`
- [Venues API](https://github.com/ayushrai7/parkmate/blob/main/src/app/api/venues/route.ts): inventory endpoint · Venue listing and management access for owner workflows. · `src/app/api/venues/route.ts`
- [Prisma DB](https://github.com/ayushrai7/parkmate/blob/main/src/lib/prisma.ts): persistence layer · Shared Prisma client and PostgreSQL-backed domain storage. · `src/lib/prisma.ts`

### Delivery

Deployment and external services.

- [S3 Storage](https://github.com/ayushrai7/parkmate/blob/main/src/lib/s3.ts): object storage · Invoice PDF storage and pre-signed download delivery. · `src/lib/s3.ts`
- [CI/CD](https://github.com/ayushrai7/parkmate/tree/main/Dockerfile): docker + actions · Container build and GitHub Actions deployment pipeline. · `Dockerfile`

## Connections

- App Router → Homepage: routes to · App Router serves the public landing experience.
- App Router → Login: routes to · App Router serves the login flow.
- App Router → Booking: routes to · App Router serves the booking flow.
- App Router → Invoice: routes to · App Router serves invoice pages.
- App Router → Owner Dashboard: routes to · App Router serves the owner dashboard.
- Homepage → UI Kit: composes · Landing screen uses shared UI primitives.
- Login → Auth UI: composes · Login screen uses authentication-specific components.
- Booking → Booking UI: composes · Booking screen is built from booking feature components.
- Invoice → Invoice UI: composes · Invoice screen is built from document components.
- Owner Dashboard → Owner UI: composes · Owner dashboard uses admin components.
- Middleware → NextAuth: protects · Middleware relies on auth state and route/session checks.
- Auth UI → NextAuth: signs in via · Client auth flows initiate NextAuth sign-in.
- NextAuth → Prisma DB: reads/writes · Auth sessions and user records are persisted through Prisma.
- Auth Routes → NextAuth: extends · Role assignment and session refresh support the main auth system.
- Booking API → Prisma DB: persists · Bookings are created and updated in the database.
- Booking API → Payment API: hands off to · Booking flow leads into payment processing.
- Payment API → Stripe Webhook: confirms via · Webhook receives Stripe payment events for final confirmation.
- Stripe Webhook → Prisma DB: updates · Payment events translate into booking state changes.
- Invoice API → S3 Storage: stores · Generated invoice PDFs are uploaded to object storage.
- Invoice API → Prisma DB: records · Invoice metadata and linkage are persisted.
- Owner API → Prisma DB: manages · Owner onboarding and management operate on shared domain data.
- Venues API → Prisma DB: queries · Venue inventory and search data come from persistence.
- CI/CD → App Router: delivers · Containerized Next.js app is deployed through CI/CD.
