Skip to content

Add codebase risk assessment reports#31

Open
morningstarxcdcode wants to merge 13 commits intomasterfrom
Abhishek
Open

Add codebase risk assessment reports#31
morningstarxcdcode wants to merge 13 commits intomasterfrom
Abhishek

Conversation

@morningstarxcdcode
Copy link
Collaborator

Summary

  • add comprehensive codebase risk assessment docs (backend, frontend, doc mismatches)
  • add executive summary index in docs/codebase-risk-assessment.md

Testing

  • not run (docs only)

VishalMahato and others added 13 commits March 1, 2026 06:42
… integration

- Updated Dashboard component to use orchestrator for SOS activation and deactivation.
- Introduced SOSRuntimeBootstrapper for handling app state recovery and deep-link triggers.
- Added new orchestrator functions for managing SOS pending intents and cooldowns.
- Integrated power button detection for triggering SOS via native module on Android.
- Enhanced background location tracking with updated distance interval settings.
- Created new files for SOS orchestrator and power button handling.
- Added comprehensive SOS emergency test checklist for validation.
- Implemented CloudinaryUtils class for handling image uploads and deletions.
- Added methods for uploading images from data URIs and file paths.
- Included signature generation for secure API requests.
- Created SOSProfile component as a placeholder in the frontend.
- Updated error.utils.ts to improve type definitions for error handling.
- Modified tsconfig.json to use ES2020 for better compatibility.
- Added Backend Architecture and Integration Guide for comprehensive documentation.
- Implemented location stabilizer utility to filter and smooth GPS updates, reducing noise and improving accuracy.
- Refactored User Dashboard and location task to integrate location stabilization, ensuring consistent updates.
- Documented changes in frontend location accuracy change log for clarity and future reference.
- Updated SOCKET_API.md to reflect new location update frequency and filtering.
- Removed outdated frontend location accuracy change log; created a new log with detailed changes.
- Revised implementation plan to include updated location handling and user experience improvements.
- Added new utility for location stabilization to reduce noise and improve accuracy.
- Reworked Dashboard component to manage location updates more effectively, preventing duplicate emissions.
- Implemented background task improvements for consistent location tracking.
- Documented changes in frontend location accuracy and filtering behavior.
Copilot AI review requested due to automatic review settings March 10, 2026 16:10
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the LifeLine emergency response system by integrating advanced AI triage capabilities with the SOS lifecycle, introducing a flexible payment and verification system for helper services, and dramatically improving the reliability and accuracy of real-time location tracking. It also includes a substantial amount of new documentation, providing detailed architectural insights, implementation plans, and comprehensive risk assessments for the entire codebase. These changes aim to create a more robust, intelligent, and user-friendly emergency platform.

