Connify-APP

CONNIFY: Decentralized Zero-Knowledge Connection Protocol Between Strangers & Peer-to-Peer Community Mesh

Production System, Cryptographic Protocol & Full-Stack Monorepo Architectural Specification
Repository Target: TheOrionGD/Connify-APP
Core Mission: Connify is a decentralized zero-knowledge social protocol for initializing communication between two or more unknown persons (strangers) in physical proximity.
Core Algorithm: Custom-invented SHARP Protocol (Syndrome-Based Error-Correction Spatial Matching Engine via Galois Field $\text{GF}(2^4)$ $\text{BCH}(15,7)$ Codes & 1024-bit Bloom Filters) - Specification & Source Code available in protocol specifications.
Monorepo Workspaces:


Table of Contents

  1. Core Philosophy & System Overview
  2. Monorepo Architectural Blueprint
  3. Cryptographic Foundation: The SHARP Protocol
  4. Backend Service Architecture (backend)
  5. Background Engines & Autonomous Security Daemons
  6. Mobile & Multi-Platform Client Architecture (Connify)
  7. Auxiliary Utilities & Engine Systems
  8. Development Workflow & Environment Configuration
  9. Automated Testing Frameworks
  10. Release Engineering & Version Synchronization
  11. Security, Privacy & Regulatory Compliance
  12. Monorepo Dependency Matrix
  13. License

1. Core Philosophy & System Overview

1.1 The Core Thesis: Safe Connection Between Strangers

At its core, Connify is a decentralized protocol for connecting strangers in physical proximity.

In modern urban environments, thousands of human beings walk past each other every day, isolated by digital silos. When someone is stranded with a flat tire, searching for a lost child, navigating an unfamiliar neighborhood at night, seeking transport in an emergency, or facing an acute crisis, the fastest and most capable source of support is almost always a nearby stranger.

However, reaching out to strangers in the real world is fraught with friction, distrust, and danger. Connify eliminates this barrier by building an ad-hoc, zero-knowledge human mesh network:

                       ┌─────────────────────────────────────────┐
                       │           THE CONNIFY MESH              │
                       │     (Connection Between Strangers)      │
                       └────────────────────┬────────────────────┘
                                            │
        ┌───────────────────────────────────┼───────────────────────────────────┐
        ▼                                   ▼                                   ▼
┌───────────────────────┐       ┌───────────────────────┐       ┌───────────────────────┐
│   EVERYDAY MUTUAL     │       │   SITUATIONAL TRUST   │       │   HIGH-URGENCY        │
│   COMMUNITY AID       │       │   & SAFE ESCORTS      │       │   PEER ASSISTANCE     │
├───────────────────────┤       ├───────────────────────┤       ├───────────────────────┤
│ • Stranded & breakdown│       │ • Safe companion walk │       │ • Medical emergencies │
│ • Transport & rides   │       │ • Danger spot alerts  │       │ • Panic & harassment  │
│ • Lost child / senior │       │ • Timed journey guard │       │ • Fire / disaster     │
│ • Blood & med supply  │       │ • Witness attestation │       │ • Offline SMS mesh    │
└───────────────────────┘       └───────────────────────┘       └───────────────────────┘

Connify enables two nearby strangers to:

  1. Discover Each Other Without Disclosing Location: Match within a local geographic radius without broadcasting raw coordinates to a central database or to potential stalkers.
  2. Authenticate the Rendezvous Instantly: Perform a zero-trust cryptographic QR handshake using hardware-bound Ed25519 keypairs.
  3. Mint Just-In-Time (JIT) Trust Capsules: Create short-lived, verifiable peer connections that grant temporary communication and coordination privileges without sharing phone numbers, real names, or permanent identities.
  4. Build Decentralized Trust Scores: Reward positive interactions with XP, Trust Badges, and reputation tokens while autonomously quarantining malicious actors.

1.2 The Stranger Trust & Privacy-Accuracy Paradox

Connecting strangers in physical space presents two fundamental paradoxes:

Paradox 1: The Stranger Trust Paradox (Anti-Luring & Safety)

Without verifiable identity and behavioral evaluation, bad actors can exploit peer-to-peer networks to manufacture fake requests, luring well-meaning strangers into secluded or dangerous physical traps. Connify solves this through:

Paradox 2: The Coordinate Jitter & Privacy Paradox

Traditional matching algorithms require transmitting plaintext GPS coordinates $(lat, lng)$ to a central cloud server, exposing users to continuous physical tracking and mass surveillance. Attempting to hide coordinates using standard cryptographic hashes ($\text{SHA-256}(lat \parallel lng)$) fails due to natural mobile sensor drift ($5\text{ m}$ drift breaks exact hash matching): \(\text{SHA-256}(12.97159, 77.59456) \ne \text{SHA-256}(12.97163, 77.59460)\)


1.3 The Connify Architecture for Peer-to-Peer Connection

Connify solves the privacy-accuracy paradox through an integrated mathematical and cryptographic pipeline:


2. Monorepo Architectural Blueprint

The codebase is organized as a high-performance monorepo:

