Maintenance Feature Capsule
Quick Summary
Tracks vehicle maintenance including routine service, repairs, and performance upgrades. Supports multiple subtypes per record, recurring schedules, and upcoming/overdue calculations. User-scoped data with vehicle ownership enforcement.
API Endpoints
Maintenance Records
POST /api/maintenance/records- Create a new maintenance recordGET /api/maintenance/records- List all records (optional filters: vehicleId, category)GET /api/maintenance/records/:id- Get single record by IDGET /api/maintenance/records/vehicle/:vehicleId- Get all records for a vehiclePUT /api/maintenance/records/:id- Update existing recordDELETE /api/maintenance/records/:id- Delete record
Maintenance Schedules
POST /api/maintenance/schedules- Create recurring scheduleGET /api/maintenance/schedules/vehicle/:vehicleId- Get schedules for a vehiclePUT /api/maintenance/schedules/:id- Update scheduleDELETE /api/maintenance/schedules/:id- Delete schedule
Utilities
GET /api/maintenance/upcoming/:vehicleId- Get upcoming/overdue maintenance (optional query: currentMileage)GET /api/maintenance/subtypes/:category- Get valid subtypes for a category
Structure
- api/ - HTTP endpoints, routes, validators
- domain/ - Business logic, types, rules
- data/ - Repository, database queries
- migrations/ - Feature-specific schema
- tests/ - All feature tests
Categories and Subtypes
Routine Maintenance (27 subtypes)
Accelerator Pedal, Air Filter Element, Brakes and Traction Control, Cabin Air Filter / Purifier, Coolant, Doors, Drive Belt, Engine Oil, Evaporative Emissions System, Exhaust System, Fluid - A/T, Fluid - Differential, Fluid - M/T, Fluid Filter - A/T, Fluids, Fuel Delivery and Air Induction, Hood Shock / Support, Neutral Safety Switch, Parking Brake System, Restraints and Safety Systems, Shift Interlock A/T, Spark Plug, Steering and Suspension, Tires, Trunk / Liftgate Shock / Support, Washer Fluid, Wiper Blade
Repair (5 subtypes)
Engine, Transmission, Drivetrain, Exterior, Interior
Performance Upgrade (5 subtypes)
Engine, Drivetrain, Suspension, Wheels/Tires, Exterior
Dependencies
Internal
core/auth- Authentication plugincore/logging- Structured loggingcore/config- Database pool
Database
- Tables:
maintenance_records,maintenance_schedules - FK:
vehicles(id)- CASCADE DELETE
Business Rules
Validation
- Category must be:
routine_maintenance,repair, orperformance_upgrade - Subtypes array must be non-empty
- All subtypes must be valid for the selected category
- Date required for records
- Vehicle must belong to user (ownership check)
- At least one interval (months OR miles OR both) required for schedules
Next Due Calculation
If interval_months AND interval_miles both set, due when EITHER condition is met (whichever comes first). If only one interval set, calculate based on that single criterion.
Due Soon / Overdue Logic
Due Soon: next_due_date within 30 days OR next_due_mileage within 500 miles Overdue: next_due_date in the past OR next_due_mileage < current odometer
Security Requirements
- All queries user-scoped (filter by user_id)
- Vehicle ownership validated before operations
- Prepared statements (never concatenate SQL)
- All routes require JWT authentication
- Users can only access their own data
Testing
# Run feature tests
npm test -- features/maintenance