Highlights

  • Comprehensive Documentation: Added extensive documentation covering backend architecture, integration guides, AI triage HLD/LLD, SOS upgrade HLD/LLD, and detailed risk assessments for both frontend and backend.
  • Enhanced SOS Lifecycle: Introduced payment approval, OTP verification, and helper-facing SOS profiles, allowing for paid/free service models and better helper information access.
  • Advanced Location Tracking: Implemented sophisticated client-side location stabilization and filtering to reduce GPS jitter and ensure reliable, consistent updates (near 5-second cadence) for both foreground and background app states.
  • AI Triage Integration: AI triage can now bind to and enrich existing SOS emergencies, allowing for a 'SOS-first' approach where an emergency is triggered immediately and then refined by AI.
  • New Helper Features: Added helper dashboard metrics (earnings, cases solved) and a new UI for incoming SOS cases.
  • Dockerized Development Environment: Updated docker-compose.yml to include MongoDB and streamline backend development setup.
  • Native Power Button SOS (Android): Added an Expo plugin and native code to enable SOS triggering via multiple power button presses on Android.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .gitignore
    • Added new ignore rules for .appdata/ and AppData/ directories.
  • Backend Architecture & Integration_Guide.md
    • Added a new comprehensive guide detailing backend architecture, AI emergency flows, helper dispatch, location tracking, and system analytics.
  • LifeLine-Backend/.env.example
    • Added environment variables for Cloudinary image upload service configuration.
  • LifeLine-Backend/docker-compose.yml
    • Configured Docker Compose to include a MongoDB service and linked the backend service to it, enabling a local Dockerized development environment.
  • LifeLine-Backend/docs/04-Business-Logic-and-Rules.md
    • Updated formatting and refined the location tracking rule to specify foreground and background behavior.
  • LifeLine-Backend/docs/11-Socket-Protocol.md
    • Updated formatting and expanded location update event descriptions to include client-side filtering and new server-to-client events.
  • LifeLine-Backend/docs/16-Backend-Features-Guide.md
    • Updated formatting and enhanced the description of real-time location services to detail GPS data handling.
  • LifeLine-Backend/docs/20-End-to-End-Workflows.md
    • Updated formatting and refined the live tracking section to reflect detailed GPS data handling.
  • LifeLine-Backend/docs/api-mismatch-report.md
    • Updated the API mismatch report to reflect new findings regarding Auth, Helper, Medical, and Notifications routes, and adjusted the action plan.
  • LifeLine-Backend/src/Ai/triage/triage.controller.mjs
    • Modified AI triage session initiation to allow binding to and updating an existing emergency record.
  • LifeLine-Backend/src/Ai/triage/triageService.mjs
    • Modified triage session management to support binding an existing emergency ID.
  • LifeLine-Backend/src/Ai/triage/triageState.mjs
    • Added emergencyId field and a method to bind an existing emergency ID to the triage state.
  • LifeLine-Backend/src/api/Auth/v1/Auth.model.mjs
    • Added profileImagePublicId field to the authentication schema.
  • LifeLine-Backend/src/api/Auth/v1/Auth.service.mjs
    • Updated user creation and update services to handle profile image public IDs.
  • LifeLine-Backend/src/api/Emergency/Emergency.controller.mjs
    • Added new endpoints for approving payments, verifying OTPs, and retrieving SOS profiles. Modified helper acceptance to include payment details.
  • LifeLine-Backend/src/api/Emergency/Emergency.model.mjs
    • Expanded the Emergency schema to include medical information, service type, detailed accepted helper information with payment status, and a comprehensive payment object.
  • LifeLine-Backend/src/api/Emergency/Emergency.routes.mjs
    • Added new API routes for emergency payment approval, OTP verification, and SOS profile retrieval.
  • LifeLine-Backend/src/api/Emergency/Emergency.service.mjs
    • Implemented new functionalities for updating emergency details, approving payments, verifying OTPs, and providing SOS profiles to helpers.
  • LifeLine-Backend/src/api/Helper/Helper.controller.mjs
    • Added a new endpoint to retrieve helper statistics.
  • LifeLine-Backend/src/api/Helper/Helper.model.mjs
    • Added fields for total earnings, pending amounts, solved cases, and active case status to the Helper schema.
  • LifeLine-Backend/src/api/Helper/Helper.routes.mjs
    • Added a new route for fetching helper statistics.
  • LifeLine-Backend/src/api/Helper/Helper.service.mjs
    • Updated dashboard metrics calculation to use actual payment data instead of mock values.
  • LifeLine-Backend/src/api/Location/Location.controller.mjs
    • Introduced a utility to parse nearby query parameters and updated search endpoints to return more detailed metadata.
  • LifeLine-Backend/src/api/NGO/NGO.controller.mjs
    • Introduced a utility to parse nearby query parameters and updated NGO search endpoints to return more detailed metadata.
  • LifeLine-Backend/src/api/Notifications/v1/Notification.controller.mjs
    • Added a new controller for managing user notifications, including fetching, marking as read, and counting unread notifications.
  • LifeLine-Backend/src/api/Notifications/v1/Notification.routes.mjs
    • Added new API routes for notification management.
  • LifeLine-Backend/src/api/Payment/Payment.controller.mjs
    • Added a new controller for creating and releasing payment records.
  • LifeLine-Backend/src/api/Payment/Payment.model.mjs
    • Added a new Mongoose model for payment transactions.
  • LifeLine-Backend/src/api/Payment/Payment.routes.mjs
    • Added new API routes for payment creation and release.
  • LifeLine-Backend/src/api/Payment/Payment.utils.mjs
    • Added new utility functions for payment-related operations.
  • LifeLine-Backend/src/api/User/User.service.mjs
    • Updated user creation and profile update services to handle profile images.
  • LifeLine-Backend/src/api/User/User.utils.mjs
    • Included profileImage in the formatted user response.
  • LifeLine-Backend/src/config/mongo.config.mjs
    • Updated MongoDB connection configuration for improved reliability.
  • LifeLine-Backend/src/server.mjs
    • Configured the server to serve static files from the 'uploads' directory and integrated new notification and payment API routes.
  • LifeLine-Backend/src/socket/SOCKET_API.md
    • Updated documentation for location update events to reflect client-side data cleaning and new server-side responses.
  • LifeLine-Backend/src/socket/handlers/triage.handler.mjs
    • Modified triage socket handler to support updating existing emergencies based on AI decisions.
  • LifeLine-Backend/src/utils/cloudinary.utils.mjs
    • Added new utility functions for interacting with Cloudinary for image uploads and deletions.
  • LifeLine-Backend/src/utils/multer.utils.mjs
    • Expanded allowed image file types to include HEIC and HEIF formats.
  • Lifeline-Frontend/Dockerfile
    • Added a new Dockerfile for containerizing the frontend application.
  • Lifeline-Frontend/app.json
    • Integrated the new power button SOS plugin and refined background location modes.
  • Lifeline-Frontend/app/(global)/Map.tsx
    • Significantly refactored location tracking with advanced smoothing algorithms, updated socket communication, and enhanced map rendering logic.
  • Lifeline-Frontend/app/(global)/SOSActiveAIScreen.tsx
    • Applied minor formatting adjustments.
  • Lifeline-Frontend/app/(main)/Home.tsx
    • Removed unused test navigation function.
  • Lifeline-Frontend/app/(main)/Login.tsx
    • Updated useEffect dependency array.
  • Lifeline-Frontend/app/(main)/SignUp.tsx
    • Applied minor formatting and refined logic for email existence checks and location data handling.
  • Lifeline-Frontend/app/(main)/_layout.tsx
    • Removed unused imports.
  • Lifeline-Frontend/app/Helper/Case.tsx
    • Added a new UI component for displaying incoming SOS cases for helpers.
  • Lifeline-Frontend/app/Helper/Dashboard.tsx
    • Integrated ExpoLocation for helper location reporting and updated socket registration. Added logic to persist user ID and role in AsyncStorage.
  • Lifeline-Frontend/app/Helper/EmergencyDetaill.tsx
    • Removed unused imports and updated API client usage.
  • Lifeline-Frontend/app/Helper/Notifications.tsx
    • Updated API client usage and applied minor formatting.
  • Lifeline-Frontend/app/Helper/SOSProfile.tsx
    • Added a new placeholder component for SOS profile viewing.
  • Lifeline-Frontend/app/Helper/_layout.tsx
    • Integrated the new Case component into the helper navigation stack.
  • Lifeline-Frontend/app/Helper/publicProfile[id].tsx
    • Removed unused imports.
  • Lifeline-Frontend/app/User/Dashboard.tsx
    • Refactored SOS activation to use a new orchestrator, integrated location stabilization, and implemented AppState-aware background/foreground tracking.
  • Lifeline-Frontend/app/User/Helper/HelperRequest.tsx
    • Removed commented-out example code.
  • Lifeline-Frontend/app/User/IncomeUserSOS.tsx
    • Applied minor formatting and updated UI layout for the SOS list.
  • Lifeline-Frontend/app/User/Nearby.tsx
    • Updated API client usage and applied minor formatting.
  • Lifeline-Frontend/app/User/Profile/AccountDetails.tsx
    • Removed unused imports.
  • Lifeline-Frontend/app/User/Profile/SavedAddressScreen.tsx
    • Removed unused imports and state, updated error handling, and removed a deprecated component.
  • Lifeline-Frontend/app/_layout.tsx
    • Integrated the new SOS runtime bootstrapper.
  • Lifeline-Frontend/plugins/withPowerButtonSOS.js
    • Added a new Expo config plugin to enable native Android power button SOS functionality.
  • Lifeline-Frontend/src/ai/sarvam-stt.ts
    • Removed unused import.
  • Lifeline-Frontend/src/config/api.ts
    • Updated API base URL parsing, added a bypass header, and expanded API endpoints to include new Auth, Emergency, User, Helper, NGO, and Payment routes.
  • Lifeline-Frontend/src/config/socket.ts
    • Updated socket URL parsing.
  • Lifeline-Frontend/src/core/Navigation.tsx
    • Removed unused import.
  • Lifeline-Frontend/src/core/Providers.tsx
    • Removed unused imports.
  • Lifeline-Frontend/src/features/Helper/Case/Components/SOSCard.tsx
    • Applied minor formatting, added a new icon, and updated priority styling.
  • Lifeline-Frontend/src/features/Helper/Dashbard/v1/Components/StatusToggle.tsx
    • Updated AsyncStorage usage and added availability status checks.
  • Lifeline-Frontend/src/features/Helper/helperSlice.ts
    • Updated API client usage, refined API base URL, and added a new thunk for fetching helper statistics.
  • Lifeline-Frontend/src/features/SOS/SOSRuntimeBootstrapper.tsx
    • Added a new component to manage SOS activation from various sources like deep links and native power button events.
  • Lifeline-Frontend/src/features/SOS/sos.orchestrator.ts
    • Added new logic for managing SOS activation, pending intents, and deep link handling.
  • Lifeline-Frontend/src/features/User/Component/UserNav.tsx
    • Applied minor formatting adjustments.
  • Lifeline-Frontend/src/features/auth/authSlice.ts
    • Updated API client usage and refined user creation and profile update logic.
  • Lifeline-Frontend/src/features/auth/locationSlice.ts
    • Updated API client usage.
  • Lifeline-Frontend/src/features/auth/medicalSlice.ts
    • Updated API client usage and removed unused imports.
  • Lifeline-Frontend/src/features/auth/screens/EmergencyContacts.tsx
    • Applied minor formatting adjustments.
  • Lifeline-Frontend/src/features/auth/screens/MedicalInfoScreen.tsx
    • Applied minor formatting and removed unused imports.
  • Lifeline-Frontend/src/features/auth/screens/SecureLocationScreen.tsx
    • Introduced advanced reverse geocoding logic using multiple services and refined location data handling.
  • Lifeline-Frontend/src/features/auth/screens/UniversalMap.tsx
    • Removed unused import.
  • Lifeline-Frontend/src/features/auth/screens/UserInfo.tsx
    • Added state for image MIME type and file name, and updated image picking and form data handling.
  • Lifeline-Frontend/src/features/auth/screens/VerifySkillsScreen.tsx
    • Applied minor formatting and removed unused state.
  • Lifeline-Frontend/src/features/auth/screens/WelcomeScreen.tsx
    • Removed unused import.
  • Lifeline-Frontend/src/features/emergency/emergencySlice.ts
    • Updated API client usage, added emergencyId to triage session, and introduced new thunks for payment approval, OTP verification, and SOS profile retrieval.
  • Lifeline-Frontend/src/features/emergency/hooks/useEmergency.ts
    • Updated emergency phase checks, refined triage response handling, and modified SOS initiation to bind triage to an existing emergency.
  • Lifeline-Frontend/src/features/emergency/services/triageApi.service.ts
    • Imported Emergency type and added emergencyId to triage start session parameters.
  • Lifeline-Frontend/src/shared/hooks/useBackgroundLocation.ts
    • Updated location tracking accuracy and interval settings for background tasks.
  • Lifeline-Frontend/src/shared/hooks/useSocket.ts
    • Updated socket service import and removed unused imports.
  • Lifeline-Frontend/src/shared/services/socket.service.ts
    • Updated user registration to include role, and location/triage updates to include additional parameters.
  • Lifeline-Frontend/src/shared/services/speech.service.ts
    • Added ESLint ignore comment and simplified error handling.
  • Lifeline-Frontend/src/shared/store/middleware/socketMiddleware.ts
    • Updated socket service import.
  • Lifeline-Frontend/src/shared/tasks/location.task.ts
    • Integrated location stabilization logic and per-user tracking for background location updates.
  • Lifeline-Frontend/src/shared/utils/error.utils.ts
    • Refined error payload type definition.
  • Lifeline-Frontend/src/shared/utils/locationStabilizer.ts
    • Added a new utility file containing logic for stabilizing and filtering location updates.
  • Lifeline-Frontend/src/utils/filePicker.utils.ts
    • Adjusted image picker aspect ratio and quality settings.
  • Lifeline-Frontend/tsconfig.json
    • Updated TypeScript compiler options.
  • ai-logs/Frontend/frontend-location-accuracy-change-log-2026-03-10-2026-03-10_17-54-21.md
    • Added a detailed log documenting frontend location accuracy changes.
  • ai-logs/Frontend/frontend-location-accuracy-change-log-2026-03-10.md
    • Added a detailed log documenting frontend location accuracy changes.
  • docs/ai-triage-sos-hld-lld.md
    • Added a new document outlining the High-Level and Low-Level Design for AI Triage to SOS integration.
  • docs/codebase-risk-assessment.md
    • Added a new document providing an executive summary of the codebase risk assessment.
  • docs/future-implementation-summary.md
    • Added a new document summarizing future implementation items across various features.
  • docs/risk-assessment-backend.md
    • Added a new document detailing the backend risk assessment.
  • docs/risk-assessment-doc-mismatches.md
    • Added a new document detailing the document mismatch risk assessment.
  • docs/risk-assessment-frontend.md
    • Added a new document detailing the frontend risk assessment.
  • docs/sos-upgrade-hld-lld.md
    • Added a new document outlining the High-Level and Low-Level Design for the SOS upgrade.
  • docs/tests/sos-first-triage-postman-testing.md
    • Added a new Postman testing guide for the SOS-first and AI triage flow.
  • docs/tests/sos-upgrade-postman-testing.md
    • Added a new Postman testing guide for the SOS upgrade features.
  • implementation_plan.md
    • Applied minor formatting changes and updated the Guardian Live Tracking section to reflect improved location update frequency and filtering.
