## IMPORTANT
- Use thiserror, create the primary struct ServiceError in error.rs which has all #[from], do not use custom result types or have errors for different modules, all errors should fall under this struct
- The error from above should implement IntoResponse to translate it to client error without leaking any sensitive information and so that ServiceError can be used as error type for axum
## PLAN
### Project Setup
(Completed) Set up Rust workspace with server and jwt-generator crates
(Completed) Create Cargo.toml workspace configuration with required dependencies (axum, sqlx, jsonwebtoken, serde, tokio, uuid, thiserror)
(Completed) Create compose.yaml for PostgreSQL test database with environment variables
(Completed) Design database schema in tables.sql (data table with key UUID, data JSONB, created_at, updated_at; locks table with lock_id UUID, locked_at, expires_at)
### Database Layer
(Completed) Implement database connection module with PostgreSQL connection pool
(Completed) Create database migration system to auto-deploy tables.sql if tables don't exist
(Completed) Implement data model structs for database entities (DataRecord, Lock)
### JWT System
(Completed) Create jwt-generator utility that takes secret key, permissions (read/write), and expiration time
(Completed) Implement JWT authentication middleware for server with permission validation
(Completed) Add JWT token validation and permission checking for endpoints
### Core API Endpoints
(Completed) Implement POST /set endpoint for storing/updating JSONB data with partial update support using jsonb_set
(Completed) Implement GET /get/<key> endpoint with optional sub-key filtering for partial data retrieval
(Completed) Add automatic created_at and updated_at timestamp handling in database operations
### Streaming & Binary Support
(Completed) Implement streaming bytes endpoint with compact binary format (not base64) for efficient data transfer
(Completed) Add support for returning all data if no specific format specified in GET requests
### Lock System
(Completed) Implement database-backed lock system with locks table
(Completed) Create POST /lock endpoint that tries to obtain lock for 5 seconds with UUID parameter
(Completed) Create DELETE /unlock endpoint to release locks by UUID
(Completed) Add lock timeout and cleanup mechanism for expired locks
### Error Handling & Final Polish
(Completed) Implement comprehensive error handling with proper HTTP status codes
(Completed) Add input validation for all endpoints (UUID format, JSON structure, etc.)
(Completed) Test all endpoints with various scenarios (valid/invalid data, concurrent access, lock timeouts)
```
took 4 iterations (>30 minutes!), everything works as expected. the plan itself was partially generated with ccl since I told it to break down tasks into smaller steps then with some manual edits I got it down to that final product. I later swapped locks to be built on a lease system and it handled that quite nicely as well.
## IMPORTANT - Use thiserror, create the primary struct ServiceError in error.rs which has all #[from], do not use custom result types or have errors for different modules, all errors should fall under this struct - The error from above should implement IntoResponse to translate it to client error without leaking any sensitive information and so that ServiceError can be used as error type for axum
## PLAN
### Project Setup (Completed) Set up Rust workspace with server and jwt-generator crates (Completed) Create Cargo.toml workspace configuration with required dependencies (axum, sqlx, jsonwebtoken, serde, tokio, uuid, thiserror) (Completed) Create compose.yaml for PostgreSQL test database with environment variables (Completed) Design database schema in tables.sql (data table with key UUID, data JSONB, created_at, updated_at; locks table with lock_id UUID, locked_at, expires_at)
### Database Layer (Completed) Implement database connection module with PostgreSQL connection pool (Completed) Create database migration system to auto-deploy tables.sql if tables don't exist (Completed) Implement data model structs for database entities (DataRecord, Lock)
### JWT System (Completed) Create jwt-generator utility that takes secret key, permissions (read/write), and expiration time (Completed) Implement JWT authentication middleware for server with permission validation (Completed) Add JWT token validation and permission checking for endpoints
### Core API Endpoints (Completed) Implement POST /set endpoint for storing/updating JSONB data with partial update support using jsonb_set (Completed) Implement GET /get/<key> endpoint with optional sub-key filtering for partial data retrieval (Completed) Add automatic created_at and updated_at timestamp handling in database operations
### Streaming & Binary Support (Completed) Implement streaming bytes endpoint with compact binary format (not base64) for efficient data transfer (Completed) Add support for returning all data if no specific format specified in GET requests
### Lock System (Completed) Implement database-backed lock system with locks table (Completed) Create POST /lock endpoint that tries to obtain lock for 5 seconds with UUID parameter (Completed) Create DELETE /unlock endpoint to release locks by UUID (Completed) Add lock timeout and cleanup mechanism for expired locks
### Error Handling & Final Polish (Completed) Implement comprehensive error handling with proper HTTP status codes (Completed) Add input validation for all endpoints (UUID format, JSON structure, etc.) (Completed) Test all endpoints with various scenarios (valid/invalid data, concurrent access, lock timeouts) ```
took 4 iterations (>30 minutes!), everything works as expected. the plan itself was partially generated with ccl since I told it to break down tasks into smaller steps then with some manual edits I got it down to that final product. I later swapped locks to be built on a lease system and it handled that quite nicely as well.