photoncloud-monorepo/docs/por/T029-practical-app-demo
centra 3eeb303dcb feat: Batch commit for T039.S3 deployment
Includes all pending changes needed for nixos-anywhere:
- fiberlb: L7 policy, rule, certificate types
- deployer: New service for cluster management
- nix-nos: Generic network modules
- Various service updates and fixes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 04:34:51 +09:00
..
src T036: Add VM cluster deployment configs for nixos-anywhere 2025-12-11 09:59:19 +09:00
Cargo.lock feat: Batch commit for T039.S3 deployment 2025-12-13 04:34:51 +09:00
Cargo.toml T036: Add VM cluster deployment configs for nixos-anywhere 2025-12-11 09:59:19 +09:00
e2e-test-results.md T036: Add VM cluster deployment configs for nixos-anywhere 2025-12-11 09:59:19 +09:00
README.md fix(lightningstor): Fix SigV4 canonicalization for AWS S3 auth 2025-12-12 06:23:46 +09:00
results.md fix(lightningstor): Fix SigV4 canonicalization for AWS S3 auth 2025-12-12 06:23:46 +09:00
task.yaml T036: Add VM cluster deployment configs for nixos-anywhere 2025-12-11 09:59:19 +09:00

PlasmaCloud Demo API

Minimal HTTP API demonstrating PlasmaCloud MVP-Alpha E2E functionality.

Overview

This demo validates that all PlasmaCloud components work together for real applications:

  • IAM: Token-based authentication
  • FlareDB: Persistent key-value storage
  • Nightlight: Prometheus metrics export
  • Platform Integration: Complete E2E data flow

Architecture

User → HTTP API → FlareDB (storage)
         ↓           ↓
       IAM (auth)  Metrics → Nightlight

API Endpoints

Method Path Auth Required Description
GET /health No Health check
GET /metrics No Prometheus metrics
POST /items Yes Create item
GET /items/:id No Retrieve item
DELETE /items/:id Yes Delete item

Prerequisites

Running PlasmaCloud services:

  • flaredb-server on port 8001
  • iam-server on port 8002 (default)

Build

cd docs/por/T029-practical-app-demo
nix develop /home/centra/cloud -c cargo build

Run

# Set environment variables (optional)
export FLAREDB_ADDR=127.0.0.1:8001
export IAM_ADDR=http://127.0.0.1:8002
export BIND_ADDR=0.0.0.0:3000

# Run the server
./target/debug/plasma-demo-api

Usage Example

# 1. Health check
curl http://localhost:3000/health

# 2. Create item (requires IAM token)
TOKEN=$(curl -X POST http://localhost:8002/auth/token \
  -H "Content-Type: application/json" \
  -d '{"tenant_id":"test","user_id":"demo"}' | jq -r '.token')

curl -X POST http://localhost:3000/items \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"id":"item1","data":"Hello PlasmaCloud"}'

# 3. Retrieve item (no auth required)
curl http://localhost:3000/items/item1

# 4. Check metrics
curl http://localhost:3000/metrics | grep items

# 5. Delete item (requires IAM token)
curl -X DELETE http://localhost:3000/items/item1 \
  -H "Authorization: Bearer $TOKEN"

Data Persistence

Items are stored in FlareDB with key format: item:{id}

Data persists across server restarts as long as FlareDB is running.

Metrics

Exported Prometheus metrics:

  • http_requests_total - Total HTTP requests
  • items_created_total - Total items created
  • items_retrieved_total - Total items retrieved

Metrics are scraped by Nightlight on the /metrics endpoint.

Implementation

  • HTTP Framework: Axum
  • Storage Client: flaredb-client (raw KV operations)
  • Auth Client: iam-client (token validation)
  • Metrics: Prometheus (text export format)
  • Runtime: Tokio async

Code Structure

src/main.rs
├── AppState - Shared state (DB, IAM, Metrics)
├── Metrics - Prometheus registry and counters
├── Routes
│   ├── /health - Health check
│   ├── /metrics - Prometheus metrics
│   ├── POST /items - Create item
│   ├── GET /items/:id - Get item
│   └── DELETE /items/:id - Delete item
└── Middleware
    └── auth_middleware - IAM token validation

Acceptance Criteria

  • Application deploys successfully
  • CRUD operations work
  • Data persists in FlareDB
  • IAM authentication validates tokens
  • Metrics exported to /metrics endpoint

Time Budget

Implementation: ~2 hours (Option A minimal scope)