o:\PROJECTS\CONNIFY-APP\
├── backend/                       # Fastify 5 Zero-Trust Node.js Service
│   ├── prisma/
│   │   ├── migrations/            # Migration schema history
│   │   └── schema.prisma          # MongoDB Atlas data models & indexes
│   ├── src/
│   │   ├── config/                # Environment schema (Zod) & Firebase Admin SDK
│   │   ├── controllers/           # HTTP controllers (Device, Episode, Capsule, Outcome, Location, Profile)
│   │   ├── middleware/            # JWT & Firebase bearer authentication, error handlers
│   │   ├── models/                # Mongoose Document models & schema definitions
│   │   ├── routes/                # REST endpoint declarations (/api/*)
│   │   ├── services/              # Risk engine, Key management, Watchdog scanner
│   │   ├── sockets/               # Ephemeral Socket.IO real-time channel coordinator
│   │   ├── types/                 # Shared TypeScript interfaces
│   │   ├── utils/                 # BCH(15,7) SHARP math, hash chaining, DB connections
│   │   ├── app.ts                 # Fastify application builder & plugin registration
│   │   └── server.ts              # Entrypoint: keys, DB, HTTP, Socket.IO, watchdog loop
│   ├── tests/                     # Node.js native test runner suite (10 test suites)
│   ├── package.json               # Backend dependencies (v3.7.5)
│   └── tsconfig.json              # TypeScript compiler configuration
│
├── Connify/                       # React Native Multi-Platform Client (Android / iOS / Web)
│   ├── android/                   # Native Android project, Gradle build system, ProGuard
│   ├── ios/                       # Native iOS Xcode project & Podfile
│   ├── assets/                    # Typography, imagery, Lottie, and sound assets
│   ├── patches/                   # Hotfixes applied via patch-package
│   ├── src/
│   │   ├── components/            # UI atoms, animations, buttons, cards, chat, inputs, modals, map
│   │   ├── data/                  # Static emergency data & local registries
│   │   ├── navigation/            # Bottom tab bar & native stack screen navigators
│   │   ├── screens/               # 25 operational screens across requester, helper & safety flows
│   │   │   ├── ActiveEpisode/     # EmergencyScreen (live incident, countdown, chat, escort)
│   │   │   ├── Feedback/          # FeedbackScreen (incident outcome, photo verification, audit)
│   │   │   ├── Governance/        # GovernanceScreen, ProtocolExplainerScreen, WitnessContactsScreen
│   │   │   ├── Hazard/            # HazardMapScreen (community risk map, AI verification)
│   │   │   ├── Helper/            # NearbyRequestsScreen, HandshakeScreen (QR scan & JIT capsule)
│   │   │   ├── Onboarding/        # SplashScreen, WelcomeScreen, GoogleAuthSuccessScreen, OnboardingScreen
│   │   │   ├── Requester/         # DashboardScreen, CreateRequestScreen, SearchingScreen
│   │   │   ├── SafetyGuard/       # TimedSafetyGuardScreen (quiet journey countdown)
│   │   │   ├── Settings/          # SettingsScreen, HistoryScreen, FrequentLocationsScreen
│   │   │   ├── EmergencyContactsScreen.tsx
│   │   │   ├── FakeCallScreen.tsx
│   │   │   ├── GovernmentEmergencyNumbersScreen.tsx
│   │   │   ├── OfflineEmergencyScreen.tsx
│   │   │   ├── UnifiedSafetyHubScreen.tsx
│   │   │   └── WomenSafetyScreen.tsx
│   │   ├── services/              # Biometrics, Keychain, Socket.IO, Geolocation, Queue, Widget Sync
│   │   │   └── api/               # Axios API wrappers with interceptors
│   │   ├── stores/                # Zustand state stores (Auth, Episode, Hazard, Location, Reward, Theme, Frequent)
│   │   ├── theme/                 # Design tokens, color palettes, typography scale
│   │   ├── types/                 # Shared frontend TypeScript interfaces
│   │   ├── utils/                 # Pure JS SHARP protocol, phone normalizer, report generator, SMS
│   │   └── widgets/               # Android Widget Bridge & Synchronization Service
│   ├── __tests__/                 # Jest component & unit test suites (11 test suites)
│   ├── bump_version.js            # Monorepo version synchronizer across all packages
│   ├── package.json               # Mobile dependencies (v3.7.5, React Native 0.86.0)
│   └── react-native.config.js     # Native asset and vector icon linkage
│
├── protocol_specs/                # Protocol Specification & Mathematical Foundations
│   ├── sharp_protocol_spec.md     # Technical specification & architecture
│   ├── protocol_analysis.md       # Deep protocol breakdown & sequence charts
│   ├── protocol_specification.txt # Formal protocol specification text document
│   ├── custom_invented_algorithm_code.txt # Standalone reference implementation of SHARP
│   ├── existing_algorithm_code.txt # Prior-art baseline comparison
│   ├── cpm_algorithm_analysis.xlsx # Critical Path Method benchmark data
│   └── cpm_real_gantt_chart.xlsx  # Mathematical convergence & latency validation
│
├── run_emulator.bat               # Android emulator launch helper
├── run_emulator.ps1               # PowerShell emulator runner script
├── start_dev.bat                  # Concurrent backend & web bundler runner
├── ACCOUNT_DELETION_GOOGLE_FORM_SETUP.md # Compliance guide for Play Store / App Store
├── PRIVACY_POLICY.md              # Zero-trace privacy and data retention policy
└── LICENSE                        # MIT License

3. Cryptographic Foundation: The SHARP Protocol

The Syndrome-Based Error-Correction Spatial Matching (SHARP) engine operates over Galois Field arithmetic to solve the GPS noise problem in zero-knowledge location matching between strangers.

sequenceDiagram
    autonumber
    participant A as Requester (Stranger A)
    participant S as Fastify Central Node
    participant B as Volunteer Peer (Stranger B)

    Note over A: 1. Sample GPS (lat, lng)<br/>2. Round coordinates to 3 decimal places<br/>3. Compute 9-cell spatial neighborhood
    Note over A: 4. Vectorize cells into 1024-bit Bloom filter (4x FNV-1a)<br/>5. Slice into 146x 7-bit blocks (m7)<br/>6. BCH(15,7) over GF(2^4) -> Extract 8-bit Parity Syndromes<br/>7. Blind cells: SHA-256(SessionKey : CellID : Role)
    A->>S: POST /api/episodes (Syndromes Hex + Blinded Hashes)<br/>[Raw coordinates are never sent]
    S->>B: Socket.IO /feed -> Broadcast New Request (Syndromes + Blinded Hashes)
    Note over B: 8. Sample local GPS<br/>9. Generate local 1024-bit Bloom filter<br/>10. Combine local 7-bit blocks with received 8-bit syndromes<br/>11. BCH Decode over GF(2^4) -> Fix bit flips caused by GPS noise<br/>12. Reconstruct Requester Bloom filter & match blinded hashes
    B->>S: POST /api/capsules/issue (Scanned Requester QR Token + Proof)
    S-->>B: Return JIT Trust Capsule Token (2h TTL)

