# aditya-singh2005/connecti architecture

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

- Interactive diagram: https://gitdiagram.com/aditya-singh2005/connecti
- Repository: https://github.com/aditya-singh2005/connecti

## Overview

#### 1. Purpose and Runtime Shape
Connecti is an Android-focused Expo/React Native prototype for privacy-preserving reconnection among existing friends. Its core journey is geofence entry → voluntary Wave/presence → mutual hint/reveal consent → BLE-verified meetup. The client is backed primarily by Supabase, with Firebase/FCM and Expo push paths, native Android location workers, and separate Python ML engines.

#### 2. Mobile Application and Navigation
Expo Router screens define authentication, profile creation, and the home-area social workflow. The app bootstrap and route shells are at `app/_layout.jsx`, `app/index.jsx`, and `app/home/_layout.js`. Primary product surfaces include home, chat, friends, discovery, profile, permission, proximity, and geofence testing under `app/home/HomeScreen.jsx`, `app/home/ChatScreen.jsx`, and `app/home/GeofenceTestScreen.jsx`.

#### 3. Identity, Social Data, and Consent Boundary
Authentication state is centrally owned by `context/AuthProvider.jsx`; the Supabase client boundary is `lib/supabase.js`. Friend relationship operations are exposed to UI through `hooks/useFriendships.jsx`, while Wave lifecycle behavior is encapsulated in `services/WaveService.js`. These layers should enforce the product invariant that only established friends participate and identities are withheld until bilateral approval.

#### 4. Geofence-Driven Presence Pipeline
JavaScript geofence orchestration spans `components/GeofenceController.js`, `hooks/useGeofenceService.js`, and `services/GeofenceManager.js`. Background task handling begins at `tasks/geofenceTask.js`. Android-native geofence registration/bridging and background maintenance are implemented in `android/app/src/main/java/com/aditya/connectiapp/NativeGeofenceModule.kt`, `android/app/src/main/java/com/aditya/connectiapp/GeofenceBroadcastReceiver.kt`, and `android/app/src/main/java/com/aditya/connectiapp/GeofenceRefreshWorker.kt`.

#### 5. Native Android Background Execution
The Android app hosts React Native through `android/app/src/main/java/com/aditya/connectiapp/MainActivity.kt` and `android/app/src/main/java/com/aditya/connectiapp/MainApplication.kt`. WorkManager-style workers cover zone polling/sync, expired Waves, and inactive presence: `ZonePollWorker.kt`, `ZoneSyncWorker.kt`, `WaveExpiryWorker.kt`, and `PresenceInactivityWorker.kt` in the same Android package. `BootCompletedReceiver.kt` restores relevant background behavior after device restart.

#### 6. Proximity and Meetup Verification
BLE discovery and proximity notifications are modeled as React hooks: `hooks/useBLEService.js`, `hooks/useBLENearbyFriends.js`, and `hooks/useBLEProximityNotifications.js`; shared BLE logic is in `lib/bleutils.js`. This is the physical-verification boundary for the final Connect phase, distinct from geofence-based coarse presence.

#### 7. Notifications and Server-Side Integrations
Client notification setup, token handling, and test surfaces are in `components/NotificationHandler.jsx`, `services/ExpoPushTokenService.js`, and `services/FCMTokenService.js`. Android notification creation is native in `android/app/src/main/java/com/aditya/connectiapp/NotificationHelper.kt`. Delivery can route through a Vercel-style push API (`connect-push-api/api/send-notification.js`), Firebase Cloud Functions (`functions/index.js`), or Supabase Edge Function chat notifications (`supabase/functions/send-chat-notification/index.ts`).

#### 8. Persistence and Decision Support
Supabase provides database/backend services; database behavior includes stale-presence cleanup in `supabase/migrations/auto_cleanup_stale_presence.sql`. The standalone Python ML subsystem calculates relationship strength, hints, and reunion probability using profile embeddings: `ml/engines/relationship_strength.py`, `ml/engines/hint_generator.py`, and `ml/engines/reunion_probability.py`. It is a decision-support boundary rather than an embedded mobile runtime.