Activity
  • No specific activity (comments, reviews, or progress updates) was provided for this pull request.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a substantial number of features and documentation, including codebase risk assessments, a full payment and OTP verification flow for emergencies, SOS profile access for helpers, and significant enhancements to location tracking on both frontend and backend. While the additions are extensive, I've identified a critical security vulnerability related to serving uploaded files publicly. I've also noted opportunities for code deduplication and schema simplification to improve maintainability. Overall, this is a major step forward, but the security issue should be addressed before merging.

Note: Security Review did not run due to the size of the PR.

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

Serving the uploads directory directly via express.static exposes all uploaded files, including potentially sensitive user profile pictures (PII), to the public without any authentication. Anyone with a direct link could access these files.

For better security, all sensitive files should be served through an authenticated route that verifies the user's permission to access the file. Alternatively, using a cloud storage service that supports signed URLs with a short expiration time (like the newly added Cloudinary integration) would be a more robust solution.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +5 to +55
const parseNearbyQueryParams = (query = {}) => {
const latitudeRaw = query.latitude ?? query.lat;
const longitudeRaw = query.longitude ?? query.lng;

if (latitudeRaw === undefined || longitudeRaw === undefined) {
throw new Error('Latitude and longitude are required.');
}

const latitude = Number(latitudeRaw);
const longitude = Number(longitudeRaw);

if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) {
throw new Error('Invalid coordinates provided.');
}

const radiusKmRaw =
query.radiusKm !== undefined
? Number(query.radiusKm)
: query.radiusMeters !== undefined
? Number(query.radiusMeters) / 1000
: query.maxDistance !== undefined
? Number(query.maxDistance) / 1000
: query.radius !== undefined
? Number(query.radius)
: 10;

const radiusUnit = String(query.radiusUnit || '').toLowerCase();
let radiusKm = radiusKmRaw;

if (radiusUnit === 'm' || radiusUnit === 'meter' || radiusUnit === 'meters') {
radiusKm = radiusKmRaw / 1000;
} else if (
radiusUnit === 'km' ||
radiusUnit === 'kilometer' ||
radiusUnit === 'kilometers'
) {
radiusKm = radiusKmRaw;
} else if (query.radius !== undefined && radiusKmRaw > 1000) {
// Backward compatibility: some clients pass radius in meters.
radiusKm = radiusKmRaw / 1000;
}

if (!Number.isFinite(radiusKm) || radiusKm <= 0) {
radiusKm = 10;
}

return {
center: { lat: latitude, lng: longitude },
radiusKm,
};
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The parseNearbyQueryParams function is duplicated from LifeLine-Backend/src/api/Location/Location.controller.mjs. This duplication makes the code harder to maintain, as any changes or bug fixes would need to be applied in both places.

To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, this function should be extracted into a shared utility file (e.g., in a src/utils directory) and imported into both controllers.

