- Add OpenSpec experimental workflow with commands (opsx-apply, opsx-archive, opsx-explore, opsx-propose) - Add Serena memory system for project context - Implement User API (UserController, UserModel, routes) - Add Specimen delete endpoint - Update Test definitions and Routes - Sync API documentation (OpenAPI) - Archive completed 2026-03-08-backend-specs change
7.4 KiB
7.4 KiB
Task Completion Checklist
This checklist should be followed after completing any development task to ensure code quality and consistency.
Immediate Post-Task Actions
1. Run Tests
# Run all tests to ensure nothing is broken
vendor/bin/phpunit
# If tests fail, run specific test file for debugging
vendor/bin/phpunit tests/feature/[SpecificTestFile].php
2. Check for PHP Syntax Errors
# Check syntax of modified files
php -l app/Controllers/YourController.php
php -l app/Models/YourModel.php
3. Verify Database Changes
# If you created a migration, verify it was applied
php spark migrate:status
# If you created a migration, run it
php spark migrate
4. Update API Documentation (CRITICAL)
- MUST update
public/api-docs.yamlafter modifying ANY controller - Update OpenAPI schema definitions for new/changed endpoints
- Update field names, types, and response formats
- Ensure schemas match actual controller responses
Code Quality Verification
Controllers Checklist
- Extends
BaseController - Uses
ResponseTrait - Defines
$this->rulesarray for validation - Validates input:
$this->validateData($input, $rules) - Uses try-catch with
$this->failServerError() - Returns consistent JSON format:
['status' => 'success', 'message' => '...', 'data' => ...] - Uses
$this->request->getJSON(true)for POST/PATCH - Uses
$this->request->getVar()for GET parameters - Proper HTTP status codes: 200 (success), 201 (created), 400 (validation), 404 (not found), 500 (error)
Models Checklist
- Extends
BaseModel(for UTC normalization) - Defines
$table,$primaryKey,$allowedFields - Uses soft deletes:
$useSoftDeletes = true,$deletedField = 'DelDate' - Wraps multi-table operations in transactions
- Uses
$this->checkDbError($db, 'context')after DB operations - Uses Query Builder, not raw SQL
- Escapes inputs properly via parameter binding
Code Style Checklist
- 2-space indentation
- Same-line opening braces:
public function index() { - No trailing whitespace
- Namespace at top:
namespace App\Controllers\... - Organized imports: Framework first, then App libraries/models
- Classes: PascalCase (
PatientController) - Methods: camelCase (
getPatient) - Variables: camelCase (
$patientId) - Database fields: PascalCase with underscores (
PatientID,NameFirst)
Security Checklist
- No secrets logged or committed (JWT_SECRET, passwords)
- User inputs validated before processing
- JWT authentication required for protected endpoints
- SQL injection prevention via Query Builder
- XSS prevention via proper escaping
Data Integrity Checklist
- UTC date normalization via BaseModel
- Soft delete using
DelDatefield - Referential integrity maintained
- Transactional data consistency via
$db->transBegin(),$db->transCommit(),$db->transRollback()
Testing Checklist
- Tests written for new functionality
- Tests extend
CIUnitTestCase - Feature tests use
FeatureTestTrait - JWT token injected via
withHeaders(['Cookie' => 'token=' . $this->token]) - Assert JSON structure:
$this->assertIsArray($body['data']) - All tests passing:
vendor/bin/phpunit
ValueSet Checklist
- If using static lookups, use
ValueSet::get('name') - Transform labels:
ValueSet::transformLabels($data, ['Field' => 'valueset']) - If modifying valueset JSON files, call
ValueSet::clearCache() - Valueset JSON files in
app/Libraries/Data/valuesets/
Database Checklist
- Migrations follow naming convention:
YYYY-MM-DD-NNNNNN_Description.php - Migrations define both
up()anddown()methods - Foreign keys properly defined
- Indexes added for performance
- Tables dropped in reverse order in
down()method
API Documentation Checklist
public/api-docs.yamlupdated with new/changed endpoints- Schemas match actual controller responses
- Field names and types documented
- Request/response examples provided
- Authentication requirements documented
Verification Steps
1. Verify API Endpoints (If Applicable)
# If you have curl, test the endpoints
curl -X GET http://localhost:8080/api/patient \
-H "Cookie: token=your_jwt_token"
# Or use a REST client like Postman
2. Check Logs
# View recent application logs
type writable\logs\log-*.log # Windows
# or
tail -f writable/logs/log-*.log # Unix/Linux
3. Check Database
# Verify database state
php spark db:table [table_name]
# Or use your database client (MySQL Workbench, phpMyAdmin, etc.)
Common Issues to Check
Potential Issues
- Tests failing: Check error messages, add debug output, verify database state
- Syntax errors: Run
php -lon modified files - Validation errors: Check
$this->rulesarray, ensure input matches expected format - Database errors: Check migration status, verify table structure
- Authentication issues: Verify JWT token, check
AuthFilter, ensure route has auth filter - Date issues: BaseModel handles UTC normalization, verify date formats
- Soft deletes: Check if
DelDatefield is being set, verify queries filter deleted records
Performance Considerations
- Database queries optimized (use indexes, avoid SELECT *)
- Caching used appropriately (ValueSet, query caching)
- N+1 query problem avoided (use eager loading)
- Large datasets paginated
Final Steps
Before Marking Task Complete
- Run all tests:
vendor/bin/phpunit - Check syntax:
php -lon modified files - Update documentation:
public/api-docs.yaml(CRITICAL) - Verify manually: Test API endpoints if applicable
- Clean up: Remove debug code, comments (unless requested)
Git Commit (If Requested)
Only commit when explicitly requested by user. If committing:
- Review changes:
git diffandgit status - Stage relevant files:
git add . - Create meaningful commit message
- Commit:
git commit -m "message" - Do NOT push unless explicitly requested
Example Task Completion Workflow
Adding a New Controller Method
- Implement controller method following pattern
- Add model methods if needed
- Add route in
app/Config/Routes.php - Create test:
php spark make:test Feature/NewEndpointTest - Implement tests
- Run tests:
vendor/bin/phpunit - Update
public/api-docs.yaml - Verify with curl or REST client
- Check syntax:
php -l app/Controllers/YourController.php - Done!
Modifying Existing Endpoint
- Modify controller/model code
- Run tests:
vendor/bin/phpunit - Update
public/api-docs.yaml - Test endpoint manually
- Check syntax:
php -lon modified files - Done!
Creating a Database Migration
- Create migration:
php spark make:migration Description - Define
up()anddown()methods - Run migration:
php spark migrate - Verify:
php spark migrate:status - Create seeder if needed
- Run tests to verify no regressions
- Done!
Quick Reference Commands
# Run all tests
vendor/bin/phpunit
# Run specific test
vendor/bin/phpunit tests/feature/SpecificTest.php
# Check PHP syntax
php -l path/to/file.php
# Run migrations
php spark migrate
# Check migration status
php spark migrate:status
# Start dev server
php spark serve
# Clear cache
php spark cache:clear