Architecture
Overview
The Smart City TVMS API is built on Cloudflare's edge infrastructure, providing global low-latency access.
┌─────────────────────────────────────────────────────────────────┐
│ Cloudflare Edge │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ Web Frontend │ │ API Worker │ │
│ │ (Pages) │───▶│ (Workers) │ │
│ │ itms.solutions │ │ api.itms.solutions│ │
│ └──────────────────┘ └────────┬─────────┘ │
│ │ │
│ ┌────────────────────────┼────────────────────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌──────────────────┐ ┌──────────────────┐ ┌─────────────┐ │
│ │ D1 Database │ │ R2 Storage │ │ KV │ │
│ │ (SQLite) │ │ (Object Store) │ │ (Cache) │ │
│ └──────────────────┘ └──────────────────┘ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘Technology Stack
Backend (API Worker)
| Component | Technology |
|---|---|
| Runtime | Cloudflare Workers |
| Framework | Hono |
| API Layer | tRPC |
| Database | Cloudflare D1 (SQLite) |
| Storage | Cloudflare R2 |
| Auth | JWT (Web Crypto API) |
| Password | bcryptjs |
Frontend (Web App)
| Component | Technology |
|---|---|
| Hosting | Cloudflare Pages |
| Framework | Next.js 14 |
| UI | Chakra UI |
| API Client | tRPC Client |
| State | React Query |
API Structure
api.itms.solutions/trpc/
├── auth.* # Authentication endpoints
├── sensors.* # Sensor management
├── reports.* # Analytics & reports
├── system.* # System configuration
│ ├── getLicense
│ ├── timezone.*
│ ├── health
│ └── getSettings
└── storage.* # File storageDatabase Schema
The D1 database uses the following core tables:
- User - System users and authentication
- Sensor - Connected sensors and devices
- Location - Physical locations/intersections
- Event - Traffic events and violations
- Report - Generated reports
Request Flow
- Client sends request to
api.itms.solutions - Cloudflare routes to nearest edge location
- Worker processes request
- Database/storage operations (if needed)
- Response sent back to client
Average latency: < 50ms globally