Backend Overview
Express API server providing REST endpoints and WebSocket real-time updates for traffic monitoring, integrating with Stellio Context Broker, Neo4j, Fuseki, and PostgreSQL.
Architectureβ
graph TB
subgraph "Express Backend :5000"
A[server.ts] --> B[Routes]
A --> C[Services]
A --> D[Agents]
A --> E[WebSocket Server]
B --> B1[Camera Routes]
B --> B2[Weather Routes]
B --> B3[AirQuality Routes]
B --> B4[Accident Routes]
B --> B5[Pattern Routes]
B --> B6[Analytics Routes]
B --> B7[Agent Routes]
C --> C1[StellioService]
C --> C2[Neo4jService]
C --> C3[FusekiService]
C --> C4[PostgresService]
C --> C5[WebSocketService]
C --> C6[DataAggregator]
D --> D1[EcoTwinAgent]
D --> D2[GraphInvestigatorAgent]
D --> D3[TrafficMaestroAgent]
end
subgraph "External Services"
F[(Stellio Context Broker)]
G[(Neo4j Graph DB)]
H[(Fuseki SPARQL)]
I[(PostgreSQL/TimescaleDB)]
J[Google Gemini AI]
K[Tavily Search API]
end
C1 --> F
C2 --> G
C3 --> H
C4 --> I
D1 --> J
D2 --> J
D2 --> K
D3 --> J
Key Featuresβ
RESTful APIβ
- 12 endpoint groups covering all traffic data types
- CORS-enabled for frontend integration
- Request validation with structured error handling
- YAML-driven configuration (
config/entities.yaml)
Real-Time Updatesβ
- WebSocket server for bidirectional communication
- Topic-based pub/sub (cameras, weather, accidents, etc.)
- Heartbeat mechanism with 30s timeout
- Automatic reconnection handling
AI Agentsβ
- EcoTwin: Environmental health advisor with AQI dispersion modeling
- GraphInvestigator: Multimodal incident analysis with GraphRAG
- TrafficMaestro: Predictive event-based congestion forecasting
Multi-Database Integrationβ
- Stellio: NGSI-LD entities (primary data source)
- Neo4j: Graph relationships and correlations
- Fuseki: SPARQL queries and LOD enrichment
- PostgreSQL: Temporal data and analytics
Source Structureβ
backend/src/
Γ’βΕΓ’ββ¬Γ’ββ¬ server.ts # Main Express server entry point
Γ’βΕΓ’ββ¬Γ’ββ¬ agents/ # AI agents (3 files)
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ EcoTwinAgent.ts
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ GraphInvestigatorAgent.ts
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ TrafficMaestroAgent.ts
Γ’βΕΓ’ββ¬Γ’ββ¬ config/ # Configuration loader
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ configLoader.ts
Γ’βΕΓ’ββ¬Γ’ββ¬ middlewares/ # Express middlewares
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ errorHandler.ts
Γ’βΕΓ’ββ¬Γ’ββ¬ routes/ # API route handlers (12 files)
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ cameraRoutes.ts
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ weatherRoutes.ts
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ airQualityRoutes.ts
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ ...
Γ’βΕΓ’ββ¬Γ’ββ¬ services/ # Data services (7 files)
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ stellioService.ts
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ neo4jService.ts
Γ’ββ Γ’βΕΓ’ββ¬Γ’ββ¬ fusekiService.ts
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ ...
Γ’βΕΓ’ββ¬Γ’ββ¬ types/ # TypeScript definitions
Γ’ββ Γ’ββΓ’ββ¬Γ’ββ¬ index.ts
Γ’ββΓ’ββ¬Γ’ββ¬ utils/ # Utility functions (5 files)
Γ’βΕΓ’ββ¬Γ’ββ¬ logger.ts
Γ’βΕΓ’ββ¬Γ’ββ¬ healthCheck.ts
Γ’ββΓ’ββ¬Γ’ββ¬ ...
Technology Stackβ
| Component | Technology | Version |
|---|---|---|
| Runtime | Node.js | 18+ |
| Framework | Express | 4.18+ |
| Language | TypeScript | 5.1+ |
| WebSocket | ws | 8.14+ |
| Database Clients | neo4j-driver, pg, sparql-http-client | - |
| AI SDK | @google/generative-ai | 0.21+ |
| Logging | Winston | 3.11+ |
Environment Configurationβ
# Server
PORT=5000
NODE_ENV=development
# CORS
CORS_ORIGIN=http://localhost:5173,http://localhost:3000
# Stellio Context Broker
STELLIO_URL=http://localhost:8080
STELLIO_NGSI_LD_PATH=/ngsi-ld/v1
# Neo4j
NEO4J_URL=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=test12345
# Fuseki
FUSEKI_URL=http://localhost:3030
FUSEKI_DATASET=lod-dataset
# PostgreSQL
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=stellio_search
# AI APIs
GEMINI_API_KEY=your_key_here
TAVILY_API_KEY=your_key_here
Quick Startβ
# Install dependencies
cd apps/traffic-web-app/backend
npm install
# Development mode
npm run dev
# Production build
npm run build
npm start
# Run tests
npm test
API Endpointsβ
| Group | Base Path | Description |
|---|---|---|
| Cameras | /api/cameras | Traffic camera entities |
| Weather | /api/weather | Weather observations |
| Air Quality | /api/air-quality | AQI and pollutant data |
| Accidents | /api/accidents | Road accident events |
| Patterns | /api/patterns | Traffic congestion patterns |
| Analytics | /api/analytics | Aggregated metrics |
| Historical | /api/historical | Time-series data |
| Correlation | /api/correlation | Entity relationships |
| Routing | /api/routing | Route planning |
| Geocoding | /api/geocoding | Address conversion |
| Agents | /api/agents | AI agent queries |
| Multi-Agent | /api/multi-agent | Combined agent analysis |
Health Checkβ
curl http://localhost:5000/health
Returns connectivity status for all backend services.