How gulatigarvit/firefly-backend-sih24 works
Project Type and Purpose
• Firefly-Backend is a Node.js (Express) API server for a dynamic fire evacuation system.
• It exposes REST endpoints to ingest real-time fire and BLE localization data, store and query information in MySQL (via Sequelize), notify external clients, and support path-planning and rescue operations.
File Structure
A. config/
• database.js – MySQL connection settings
• firebase.js – Firebase Cloud Messaging for push notifications
• http.js – global HTTP settings (ports, timeouts)
• enums.js – shared constants (status codes, roles)
B. models/
• building, city, fire_station, firefighter, incident, node (BLE beacon), user, incident_user
• index.js – sets up Sequelize models and relationships
C. controllers/ → HTTP layer
• building.js, fire_station.js, firefighter.js, incident.js, node.js, user.js
D. routes/ → Express.js routers wired to controllers
E. services/ → Business logic / data-access layer
• fire_station.js, incident.js, node.js, notification.js (wraps Firebase), user.js
F. middlewares/ → Cross-cutting concerns
• error handling, entity-exists checks
G. index.js → Bootstraps Express server, wires config, routes, error middleware
README for Additional Insights
• Tech Stack: Node.js/Express, MySQL + Sequelize
• Integrations:
• Mobile App (Flutter) for occupants
• Web Portal (React/TS) for fire stations/firefighters
• Arduino hardware (BLE sensors, fire detectors)
• Python Nav Engine (path planning & fire spread)
a. Main Components
1. IoT Layer: BLE sensors & fire detectors → publish sensor data (MQTT/HTTP) to Backend
2. Firefly API Server (Node.js/Express)
• HTTP REST endpoints (controllers + routes)
• Business logic (services)
• Middlewares for auth & validation
• Notification module (Firebase FCM)
3. Database (MySQL + Sequelize ORM)
4. External Services
• Firebase Cloud Messaging
• Path-Planning Service (Python nav engine)
5. Clients
• Mobile App (Flutter)
• Web Portal (React/TS)
b. Relationships & Data Flows
• BLE sensor → POST /nodes → node controller → service → DB
• Fire detector → POST /incident → incident controller → service → DB
• API Server → publishes notifications via Firebase → Mobile & Portal subscribe
• Clients query GET /incidents, GET /nodes, GET /routes
• API Server ↔ Path-Planning Service over HTTP/gRPC for dynamic route computation
c. Architectural Patterns & Principles
• Layered architecture: controllers (API), services (business), models (data)
• MVC-inspired separation (routes → controllers → services → models)
• Cross-cutting via Express middlewares
• Event-driven notifications (Firebase)
d. Key Technologies
• Node.js / Express.js
• Sequelize ORM → MySQL
• Firebase Cloud Messaging
• External Python microservice for navigation
• BLE sensors, Arduino firmware