Comment on lines +241 to +269
acceptedHelpers: [
{
helperId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Auth',
},
serviceType: {
type: String,
},
amount: {
type: Number,
min: 0,
},
method: {
type: String,
enum: ['cash', 'upi', 'card'],
},
paymentId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Payment',
},
paymentStatus: {
type: String,
enum: ['pending', 'approved', 'verified', 'released', 'failed', 'free'],
default: 'free',
},
acceptedAt: Date,
},
],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The schema introduces a new acceptedHelpers array. This seems to duplicate information that could be derived from the status field within the existing assignedHelpers array (e.g., when a helper's status is 'accepted').

Maintaining two separate lists for assigned and accepted helpers can lead to data inconsistency and complicates the logic for managing helper states. Consider relying solely on the status within the assignedHelpers array to determine which helpers have accepted the request. This would centralize state management.

| **Helper** | ⚠️ Partial | Frontend config is wrong, but helperSlice uses correct `/api/helpers/v1/*`. |
| **Emergency** | ✅ Mostly Match | Core flows align; new features missing in frontend config. |
| **Medical** | ✅ Match | Frontend `medicalSlice` uses `/api/medical/v1/*` correctly. |
| **Notifications** | ❌ Missing | Frontend calls `/api/notifications/v1/*` but backend has no route registered. |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This report indicates that notification routes are missing in the backend. However, this same pull request adds the necessary notification routes in LifeLine-Backend/src/api/Notifications/v1/Notification.routes.mjs and registers them in server.mjs.

This discrepancy makes the documentation inconsistent with the codebase. Please update this document to reflect the latest changes to avoid confusion for future development and testing.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a set of risk-assessment and testing/design documents for SOS upgrade + AI triage flows, alongside substantial frontend/backend implementation updates to support location stabilization, SOS orchestration, notifications, payments, and triage-to-existing-emergency binding.

Changes:

  • Added multiple docs: SOS upgrade/triage Postman guides, HLD/LLD specs, and consolidated risk assessment/index docs.
  • Frontend: implemented location stabilization, SOS runtime bootstrap/recovery, expanded API endpoint mappings, and updated multiple screens/slices to align with new flows.
  • Backend: added Notifications + Payments routers/controllers/models, extended Emergency + Helper models/services, and updated triage handlers to bind/update existing emergencies.

Reviewed changes

Copilot reviewed 106 out of 109 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
docs/tests/sos-upgrade-postman-testing.md Postman guide for SOS upgrade (payment/OTP/profile/stats).
docs/tests/sos-first-triage-postman-testing.md Postman guide for SOS-first + AI triage enrichment flow.
docs/sos-upgrade-hld-lld.md HLD/LLD spec for SOS upgrade roadmap (payments/OTP/profile/stats).
docs/risk-assessment-doc-mismatches.md Doc mismatch tracking and appendix index.
docs/future-implementation-summary.md Consolidated future work sequencing across subsystems.
docs/codebase-risk-assessment.md Executive summary index for risk assessment reports.
docs/ai-triage-sos-hld-lld.md HLD/LLD spec for AI triage → SOS integration and rules.
ai-logs/Frontend/frontend-location-accuracy-change-log-2026-03-10.md Log describing frontend location accuracy changes.
ai-logs/Frontend/frontend-location-accuracy-change-log-2026-03-10-2026-03-10_17-54-21.md Duplicate/detailed log copy incl. doc sync notes.
ai-logs/Backend/.gitkeep Keeps backend ai-logs directory tracked.
Lifeline-Frontend/tsconfig.json TS compiler settings adjustments (bundler resolution, libs).
Lifeline-Frontend/src/utils/filePicker.utils.ts Image picker defaults (square crop, reduced quality).
Lifeline-Frontend/src/shared/utils/locationStabilizer.ts New location filtering/smoothing + emit decision logic.
Lifeline-Frontend/src/shared/utils/error.utils.ts Type cleanup for API error payload shape.
Lifeline-Frontend/src/shared/tasks/location.task.ts Background location task stabilization + socket readiness + role support.
Lifeline-Frontend/src/shared/store/middleware/socketMiddleware.ts Update socket service import style.
Lifeline-Frontend/src/shared/services/speech.service.ts Lint suppression for require + simplified catch.
Lifeline-Frontend/src/shared/services/socket.service.ts Adds role/userId to location update + triage emergencyId param + import style.
Lifeline-Frontend/src/shared/hooks/useSocket.ts Socket hook import cleanup and unused selector removal.
Lifeline-Frontend/src/shared/hooks/useBackgroundLocation.ts Background tracking options updated (highest accuracy, 5s intervals).
Lifeline-Frontend/src/features/emergency/services/triageApi.service.ts Triage API supports emergencyId binding + typed emergencyData.
Lifeline-Frontend/src/features/emergency/hooks/useEmergency.ts SOS-first triage flow: trigger SOS first, then start triage with emergencyId.
Lifeline-Frontend/src/features/emergency/emergencySlice.ts Adds payment/OTP/profile thunks; enhances accept helper payload.
Lifeline-Frontend/src/features/auth/screens/WelcomeScreen.tsx Removes unused theme destructuring.
Lifeline-Frontend/src/features/auth/screens/VerifySkillsScreen.tsx Formatting cleanup; removes unused loading state.
Lifeline-Frontend/src/features/auth/screens/UserInfo.tsx Better image metadata handling (mime type + filename normalization).
Lifeline-Frontend/src/features/auth/screens/UniversalMap.tsx Removes unused Platform import.
Lifeline-Frontend/src/features/auth/screens/SecureLocationScreen.tsx Reverse-geocode enrichment with multiple providers + race protection.
Lifeline-Frontend/src/features/auth/screens/MedicalInfoScreen.tsx Removes unused imports/selectors and tightens variable usage.
Lifeline-Frontend/src/features/auth/screens/EmergencyContacts.tsx Hook dependency fixes + const correctness.
Lifeline-Frontend/src/features/auth/medicalSlice.ts Switches to named api import; formatting cleanup.
Lifeline-Frontend/src/features/auth/locationSlice.ts Switches to named api import.
Lifeline-Frontend/src/features/auth/authSlice.ts Switches to named api import; FormData header handling cleanup.
Lifeline-Frontend/src/features/User/Component/UserNav.tsx Tailwind class ordering cleanup.
Lifeline-Frontend/src/features/SOS/sos.orchestrator.ts New SOS activation orchestration + pending intent persistence.
Lifeline-Frontend/src/features/SOS/SOSRuntimeBootstrapper.tsx New runtime bootstrapper for triggers (deeplink, native power button, recovery).
Lifeline-Frontend/src/features/Helper/helperSlice.ts Align helper endpoints + adds helper stats thunk.
Lifeline-Frontend/src/features/Helper/Dashbard/v1/Components/StatusToggle.tsx Persists helper role/availability for background tracking and awaits start/stop.
Lifeline-Frontend/src/features/Helper/Case/Components/SOSCard.tsx UI refactor: richer priority styling and metadata display.
Lifeline-Frontend/src/core/Providers.tsx Fixes imports and store typing usage.
Lifeline-Frontend/src/core/Navigation.tsx Removes unused React import (component stub).
Lifeline-Frontend/src/config/socket.ts Trims env socket URL for safer config parsing.
Lifeline-Frontend/src/config/api.ts Named api export + expanded endpoint map (notifications, payments, emergency payment endpoints).
Lifeline-Frontend/src/ai/sarvam-stt.ts Removes unused FileSystem import.
Lifeline-Frontend/app/_layout.tsx Adds SOSRuntimeBootstrapper into app root.
Lifeline-Frontend/app/User/Profile/SavedAddressScreen.tsx Uses Alert instead of unused error state; removes unused TextAreaField.
Lifeline-Frontend/app/User/Profile/AccountDetails.tsx Removes unused local imports; delegates to feature component.
Lifeline-Frontend/app/User/Nearby.tsx Uses named api import; minor formatting.
Lifeline-Frontend/app/User/IncomeUserSOS.tsx UI refactor for incoming SOS list screen.
Lifeline-Frontend/app/User/Helper/HelperRequest.tsx Removes commented-out socketService example block.
Lifeline-Frontend/app/User/Dashboard.tsx Foreground/background location mode switching + stabilization + SOS hold time tweak.
Lifeline-Frontend/app/Helper/publicProfile[id].tsx Removes unused router params/navigation hooks.
Lifeline-Frontend/app/Helper/_layout.tsx Adds Case screen into stack and adjusts CaseDetails registration.
Lifeline-Frontend/app/Helper/SOSProfile.tsx Placeholder SOS profile screen.
Lifeline-Frontend/app/Helper/Notifications.tsx Notifications list UI refactor + fetch logic cleanup.
Lifeline-Frontend/app/Helper/EmergencyDetaill.tsx Uses named api import; removes unused imports.
Lifeline-Frontend/app/Helper/Dashboard.tsx Adds helper foreground location reporting when available.
Lifeline-Frontend/app/Helper/Case.tsx New incoming SOS cases UI screen (static data).
Lifeline-Frontend/app/(main)/_layout.tsx Removes unused react-native imports.
Lifeline-Frontend/app/(main)/SignUp.tsx Formatting + safer coordinate parsing.
Lifeline-Frontend/app/(main)/Login.tsx Effect deps updated to include router.
Lifeline-Frontend/app/(main)/Home.tsx Removes test-only navigation helper and unused imports.
Lifeline-Frontend/app/(global)/SOSActiveAIScreen.tsx Formatting cleanup and minor layout adjustments.
Lifeline-Frontend/app.json Adds custom power-button plugin; formatting cleanup.
Lifeline-Frontend/Dockerfile Adds container config for running Expo dev server.
LifeLine-Backend/src/utils/multer.utils.mjs Allows HEIC/HEIF image uploads.
LifeLine-Backend/src/utils/cloudinary.utils.mjs Adds Cloudinary upload/delete helper utility.
LifeLine-Backend/src/socket/handlers/triage.handler.mjs Supports emergencyId binding + updates existing emergency from triage.
LifeLine-Backend/src/socket/SOCKET_API.md Updates socket docs for location cadence/filtering + payload fields.
LifeLine-Backend/src/server.mjs Serves /uploads statically; mounts notifications + payments routes.
LifeLine-Backend/src/config/mongo.config.mjs Trims Mongo URI and forces IPv4 family option.
LifeLine-Backend/src/api/User/User.utils.mjs Includes profileImage in user responses.
LifeLine-Backend/src/api/User/User.service.mjs Accepts/updates profileImage fields.
LifeLine-Backend/src/api/Payment/Payment.utils.mjs CRUD helpers for Payment model.
LifeLine-Backend/src/api/Payment/Payment.routes.mjs Adds authenticated payments router (create/release).
LifeLine-Backend/src/api/Payment/Payment.model.mjs Adds Payment schema.
LifeLine-Backend/src/api/Payment/Payment.controller.mjs Adds Payment create/release endpoints.
LifeLine-Backend/src/api/Notifications/v1/Notification.routes.mjs Adds authenticated notifications routes.
LifeLine-Backend/src/api/Notifications/v1/Notification.controller.mjs Implements list/unread/read endpoints for notifications.
LifeLine-Backend/src/api/NGO/NGO.controller.mjs Robust nearby query parsing + geoNear aggregation and meta.
LifeLine-Backend/src/api/Location/Location.controller.mjs Robust nearby query parsing + meta in responses.
LifeLine-Backend/src/api/Helper/Helper.service.mjs Computes earnings from Payment collection instead of mock values.
LifeLine-Backend/src/api/Helper/Helper.routes.mjs Adds helper stats route.
LifeLine-Backend/src/api/Helper/Helper.model.mjs Adds earnings/performance fields to helper schema.
LifeLine-Backend/src/api/Helper/Helper.controller.mjs Adds helper stats controller method.
LifeLine-Backend/src/api/Emergency/Emergency.routes.mjs Adds payment approve/verify + SOS profile endpoints.
LifeLine-Backend/src/api/Emergency/Emergency.model.mjs Adds medicalInfo + payment fields + richer helper acceptance data.
LifeLine-Backend/src/api/Emergency/Emergency.controller.mjs Accept helper includes service/amount/method; adds approve/verify/profile endpoints.
LifeLine-Backend/src/api/Auth/v1/Auth.service.mjs Adds profile image public-id field handling.
LifeLine-Backend/src/api/Auth/v1/Auth.model.mjs Adds profileImagePublicId field.
LifeLine-Backend/src/Ai/triage/triageState.mjs Stores bound emergencyId in session state.
LifeLine-Backend/src/Ai/triage/triageService.mjs Supports emergencyId binding and ownership validation via effective userId.
LifeLine-Backend/src/Ai/triage/triage.controller.mjs Supports emergencyId binding and emergency update vs create.
LifeLine-Backend/docs/api-mismatch-report.md Updates mismatch report contents (now partially stale vs current PR).
LifeLine-Backend/docs/20-End-to-End-Workflows.md Formatting + updated location tracking behavior description.
LifeLine-Backend/docs/16-Backend-Features-Guide.md Formatting + location tracking behavior updates.
LifeLine-Backend/docs/11-Socket-Protocol.md Formatting + expanded location event/payload documentation.
LifeLine-Backend/docs/04-Business-Logic-and-Rules.md Formatting + updated location tracking rule description.
LifeLine-Backend/docker-compose.yml Adds mongo service + env + log rotation options.
LifeLine-Backend/.env.example Adds Cloudinary config variables; formatting fix.
.gitignore Adds Windows AppData ignores.
Comments suppressed due to low confidence (1)

Lifeline-Frontend/src/shared/services/socket.service.ts:234

  • Socket re-registration on reconnect calls registerUser(this.state.userId) but SocketServiceState does not track the user's role, so reconnects will typically re-register without a role. Since backend logic can depend on socket.userRole for location handling, consider persisting role in service state and always emitting { userId, role } once known.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +5
# Codebase Risk Assessment (LifeLine)

Date: 2026-03-10
Scope: Backend, Frontend, and Documentation
Method: Static review of code paths and configuration. No runtime tests executed.
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says "docs only", but this PR includes substantial runtime code changes (frontend + backend: sockets, location tracking, payment/notification routes, etc.). Please update the PR description/testing notes to reflect that this is not a docs-only change so reviewers apply the right level of scrutiny and CI expectations.

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +37
setErrorMessage(null);
setLoading(true);
const response = await api.get(`/api/notifications/v1/user/${userId}`);
const data = response?.data?.data;
setNotifications(Array.isArray(data) ? data : []);
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This screen fetches notifications from /api/notifications/v1/user/${userId}, but the backend notifications router exposes GET /api/notifications/v1 (scoped by the authenticated user) and does not define a /user/:id path. As written, this request will 404 in production; switch to API_ENDPOINTS.NOTIFICATIONS.LIST (or equivalent) and rely on auth for scoping.

Copilot uses AI. Check for mistakes.
| **Helper** | ⚠️ Partial | Frontend config is wrong, but helperSlice uses correct `/api/helpers/v1/*`. |
| **Emergency** | ✅ Mostly Match | Core flows align; new features missing in frontend config. |
| **Medical** | ✅ Match | Frontend `medicalSlice` uses `/api/medical/v1/*` correctly. |
| **Notifications** | ❌ Missing | Frontend calls `/api/notifications/v1/*` but backend has no route registered. |
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc still states that the backend does not register /api/notifications/v1/* routes, but src/server.mjs in this PR now mounts notificationRoutes at /api/notifications/v1. Please update this mismatch report accordingly (otherwise it will immediately be stale/misleading).

Suggested change
| **Notifications** | ❌ Missing | Frontend calls `/api/notifications/v1/*` but backend has no route registered. |
| **Notifications** | ✅ Match | Frontend and backend both use `/api/notifications/v1/*`. |

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +15
try {
const { emergencyId, helperId, userId, amount, method, serviceType } =
req.body;
const payment = await PaymentUtils.createPayment({
emergencyId,
helperId,
userId,
amount,
method,
serviceType,
});
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createPayment trusts helperId and userId from the request body. This allows any authenticated caller to create payments on behalf of other users/helpers. Derive userId from req.user.userId and validate that (emergencyId, helperId) correspond to an actual assignment/acceptance before creating a payment record.

Copilot uses AI. Check for mistakes.
Comment on lines +25 to +29
const payment = await PaymentUtils.updatePaymentStatus(
paymentId,
'released',
);
res.status(200).json({ success: true, data: payment });
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

releasePayment unconditionally marks any payment as released for any authenticated user, with no authorization (owner/assigned helper) and no state-transition validation (e.g., only after OTP verification). This is a critical escalation path. Enforce that the caller is allowed to release this payment (likely the emergency owner) and that the current status allows transition to released; return 404/403/409 accordingly when violated.

Suggested change
const payment = await PaymentUtils.updatePaymentStatus(
paymentId,
'released',
);
res.status(200).json({ success: true, data: payment });
// Load the payment first to perform authorization and state checks
const payment = await PaymentUtils.getPaymentById(paymentId);
if (!payment) {
return res
.status(404)
.json({ success: false, message: 'Payment not found' });
}
// Determine caller identity from common auth properties
const callerId =
(req.user && req.user.id) ||
req.userId ||
(req.auth && (req.auth.id || req.auth.userId));
if (!callerId) {
// Authenticated context is expected here; treat missing caller as forbidden
return res
.status(403)
.json({ success: false, message: 'Forbidden' });
}
// Only the emergency owner or assigned helper is allowed to release the payment
if (payment.userId !== callerId && payment.helperId !== callerId) {
return res
.status(403)
.json({ success: false, message: 'Forbidden' });
}
// Enforce valid state transition to "released"
if (payment.status !== 'otp_verified') {
return res.status(409).json({
success: false,
message: 'Invalid payment status for release',
});
}
const updatedPayment = await PaymentUtils.updatePaymentStatus(
paymentId,
'released',
);
res.status(200).json({ success: true, data: updatedPayment });

Copilot uses AI. Check for mistakes.
Comment on lines +124 to +170
useEffect(() => {
if (!userId || !isAvailable) return;

let isActive = true;
let timerId: ReturnType<typeof setInterval> | null = null;

const reportLocation = async () => {
try {
if (!isActive) return;
if (!socketService.isConnected()) {
socketService.connect();
return;
}

socketService.registerUser(userId, "helper");

const loc = await ExpoLocation.getCurrentPositionAsync({
accuracy: ExpoLocation.Accuracy.Highest,
mayShowUserSettingsDialog: true,
});

socketService.updateLocation({
latitude: loc.coords.latitude,
longitude: loc.coords.longitude,
accuracy: loc.coords.accuracy || undefined,
altitude: loc.coords.altitude || undefined,
speed: loc.coords.speed || undefined,
heading: loc.coords.heading || undefined,
userId,
role: "helper",
timestamp: new Date().toISOString(),
});
} catch (error) {
console.error("Helper foreground location report failed:", error);
}
};

const bootstrap = async () => {
const { status } = await ExpoLocation.requestForegroundPermissionsAsync();
if (status !== "granted") {
console.warn("Helper foreground location permission denied.");
return;
}

await reportLocation();
timerId = setInterval(reportLocation, HELPER_LOCATION_UPDATE_INTERVAL_MS);
};
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper dashboard starts a foreground setInterval location reporter when isAvailable is true, but availability toggle also starts background tracking via useBackgroundLocation(). Without coordinating foreground vs background modes (like the user dashboard does with AppState), helpers may emit duplicate location updates and drain battery. Consider switching modes based on app state or disabling the background task while this foreground loop is active.

Copilot uses AI. Check for mistakes.
);
// /api/helpers/v1/checkCurrentAvailability/699ac6a6e6b3b33cff46e09b
router.post('/', AuthMiddleware.authenticate, HelperController.createHelper);
router.get('/stats/:id', HelperController.getHelperStats);
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GET /stats/:id is added without AuthMiddleware.authenticate, unlike other sensitive helper endpoints. This exposes earnings/performance data publicly by helper ID. Add auth middleware here and enforce that only the helper (or an admin role) can access their stats.

Suggested change
router.get('/stats/:id', HelperController.getHelperStats);
router.get(
'/stats/:id',
AuthMiddleware.authenticate,
HelperController.getHelperStats,
);

Copilot uses AI. Check for mistakes.
Comment on lines 92 to 96
LOGIN: "/api/auth/v1/login",
REGISTER: "/api/auth/v1/create/user/auth",
CHECK_EMAIL: "/api/auth/v1/check-email",
VERIFY_EMAIL: "/api/auth/v1/verify-email",
CHECK_EMAIL: (email: string) => `/api/auth/v1/check-email/${email}`,
VERIFY_EMAIL: (token: string) => `/api/auth/v1/verify-email/${token}`,
FORGOT_PASSWORD: "/api/auth/v1/forgot-password",
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHECK_EMAIL and VERIFY_EMAIL embed user-provided values directly into the URL path. Emails/tokens can contain characters that must be URL-encoded (e.g., +, @, /). Encode these path segments (e.g., encodeURIComponent) at construction time to avoid broken requests.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 106 out of 109 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants