A production-ready Federated Learning system with three main components following the "Modern Privacy" stack.
fl-system/
├── fl-server/ # FastAPI backend with Socket.io
│ ├── main.py # Main server application
│ ├── fedavg_service.py # Federated Averaging algorithm
│ ├── requirements.txt # Python dependencies
│ └── Dockerfile # Docker configuration
├── fl-client/ # React frontend with TensorFlow.js
│ ├── src/
│ │ ├── App.js # Main React component
│ │ ├── App.css # Styling
│ │ ├── index.js # Entry point
│ │ └── trainingService.js # Training utilities
│ ├── public/
│ │ └── index.html
│ └── package.json
├── fl-dashboard/ # Next.js admin dashboard
│ ├── src/
│ │ ├── pages/
│ │ │ ├── _app.js
│ │ │ └── index.js
│ │ └── styles/
│ └── package.json
└── PLAN.md # Development plan
# Start all services
docker-compose up
# Access points:
# - FL Server: http://localhost:8000
# - FL Client: http://localhost:3000
# - Dashboard: http://localhost:5000# Install dependencies
cd fl-server
pip install -r requirements.txt
# Start the server
python main.pyServer will be available at http://localhost:8000
Available Endpoints:
GET /- API informationGET /health- Health checkGET /model/global- Get global model weightsPOST /model/update- Submit weight updateGET /stats- Server statisticsWS /ws/{client_id}- WebSocket connection
cd fl-client
npm install
npm startClient will be available at http://localhost:3000
Features:
- Connects to server via WebSocket
- Downloads global model automatically
- Trains model locally using TensorFlow.js
- Sends weight updates to server
- Real-time status updates
cd fl-dashboard
npm install
npm run devDashboard will be available at http://localhost:5000
Features:
- Real-time system health monitoring
- Model accuracy trends
- Client participation statistics
- Federated averaging progress
- Server Initialization: Server creates initial model weights
- Client Download: Clients connect and download global model
- Local Training: Clients train on their local data (TensorFlow.js)
- Weight Update: Clients send only weight updates (not raw data)
- Aggregation: Server performs Federated Averaging (FedAvg)
- Model Update: New global model is distributed to all clients
- Raw data never leaves user device
- Only model weight updates are shared
- Differential privacy support (client-side)
- No central storage of sensitive data
{
"status": "healthy",
"connected_clients": 5,
"model_version": 3
}{
"model": {
"version": 0,
"layers": [...],
"metadata": {...}
},
"model_version": 0,
"client_count": 5
}{
"client_id": "client_abc123",
"weights": {...},
"accuracy": 0.85,
"samples_trained": 1000
}Client to Server:
weight_update- Send weight updatesrequest_model- Request latest model
Server to Client:
model_update- Receive model updateupdate_received- Update acknowledgmenttraining_round_complete- Round completion notification
| Layer | Technology |
|---|---|
| Frontend | React.js + TensorFlow.js |
| Backend | FastAPI + Socket.io |
| ML | TensorFlow/Keras (server), TensorFlow.js (client) |
| Database | MongoDB (for model metadata) |
| Real-time | WebSockets (Socket.io) |
| Containerization | Docker |
Federated Learning System
+-------------+ +-----------------+ +-------------+
| Client 1 | | FL Server | | Dashboard |
| (React.js) |◄──►| (FastAPI) |◄──►| (Next.js) |
| Training | | Aggregation | | Monitoring |
+------+------+ +--------+--------+ +-------------+
| |
| Weight Updates |
| (WebSocket) |
v v
+-------------+ +-----------------+
| Client N | | FedAvg Service |
| Training | | Model Updates |
+-------------+ +-----------------+
# Health check
curl http://localhost:8000/health
# Get model
curl http://localhost:8000/model/global
# Get stats
curl http://localhost:8000/stats- Open multiple browser tabs at
http://localhost:3000 - Each tab gets a unique client ID
- Click "Train Local Model" on each
- Watch Dashboard for aggregation progress
- Client Authentication: Unique client IDs for tracking
- Secure Communication: WebSocket connections
- Differential Privacy: Optional noise addition (see
fl-client/src/differentialPrivacy.js) - No Raw Data Exposure: Only model weights transmitted
The Dashboard displays:
- Model accuracy over rounds
- Training loss trends
- Client participation rates
- Round completion times
- System resource utilization
- Phase 1: Environment and Backend Setup (Complete)
- Phase 2: Client-side training with real data
- Phase 3: Advanced Federated Averaging (secure aggregation)
- Phase 4: Enhanced Dashboard with more visualizations
MIT License - See LICENSE file for details
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
Built with for privacy-preserving machine learning