How sai8143/safenex works
SafeNex detects road collisions from uploaded images or continuous CCTV streams, confirms incidents, stores evidence and accident records, then dispatches location-aware alerts to emergency departments. The mobile app provides a camera/GPS reporting flow plus department and history interfaces. The graph follows the documented workflow and relationships visible in the supplied excerpts and SOURCE INDEX; portal page files and several service implementations were not included in the file tree or sampled source.
Main entry points: main.py FastAPI routes · rtsp_stream.py RTSP stream worker · video_detector.py Stream frame pipeline · api.js Mobile API client
Components 24
Mobile reporting
- Mobile tabs
mobile-app/App.js - Camera and GPS
mobile-app/src/screens/CameraScreen.js - Mobile API client
mobile-app/src/services/api.js - Backend URL config
mobile-app/src/config.js - Impact trigger
mobile-app/src/utils/impactDetector.js - Department portals
mobile-app/src/screens/DepartmentScreens.js - Accident history
mobile-app/src/screens/HistoryScreen.js - Connection settings
mobile-app/src/screens/SettingsScreen.js
Detection and ingest
- FastAPI routes
backend/app/main.py - RTSP stream worker
backend/app/services/rtsp_stream.py
Incident analysis
- Stream frame pipeline
backend/app/services/video_detector.py - Vehicle and damage detection
backend/app/services/ai_detector.py - Vehicle tracking
backend/app/services/tracker.py - Temporal verification
backend/app/services/temporal_filter.py - Accident decision and severity
backend/app/services/decision_engine.py
Persistence and response
- Emergency alert builder
backend/app/services/notifier.py - Facility distance and ETA
backend/app/services/location.py - WebSocket broadcaster
backend/app/services/websocket_manager.py - Accident database
backend/app/database.py - Accident records
backend/app/models.py
Other components
- Camera operator
- CCTV / webcam
- Hospital / police / EMS
- Surveillance dashboard
backend/app/main.py
Connections 37
- Camera operator → Mobile tabs: uses
mobile-app/App.js - Mobile tabs → Camera and GPS: shows
mobile-app/App.js - Mobile tabs → Department portals: shows
mobile-app/App.js - Mobile tabs → Connection settings: shows
mobile-app/App.js - Camera and GPS → Mobile API client: sends image
mobile-app/src/screens/CameraScreen.js - Camera and GPS → Impact trigger: uses
mobile-app/src/screens/CameraScreen.js - Mobile API client → Backend URL config: gets endpoint
mobile-app/src/services/api.js - Mobile API client → FastAPI routes: posts alert
mobile-app/src/services/api.js - Department portals → Mobile API client: uses
mobile-app/src/screens/DepartmentScreens.js - Accident history → Mobile API client: uses
mobile-app/src/services/api.js - Connection settings → Mobile API client: uses
mobile-app/src/screens/SettingsScreen.js - CCTV / webcam → RTSP stream worker: provides frames
README.md - CCTV / webcam → FastAPI routes: uploads frames
README.md - FastAPI routes → Vehicle and damage detection: analyzes image
backend/app/main.py - FastAPI routes → Stream frame pipeline: analyzes frame
backend/app/main.py - FastAPI routes → RTSP stream worker: starts stream
backend/app/main.py - RTSP stream worker → Stream frame pipeline: processes frames
backend/app/services/rtsp_stream.py - RTSP stream worker → Vehicle and damage detection: analyzes evidence
backend/app/services/rtsp_stream.py - Stream frame pipeline → Vehicle and damage detection: detects vehicles
backend/app/services/video_detector.py - Stream frame pipeline → Vehicle tracking: tracks vehicles
backend/app/services/video_detector.py - Stream frame pipeline → Temporal verification: verifies persistence
backend/app/services/video_detector.py - Stream frame pipeline → Accident decision and severity: evaluates incident
backend/app/services/video_detector.py - Vehicle and damage detection → Accident decision and severity: classifies evidence
backend/app/services/ai_detector.py - FastAPI routes → Accident database: uses sessions
backend/app/main.py - FastAPI routes → Accident records: reads and writes
backend/app/main.py - RTSP stream worker → Accident database: persists incident
backend/app/services/rtsp_stream.py - RTSP stream worker → Accident records: creates record
backend/app/services/rtsp_stream.py - FastAPI routes → Emergency alert builder: dispatches confirmed
README.md - RTSP stream worker → Emergency alert builder: notifies on confirmation
backend/app/services/rtsp_stream.py - Emergency alert builder → Facility distance and ETA: calculates facilities
backend/app/services/notifier.py - Emergency alert builder → WebSocket broadcaster: broadcasts alerts
backend/app/services/notifier.py - WebSocket broadcaster → Hospital / police / EMS: pushes alerts
README.md - FastAPI routes → Surveillance dashboard: serves dashboard
backend/app/main.py - Surveillance dashboard → WebSocket broadcaster: receives live alerts
README.md - Emergency alert builder → Hospital / police / EMS: dispatches response
README.md - FastAPI routes → Accident records: lists history
backend/app/main.py - FastAPI routes → WebSocket broadcaster: routes socket clients
backend/app/main.py