How mengxi47/red-safe works
Project Type and Purpose
• Full-stack, distributed edge-computing system
• Deep-learning inference at camera/edge, C++ API server, iOS client, SQL database, APNs integration
File Structure
• Top-level:
– api-server/ (C++ back-end, layered MVC-style: core, model, service, util)
– pytorch/ (Python deep-learning scripts: data prep, training, fall logic, packaging)
– docs/ (architecture image, interaction spec)
– server.crt/key (TLS for API server)
• Layering in api-server:
– core: HTTP server, controllers, session management
– service: business logic (user/device registration, login/logout, event routing)
– model: SQL connection manager, ORM-style SQL model
– util: logging, timestamp helpers
• pytorch:
– download_youtube.py, extract_data.py (data pipeline)
– fall_logic/{rule_based, model_based}
– model/lstm_model.py, ONNX/TensorRT packaging
– train.py, package_project.py, init_project.py, run_all.py
README for Insights
• Real-time fall/immobilization detection (<50 ms) on edge
• APNs for iOS push alerts
• Extensible to multi-camera, wearable heart-rate
Main Components
A. Edge Device (Camera + Edge Inference)
– Python runtime, ONNX Runtime/TensorRT
– Modules: data capture → preprocess → fall logic (rule/model-based) → event generation
B. API Server (C++ Service)
– Ingress: HTTPS/TLS
– Controller layer: request parsing, routing
– Service layer: registration, login, bind, event handling
– Model layer: SQL DB access
– Util layer: logging, timestamps
C. Database
– SQL (MySQL/SQLite) storing users, devices, sessions, events
D. External Services
– Apple Push Notification Service (APNs)
E. Clients
– iOS App (mobile)
– Future: Watch/heart-rate wearable
Relationships and Interactions
1. Edge device captures video → runs inferencing → on detection, POST event to API server
2. API server authenticates session, invokes Service layer → writes to DB → triggers APNs push
3. iOS App receives push → user views alert
4. User registration/login flows: mobile ↔ API server ↔ DB
5. Device registration/binding: mobile ↔ API server ↔ DB
Architectural Patterns & Principles
• Layered (Controller → Service → Model → Util)
• Separation of concerns: Inference at edge, business logic & persistence in API
• Event-driven notifications via APNs
• Extensibility: add new services or data sources by following service layer pattern