3.1 Mathematical Mechanics of Zero-Knowledge Proximity

1. Galois Field $\text{GF}(2^4)$ Definition

The field contains 16 elements generated by the primitive polynomial: \(p(x) = x^4 + x + 1 \quad (\text{Hex Representation: } \mathtt{0x13})\) Multiplication and division are computed using exponential (GF_EXP) and logarithmic (GF_LOG) lookup tables initialized at startup:

// backend/src/utils/sharp.ts (Lines 116-129)
let val = 1;
for (let i = 0; i < 15; i++) {
  GF_EXP[i] = val;
  GF_EXP[i + 15] = val;
  GF_LOG[val] = i;
  val <<= 1;
  if (val & 0x10) val ^= 0x13;
}

2. $\text{BCH}(15,7)$ Code Construction

A systematic generator polynomial $G(x) = \mathtt{0x1D1}$ ($x^8 + x^7 + x^6 + x^4 + 1$) maps 7-bit spatial message blocks ($m_7$) to 15-bit codewords ($c_{15}$): \(c_{15} = (m_7 \ll 8) \oplus \text{rem}(m_7 \ll 8, G(x))\) The lower 8 bits represent the Parity Syndrome. The 7-bit data block is discarded, and only the 8-bit parity syndrome is transmitted across the wire.

3. Decoding & Error Correction

Upon receiving the 8-bit syndrome, Device B combines it with its own locally generated 7-bit message block $m’7$ to construct a candidate codeword $r{15} = (m’_7 \ll 8) \mid \text{Syndrome}_8$. The Peterson-Gorenstein-Zierler decoder evaluates power-sum syndromes $S_1, S_2, S_3, S_4$: \(S_j = \sum_{i=0}^{14} r_i \cdot \alpha^{i \cdot j} \pmod{p(x)}\) The error-locator polynomial determinant is: \(\Delta = (S_1 \cdot S_3) \oplus (S_2 \cdot S_2)\)

4. Spatial Discretization & Vectorization


4. Backend Service Architecture (backend)

The backend service is powered by Fastify 5 and TypeScript, structured with separation of concerns between controllers, data models, routes, services, and middleware.

graph TD
    subgraph Client Requests
        M[Connify React Native App]
        W[Connify Expo Web App]
    end

    subgraph Fastify Gateway
        R[Rate Limiter: 100 req/min]
        C[CORS: Strict Origin Handling]
        A[Auth Middleware: Ed25519 Session / Firebase Bearer]
    end

    subgraph Core Controllers
        DC[DeviceController: /api/devices]
        EC[EpisodeController: /api/episodes]
        CC[CapsuleController: /api/capsules]
        OC[OutcomeController: /api/outcomes]
        LC[LocationController: /api/locations]
        PC[ProfileController: /api/profile]
        AC[AdminController: /api/admin]
    end

    subgraph Background Services
        WD[LocationWatchdogService: 10s Interval]
        BRE[BehavioralRiskEngine]
        KS[KeyService: Ed25519 PKCS8/SPKI]
        SIO[Socket.IO Real-Time Engine]
    end

    subgraph External Infrastructure
        DB[(MongoDB Atlas)]
        FCM[Firebase Cloud Messaging]
        BRV[Brevo SMTP / Transactional API]
    end

    M & W --> R --> C --> A
    A --> DC & EC & CC & OC & LC & PC & AC
    EC --> BRE
    CC --> KS
    LC --> WD
    WD --> FCM & BRV
    DC & EC & CC & OC & LC & PC & AC --> DB
    EC & CC --> SIO

4.1 Lifecycle & Startup Sequence

In backend/src/server.ts, the initialization sequence executes six distinct phases:

  1. Database Connection (connectDB): Connects to MongoDB Atlas using Mongoose connection pooling.
  2. Cryptographic Key Management (initKeys): Validates the presence of JWT_PRIVATE_KEY and JWT_PUBLIC_KEY. In development mode, if absent, it autonomously generates an Ed25519 keypair, outputs PKCS8/SPKI PEM formats with escaped newlines, and cleanly terminates with instructions for .env.
  3. Firebase Admin SDK Setup (initFirebase): Parses the FIREBASE_SERVICE_ACCOUNT_KEY environment JSON and registers push notification dispatch capabilities.
  4. Fastify Application Assembly (buildApp):
    • Registers @fastify/cors permitting pre-flight verification across methods ['GET', 'POST', 'PATCH', 'DELETE', 'OPTIONS'].
    • Registers @fastify/rate-limit with a global policy of 100 requests per 1-minute sliding window.
    • Attaches errorHandler to normalize exceptions into standard JSON payloads.
    • Mounts health checks, device routes, episode routes, capsule routes, outcome routes, profile routes, auth routes, and administrative endpoints.
  5. Real-Time WebSocket Server (initSockets): Binds a Socket.IO server to Fastify’s native Node.js HTTP server. Configures socket authentication middleware to verify device session tokens during handshake.
  6. Watchdog Daemon Background Task: Starts an unblocked background scanner (LocationWatchdogService.checkSignalLossAndNotifyGuardians) running on a 10,000 ms (10-second) interval.

4.2 Data Models & Persistence Invariants

