Full-Stack IoT Architecture for Real-Time Earthquake Detection
Version 0.9.0 (Release Candidate)
QuakeGuard is a Full-Stack IoT architecture for real-time detection, analysis, and reporting of seismic events.
The system uses intelligent edge sensors (ESP32-C3) that analyze vibrations locally and transmit cryptographically secured data to an asynchronous cloud backend. The backend is engineered to handle the massive traffic spikes (Thundering Herd effect) typical during widespread earthquake events, ensuring reliable alarm delivery without bottlenecking. A React Native mobile app receives real-time haptic and visual alerts via WebSocket.
The project is highly modular, following Microservices and Event-Driven Design principles across three main layers:
- Hardware: ESP32-C3 SuperMini paired with an ADXL345 Accelerometer.
- Edge Computing: 100Hz sampling rate, applying Digital High-Pass Filters (HPF) and the STA/LTA (Short Term/Long Term Average) seismic algorithm directly on the device.
- Security: Hardware-level digital signing of payloads using ECDSA (NIST256p).
- Resilience: Temporal timestamp reconstruction to mitigate network latency and out-of-order packet delivery.
- Core API: Built with FastAPI (Python 3.11) for high-performance asynchronous routing.
- Security Layer: Dedicated
src/security.pymodule enforcing API Key authentication, ECDSA signature verification, and Anti-Replay timestamp validation on every IoT payload. - Event Pattern: Producer-Consumer architecture leveraging Redis as a Message Broker to decouple ingestion from processing. Includes a fixed-window Rate Limiter (50 req/s per IP).
- Real-Time Alerts: Redis Pub/Sub listener broadcasts CRITICAL seismic alerts to all connected mobile clients via WebSocket.
- Persistence: PostgreSQL + PostGIS for robust geospatial data management.
- Observability:
GET /healthendpoint for Docker/Kubernetes liveness probing, concurrently pinging both PostgreSQL and Redis. - Performance: Fully asynchronous architecture stress-tested at >500 Req/s with 150 concurrent sensors.
- Framework: React Native (Expo) with TypeScript for cross-platform compatibility.
- Architecture: Zustand for client-side state management, TanStack Query + Axios for server-state caching and background refetching.
- Real-Time: WebSocket context with exponential backoff reconnection, delivering live visual and haptic (SOS pattern) seismic alerts.
- Navigation: Expo Router file-based routing with a 3-tab Bottom Navigator (Monitor, Sensors Map, Settings).
Data integrity is paramount in emergency systems. Every telemetry packet transmitted by the edge sensors is cryptographically signed.
{
"value": 250,
"timestamp": 17000000,
"signature": "a1b2c3d4e5f6..."
}The backend verifies the signature (SHA256 + ECDSA) against the sensor's registered public key before accepting any payload. This strictly prevents Man-in-the-Middle (MitM) and Spoofing attacks, ensuring alarms cannot be falsely triggered by malicious actors. Replay attacks are blocked via a 60-second timestamp validation window.
- Docker & Docker Compose
- PlatformIO (VS Code Extension)
- Node.js 18+ & Expo Go (mobile app)
Before launching, set the required secrets:
cd backend-data-elaborator/api
cp .env.example .env
# Edit .env with your own IOT_API_KEY and MOBILE_WS_TOKENcd backend-data-elaborator/api
docker compose up --build -dThe backend will be live at http://localhost:8000.
API documentation is auto-generated at http://localhost:8000/docs.
Health status is available at http://localhost:8000/health.
- Edit
iot-data-harvester/esp32_config.envwith your local network IP and WiFi credentials. - Flash the firmware to the ESP32-C3 via PlatformIO.
⚠️ IMPORTANT: On first boot, copy the generatedPUBLIC KEYfrom the serial monitor and register the device via the Swagger UI athttp://localhost:8000/docs.
cd frontend-mobile-app
npm install
npx expo startScan the QR code with Expo Go. Ensure your phone is on the same WiFi network as the backend machine.
To validate the full backend pipeline (ingestion → Redis → worker → PostGIS → WebSocket alerts):
cd backend-data-elaborator/api
export API_URL="http://localhost:8000"
export NUM_SENSORS=150
export CONCURRENCY_LIMIT=50
python -m tests.stress_testA successful run ends with 🏆 SYSTEM CERTIFIED, confirming all three phases: load handling, security attack blocking, and E2E database persistence.
QuakeGuard/
├── backend-data-elaborator/
│ └── api/
│ ├── src/
│ │ ├── main.py # FastAPI gateway
│ │ ├── security.py # ECDSA, API Key, Anti-Replay
│ │ ├── worker.py # Redis consumer + alert engine
│ │ ├── models.py # SQLAlchemy models
│ │ ├── schemas.py # Pydantic schemas
│ │ └── database.py # DB engine and session
│ ├── tests/
│ │ └── stress_test.py # Critical E2E stress test
│ └── docker-compose.yml
├── frontend-mobile-app/
│ ├── app/ # Expo Router screens
│ ├── src/
│ │ ├── api/ # Axios client + TanStack Query hooks
│ │ └── store/ # Zustand state slices
│ └── context/
│ └── WebSocketContext.tsx # Real-time alert context
└── iot-data-harvester/
└── src/ # ESP32-C3 C++ firmware
Developed by GiZano
Open Source — AGPL-3.0 License