Architecture Overview
End-to-end system map for Next.js frontend, Express API, provider daemon, and data synchronization.
Platform topology
DCP runs as a three-plane architecture:
- **Control plane (Web + API)**
: Next.js 14 on `dcp.sa` and the Express API on `api.dcp.sa`.
- **Execution plane (Provider GPUs)**
: `dc1_daemon.py` on provider machines polls for jobs, executes workloads in approved container images, and reports heartbeat state.
- **Data plane (SQLite + Supabase sync)**
: SQLite is the write source for operational state, with a bridge that mirrors key records to Supabase for faster reads and analytics.
Request flow (renter job)
- Renter authenticates with `x-renter-key` or `?key=`.
- `POST /api/jobs/submit` creates a job row and places a prepay estimate in halala.
- Provider daemon polls `GET /api/providers/:key/jobs` for eligible work.
- Daemon executes workload in isolated containers and reports result to `POST /api/providers/job-result`.
- Backend runs completion-based settlement (`75%` provider / `25%` platform) once execution finishes.
- Renter retrieves output from `GET /api/jobs/:id/output` for completed jobs.
Core services
- **Next.js frontend**: dashboards, onboarding, docs, and marketplace browsing.
- **Express backend**: auth, routing, billing, queueing, and admin controls.
- **Provider daemon**: heartbeat every 30s, readiness checks, and secure containerized execution.
- **Supabase sync bridge**: periodic replication for analytics and real-time UI views.
Security and trust boundaries
- API keys are role-scoped: provider, renter, admin.
- Admin operations require `x-admin-token`.
- Job and daemon endpoints enforce role checks and status transitions.
- Standard error format across API:
{ "error": "descriptive message" }Billing model summary
- Currency: SAR, internal unit: halala.
- A prepay estimate is reserved at submit time.
- Final settlement uses actual completed runtime; unused reserved amount is handled through balance updates.
- Revenue split on completed fees: provider `75%`, DCP `25%`.
Operational notes
- Provider heartbeats every 30 seconds drive online/stale/offline state.
- Rate limits and CORS protections are enforced at API layer.
- Queue visibility is scoped by actor for tenant isolation.