Defined in backend/prisma/schema.prisma and mirrored in Mongoose schemas (backend/src/models/index.ts):

1. Device (devices)

2. Episode (episodes)

3. Capsule (capsules)

4. Outcome (outcomes)

5. AuditLog (audit_log)

6. Profile (profiles)

7. Guardian (guardians)

8. DeviceLocation (device_locations)

9. DeviceChallenge (device_challenges)


4.3 Comprehensive REST API Endpoints

Devices (/api/devices)

| Method | Endpoint | Auth | Description & Request Validation | | :— | :— | :— | :— | | POST | /api/devices/register | Firebase Bearer | Upserts hardware node registration. Body: { deviceFingerprintHash: string(64), publicKey: string, phoneHash?: string }. Returns { deviceId, token, tokenType: 'Bearer', expiresIn: '30d' }. | | POST | /api/devices/challenge | Device Session | Requests a 60-second single-use challenge. Rate limit: 5 req/min. Returns { challenge, expiresInSeconds: 60 }. | | POST | /api/devices/verify | Device Session | Verifies detached Ed25519 signature of challenge nonce using registered public key. Body: { challenge, signature }. Consumes nonce atomically. |

Episodes (/api/episodes)

| Method | Endpoint | Auth | Description & Request Validation | | :— | :— | :— | :— | | POST | /api/episodes | Device Session | Creates an assistance or emergency broadcast. Checks BehavioralRiskEngine.assertEligibilityForEpisodeTrigger. Body: { category, urgency (1-5), latitude, longitude, radiusMeters, blindedGridSigs, helperValidationKey, gridCellsJson, isDuress? }. | | GET | /api/episodes/nearby | Device Session | Finds active episodes via $geoWithin spherical geometry. Query: latitude, longitude, radiusMeters. Returns filtered metadata with relative distances in meters. | | GET | /api/episodes/:id | Device Session | Retrieves single episode status, TTL expiry, and blinded SHARP parameters. | | PATCH | /api/episodes/:id/cancel | Device Session | Cancels episode. Enforces owner authorization (requesterDeviceId === sub). Broadcasts episode_cancelled to room and feed. | | POST | /api/episodes/:id/threat-abort | Device Session | Responder threat abort. Marks episode THREAT_ABORTED. Increments requester device suspiciousCount; quarantines if count $\ge 2$. |

Capsules (/api/capsules)

| Method | Endpoint | Auth | Description & Request Validation | | :— | :— | :— | :— | | POST | /api/capsules/issue | Device Session | Issues a 2-hour JIT Trust Capsule between two strangers. Cryptographically verifies requester QR token signature and checks for nonce reuse. Body: { episodeId, helperDeviceId, verificationData: { qrToken, blindedGridCell } }. Persists SHA-256 hash of token. | | POST | /api/capsules/redeem | Device Session | Verifies capsule token JWS signature via KeyService. Atomically transitions capsule from issued to redeemed and episode to active. | | POST | /api/capsules/:id/revoke | Device Session | Revokes an issued capsule. Updates state to revoked. Writes CAPSULE_REVOKED to audit ledger. | | POST | /api/capsules/verify-qr | Device Session | Standalone verification endpoint checking Ed25519 signature and validity of a QR token without consuming the nonce. |

Locations & Emergency Guardians (/api/locations)

| Method | Endpoint | Auth | Description & Request Validation | | :— | :— | :— | :— | | POST | /api/locations/ping | Device Session | Updates device location (1-point sliding window). Body: { latitude, longitude, accuracy?, batteryLevel? }. Triggers automated recovery notifications if signal was previously lost. | | POST | /api/locations/guardians | Device Session | Registers emergency guardian. Body: { userFullName, fullName, phone, relationship, email?, fcmToken? }. | | POST | /api/locations/watchdog/scan | Device Session | Manually triggers the watchdog scanner loop. |

Outcomes (/api/outcomes)

| Method | Endpoint | Auth | Description & Request Validation | | :— | :— | :— | :— | | POST | /api/outcomes | Device Session | Records anonymous resolution record. Body: { episodeId, result: 'success'\|'failure'\|'SAFE_RESOLVED'\|'SUSPICIOUS_BEHAVIOR'\|'ACTIVE_THREAT', category, riskLevel? (1-5), completedInWindow: boolean }. |

Authentication & Profiles (/api/auth, /api/profile)

| Method | Endpoint | Auth | Description & Request Validation | | :— | :— | :— | :— | | POST | /api/auth/send-email-otp | Public | Generates 7-digit OTP (10-minute expiry). Dispatches HTML email via Brevo SMTP API. | | POST | /api/auth/verify-email-otp | Public | Verifies email OTP. Consumes token upon success. | | POST | /api/profile | Device Session | Upserts user profile. Extracts embedded guardian details from medicalNotes JSON and syncs them to the Guardian collection. | | POST | /api/profile/upgrade | Device Session | Upgrades anonymous guest profile to permanent profile with required guardian information. | | GET | /api/profile | Device Session | Fetches profile record associated with the authenticated device. |

Administrative API (/api/admin)

| Method | Endpoint | Auth | Description & Output | | :— | :— | :— | :— | | GET | /api/admin/dashboard | Device Session | Aggregated metrics: total episodes, user episodes, counts by status, success rate, and active episodes list. | | GET | /api/admin/guardians | Device Session | Paginated guardian nodes with trust scores and connection methods. | | GET | /api/admin/sos-alerts | Device Session | Paginated emergency episodes with hazard levels and coordinates. | | GET | /api/admin/jit-credentials | Device Session | Paginated list of issued JIT Trust Capsules. | | GET | /api/admin/audit-ledgers | Device Session | Verifies cryptographic integrity of the entire audit chain from block 0. Returns validation states per block. | | POST | /api/admin/simulate/episode | Device Session | Simulates emergency broadcast creation for testing. | | POST | /api/admin/simulate/checkin | Device Session | Simulates incident resolution and check-in. | | POST | /api/admin/simulate/corrupt | Device Session | Tamper testing endpoint; deliberately corrupts the hash of the latest audit log entry to verify chain validation failures. | | POST | /api/admin/simulate/reset | Device Session | Self-healing endpoint; recalculates and repairs the audit ledger hash chain. | | POST | /api/admin/wipe-database | Device Session | Purges all MongoDB collections (Devices, Profiles, Episodes, Capsules, Outcomes, Logs). |


4.4 Global Error Codes & Handling

Every error thrown by the Fastify service is formatted through backend/src/middleware/errorHandler.ts into a consistent structure:

{
  "success": false,
  "error": {
    "code": "ERROR_CODE_STRING",
    "message": "Human-readable explanation of error condition",
    "details": {}
  }
}

Standard Error Codes Dictionary:


5. Background Engines & Autonomous Security Daemons

5.1 Location Watchdog Daemon & Signal-Loss Protocol

Located in backend/src/services/LocationWatchdogService.ts, this service operates as a continuous safety monitor:

5.2 Behavioral Risk & Anti-Luring Engine

Located in backend/src/services/BehavioralRiskEngine.ts, this engine evaluates device behavior before permitting a broadcast to strangers:

  1. Mandatory Guardian Check (assertMandatoryGuardian):
    • Queries Guardian.countDocuments({ deviceId }). If 0, searches profile medicalNotes for auto-heal data. If still 0, rejects request with GUARDIAN_REQUIRED.
  2. Velocity & Luring Detection:
    • Queries episodes created by the device in the preceding 10 minutes: \(\text{recentCount} = \text{count}(\text{requesterDeviceId} = \text{deviceId}, \text{createdAt} \ge \text{now} - 10\text{ min})\)
    • If $\text{recentCount} \ge 2$: Flags isVelocityCapped = true and deducts $(\text{recentCount} - 1) \times 40$ points. Rejects broadcast with PREDATORY_LURING_DETECTED.
  3. Resolution Ratio Penalty:
    • Calculates the ratio of completed/resolved episodes to total episodes: \(\text{Ratio} = \frac{\text{Successful Outcomes}}{\text{Total Episodes}}\)
    • If $\text{Ratio} < 0.5$ across $\ge 3$ incidents, deducts $\text{round}((1 - \text{Ratio}) \times 30)$ points.
  4. Suspicious Behavioral Deductions:
    • Deducts $\text{suspiciousCount} \times 35$ points for each threat abort recorded against the device.
  5. Eligibility Enforcement:
    • Computes $\text{Score} = \max(0, 100 - \sum \text{Penalties})$.
    • Persists updated harmlessnessScore to Device record.
    • Rejects broadcast if isQuarantined === true, isVelocityCapped === true, or Score < 40.

5.3 Socket.IO Ephemeral Real-Time Mesh Architecture

Located in backend/src/sockets/index.ts, Socket.IO coordinates ephemeral in-memory communication channels:

graph TD
    Client[Client Device] -->|1. Connect with JWT| Sock[Socket.IO Server]
    Sock -->|2. Verify Token via KeyService| Auth{Authenticated?}
    Auth -- No --> Drop[Disconnect Socket]
    Auth -- Yes --> Reg[Attach deviceId & fingerprint to socket.data]

    Reg -->|join_episode| Room[Room: episode:ID]
    Reg -->|join_feed| Feed[Global Feed Room]

    Room -->|send_message| Chat[Ephemeral In-Flight Message Broadcast]
    Room -->|update_responder_location| Pos[Live Volunteer Coordinates Broadcast]
    Room -->|offer_support| Accept[Helper Accepted Broadcast]
    Room -->|location_ping| Watchdog[Update Sliding Location in DB]
    
    Room -->|episode_expired / cancelled| Teardown[Disconnect All Sockets & Purge Room]

Socket.IO Event Definitions:

| Event Name | Direction | Payload Structure | Functional Purpose | | :— | :— | :— | :— | | join_episode | Client $\to$ Server | { episodeId: string } | Enforces membership authorization (requester or matched helper). Joins socket to episode:{id}. | | offer_support | Helper $\to$ Server | { episodeId, latitude, longitude } | Marks episode as matched. Broadcasts helper_accepted with volunteer coordinates to the requester. | | update_responder_location | Helper $\to$ Server | { episodeId, latitude, longitude } | Broadcasts responder_location_updated to requester during transit. | | send_message | Client $\to$ Server | { episodeId, message } | Emits new_message to room participants. In-flight messages exist only in memory and are never persisted. | | leave_episode | Client $\to$ Server | { episodeId } | Removes client socket from room; broadcasts user_left. | | location_ping | Client $\to$ Server | { latitude, longitude, accuracy } | Calls LocationWatchdogService.updateLocationPing directly over WebSocket. | | join_feed / leave_feed | Client $\to$ Server | None | Subscribes idle volunteer devices to the global distress feed. | | new_episode | Server $\to$ Feed | Episode metadata | Broadcasts new emergency requests to nearby volunteer nodes. | | capsule_issued | Server $\to$ Room | { episodeId, status, capsuleId } | Notifies participants that handshake verification succeeded. | | episode_expired | Server $\to$ Room | { episodeId, message } | Signals TTL expiration and forces all room sockets to disconnect. | | episode_cancelled | Server $\to$ Room | { episodeId, message } | Signals cancellation and closes the channel. |

5.4 Hash-Chained Tamper-Evident Audit Ledger

Located in backend/src/utils/audit.ts and backend/src/routes/admin.ts:


6. Mobile & Multi-Platform Client Architecture (Connify)

The client application is built on React Native 0.86.0 and React 19 with full cross-platform capabilities (Android, iOS, and Expo Web), utilizing Zustand for state management, React Navigation 7 for routing, and native hardware integrations.

6.1 Native Hardware Modules & Keypair Derivation

6.2 State Management (Zustand Stores)

1. authStore.ts

2. episodeStore.ts

3. locationStore.ts

4. hazardStore.ts

5. rewardStore.ts

6. frequentLocationsStore.ts

7. themeStore.ts


6.3 The 25 Operational Application Screens

Navigation Architecture
├── Onboarding & Authentication
│   ├── SplashScreen (Bootstrap & Keypair Check)
│   ├── WelcomeScreen (OAuth / OTP / Guest Hub)
│   ├── GoogleAuthSuccessScreen (OAuth Sync Verification)
│   └── OnboardingScreen (Interactive Safety Guide)
│
├── Main Tab Navigation
│   ├── DashboardScreen (Circular Radar Visualizer & Connect with Strangers)
│   ├── UnifiedSafetyHubScreen (Master Safety Console & Siren)
│   ├── NearbyRequestsScreen (Volunteer Incident Discovery Feed)
│   ├── HistoryScreen (Cryptographic Audit Trail)
│   └── SettingsScreen (Profile, Guardians, Themes, Account Deletion)
│
├── Requester & Peer Connection Workflow
│   ├── CreateRequestScreen (22-Category Assistance & Biometric Gate)
│   ├── SearchingScreen (Active Radar Polling & Swarm Listeners)
│   ├── HandshakeScreen (QR Scanners & JIT Capsule Issuance)
│   ├── EmergencyScreen (Active Incident, Countdown & P2P Chat)
│   └── FeedbackScreen (Post-Incident Audit & Photo Verification)
│
├── Safety Hub & Rapid Interventions
│   ├── WomenSafetyScreen (1-Tap Sirens & SOS SMS)
│   ├── OfflineEmergencyScreen (Cellular SMS Distress Dispatch)
│   ├── FakeCallScreen (Configurable Incoming Exit Call Engine)
│   ├── EmergencyContactsScreen (Guardian Management & Keychain Sync)
│   ├── GovernmentEmergencyNumbersScreen (National Hotlines 112/100/1091)
│   └── TimedSafetyGuardScreen (Quiet Journey Countdown Watcher)
│
├── Hazard Intelligence & Community Safety
│   └── HazardMapScreen (Community Danger Spots & AI Cross-Verification)
│
└── Governance, Audits & Decentralized Protocols
    ├── GovernanceScreen (Decentralized Parameters & Trust Engine)
    ├── ProtocolExplainerScreen (Galois Field BCH Math Explainer)
    └── WitnessContactsScreen (Bystander Witness Attestations)
  1. SplashScreen.tsx: Bootstraps device credentials, checks connectivity, initializes notification channels, and routes to Welcome or Main.
  2. WelcomeScreen.tsx: Multi-mode authentication hub supporting Google OAuth, email/password, 7-digit email OTP, or guest mode.
  3. GoogleAuthSuccessScreen.tsx: Onboarding screen confirming profile data sync from Google accounts.
  4. OnboardingScreen.tsx: Interactive multi-step explainer illustrating zero-knowledge location privacy and responder rendezvous.
  5. DashboardScreen.tsx: Primary user dashboard featuring a dynamic circular radar visualizer, 1-tap quick SOS trigger, “Connect with a Nearby Helper” launcher, system status telemetry, and active safety timer counters.
  6. UnifiedSafetyHubScreen.tsx: Unified protection console with a high-decibel audible panic alarm, 1-tap offline GPS emergency SMS dispatching, primary guardian call/SMS/WhatsApp triggers, national hotlines, and instant exit call scheduling.
  7. CreateRequestScreen.tsx: Broadcast configuration supporting 22 peer request categories across mutual aid, medical, transport, and safety with urgency ratings (1–5) and SHARP Bloom filter generation.
  8. SearchingScreen.tsx: Radar screen displaying live status while polling for nearby volunteer peers and listening for socket acceptance.
  9. NearbyRequestsScreen.tsx: Proximity discovery feed for volunteer responders, displaying nearby distress episodes with distance in meters and urgency ratings.
  10. HandshakeScreen.tsx: Rendezvous verification screen between two strangers. Requesters display an Ed25519-signed QR code with a 90-second nonce; helpers scan the code using the camera to issue the JIT Trust Capsule. Supports Covert Duress PIN input and Bystander Witness Attestation signing.
  11. EmergencyScreen.tsx: Active incident screen featuring a 15-minute countdown clock, encrypted P2P chat, stalled responder detection, and safe escort tracking mode.
  12. FeedbackScreen.tsx: Post-incident screen recording resolution status, risk levels (1–5), photographic verification, and audit report generation.
  13. HistoryScreen.tsx: Local audit trail showing past emergency broadcasts and cryptographic proofs.
  14. SettingsScreen.tsx: Configuration center for editing profiles, linking Google accounts, managing guardians, switching themes, and submitting account deletion requests.
  15. EmergencyContactsScreen.tsx: Interface for adding and removing emergency contacts, stored securely in react-native-keychain.
  16. GovernmentEmergencyNumbersScreen.tsx: Direct dial directory for emergency services (112, 100, 102, 108, 1091, 181, 1930).
  17. WomenSafetyScreen.tsx: Quick-access safety screen with audible sirens and 1-tap emergency SMS broadcasting.
  18. OfflineEmergencyScreen.tsx: Fallback screen for cellular SMS-based distress broadcasts when mobile data is unavailable.
  19. FakeCallScreen.tsx: Simulates realistic incoming calls from configurable contacts (‘Mom’, ‘Dad’, ‘Safety Dispatch’, ‘Office Guard’) with customizable delays (instant, 5s, 15s, 30s) to assist users in discreetly exiting hazardous situations.
  20. TimedSafetyGuardScreen.tsx: Quiet journey countdown timer. Users specify destination and duration. If the user fails to check in before the timer reaches zero, automatic SMS and push notifications are dispatched to emergency contacts.
  21. HazardMapScreen.tsx: Community risk map. Users report danger spots, which are evaluated by the AI Hazard Verification Engine (aiHazardService) against municipal logs and lighting grid feeds.
  22. FrequentLocationsScreen.tsx: Manages user-configured safe geofences (e.g., Home, University, Office).
  23. GovernanceScreen.tsx: Interactive governance overview detailing protocol trust scores, community validators, and decentralized parameters.
  24. ProtocolExplainerScreen.tsx: In-app educational module breaking down Bloom filter spatial indexing and Peterson-Gorenstein-Zierler decoding.
  25. WitnessContactsScreen.tsx: Direct management screen for designated bystander witnesses providing secondary rendezvous attestations.