Main entry points: [`lib/supabase.js`](https://github.com/aditya-singh2005/connecti/blob/main/lib/supabase.js) (Supabase backend), [`services/WaveService.js`](https://github.com/aditya-singh2005/connecti/blob/main/services/WaveService.js) (Wave consent lifecycle), [`components/NotificationHandler.jsx`](https://github.com/aditya-singh2005/connecti/blob/main/components/NotificationHandler.jsx) (Client notifications), [`app/_layout.jsx`](https://github.com/aditya-singh2005/connecti/blob/main/app/_layout.jsx) (Routes and product screens)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Expo mobile app"]
  node_routes["Routes and product screens<br/>Expo Router<br/>[_layout.jsx]"]
  node_auth["Auth state<br/>React context<br/>[AuthProvider.jsx]"]
  node_friendships["Friend relationships<br/>React hook<br/>[useFriendships.jsx]"]
  node_waves["Wave consent lifecycle<br/>[WaveService.js]"]
  node_ble["BLE meetup verification<br/>React hooks<br/>[useBLEService.js]"]
  node_notifications["Client notifications<br/>Token and notification service"]
end

subgraph group_presence["Presence pipeline"]
  node_geofence_ui["Geofence controller<br/>React component"]
  node_geofence_service["Geofence orchestration<br/>Hook and service"]
  node_geofence_task["Background geofence task<br/>Expo task<br/>[geofenceTask.js]"]
end

subgraph group_android["Android native runtime"]
  node_native_geofence{{"Native geofence bridge<br/>Kotlin module"}}
  node_geofence_receiver["Geofence event receiver<br/>Android receiver"]
  node_background_workers["Background maintenance<br/>Android workers"]
  node_android_host["Android app host<br/>React Native host<br/>[MainApplication.kt]"]
end

subgraph group_backend["Backend and delivery"]
  node_supabase[("Supabase backend<br/>Database and backend<br/>[supabase.js]")]
  node_presence_cleanup["Stale presence cleanup<br/>SQL migration"]
  node_push_api["Push delivery API<br/>Vercel API route"]
  node_firebase_functions["Firebase push functions<br/>Cloud Functions<br/>[index.js]"]
  node_chat_notification["Chat notification function<br/>Supabase Edge Function<br/>[index.ts]"]
end

subgraph group_ml["Decision support"]
  node_ml_engines["Relationship ML engines<br/>Python engines"]
end

node_routes -->|"reads session"| node_auth
node_routes -->|"social UI"| node_friendships
node_routes -->|"creates and approves"| node_waves
node_auth -->|"auth state"| node_supabase
node_friendships -->|"friend graph"| node_supabase
node_waves -->|"waves and consent"| node_supabase
node_geofence_ui -->|"controls"| node_geofence_service
node_geofence_service -->|"registers zones"| node_native_geofence
node_native_geofence -->|"Android transitions"| node_geofence_receiver
node_geofence_receiver -->|"dispatches event"| node_geofence_task
node_geofence_task -->|"updates presence"| node_waves
node_background_workers -->|"syncs and cleans"| node_supabase
node_android_host -->|"hosts module"| node_native_geofence
node_android_host -->|"schedules work"| node_background_workers
node_waves -->|"eligible mutual meetup"| node_ble
node_ble -->|"nearby alert"| node_notifications
node_notifications -.->|"push delivery"| node_push_api
node_notifications -.->|"FCM delivery"| node_firebase_functions
node_supabase -->|"chat events"| node_chat_notification
node_chat_notification -.->|"pushes chat alert"| node_notifications
node_supabase -->|"applies cleanup"| node_presence_cleanup
node_supabase -.->|"profile inputs"| node_ml_engines
node_ml_engines -.->|"hints and probability"| node_waves

click node_routes "https://github.com/aditya-singh2005/connecti/blob/main/app/_layout.jsx"
click node_auth "https://github.com/aditya-singh2005/connecti/blob/main/context/AuthProvider.jsx"
click node_friendships "https://github.com/aditya-singh2005/connecti/blob/main/hooks/useFriendships.jsx"
click node_waves "https://github.com/aditya-singh2005/connecti/blob/main/services/WaveService.js"
click node_geofence_ui "https://github.com/aditya-singh2005/connecti/blob/main/components/GeofenceController.js"
click node_geofence_service "https://github.com/aditya-singh2005/connecti/blob/main/hooks/useGeofenceService.js"
click node_geofence_task "https://github.com/aditya-singh2005/connecti/blob/main/tasks/geofenceTask.js"
click node_native_geofence "https://github.com/aditya-singh2005/connecti/blob/main/android/app/src/main/java/com/aditya/connectiapp/NativeGeofenceModule.kt"
click node_geofence_receiver "https://github.com/aditya-singh2005/connecti/blob/main/android/app/src/main/java/com/aditya/connectiapp/GeofenceBroadcastReceiver.kt"
click node_background_workers "https://github.com/aditya-singh2005/connecti/blob/main/android/app/src/main/java/com/aditya/connectiapp/GeofenceRefreshWorker.kt"
click node_android_host "https://github.com/aditya-singh2005/connecti/blob/main/android/app/src/main/java/com/aditya/connectiapp/MainApplication.kt"
click node_ble "https://github.com/aditya-singh2005/connecti/blob/main/hooks/useBLEService.js"
click node_notifications "https://github.com/aditya-singh2005/connecti/blob/main/components/NotificationHandler.jsx"
click node_supabase "https://github.com/aditya-singh2005/connecti/blob/main/lib/supabase.js"
click node_presence_cleanup "https://github.com/aditya-singh2005/connecti/blob/main/supabase/migrations/auto_cleanup_stale_presence.sql"
click node_push_api "https://github.com/aditya-singh2005/connecti/blob/main/connect-push-api/api/send-notification.js"
click node_firebase_functions "https://github.com/aditya-singh2005/connecti/blob/main/functions/index.js"
click node_chat_notification "https://github.com/aditya-singh2005/connecti/blob/main/supabase/functions/send-chat-notification/index.ts"
click node_ml_engines "https://github.com/aditya-singh2005/connecti/blob/main/ml/engines/relationship_strength.py"

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_routes,node_auth,node_friendships,node_waves,node_ble,node_notifications toneBlue
class node_geofence_ui,node_geofence_service,node_geofence_task toneAmber
class node_native_geofence,node_geofence_receiver,node_background_workers,node_android_host toneMint
class node_supabase,node_presence_cleanup,node_push_api,node_firebase_functions,node_chat_notification toneRose
class node_ml_engines toneIndigo
```

## Components

### Expo mobile app

- [Routes and product screens](https://github.com/aditya-singh2005/connecti/blob/main/app/_layout.jsx): Expo Router · Authentication and home social surfaces. · `app/_layout.jsx`
- [Auth state](https://github.com/aditya-singh2005/connecti/blob/main/context/AuthProvider.jsx): React context · `context/AuthProvider.jsx`
- [Friend relationships](https://github.com/aditya-singh2005/connecti/blob/main/hooks/useFriendships.jsx): React hook · Limits social participation to established friends. · `hooks/useFriendships.jsx`
- [Wave consent lifecycle](https://github.com/aditya-singh2005/connecti/blob/main/services/WaveService.js): Service · Manages voluntary presence and bilateral reveal consent. · `services/WaveService.js`
- [BLE meetup verification](https://github.com/aditya-singh2005/connecti/blob/main/hooks/useBLEService.js): React hooks · Verifies nearby friends after coarse geofence presence. · `hooks/useBLEService.js`
- [Client notifications](https://github.com/aditya-singh2005/connecti/blob/main/components/NotificationHandler.jsx): Token and notification service · `components/NotificationHandler.jsx`

### Presence pipeline

- [Geofence controller](https://github.com/aditya-singh2005/connecti/blob/main/components/GeofenceController.js): React component · `components/GeofenceController.js`
- [Geofence orchestration](https://github.com/aditya-singh2005/connecti/blob/main/hooks/useGeofenceService.js): Hook and service · `hooks/useGeofenceService.js`
- [Background geofence task](https://github.com/aditya-singh2005/connecti/blob/main/tasks/geofenceTask.js): Expo task · `tasks/geofenceTask.js`

### Android native runtime

- [Native geofence bridge](https://github.com/aditya-singh2005/connecti/blob/main/android/app/src/main/java/com/aditya/connectiapp/NativeGeofenceModule.kt): Kotlin module · Registers Android geofences for the React Native layer. · `android/app/src/main/java/com/aditya/connectiapp/NativeGeofenceModule.kt`
- [Geofence event receiver](https://github.com/aditya-singh2005/connecti/blob/main/android/app/src/main/java/com/aditya/connectiapp/GeofenceBroadcastReceiver.kt): Android receiver · `android/app/src/main/java/com/aditya/connectiapp/GeofenceBroadcastReceiver.kt`
- [Background maintenance](https://github.com/aditya-singh2005/connecti/blob/main/android/app/src/main/java/com/aditya/connectiapp/GeofenceRefreshWorker.kt): Android workers · Refreshes geofences and cleans expired waves or inactive presence. · `android/app/src/main/java/com/aditya/connectiapp/GeofenceRefreshWorker.kt`
- [Android app host](https://github.com/aditya-singh2005/connecti/blob/main/android/app/src/main/java/com/aditya/connectiapp/MainApplication.kt): React Native host · `android/app/src/main/java/com/aditya/connectiapp/MainApplication.kt`

### Backend and delivery

- [Supabase backend](https://github.com/aditya-singh2005/connecti/blob/main/lib/supabase.js): Database and backend · Primary persistence, auth, and realtime boundary. · `lib/supabase.js`
- [Stale presence cleanup](https://github.com/aditya-singh2005/connecti/blob/main/supabase/migrations/auto_cleanup_stale_presence.sql): SQL migration · `supabase/migrations/auto_cleanup_stale_presence.sql`
- [Push delivery API](https://github.com/aditya-singh2005/connecti/blob/main/connect-push-api/api/send-notification.js): Vercel API route · `connect-push-api/api/send-notification.js`
- [Firebase push functions](https://github.com/aditya-singh2005/connecti/blob/main/functions/index.js): Cloud Functions · `functions/index.js`
- [Chat notification function](https://github.com/aditya-singh2005/connecti/blob/main/supabase/functions/send-chat-notification/index.ts): Supabase Edge Function · `supabase/functions/send-chat-notification/index.ts`

### Decision support

- [Relationship ML engines](https://github.com/aditya-singh2005/connecti/blob/main/ml/engines/relationship_strength.py): Python engines · Computes relationship strength, hints, and reunion probability from profile embeddings. · `ml/engines/relationship_strength.py`

## Connections

- Routes and product screens → Auth state: reads session
- Routes and product screens → Friend relationships: social UI
- Routes and product screens → Wave consent lifecycle: creates and approves
- Auth state → Supabase backend: auth state
- Friend relationships → Supabase backend: friend graph
- Wave consent lifecycle → Supabase backend: waves and consent
- Geofence controller → Geofence orchestration: controls
- Geofence orchestration → Native geofence bridge: registers zones
- Native geofence bridge → Geofence event receiver: Android transitions
- Geofence event receiver → Background geofence task: dispatches event
- Background geofence task → Wave consent lifecycle: updates presence
- Background maintenance → Supabase backend: syncs and cleans
- Android app host → Native geofence bridge: hosts module
- Android app host → Background maintenance: schedules work
- Wave consent lifecycle → BLE meetup verification: eligible mutual meetup
- BLE meetup verification → Client notifications: nearby alert
- Client notifications → Push delivery API: push delivery
- Client notifications → Firebase push functions: FCM delivery
- Supabase backend → Chat notification function: chat events
- Chat notification function → Client notifications: pushes chat alert
- Supabase backend → Stale presence cleanup: applies cleanup
- Supabase backend → Relationship ML engines: profile inputs
- Relationship ML engines → Wave consent lifecycle: hints and probability
