# Simple REST API Implementation Plan ## Project Overview Implement a minimal REST API for task management demonstrating core REST principles with Express.js. ## Implementation Phases ### Phase 1: Project Setup and Core Structure (10 minutes) **SPARC Mode**: `code` **Tasks**: 1. Initialize npm project with package.json 2. Install minimal dependencies (express, dev dependencies) 3. Create basic server.js with Express setup 4. Implement health check endpoint 5. Add basic error handling middleware **Deliverables**: - package.json with scripts and dependencies - server.js with basic Express server - Working health check endpoint **Command**: ```bash npx claude-flow sparc run code "Setup Express server with health endpoint for rest-api-simple" --non-interactive ``` --- ### Phase 2: Implement CRUD Operations (15 minutes) **SPARC Mode**: `tdd` **Tasks**: 1. Write tests for all CRUD endpoints 2. Implement GET /api/v1/tasks (list all) 3. Implement GET /api/v1/tasks/:id (get single) 4. Implement POST /api/v1/tasks (create) 5. Implement PUT /api/v1/tasks/:id (update) 6. Implement DELETE /api/v1/tasks/:id (delete) 7. Add in-memory data store **Test Coverage**: - Happy path for each endpoint - Error cases (404, 400) - Input validation - Response format verification **Command**: ```bash npx claude-flow sparc run tdd "Implement CRUD operations for tasks with full test coverage" --non-interactive ``` --- ### Phase 3: Input Validation and Error Handling (10 minutes) **SPARC Mode**: `code` **Tasks**: 1. Add input validation for POST/PUT operations 2. Implement consistent error response format 3. Add proper HTTP status codes 4. Handle edge cases (invalid IDs, missing fields) 5. Add request logging **Deliverables**: - Robust error handling - Input validation - Consistent API responses **Command**: ```bash npx claude-flow sparc run code "Add input validation and error handling to REST API" --non-interactive ``` --- ### Phase 4: Documentation and Examples (10 minutes) **SPARC Mode**: `docs-writer` **Tasks**: 1. Create comprehensive README.md 2. Add usage examples with curl commands 3. Document environment variables 4. Add quick start guide 5. Include API endpoint reference 6. Add troubleshooting section **Deliverables**: - README.md with full documentation - Example requests for all endpoints - Setup and deployment instructions **Command**: ```bash npx claude-flow sparc run docs-writer "Create comprehensive documentation for simple REST API" --non-interactive ``` --- ### Phase 5: Performance and Security Review (5 minutes) **SPARC Mode**: `security-review` **Tasks**: 1. Review code for security vulnerabilities 2. Check for any hardcoded values 3. Verify no sensitive data exposure 4. Ensure proper error messages (no stack traces) 5. Document security considerations **Command**: ```bash npx claude-flow sparc run security-review "Review REST API for security best practices" --non-interactive ``` --- ## File Structure ``` examples/rest-api-simple/ ├── server.js # Main application file ├── server.test.js # Test suite ├── package.json # Dependencies and metadata ├── package-lock.json # Lock file ├── README.md # User documentation ├── architecture.md # System design (already created) ├── api-specification.md # API contracts (already created) └── implementation-plan.md # This file ``` ## Testing Strategy ### Unit Tests - Test each route handler independently - Mock request/response objects - Verify business logic ### Integration Tests - Test full HTTP request/response cycle - Verify API contracts - Test error scenarios ### Test Execution ```bash # Run all tests npm test # Run tests in watch mode npm run test:watch # Run with coverage npm run test:coverage ``` ## Development Workflow 1. **Start Development Server** ```bash npm run dev # Uses nodemon for auto-reload ``` 2. **Run Tests** ```bash npm test ``` 3. **Manual Testing** ```bash # Use curl or Postman to test endpoints curl http://localhost:3000/api/v1/tasks ``` ## Success Criteria - [ ] All CRUD operations working correctly - [ ] 100% test coverage for routes - [ ] Proper error handling and validation - [ ] Clean, readable code structure - [ ] Comprehensive documentation - [ ] No security vulnerabilities - [ ] Can be set up and running in < 2 minutes ## Next Steps After Implementation ### Immediate Extensions (Optional) 1. Add pagination support 2. Add search/filter capabilities 3. Add sorting options 4. Add bulk operations ### Future Enhancements 1. Database integration (MongoDB/PostgreSQL) 2. Authentication (JWT) 3. Rate limiting 4. API versioning strategy 5. Swagger/OpenAPI documentation 6. Docker containerization ## Parallel Execution with Swarm For faster implementation, use background swarms: ```bash # Complete implementation in parallel npx claude-flow swarm "Implement complete simple REST API based on architecture" \ --strategy development --background --parallel --testing \ --max-agents 4 --output ./ # Monitor progress npx claude-flow monitor ``` ## Time Estimate - **Total Time**: ~50 minutes sequential, ~15 minutes with parallel swarms - **Lines of Code**: ~200-300 (keeping it simple) - **Test Coverage**: > 90% ## Dependencies ### Production - `express`: ^4.18.2 ### Development - `jest`: ^29.7.0 - `supertest`: ^6.3.3 - `nodemon`: ^3.0.1 ## Environment Variables - `PORT`: Server port (default: 3000) - `NODE_ENV`: Environment (development/production) No other configuration needed!