# saurav2701/finder-a-dating-app architecture

> Architecture diagram of the GitHub repository saurav2701/finder-a-dating-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saurav2701/finder-a-dating-app
- Repository: https://github.com/saurav2701/finder-a-dating-app

## Overview

#### Purpose and entry points
This is a monorepo for a swipe-based matching application with authenticated profiles, photo uploads, mutual matches, and real-time chat. The primary user-facing runtime is a Next.js app rooted at `apps/web/app/page.tsx`; its shared shell and request protection are in `apps/web/app/layout.tsx` and `apps/web/middleware.ts`. A separate Node socket service provides live chat transport through `apps/socket-server/index.js`.

#### Web application and route structure
Next.js App Router pages define the main product surfaces: authentication (`apps/web/app/login/page.tsx`, `apps/web/app/signup/page.tsx`), profile management (`apps/web/app/profile/page.tsx`), matches (`apps/web/app/matches/page.tsx`), and a match-specific chat room (`apps/web/app/chat/[matchId]/page.tsx`). Shared interaction/UI pieces are concentrated in `apps/web/components/Navbar.tsx`, `apps/web/components/card.tsx`, and `apps/web/components/photoUpload.tsx`.

#### Authentication and identity boundary
NextAuth is exposed through `apps/web/app/api/auth/[...nextauth]/route.ts`, with auth configuration and server helpers in `apps/web/app/auth.config.ts` and `apps/web/auth.ts`. Signup is a separate OTP workflow: clients request and validate an OTP through `apps/web/app/api/signup/send-otp/route.ts` and `apps/web/app/api/signup/verify-otp/route.ts`. Session-aware routing is an important boundary: page/API handlers should rely on the auth layer rather than trust client-supplied user identity.

#### Matching and profile flow
Profile reads/updates are handled by `apps/web/app/api/profile/route.ts`. The discovery/swipe flow is split between candidate retrieval (`apps/web/app/api/showUsers/route.ts`) and mutation (`apps/web/app/api/swipe/route.ts`). The likely control flow is: authenticated user retrieves eligible profiles, submits a directional swipe, then downstream persistence determines whether a reciprocal swipe produces a match visible in the matches and chat routes.

#### Media upload pipeline
Photo upload is intentionally two-stage: `apps/web/app/api/photos/presign/route.ts` issues upload authorization, while `apps/web/app/api/photos/confirm/route.ts` confirms the uploaded asset for application persistence. Supabase client/server adapters at `apps/web/lib/supabase/client.ts` and `apps/web/lib/supabase/server.ts` mark object storage as an external boundary. The browser should upload directly using a presigned flow; the application should only persist confirmed, authorized photo references.

#### Realtime chat subsystem
Chat rendering is scoped by match ID in `apps/web/app/chat/[matchId]/ChatRoom.tsx`. Client socket lifecycle management is centralized in `apps/web/hooks/useSocket.ts`, and the independent Socket.IO-style service entry point is `apps/socket-server/index.js`. This separates durable application data/API handling in Next.js from transient connection, room, and message-event delivery in the socket process. Authorization must ensure a connected user belongs to the requested match room.

#### Persistence and infrastructure
Database ownership is centralized in the reusable DB package: `packages/db/prisma/schema.prisma`, `packages/db/index.js`, and its migration history under `packages/db/prisma/migrations`. The migrations include NextAuth tables and user fields, indicating shared persistence for identity and product entities. Redis is integrated from the web app via `apps/web/lib/redis.ts`, likely for ephemeral OTP, session-adjacent, cache, or realtime-support state. Material runtimes are therefore Next.js/TypeScript, a separate Node socket server, Prisma-managed database access, Redis, and Supabase-backed media services.

Main entry points: [`apps/web/auth.ts`](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/auth.ts) (Auth and session layer), [`packages/db/index.js`](https://github.com/saurav2701/finder-a-dating-app/blob/main/packages/db/index.js) (Shared database access), [`apps/web/app/api/photos/confirm/route.ts`](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/api/photos/confirm/route.ts) (Photo authorization), [`apps/web/app/api/profile/route.ts`](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/api/profile/route.ts) (Profile API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Next.js web app"]
  node_home["Swipe discovery<br/>Next.js page<br/>[page.tsx]"]
  node_product_pages["Account and match pages<br/>Next.js pages<br/>[page.tsx]"]
  node_app_shell["App shell<br/>Next.js layout<br/>[layout.tsx]"]
  node_middleware["Request protection<br/>Next.js middleware<br/>[middleware.ts]"]
  node_ui_components["Shared UI<br/>React components<br/>[photoUpload.tsx]"]
  node_auth{{"Auth and session layer<br/>NextAuth<br/>[auth.ts]"}}
  node_nextauth_route["NextAuth endpoint<br/>API route<br/>[route.ts]"]
  node_otp_routes["Signup OTP flow<br/>API routes<br/>[route.ts]"]
  node_profile_api["Profile API<br/>API route<br/>[route.ts]"]
  node_discovery_api["Discovery and swipe APIs<br/>API routes<br/>[route.ts]"]
  node_photo_pipeline["Photo authorization<br/>API routes<br/>[route.ts]"]
end

subgraph group_realtime["Realtime chat"]
  node_chat_room["Chat room client<br/>React component<br/>[ChatRoom.tsx]"]
  node_socket_hook["Socket client lifecycle<br/>React hook<br/>[useSocket.ts]"]
  node_socket_server{{"Chat transport<br/>Node socket service<br/>[index.js]"}}
end

subgraph group_data["Data services"]
  node_db_package[("Shared database access<br/>Prisma package<br/>[index.js]")]
  node_redis[("Redis<br/>Ephemeral state<br/>[redis.ts]")]
  node_supabase[("Supabase storage<br/>External media service<br/>[server.ts]")]
end

node_app_shell -->|"hosts"| node_home
node_middleware -->|"checks session"| node_auth
node_product_pages -->|"uses identity"| node_auth
node_nextauth_route -->|"exposes"| node_auth
node_auth -->|"identity records"| node_db_package
node_otp_routes -->|"stores OTP state"| node_redis
node_otp_routes -->|"creates verified user"| node_db_package
node_home -->|"fetches and submits swipes"| node_discovery_api
node_product_pages -->|"manages profile"| node_profile_api
node_discovery_api -->|"authorizes user"| node_auth
node_discovery_api -->|"candidates, swipes, matches"| node_db_package
node_profile_api -->|"authorizes user"| node_auth
node_profile_api -->|"profile data"| node_db_package
node_ui_components -->|"requests upload flow"| node_photo_pipeline
node_photo_pipeline -->|"authorizes owner"| node_auth
node_photo_pipeline -->|"presigns and confirms assets"| node_supabase
node_photo_pipeline -->|"persists photo reference"| node_db_package
node_chat_room -->|"connects through"| node_socket_hook
node_socket_hook -->|"room events"| node_socket_server
node_socket_server -->|"validates match membership"| node_db_package

click node_home "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/page.tsx"
click node_product_pages "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/matches/page.tsx"
click node_app_shell "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/layout.tsx"
click node_middleware "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/middleware.ts"
click node_ui_components "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/components/photoUpload.tsx"
click node_auth "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/auth.ts"
click node_nextauth_route "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/api/auth/%5B...nextauth%5D/route.ts"
click node_otp_routes "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/api/signup/verify-otp/route.ts"
click node_profile_api "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/api/profile/route.ts"
click node_discovery_api "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/api/swipe/route.ts"
click node_photo_pipeline "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/api/photos/confirm/route.ts"
click node_chat_room "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/chat/%5BmatchId%5D/ChatRoom.tsx"
click node_socket_hook "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/hooks/useSocket.ts"
click node_socket_server "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/socket-server/index.js"
click node_db_package "https://github.com/saurav2701/finder-a-dating-app/blob/main/packages/db/index.js"
click node_redis "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/lib/redis.ts"
click node_supabase "https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/lib/supabase/server.ts"

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_home,node_product_pages,node_app_shell,node_middleware,node_ui_components,node_auth,node_nextauth_route,node_otp_routes,node_profile_api,node_discovery_api,node_photo_pipeline toneBlue
class node_chat_room,node_socket_hook,node_socket_server toneAmber
class node_db_package,node_redis,node_supabase toneMint
```

## Components

### Next.js web app

User interface, protected routes, and application APIs.

- [Swipe discovery](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/page.tsx): Next.js page · Primary product entry point. · `apps/web/app/page.tsx`
- [Account and match pages](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/matches/page.tsx): Next.js pages · Login, signup, profile, matches, and chat routes. · `apps/web/app/matches/page.tsx`
- [App shell](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/layout.tsx): Next.js layout · `apps/web/app/layout.tsx`
- [Request protection](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/middleware.ts): Next.js middleware · Enforces session-aware routing. · `apps/web/middleware.ts`
- [Shared UI](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/components/photoUpload.tsx): React components · Navigation, cards, and photo upload interaction. · `apps/web/components/photoUpload.tsx`
- [Auth and session layer](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/auth.ts): NextAuth · Server-side identity boundary for pages and APIs. · `apps/web/auth.ts`
- [NextAuth endpoint](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/api/auth/%5B...nextauth%5D/route.ts): API route · `apps/web/app/api/auth/[...nextauth]/route.ts`
- [Signup OTP flow](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/api/signup/verify-otp/route.ts): API routes · Issues and validates signup verification codes. · `apps/web/app/api/signup/verify-otp/route.ts`
- [Profile API](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/api/profile/route.ts): API route · Reads and updates authenticated profiles. · `apps/web/app/api/profile/route.ts`
- [Discovery and swipe APIs](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/api/swipe/route.ts): API routes · Returns candidates and records directional swipes. · `apps/web/app/api/swipe/route.ts`
- [Photo authorization](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/api/photos/confirm/route.ts): API routes · Presigns uploads then confirms authorized assets. · `apps/web/app/api/photos/confirm/route.ts`

### Realtime chat

Independent process for transient chat delivery.

- [Chat room client](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/app/chat/%5BmatchId%5D/ChatRoom.tsx): React component · Renders the room scoped to a match ID. · `apps/web/app/chat/[matchId]/ChatRoom.tsx`
- [Socket client lifecycle](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/hooks/useSocket.ts): React hook · `apps/web/hooks/useSocket.ts`
- [Chat transport](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/socket-server/index.js): Node socket service · Manages connections, rooms, and message events. · `apps/socket-server/index.js`

### Data services

Shared persistence and external state boundaries.

- [Shared database access](https://github.com/saurav2701/finder-a-dating-app/blob/main/packages/db/index.js): Prisma package · Owns schema, migrations, and product/identity persistence. · `packages/db/index.js`
- [Redis](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/lib/redis.ts): Ephemeral state · Supports OTP, cache, session-adjacent, or realtime state. · `apps/web/lib/redis.ts`
- [Supabase storage](https://github.com/saurav2701/finder-a-dating-app/blob/main/apps/web/lib/supabase/server.ts): External media service · Browser receives direct-upload authorization through the app. · `apps/web/lib/supabase/server.ts`

## Connections

- App shell → Swipe discovery: hosts
- Request protection → Auth and session layer: checks session
- Account and match pages → Auth and session layer: uses identity
- NextAuth endpoint → Auth and session layer: exposes
- Auth and session layer → Shared database access: identity records
- Signup OTP flow → Redis: stores OTP state
- Signup OTP flow → Shared database access: creates verified user
- Swipe discovery → Discovery and swipe APIs: fetches and submits swipes
- Account and match pages → Profile API: manages profile
- Discovery and swipe APIs → Auth and session layer: authorizes user
- Discovery and swipe APIs → Shared database access: candidates, swipes, matches
- Profile API → Auth and session layer: authorizes user
- Profile API → Shared database access: profile data
- Shared UI → Photo authorization: requests upload flow
- Photo authorization → Auth and session layer: authorizes owner
- Photo authorization → Supabase storage: presigns and confirms assets
- Photo authorization → Shared database access: persists photo reference
- Chat room client → Socket client lifecycle: connects through
- Socket client lifecycle → Chat transport: room events
- Chat transport → Shared database access: validates match membership
