mirror of
https://github.com/blackboxprogramming/BlackRoad-Operating-System.git
synced 2026-03-17 07:57:19 -05:00
This commit transforms the BlackRoad OS from a static mockup into a fully functional web-based operating system with real backend integration. ## Major Changes ### Backend (New Features) 1. **Device Management System** (IoT/Raspberry Pi) - New models: Device, DeviceMetric, DeviceLog - Router: /api/devices with full CRUD operations - Device heartbeat system for status monitoring - Metrics tracking (CPU, RAM, temperature) 2. **Mining Stats & Control** (RoadCoin Miner) - Router: /api/miner with status, stats, control endpoints - Simulated mining with hashrate, shares, temperature - Start/stop mining controls - Lifetime statistics and recent blocks listing 3. **Static File Serving** - Backend now serves front-end from /backend/static/ - index.html served at root URL - API routes under /api/* namespace 4. **Updated User Model** - Added devices relationship ### Frontend (New Features) 1. **API Client Module** (api-client.js) - Centralized API communication layer - Automatic base URL detection (dev vs prod) - JWT token management with auto-refresh - Error handling and 401 redirects 2. **Authentication System** (auth.js) - Login/Register modal UI - Session persistence via localStorage - Auto-logout on token expiration - Keyboard shortcuts (Enter to submit) 3. **Application Modules** (apps.js) - Dynamic data loading for all desktop windows - Auto-refresh for real-time data (miner, blockchain) - Event-driven architecture - Lazy loading (data fetched only when window opens) 4. **Enhanced UI** - Added 380+ lines of CSS for new components - Auth modal styling - Miner dashboard layout - Blockchain explorer tables - Wallet balance display - Device management cards 5. **Live Window Integration** - RoadCoin Miner: Real mining stats, start/stop controls - RoadChain Explorer: Live blockchain data, mine block button - Wallet: Real-time balance, transaction history - Raspberry Pi: Device status dashboard - RoadMail: Live inbox from API - Social Feed: Real posts from database - BlackStream: Video grid from API - AI Assistant: Conversation UI ### Configuration - Updated .env.example with: - ROADCHAIN_RPC_URL, ROADCOIN_POOL_URL - MQTT broker settings for device management - Production CORS origins (www.blackroad.systems) - PORT configuration for Railway deployment ### Documentation - Added INTEGRATION_GUIDE.md (400+ lines) - Complete architecture overview - API endpoint documentation - Environment configuration guide - Development workflow - Troubleshooting section ## Technical Details - All windows now connect to real backend APIs - Authentication required before OS access - User-specific data isolation - Proper error handling and loading states - Retro Windows 95 aesthetic preserved ## What's Working ✅ Full authentication flow (login/register) ✅ Mining stats and control ✅ Blockchain explorer with live data ✅ Wallet with real balance ✅ Device management dashboard ✅ Email inbox integration ✅ Social feed integration ✅ Video platform integration ✅ Static file serving ✅ CORS configuration ## Future Enhancements - Real XMRig integration - WebSocket for real-time updates - MQTT broker for device heartbeats - OpenAI/Anthropic API integration - File uploads to S3 - Email sending via SMTP ## Files Added - backend/app/models/device.py - backend/app/routers/devices.py - backend/app/routers/miner.py - backend/static/index.html - backend/static/js/api-client.js - backend/static/js/auth.js - backend/static/js/apps.js - INTEGRATION_GUIDE.md ## Files Modified - backend/app/main.py (added routers, static file serving) - backend/app/models/user.py (added devices relationship) - backend/.env.example (added device & mining variables) Tested locally with Docker Compose (PostgreSQL + Redis). Ready for Railway deployment.
111 lines
3.7 KiB
Python
111 lines
3.7 KiB
Python
"""Device management models for IoT/Raspberry Pi integration."""
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
from sqlalchemy import Column, Integer, String, Boolean, DateTime, Float, JSON, ForeignKey, Text
|
|
from sqlalchemy.orm import relationship
|
|
from app.database import Base
|
|
|
|
|
|
class Device(Base):
|
|
"""IoT Device model - Raspberry Pi, Jetson, etc."""
|
|
|
|
__tablename__ = "devices"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
device_id = Column(String(100), unique=True, index=True, nullable=False) # Unique device identifier
|
|
name = Column(String(200), nullable=False) # User-friendly name
|
|
device_type = Column(String(50), nullable=False) # pi5, pi400, jetson, etc.
|
|
|
|
# Connection info
|
|
ip_address = Column(String(45)) # IPv4 or IPv6
|
|
hostname = Column(String(255))
|
|
mac_address = Column(String(17))
|
|
|
|
# Status
|
|
is_online = Column(Boolean, default=False)
|
|
status = Column(String(50), default="offline") # online, offline, error, maintenance
|
|
last_seen = Column(DateTime)
|
|
|
|
# System info
|
|
os_version = Column(String(100))
|
|
kernel_version = Column(String(100))
|
|
uptime_seconds = Column(Integer, default=0)
|
|
|
|
# Hardware specs
|
|
cpu_model = Column(String(200))
|
|
cpu_cores = Column(Integer)
|
|
ram_total_mb = Column(Integer)
|
|
disk_total_gb = Column(Integer)
|
|
|
|
# Current metrics
|
|
cpu_usage_percent = Column(Float, default=0.0)
|
|
ram_usage_percent = Column(Float, default=0.0)
|
|
disk_usage_percent = Column(Float, default=0.0)
|
|
temperature_celsius = Column(Float)
|
|
|
|
# Services running
|
|
services = Column(JSON, default=list) # List of active services
|
|
|
|
# Capabilities
|
|
capabilities = Column(JSON, default=list) # mining, sensor, camera, etc.
|
|
|
|
# Metadata
|
|
location = Column(String(200)) # Physical location
|
|
description = Column(Text)
|
|
tags = Column(JSON, default=list)
|
|
|
|
# Ownership
|
|
owner_id = Column(Integer, ForeignKey("users.id"))
|
|
owner = relationship("User", back_populates="devices")
|
|
|
|
# Timestamps
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Relations
|
|
metrics = relationship("DeviceMetric", back_populates="device", cascade="all, delete-orphan")
|
|
logs = relationship("DeviceLog", back_populates="device", cascade="all, delete-orphan")
|
|
|
|
|
|
class DeviceMetric(Base):
|
|
"""Time-series metrics for devices."""
|
|
|
|
__tablename__ = "device_metrics"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
device_id = Column(Integer, ForeignKey("devices.id", ondelete="CASCADE"), nullable=False)
|
|
|
|
# Metric data
|
|
timestamp = Column(DateTime, default=datetime.utcnow, index=True)
|
|
cpu_usage = Column(Float)
|
|
ram_usage = Column(Float)
|
|
disk_usage = Column(Float)
|
|
temperature = Column(Float)
|
|
network_bytes_sent = Column(Integer)
|
|
network_bytes_received = Column(Integer)
|
|
|
|
# Custom metrics (JSON for flexibility)
|
|
custom_data = Column(JSON, default=dict)
|
|
|
|
# Relationship
|
|
device = relationship("Device", back_populates="metrics")
|
|
|
|
|
|
class DeviceLog(Base):
|
|
"""Device event logs."""
|
|
|
|
__tablename__ = "device_logs"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
device_id = Column(Integer, ForeignKey("devices.id", ondelete="CASCADE"), nullable=False)
|
|
|
|
# Log data
|
|
timestamp = Column(DateTime, default=datetime.utcnow, index=True)
|
|
level = Column(String(20), nullable=False) # info, warning, error, critical
|
|
category = Column(String(50)) # system, network, service, hardware
|
|
message = Column(Text, nullable=False)
|
|
details = Column(JSON, default=dict)
|
|
|
|
# Relationship
|
|
device = relationship("Device", back_populates="logs")
|