6.4 The 22 Peer Request & Assistance Categories

Defined in Connify/src/screens/Requester/CreateRequestScreen.tsx:

Category Name Icon Name Description Backend Mapped Category
Medical Emergency medical-services Urgent medical aid, trauma, or cardiac emergency medical
Security & Assault security Physical threat, active assault, or immediate danger emergency
Fire & Explosion local-fire-department Active fire outbreak, smoke, or explosion hazard emergency
Women Safety & Harassment health-and-safety SOS panic, stalking, or female safety intervention emergency
Accident & Collision car-crash Road crash, vehicular accident, or injury on transit medical
Transport & Evacuation local-taxi Emergency transport, ride share, or safe evacuation transport
Disaster & Flood thunderstorm Flash flood, storm, earthquake, or severe hazard emergency
Domestic Violence & Abuse gavel Domestic abuse, violent dispute, or protective distress emergency
Child Emergency & Lost child-care Missing child, infant distress, or pediatric emergency general
Senior Citizen Assist elderly Elderly fall, confusion, or senior assistance general
Mental Health Crisis psychology Severe distress, panic attack, or psychological aid medical
Stranded & Breakdown build Vehicle breakdown, flat tire, or isolated location general
Blood & Organ Need bloodtype Urgent blood donor requirement or rare group need medical
Oxygen & Med Supply vaccines Critical oxygen cylinder or lifesaving medication medical
Cyber Threat & Stalking phishing Digital harassment, blackmail, or cyber stalking general
Animal Rescue & Hazard pets Injured animal, rabid hazard, or wildlife rescue general
Power Grid & Blackout power-off Complete power failure, grid blackout, or electrical hazard general
Gas & Chemical Leak warning-amber Toxic gas leak, chemical spill, or gas cylinder hazard emergency
Theft & Burglary lock Active break-in, theft, robbery, or property intrusion emergency
Food & Water Crisis set-meal Emergency food, clean water shortage, or relief general
Shelter & Homeless Relief night-shelter Extreme weather shelter, displacement, or emergency bed general
General Request report-problem General community assistance or unlisted distress general

6.5 Offline Resilience & Transaction Queue

Implemented in Connify/src/services/OfflineQueueService.ts and QueueHandlers.ts:

6.6 Covert Duress, Stalled Responders & Safety Checks

6.7 Android Home & Lock Screen Widget Integration

Implemented in Connify/src/widgets/widgetBridge.ts and widgetSyncService.ts:


7. Auxiliary Utilities & Engine Systems

7.1 AI Hazard Cross-Verification Service

Located in Connify/src/services/aiHazardService.ts, this service evaluates user-reported safety hazards:

7.2 Standardized Emergency SMS Formatter

Located in Connify/src/utils/smsFormatter.ts, this utility compiles offline cellular SMS messages with 5 standardized components:

[EMERGENCY SAFETY ALERT]
User: Elena Vance
Relationship: Primary Guardian
Reason: Emergency distress signal triggered from Connify Safety app
Last Location: Lat 12.97159, Lng 77.59456
Map Link: https://maps.google.com/?q=12.97159,77.59456

7.3 Cryptographic Incident Audit Report Generator

Located in Connify/src/utils/reportGenerator.ts, this generator produces a formatted audit record upon incident completion:

====================================================
         CONNIFY EMERGENCY INCIDENT AUDIT REPORT          
====================================================
Generated On      : 2026-09-07, 14:15:00
Incident ID       : ep-67c8a1b2c3d4e5f60718293a
Verification Hash : 0X_AUDIT_9F8E7D6C

----------------------------------------------------
1. INCIDENT DETAILS
----------------------------------------------------
Category          : MEDICAL EMERGENCY
Urgency Level     : LEVEL 4
User Identity     : Safety User
Start Time        : 14:00:15
Resolution Time   : 14:14:45
Handshake Time    : 14:05:22

----------------------------------------------------
2. LOCATION & TELEMETRY LOGS
----------------------------------------------------
GPS Coordinates   : 12.97160, 77.59457
Responder Device  : 67c8a1f0e4...
Responder Credentials: Verified Volunteer Responder

----------------------------------------------------
3. SECURITY & VERIFICATION AUDIT
----------------------------------------------------
Zero-Trust Handshake : PASSED (Cryptographic Key Exchange Verified)
Duress Safety Pin   : NONE (Clean Authentication)
Witness Attestations: 1 Bystander Witness Signature(s) Recorded
Safe Escort Mode    : COMPLETED (Safe Arrival Confirmed)

----------------------------------------------------
4. COMPLIANCE & PRIVACY NOTICE
----------------------------------------------------
Privacy Protocol  : Zero-Trace Ephemeral Session
Data Retention    : This local audit record is encrypted on-device. All server-side telemetry has been permanently discarded.
====================================================

8. Development Workflow & Environment Configuration

8.1 Prerequisites & Tooling

8.2 Environment Variables Configuration

Backend (backend/.env)

# MongoDB Connection String
DATABASE_URL="mongodb://localhost:27017/Connify"

# Server Port and Environment
PORT=5000
NODE_ENV=development

# Ed25519 JWT Cryptographic Keys (PEM with escaped newlines)
# Generated automatically by KeyService in development if left blank
JWT_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"
JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----"

# Firebase Admin SDK Service Account (Single-line JSON string)
FIREBASE_SERVICE_ACCOUNT_KEY='{"type":"service_account","project_id":"connify-app",...}'

# Brevo API Key for Email OTP and Watchdog Guardian Alerts
BREVO_API_KEY="xkeysib-..."
SMTP_USER="alerts@connify.app"

Mobile Client (Connify/.env)

# URL pointing to the running backend service
API_BASE_URL=http://10.0.2.2:5000   # Android Emulator host loopback
# API_BASE_URL=http://localhost:5000 # iOS Simulator or Web development

8.3 Installation & Startup Commands

1. Repository Setup

git clone https://github.com/TheOrionGD/Connify-APP.git
cd Connify-APP

2. Backend Initialization

cd backend
npm install
npm run prisma:generate

3. Mobile & Multi-Platform Client Initialization

cd ../Connify
npm install
# Postinstall automatically applies patches via patch-package

Running Development Servers

Using Concurrent Helper Script (Windows):

start_dev.bat

Starting Services Individually:

Start Backend (Port 5000 with Hot Reload):

cd backend
npm run dev

Start React Native Metro Bundler:

cd Connify
npm start

Launch Android Application:

cd Connify
npm run android

Launch Web Version (Expo Web):

cd Connify
npm run web

9. Automated Testing Frameworks

9.1 Backend Test Suites

Executed using the native Node.js test runner and tsx:

cd backend
npm run test:all

Test Suite Breakdown:

  1. tests/allEndpoints.test.ts: End-to-end REST API integration tests across device, episode, capsule, and outcome endpoints.
  2. tests/CapsuleController.test.ts: Tests capsule minting, QR code signature verification, single-use token redemption, and revocation.
  3. tests/deviceRegistration.test.ts: Tests device registration and key rotation flows.
  4. tests/deviceChallenge.test.ts: Validates 60-second challenge nonce generation and consumption.
  5. tests/harmlessnessSystem.test.ts: Tests Harmlessness Score calculations and velocity cap enforcement.
  6. tests/locationWatchdog.test.ts: Simulates signal loss timeouts and guardian notification dispatch.
  7. tests/profileMigration.test.ts: Tests profile updates and guardian synchronization.
  8. tests/symmetricVerificationPipeline.test.ts: Tests end-to-end SHARP protocol Galois Field arithmetic and BCH decoding.
  9. tests/adminAuth.test.ts: Verifies authentication on administrative routes.
  10. tests/e2eJourney.test.ts: Simulates a complete multi-device emergency lifecycle from broadcast to resolution.

9.2 Mobile & Client Test Suites

Executed using Jest:

cd Connify
npm test

Test Suite Breakdown:

  1. __tests__/sharp.test.ts: Tests client-side BCH(15,7) encoding, syndrome extraction, and error correction.
  2. __tests__/secureKeyService.test.ts: Tests Ed25519 key generation and detached signature generation.
  3. __tests__/authStore.test.ts: Validates Zustand authentication state transitions and credential derivations.
  4. __tests__/episodeStore.test.ts: Tests episode state transitions, timer countdowns, and secondary responder registration.
  5. __tests__/apiClient.test.ts: Verifies Axios request/response interceptors and bearer token injection.
  6. __tests__/apiServices.test.ts: Tests API communication modules across devices, episodes, and capsules.
  7. __tests__/handshakeQr.test.ts: Tests QR token generation, base64url encoding, and payload parsing.
  8. __tests__/feedMultiUser.test.ts: Tests multi-user Socket.IO event handling on the feed channel.
  9. __tests__/components.test.tsx: Tests rendering and styling of core UI components.
  10. __tests__/themeStore.test.ts: Validates dark and light theme switching.
  11. __tests__/App.test.tsx: Verifies root application mounting.

10. Release Engineering & Version Synchronization

Monorepo versioning is managed through Connify/bump_version.js.

10.1 Version Synchronization Script

cd Connify
npm run bump:patch   # e.g., 3.7.5 -> 3.7.6
npm run bump:minor   # e.g., 3.7.5 -> 3.8.0
npm run bump:major   # e.g., 3.7.5 -> 4.0.0

This script updates four configuration files simultaneously:

  1. Connify/package.json (version)
  2. Connify/app.json (expo.version, version)
  3. backend/package.json (version)
  4. Connify/android/app/build.gradle (increments versionCode, updates versionName)

10.2 Compiling Android Production Releases

Build Release APK:

cd Connify
npm run build:android-apk
# Outputs: Connify/android/app/build/outputs/apk/release/app-release.apk

Build Android App Bundle (AAB for Google Play):

cd Connify
npm run build:android-bundle
# Outputs: Connify/android/app/build/outputs/bundle/release/app-release.aab

11. Security, Privacy & Regulatory Compliance

11.1 Zero-Trace Geolocation Invariants

11.2 Replay Attack Prevention

Every QR token issued during the physical handshake includes a unique UUIDv4 nonce:

11.3 Account & Data Deletion Compliance

The codebase satisfies Google Play Console Data Safety policies and Apple App Store Guideline 5.1.1(v):


12. Monorepo Dependency Matrix

Backend Dependencies (backend/package.json)

Mobile & Multi-Platform Dependencies (Connify/package.json)


13. License

Distributed under the MIT License. See LICENSE for full legal text.