# ru-mais/datie architecture

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

- Interactive diagram: https://gitdiagram.com/ru-mais/datie
- Repository: https://github.com/ru-mais/datie

## Overview

#### Purpose and Runtime
Datie is a security-focused dating platform built with Next.js 15 App Router and React. Firebase supplies authentication and Firestore persistence; Google Cloud Vision moderates profile images. The application’s primary shell is `src/app/layout.tsx`, with the landing route at `src/app/page.tsx`.

#### Identity and Session Boundary
Authentication state is centralized in `src/context/AuthContext.tsx`, backed by Firebase initialization in `src/lib/firebase.ts`. The login and signup flows at `src/app/login/page.tsx` and `src/app/signup/page.tsx` implement the phone-first identity gate, linking verified phone identity to account credentials. SMS OTP dispatch is server-mediated by `src/app/api/send-otp/route.ts`.

#### Profile Lifecycle
Authenticated users manage their own dating profile through `src/app/profile/page.tsx`; public or matched-user inspection is routed through `src/app/profile/[uid]/page.tsx`. Profile completeness is an important eligibility boundary because discovery excludes incomplete profiles. Uploaded profile media passes through server-side image safety evaluation before it can become usable profile content.

#### AI Content-Moderation Service
`src/app/api/vision/route.ts` is the backend boundary for Google Cloud Vision Safe Search analysis. It receives image-review requests from the client, calls the external Vision API using server-side credentials, and determines whether content such as explicit material, violence, or spoofing should be blocked. This keeps the Vision API key outside browser code.

#### Discovery, Likes, and Match Formation
`src/app/discover/page.tsx` is the candidate-feed entry point. Its Firestore-driven selection is intended to omit blocked, previously liked, and incomplete profiles. Match-oriented views are separated into `src/app/matches/page.tsx` and individual chat routes under `src/app/chat/[matchId]/page.tsx`, where reciprocal interest becomes a durable match/chat relationship.

#### Messaging and Safety Controls
Match-specific conversations are hosted at `src/app/chat/[matchId]/page.tsx`. The chat layer applies real-time client interaction controls for profanity and suspicious external links, while Firestore is the durable conversation store. User-level blocking and message editing/deletion are part of the control model and must align with Firestore authorization rules in `firestore.rules`.

#### Administration and Data Operations
Administrative operations are isolated from user-facing routes: `src/app/admin/page.tsx` provides the admin entry point and `src/app/api/admin/cleanup-user/route.ts` provides a privileged cleanup endpoint. This boundary is material because account cleanup may span Firebase Auth and Firestore records and therefore requires stronger authorization than ordinary client operations.

#### Navigation and Enforcement
`src/components/Navbar.tsx` provides shared navigation across the App Router’s principal surfaces. Client behavior is constrained by Firebase/Firestore security policy in `firestore.rules`; API routes handle operations requiring secrets or elevated service integration, while browser code uses public Firebase configuration from `src/lib/firebase.ts`.

Main entry points: [`src/components/Navbar.tsx`](https://github.com/ru-mais/datie/blob/main/src/components/Navbar.tsx) (Shared navigation), [`src/app/api/admin/cleanup-user/route.ts`](https://github.com/ru-mais/datie/blob/main/src/app/api/admin/cleanup-user/route.ts) (User cleanup endpoint), [`src/context/AuthContext.tsx`](https://github.com/ru-mais/datie/blob/main/src/context/AuthContext.tsx) (Auth state), [`src/app/layout.tsx`](https://github.com/ru-mais/datie/blob/main/src/app/layout.tsx) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["App Router UI"]
  node_shell["App shell<br/>Next.js layout<br/>[layout.tsx]"]
  node_navbar["Shared navigation<br/>React component<br/>[Navbar.tsx]"]
  node_landing["Landing route<br/>App route<br/>[page.tsx]"]
  node_own_profile["Profile management<br/>App route<br/>[page.tsx]"]
  node_public_profile["Profile inspection<br/>Dynamic app route<br/>[page.tsx]"]
  node_discovery["Discovery feed<br/>App route<br/>[page.tsx]"]
  node_matches["Matches<br/>App route<br/>[page.tsx]"]
  node_chat["Match chat<br/>Dynamic app route<br/>[page.tsx]"]
end

subgraph group_identity["Identity"]
  node_auth_context["Auth state<br/>React context<br/>[AuthContext.tsx]"]
  node_firebase_client["Firebase client<br/>Firebase initialization<br/>[firebase.ts]"]
  node_login["Login<br/>App route<br/>[page.tsx]"]
  node_signup["Signup<br/>App route<br/>[page.tsx]"]
end

subgraph group_services["Server Services"]
  node_send_otp{{"SMS OTP endpoint<br/>API route<br/>[route.ts]"}}
  node_vision_api{{"Image moderation<br/>API route<br/>[route.ts]"}}
  node_cloud_vision["Google Cloud Vision<br/>External API"]
  node_admin["Admin console<br/>App route<br/>[page.tsx]"]
  node_cleanup{{"User cleanup endpoint<br/>Privileged API route<br/>[route.ts]"}}
end

subgraph group_data["Data &amp; Policy"]
  node_firestore[("Firestore<br/>Persistence")]
  node_rules["Firestore policy<br/>Security rules<br/>[firestore.rules]"]
end

node_shell -->|"renders"| node_navbar
node_shell -->|"hosts"| node_landing
node_navbar -->|"navigates"| node_login
node_navbar -->|"navigates"| node_discovery
node_auth_context -->|"uses"| node_firebase_client
node_login -->|"establishes session"| node_auth_context
node_signup -->|"requests OTP"| node_send_otp
node_signup -->|"creates session"| node_auth_context
node_own_profile -->|"reviews uploads"| node_vision_api
node_vision_api -->|"Safe Search request"| node_cloud_vision
node_own_profile -->|"stores profile"| node_firestore
node_public_profile -->|"reads profile"| node_firestore
node_discovery -->|"queries eligible candidates"| node_firestore
node_matches -->|"reads matches"| node_firestore
node_chat -->|"realtime messages"| node_firestore
node_firestore -->|"client access enforced by"| node_rules
node_admin -->|"invokes"| node_cleanup
node_cleanup -->|"cleans records"| node_firestore
node_cleanup -.->|"cleanup spans Firebase identity"| node_firebase_client

click node_shell "https://github.com/ru-mais/datie/blob/main/src/app/layout.tsx"
click node_navbar "https://github.com/ru-mais/datie/blob/main/src/components/Navbar.tsx"
click node_landing "https://github.com/ru-mais/datie/blob/main/src/app/page.tsx"
click node_auth_context "https://github.com/ru-mais/datie/blob/main/src/context/AuthContext.tsx"
click node_firebase_client "https://github.com/ru-mais/datie/blob/main/src/lib/firebase.ts"
click node_login "https://github.com/ru-mais/datie/blob/main/src/app/login/page.tsx"
click node_signup "https://github.com/ru-mais/datie/blob/main/src/app/signup/page.tsx"
click node_send_otp "https://github.com/ru-mais/datie/blob/main/src/app/api/send-otp/route.ts"
click node_own_profile "https://github.com/ru-mais/datie/blob/main/src/app/profile/page.tsx"
click node_public_profile "https://github.com/ru-mais/datie/blob/main/src/app/profile/%5Buid%5D/page.tsx"
click node_vision_api "https://github.com/ru-mais/datie/blob/main/src/app/api/vision/route.ts"
click node_discovery "https://github.com/ru-mais/datie/blob/main/src/app/discover/page.tsx"
click node_matches "https://github.com/ru-mais/datie/blob/main/src/app/matches/page.tsx"
click node_chat "https://github.com/ru-mais/datie/blob/main/src/app/chat/%5BmatchId%5D/page.tsx"
click node_admin "https://github.com/ru-mais/datie/blob/main/src/app/admin/page.tsx"
click node_cleanup "https://github.com/ru-mais/datie/blob/main/src/app/api/admin/cleanup-user/route.ts"
click node_rules "https://github.com/ru-mais/datie/blob/main/firestore.rules"

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_shell,node_navbar,node_landing,node_own_profile,node_public_profile,node_discovery,node_matches,node_chat toneBlue
class node_auth_context,node_firebase_client,node_login,node_signup toneAmber
class node_send_otp,node_vision_api,node_cloud_vision,node_admin,node_cleanup toneMint
class node_firestore,node_rules toneRose
```

## Components

### App Router UI

- [App shell](https://github.com/ru-mais/datie/blob/main/src/app/layout.tsx): Next.js layout · Shared application shell. · `src/app/layout.tsx`
- [Shared navigation](https://github.com/ru-mais/datie/blob/main/src/components/Navbar.tsx): React component · `src/components/Navbar.tsx`
- [Landing route](https://github.com/ru-mais/datie/blob/main/src/app/page.tsx): App route · `src/app/page.tsx`
- [Profile management](https://github.com/ru-mais/datie/blob/main/src/app/profile/page.tsx): App route · Authenticated user profile lifecycle. · `src/app/profile/page.tsx`
- [Profile inspection](https://github.com/ru-mais/datie/blob/main/src/app/profile/%5Buid%5D/page.tsx): Dynamic app route · Views public or matched-user profiles. · `src/app/profile/[uid]/page.tsx`
- [Discovery feed](https://github.com/ru-mais/datie/blob/main/src/app/discover/page.tsx): App route · Excludes blocked, liked, and incomplete profiles. · `src/app/discover/page.tsx`
- [Matches](https://github.com/ru-mais/datie/blob/main/src/app/matches/page.tsx): App route · Reciprocal likes become durable matches. · `src/app/matches/page.tsx`
- [Match chat](https://github.com/ru-mais/datie/blob/main/src/app/chat/%5BmatchId%5D/page.tsx): Dynamic app route · Realtime messaging with client safety controls. · `src/app/chat/[matchId]/page.tsx`

### Identity

- [Auth state](https://github.com/ru-mais/datie/blob/main/src/context/AuthContext.tsx): React context · Central client session boundary. · `src/context/AuthContext.tsx`
- [Firebase client](https://github.com/ru-mais/datie/blob/main/src/lib/firebase.ts): Firebase initialization · Public browser Firebase configuration. · `src/lib/firebase.ts`
- [Login](https://github.com/ru-mais/datie/blob/main/src/app/login/page.tsx): App route · `src/app/login/page.tsx`
- [Signup](https://github.com/ru-mais/datie/blob/main/src/app/signup/page.tsx): App route · Phone-first account enrollment. · `src/app/signup/page.tsx`

### Server Services

- [SMS OTP endpoint](https://github.com/ru-mais/datie/blob/main/src/app/api/send-otp/route.ts): API route · Server-mediated OTP dispatch. · `src/app/api/send-otp/route.ts`
- [Image moderation](https://github.com/ru-mais/datie/blob/main/src/app/api/vision/route.ts): API route · Server-side Safe Search decision boundary. · `src/app/api/vision/route.ts`
- **Google Cloud Vision**: External API · Safe Search image analysis.
- [Admin console](https://github.com/ru-mais/datie/blob/main/src/app/admin/page.tsx): App route · `src/app/admin/page.tsx`
- [User cleanup endpoint](https://github.com/ru-mais/datie/blob/main/src/app/api/admin/cleanup-user/route.ts): Privileged API route · Coordinates account cleanup across Auth and Firestore. · `src/app/api/admin/cleanup-user/route.ts`

### Data & Policy

- **Firestore**: Persistence · Profiles, likes, matches, blocks, and conversations.
- [Firestore policy](https://github.com/ru-mais/datie/blob/main/firestore.rules): Security rules · Authorizes client data operations. · `firestore.rules`

## Connections

- App shell → Shared navigation: renders
- App shell → Landing route: hosts
- Shared navigation → Login: navigates
- Shared navigation → Discovery feed: navigates
- Auth state → Firebase client: uses
- Login → Auth state: establishes session
- Signup → SMS OTP endpoint: requests OTP
- Signup → Auth state: creates session
- Profile management → Image moderation: reviews uploads
- Image moderation → Google Cloud Vision: Safe Search request
- Profile management → Firestore: stores profile
- Profile inspection → Firestore: reads profile
- Discovery feed → Firestore: queries eligible candidates
- Matches → Firestore: reads matches
- Match chat → Firestore: realtime messages
- Firestore → Firestore policy: client access enforced by
- Admin console → User cleanup endpoint: invokes
- User cleanup endpoint → Firestore: cleans records
- User cleanup endpoint → Firebase client: cleanup spans Firebase identity
