Skip to content

abdelaziz-belhachmi/Dynamic-Emergency-Routing-with-Blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏙️ Smart City - Dynamic Emergency Routing with Blockchain

Système de Routage Dynamique pour Véhicules d'Urgence avec Hyperledger Fabric


📋 Quick Start

# 1. Install everything (Docker, Node.js, Fabric, dependencies)
./install.sh

# 2. Start the entire system
./start.sh

# 3. Open in browser
# Frontend: http://localhost:3001
# Backend:  http://localhost:3000

# 4. Stop the system
./stop.sh

🏗️ Architecture

┌─────────────────────────────────────────────────────────────┐
│                    Frontend React                           │
│  - Dashboard interactif (Material-UI)                       │
│  - Carte de ville en grille 10×10                          │
│  - WebSocket temps réel                                     │
│                       Port 3001                             │
└─────────────────────────────────────────────────────────────┘
                            ↕ HTTP/WebSocket
┌─────────────────────────────────────────────────────────────┐
│                  Backend Node.js API                        │
│  - Express.js + Socket.IO                                   │
│  - Hyperledger Fabric SDK                                   │
│  - Winston Logger                                           │
│                       Port 3000                             │
└─────────────────────────────────────────────────────────────┘
                            ↕ Fabric SDK (gRPC)
┌─────────────────────────────────────────────────────────────┐
│              Réseau Hyperledger Fabric 2.5                  │
│                                                             │
│   ┌──────────────┐  ┌──────────────┐  ┌──────────────┐    │
│   │   CityOrg    │  │ HospitalOrg  │  │   FireOrg    │    │
│   │  peer0/peer1 │  │  peer0/peer1 │  │  peer0/peer1 │    │
│   └──────────────┘  └──────────────┘  └──────────────┘    │
│                                                             │
│   ┌──────────────┐         ┌─────────────────────┐        │
│   │  PoliceOrg   │         │      Orderer        │        │
│   │  peer0/peer1 │         │   (RAFT Consensus)  │        │
│   └──────────────┘         └─────────────────────┘        │
│                                                             │
│   Channel: routing | Chaincode: DynamicRoutingCC (JS)      │
└─────────────────────────────────────────────────────────────┘

📁 Project Structure

blockchain/
├── install.sh              # Install all dependencies
├── start.sh                # Start entire system
├── stop.sh                 # Stop entire system
│
├── chaincode/              # Smart Contract (Hyperledger Fabric)
│   ├── lib/
│   │   └── dynamicRouting.js
│   ├── index.js
│   └── package.json
│
├── network/                # Hyperledger Fabric Network Configuration
│   ├── configtx.yaml
│   ├── crypto-config.yaml
│   ├── docker-compose.yaml
│   └── scripts/
│       ├── create-channel.sh
│       └── deploy-chaincode.sh
│
├── backend/                # Node.js REST API
│   ├── src/
│   │   ├── server.js
│   │   ├── fabric.js
│   │   └── routes/
│   │       ├── vehicles.js
│   │       ├── emergencies.js
│   │       ├── routing.js
│   │       └── system.js
│   └── package.json
│
└── frontend/               # React Dashboard
    ├── public/
    ├── src/
    │   ├── App.js
    │   ├── components/
    │   │   ├── Layout.js
    │   │   ├── CityMap.js
    │   │   ├── VehiclePanel.js
    │   │   ├── EmergencyPanel.js
    │   │   ├── StatsPanel.js
    │   │   └── TransactionLog.js
    │   └── services/
    │       └── api.js
    └── package.json

🔧 API Endpoints

Vehicles

Method Endpoint Description
GET /api/vehicles List all vehicles
POST /api/vehicles/register Register new vehicle
GET /api/vehicles/:id Get vehicle by ID
PUT /api/vehicles/:id/position Update position

Emergencies

Method Endpoint Description
GET /api/emergencies/active List active emergencies
POST /api/emergencies/declare Declare emergency

Routing

Method Endpoint Description
POST /api/routing/calculate Calculate route
POST /api/routing/reserve Reserve route
POST /api/routing/recalculate Recalculate after blockage

System

Method Endpoint Description
GET /api/system/stats System statistics
GET /api/system/health Health check
POST /api/system/attack Simulate attack

🚗 Vehicle Types

Type Icon Priority
NORMAL 🚗 0
AMBULANCE 🚑 10+
FIRE 🚒 10+
POLICE 🚓 10+

🚨 Emergency Types

  • ACCIDENT - Traffic accident
  • FIRE - Fire emergency
  • MEDICAL - Medical emergency
  • CRIME - Criminal incident

🔒 Security Features

  • MSP (Membership Service Provider) - Organization authentication
  • TLS - Encrypted communications
  • Endorsement Policy - Multi-org consensus validation
  • Immutability - Unalterable transaction history
  • Attack Detection - Simulated attack blocking

Simulated Attack Types

  • DOUBLE_RESERVATION - Double booking attempt
  • FAKE_EMERGENCY - False emergency declaration
  • ROUTE_HIJACK - Route tampering attempt

🌐 Ports Used

Service Port
Frontend React 3001
Backend API 3000
Orderer 7050
CityOrg Peer0 7051
CityOrg Peer1 7151
HospitalOrg Peer0 8051
HospitalOrg Peer1 8151
FireOrg Peer0 9051
FireOrg Peer1 9151
PoliceOrg Peer0 10051
PoliceOrg Peer1 10151

📝 Troubleshooting

Docker permission error

# Add user to docker group
sudo usermod -aG docker $USER
# Logout and login, or run:
newgrp docker

Ports already in use

# Check what's using the port
sudo lsof -i :3000
sudo lsof -i :3001
# Kill the process
kill -9 <PID>

Reset everything

./stop.sh  # Answer 'y' to clean up data
./start.sh

📄 License

Apache-2.0


👥 Organizations

Organization Role Peers
CityOrg Municipal management peer0, peer1
HospitalOrg Hospital services (ambulances) peer0, peer1
FireOrg Fire services peer0, peer1
PoliceOrg Police services peer0, peer1

About

Système de Routage Dynamique pour Véhicules d'Urgence avec Hyperledger Fabric

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published