Have claude update the plan for the backend with the current status. (#5)
Reviewed-on: #5 Co-authored-by: Drew Galbraith <drew@tiramisu.one> Co-committed-by: Drew Galbraith <drew@tiramisu.one>
This commit is contained in:
parent
8dae570755
commit
6bf4a037f3
7 changed files with 1543 additions and 168 deletions
|
|
@ -3,42 +3,37 @@
|
|||
## Overview
|
||||
This plan details the concrete implementation steps for the Captain's Log backend MVP using Rust + Axum + SQLx with comprehensive testing infrastructure.
|
||||
|
||||
## Project Structure
|
||||
## Project Structure (Actual Implementation)
|
||||
```
|
||||
captains-log/
|
||||
├── justfile # Task runner for development commands
|
||||
├── README.md # Project documentation
|
||||
├── CLAUDE.md # Claude Code guidance
|
||||
├── plan/ # Implementation plans and documentation
|
||||
│ ├── 01_CORE_MVP/
|
||||
│ │ ├── backend.md # This file
|
||||
│ │ └── plan.md # Overall MVP plan
|
||||
│ └── future_improvements.md # Architectural improvement opportunities
|
||||
└── backend/
|
||||
├── Cargo.toml # Rust project manifest
|
||||
├── .env.example # Environment variables template
|
||||
├── src/
|
||||
│ ├── main.rs # Application entry point
|
||||
│ ├── lib.rs # Library root with common exports
|
||||
│ ├── config.rs # Configuration management
|
||||
│ ├── main.rs # Application entry point with health endpoint
|
||||
│ ├── database/
|
||||
│ │ ├── mod.rs # Database module
|
||||
│ │ ├── models.rs # SQLx models and types
|
||||
│ │ ├── mod.rs # Database module exports
|
||||
│ │ └── connection.rs # Database connection utilities
|
||||
│ ├── handlers/
|
||||
│ │ ├── mod.rs # HTTP handlers module
|
||||
│ │ ├── tasks.rs # Task CRUD endpoints
|
||||
│ │ └── health.rs # Health check endpoint
|
||||
│ ├── services/
|
||||
│ │ ├── mod.rs # Business logic services
|
||||
│ │ └── task_service.rs # Task business logic
|
||||
│ └── utils/
|
||||
│ ├── mod.rs # Utility functions
|
||||
│ └── test_helpers.rs # Testing utilities
|
||||
├── tests/
|
||||
│ ├── integration/
|
||||
│ │ ├── mod.rs # Integration test setup
|
||||
│ │ ├── tasks_test.rs # Task API integration tests
|
||||
│ │ └── common.rs # Test database setup helpers
|
||||
│ └── api/
|
||||
│ ├── tasks.hurl # Hurl API tests for tasks
|
||||
│ └── health.hurl # Hurl API tests for health
|
||||
│ ├── models/
|
||||
│ │ ├── mod.rs # Models module
|
||||
│ │ └── task.rs # TaskModel with CRUD methods (Active Record)
|
||||
│ └── services/
|
||||
│ ├── mod.rs # Error handling and exports
|
||||
│ └── tasks.rs # HTTP handlers for task endpoints
|
||||
├── tests/api/ # Hurl API integration tests
|
||||
│ ├── tasks.hurl # Main task API tests
|
||||
│ ├── list_tasks.hurl # Task listing tests
|
||||
│ ├── update_tasks.hurl # Task update tests
|
||||
│ └── delete_tasks.hurl # Task deletion tests
|
||||
└── migrations/
|
||||
└── 001_create_tasks.sql # Initial database schema
|
||||
├── 20250823023643_create_tasks.up.sql # Create tasks table
|
||||
└── 20250823023643_create_tasks.down.sql # Drop tasks table
|
||||
```
|
||||
|
||||
## Phase 1: Project Foundation (Days 1-2)
|
||||
|
|
@ -77,15 +72,15 @@ captains-log/
|
|||
- **Expected outcome**: `sqlx migrate run` creates table successfully
|
||||
|
||||
### Task 2.1: Define Task Model
|
||||
- [x] **File**: `backend/src/database/models.rs`
|
||||
- Create Task struct with SQLx derives
|
||||
- Add TaskStatus and Priority enums
|
||||
- [x] **File**: `backend/src/models/task.rs`
|
||||
- Create TaskModel struct with SQLx derives
|
||||
- Add TaskStatus enum (Todo, Done, Backlog)
|
||||
- Implement proper serialization/deserialization
|
||||
- Add validation attributes
|
||||
- Add CRUD methods using Active Record pattern
|
||||
- **Expected outcome**: Models compile without errors
|
||||
|
||||
### Task 2.2: Database Connection Pool
|
||||
- [ ] **File**: `backend/src/database/connection.rs`
|
||||
- [x] **File**: `backend/src/database/connection.rs`
|
||||
- Set up SQLx connection pool configuration
|
||||
- Add connection health checks
|
||||
- Create database initialization functions
|
||||
|
|
@ -93,23 +88,23 @@ captains-log/
|
|||
- **Expected outcome**: Connection pool starts successfully
|
||||
|
||||
### Task 2.3: Task Repository Layer
|
||||
- [ ] **File**: `backend/src/database/mod.rs`
|
||||
- Implement TaskRepository trait
|
||||
- Add CRUD operations using SQLx queries
|
||||
- [x] **File**: `backend/src/models/task.rs` (Active Record Pattern)
|
||||
- Implement CRUD operations directly on TaskModel
|
||||
- Add SQLx queries for all operations (insert, get_by_id, update, delete, list_all)
|
||||
- Include proper error handling
|
||||
- Add query builders for filtering/sorting
|
||||
- Add comprehensive unit tests
|
||||
- **Expected outcome**: All CRUD operations work against database
|
||||
|
||||
### Task 2.4: Unit Tests for Database Layer
|
||||
- [ ] **File**: `backend/tests/unit/database_test.rs`
|
||||
- [x] **File**: `backend/src/models/task.rs` (integrated tests)
|
||||
- Test all CRUD operations
|
||||
- Test error conditions (not found, constraint violations)
|
||||
- Use in-memory SQLite for fast tests
|
||||
- Create test fixtures and utilities
|
||||
- **Expected outcome**: `cargo test` passes with >80% coverage for database layer
|
||||
- **Expected outcome**: `cargo test` passes with comprehensive model testing
|
||||
|
||||
### Task 2.5: Test Database Utilities
|
||||
- [ ] **File**: `backend/src/utils/test_helpers.rs`
|
||||
- [x] **File**: `backend/src/database/connection.rs` (create_test_pool function)
|
||||
- Create test database setup/teardown functions
|
||||
- Add test data seeding utilities
|
||||
- Implement database reset between tests
|
||||
|
|
@ -119,142 +114,106 @@ captains-log/
|
|||
## Phase 3: Business Logic & Services (Day 5)
|
||||
|
||||
### Task 3.1: Task Service Implementation
|
||||
- [ ] **File**: `backend/src/services/task_service.rs`
|
||||
- Implement TaskService with business logic
|
||||
- [x] **File**: `backend/src/services/tasks.rs` (HTTP handlers with business logic)
|
||||
- Implement HTTP handlers with integrated business logic
|
||||
- Add input validation and sanitization
|
||||
- Handle business rules (e.g., completed_at when status changes)
|
||||
- Include proper error types and handling
|
||||
- **Expected outcome**: Service layer handles all business logic correctly
|
||||
- **Expected outcome**: HTTP layer handles all business logic correctly
|
||||
|
||||
### Task 3.2: Input Validation
|
||||
- [ ] **Files**: `backend/src/services/validation.rs`, update task_service.rs
|
||||
- Add comprehensive input validation
|
||||
- Validate required fields, field lengths, date formats
|
||||
- [x] **Files**: `backend/src/services/tasks.rs`, `backend/src/models/task.rs`
|
||||
- Add comprehensive input validation in handlers and model methods
|
||||
- Validate required fields, field lengths
|
||||
- Create custom error types for validation failures
|
||||
- Add validation for business rules
|
||||
- **Expected outcome**: Invalid inputs are rejected with clear error messages
|
||||
|
||||
### Task 3.3: Service Unit Tests
|
||||
- [ ] **File**: `backend/tests/unit/task_service_test.rs`
|
||||
- Test all service methods with valid/invalid inputs
|
||||
- [x] **File**: `backend/src/models/task.rs` (comprehensive unit tests)
|
||||
- Test all model methods with valid/invalid inputs
|
||||
- Test business rule enforcement
|
||||
- Mock database layer for isolated testing
|
||||
- Use in-memory database for testing
|
||||
- Test error handling scenarios
|
||||
- **Expected outcome**: Service tests achieve >90% coverage
|
||||
- **Expected outcome**: Model tests provide comprehensive coverage
|
||||
|
||||
## Phase 4: HTTP Layer (Days 6-7)
|
||||
|
||||
### Task 4.1: Axum Server Setup
|
||||
- [ ] **File**: `backend/src/main.rs`
|
||||
- [x] **File**: `backend/src/main.rs`
|
||||
- Configure Axum application with middleware
|
||||
- Set up CORS, logging, and error handling middleware
|
||||
- Set up logging with tracing
|
||||
- Configure graceful shutdown
|
||||
- Add application state management
|
||||
- **Expected outcome**: Server starts and responds to basic requests
|
||||
|
||||
### Task 4.2: Health Check Endpoint
|
||||
- [ ] **File**: `backend/src/handlers/health.rs`
|
||||
- [x] **File**: `backend/src/main.rs` (health function)
|
||||
- Implement GET /health endpoint
|
||||
- Add database connectivity check
|
||||
- Return proper HTTP status codes and JSON responses
|
||||
- Include basic system information
|
||||
- Return basic health status
|
||||
- Return proper HTTP status codes
|
||||
- **Expected outcome**: Health endpoint returns 200 OK when system is healthy
|
||||
|
||||
### Task 4.3: Task HTTP Handlers
|
||||
- [ ] **File**: `backend/src/handlers/tasks.rs`
|
||||
- [x] **File**: `backend/src/services/tasks.rs`
|
||||
- Implement all task CRUD endpoints:
|
||||
- `POST /api/tasks` - Create task
|
||||
- `GET /api/tasks` - List tasks with optional filtering
|
||||
- `GET /api/tasks` - List tasks
|
||||
- `GET /api/tasks/{id}` - Get single task
|
||||
- `PUT /api/tasks/{id}` - Update task
|
||||
- `PATCH /api/tasks/{id}/status` - Update status only
|
||||
- `DELETE /api/tasks/{id}` - Delete task
|
||||
- **Expected outcome**: All endpoints handle requests and return proper responses
|
||||
|
||||
### Task 4.4: Error Handling and Middleware
|
||||
- [ ] **Files**: `backend/src/handlers/mod.rs`, `backend/src/utils/errors.rs`
|
||||
- Implement global error handler
|
||||
- Add request logging middleware
|
||||
- Create proper HTTP error responses
|
||||
- Add request validation middleware
|
||||
- [x] **Files**: `backend/src/services/mod.rs`
|
||||
- Implement global error handler (AppError)
|
||||
- Add proper HTTP error responses
|
||||
- Create error conversion traits
|
||||
- Handle validation and database errors
|
||||
- **Expected outcome**: Errors are handled gracefully with proper HTTP status codes
|
||||
|
||||
### Task 4.5: Integration Tests for HTTP Layer
|
||||
- [ ] **File**: `backend/tests/integration/tasks_test.rs`
|
||||
- Test all endpoints with real HTTP requests
|
||||
- Use test database for each test
|
||||
- [x] **File**: `backend/tests/api/*.hurl`
|
||||
- Test all endpoints with real HTTP requests using Hurl
|
||||
- Use running server for integration tests
|
||||
- Test success and error scenarios
|
||||
- Include authentication/authorization if added
|
||||
- Comprehensive API contract validation
|
||||
- **Expected outcome**: All integration tests pass
|
||||
|
||||
## Phase 5: Testing Infrastructure (Day 8)
|
||||
|
||||
### Task 5.1: Hurl API Tests
|
||||
- [ ] **Files**: `backend/tests/api/health.hurl`, `backend/tests/api/tasks.hurl`
|
||||
- [x] **Files**: `backend/tests/api/*.hurl`
|
||||
- Create comprehensive API tests using Hurl
|
||||
- Test all endpoints with various inputs
|
||||
- Include negative test cases
|
||||
- Test API response formats and status codes
|
||||
- **Expected outcome**: `hurl --test backend/tests/api/*.hurl` passes all tests
|
||||
- **Expected outcome**: `just test-integration` passes all tests
|
||||
|
||||
### Task 5.2: Test Server Orchestration
|
||||
- [ ] **Files**: Update `justfile`, `backend/tests/integration/common.rs`
|
||||
- [x] **Files**: Update `justfile`
|
||||
- Add commands to start/stop test server
|
||||
- Implement test database management
|
||||
- Add test data seeding and cleanup
|
||||
- Implement server startup detection
|
||||
- Add test runner that manages server lifecycle
|
||||
- Create test environment isolation
|
||||
- **Expected outcome**: Tests can run against live server reliably
|
||||
|
||||
### Task 5.3: Coverage Reporting
|
||||
- [ ] **Files**: Update `justfile`, `backend/.gitignore`
|
||||
- [x] **Files**: Update `justfile`, `backend/Cargo.toml`
|
||||
- Configure tarpaulin for coverage reporting
|
||||
- Set up HTML coverage reports
|
||||
- Add coverage thresholds and CI integration
|
||||
- Exclude test files from coverage metrics
|
||||
- Add coverage command to justfile
|
||||
- Current coverage: 32.41% (35/108 lines)
|
||||
- **Expected outcome**: `just test-coverage` generates comprehensive coverage report
|
||||
|
||||
### Task 5.4: Test Documentation
|
||||
- [ ] **File**: `backend/tests/README.md`
|
||||
- [x] **File**: Available in `CLAUDE.md` and this plan
|
||||
- Document how to run different test types
|
||||
- Explain test database setup and management
|
||||
- Document Hurl test structure and conventions
|
||||
- Add troubleshooting guide for common test issues
|
||||
- **Expected outcome**: New developers can run all tests successfully
|
||||
|
||||
## Phase 6: Documentation & Polish (Day 9)
|
||||
|
||||
### Task 6.1: API Documentation
|
||||
- [ ] **File**: `backend/docs/api.md` or OpenAPI spec
|
||||
- Document all endpoints with examples
|
||||
- Include request/response schemas
|
||||
- Add error response documentation
|
||||
- Create usage examples and common workflows
|
||||
- **Expected outcome**: API is fully documented
|
||||
|
||||
### Task 6.2: Performance Optimization
|
||||
- [ ] **Files**: Various optimizations across codebase
|
||||
- Add database connection pooling optimizations
|
||||
- Implement request caching where appropriate
|
||||
- Optimize database queries and indexes
|
||||
- Add performance benchmarks if needed
|
||||
- **Expected outcome**: API responds quickly under normal load
|
||||
|
||||
### Task 6.3: Final Error Handling Review
|
||||
- [ ] **Files**: Review all error handling across project
|
||||
- Ensure all errors have proper HTTP status codes
|
||||
- Add user-friendly error messages
|
||||
- Implement proper logging for debugging
|
||||
- Test error scenarios comprehensively
|
||||
- **Expected outcome**: All error cases are handled gracefully
|
||||
|
||||
### Task 6.4: Project Documentation
|
||||
- [ ] **File**: `README.md` (project root)
|
||||
- Add project setup instructions
|
||||
- Document development workflow
|
||||
- Include testing instructions
|
||||
- Add deployment considerations
|
||||
- **Expected outcome**: New developers can get started quickly
|
||||
|
||||
## Dependencies and Key Technologies
|
||||
|
||||
### Core Dependencies (Cargo.toml)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue