Build a complete fleet management system with maintenance scheduling, fuel tracking, and cost analytics
* Preview is for reference only. Actual results may vary depending on the AI model, variable values, and tools used.
You are a senior full-stack engineer specialising in practical operations management systems for Malaysian SMEs. Build a complete Fleet & Vehicle Maintenance Tracker to replace manual Excel-based tracking.
## Company Context
- Company: {{company_name}}
- Vehicle types: {{vehicle_types}}
- Service interval: every {{service_intervals}} km or by time
- Fuel types: {{fuel_types}}
## Tech Stack
- Next.js 14 (App Router) + TypeScript
- Tailwind CSS + shadcn/ui component library
- Supabase (PostgreSQL + Row Level Security + Storage)
- Vercel hosting
- Recharts for fuel efficiency and cost analytics charts
- Supabase Storage for vehicle and maintenance photos
## Database Schema
Provide full SQL for each table including indexes and RLS policies.
### Table: vehicles
- id UUID PRIMARY KEY
- plate_number TEXT UNIQUE NOT NULL (Malaysian format e.g. WKL 3847)
- make TEXT NOT NULL, model TEXT NOT NULL, year INTEGER
- type TEXT (Lorry / Van / Car / Motorcycle)
- vin TEXT UNIQUE (chassis number)
- color TEXT, fuel_type TEXT
- current_mileage INTEGER DEFAULT 0
- assigned_driver_id UUID REFERENCES drivers(id)
- insurance_expiry DATE, road_tax_expiry DATE, puspakom_expiry DATE
- photo_url TEXT
- status TEXT DEFAULT 'active' (active / inactive / workshop)
- notes TEXT, created_at TIMESTAMPTZ, updated_at TIMESTAMPTZ
- Indexes: plate_number, assigned_driver_id, status
### Table: drivers
- id UUID PRIMARY KEY
- name TEXT NOT NULL, ic_number TEXT UNIQUE
- license_number TEXT UNIQUE NOT NULL
- license_class TEXT (B / D / E / GDL)
- license_expiry DATE NOT NULL
- phone TEXT, email TEXT
- status TEXT DEFAULT 'active'
- created_at TIMESTAMPTZ
- Indexes: license_number, license_expiry
### Table: maintenance_records
- id UUID PRIMARY KEY
- vehicle_id UUID REFERENCES vehicles(id) NOT NULL
- service_type TEXT NOT NULL (Engine Oil / Tyre Rotation / Brake Service / Full Service / AC Service / others)
- service_date DATE NOT NULL
- mileage_at_service INTEGER NOT NULL
- cost NUMERIC(10,2) NOT NULL (RM)
- workshop TEXT, workshop_address TEXT
- next_service_mileage INTEGER, next_service_date DATE
- invoice_number TEXT, notes TEXT
- photos TEXT[] (array of Supabase Storage URLs)
- created_by UUID REFERENCES auth.users(id)
- created_at TIMESTAMPTZ
- Indexes: vehicle_id, service_date, service_type
### Table: fuel_records
- id UUID PRIMARY KEY
- vehicle_id UUID REFERENCES vehicles(id) NOT NULL
- driver_id UUID REFERENCES drivers(id)
- date DATE NOT NULL
- fuel_type TEXT NOT NULL
- litres NUMERIC(8,2) NOT NULL
- cost_per_litre NUMERIC(6,3)
- total_cost NUMERIC(10,2) NOT NULL (RM)
- mileage INTEGER NOT NULL
- station TEXT, full_tank BOOLEAN DEFAULT TRUE
- receipt_url TEXT
- created_at TIMESTAMPTZ
- Indexes: vehicle_id, date, driver_id
### Table: maintenance_schedules
- id UUID PRIMARY KEY
- vehicle_id UUID REFERENCES vehicles(id) NOT NULL
- service_type TEXT NOT NULL
- interval_km INTEGER, interval_months INTEGER
- last_service_mileage INTEGER, last_service_date DATE
- next_service_mileage INTEGER (auto-calculated), next_service_date DATE (auto-calculated)
- is_active BOOLEAN DEFAULT TRUE
- Indexes: vehicle_id, next_service_mileage, next_service_date
### Table: reminders
- id UUID PRIMARY KEY
- vehicle_id UUID REFERENCES vehicles(id) NOT NULL
- reminder_type TEXT NOT NULL (maintenance / insurance / road_tax / puspakom / driver_license)
- due_date DATE NOT NULL, due_mileage INTEGER
- status TEXT DEFAULT 'pending' (pending / acknowledged / completed)
- sent_at TIMESTAMPTZ, acknowledged_at TIMESTAMPTZ, notes TEXT
- Indexes: vehicle_id, due_date, status
### RLS Policies
- All tables: authenticated users can SELECT, INSERT, UPDATE
- reminders, vehicles: anon role can SELECT (for public read-only views)
- Always wrap auth.uid() as (select auth.uid()) to avoid per-row evaluation
- Create foreign key indexes manually — Postgres does NOT auto-index FK columns
## Core Features
### 1. Vehicle Registry
- Create / edit / deactivate vehicles with full details
- Upload vehicle photo to Supabase Storage
- Display: plate number, make/model/year, insurance expiry, road tax expiry, Puspakom expiry
- Assign driver to vehicle
- Auto-update current mileage when fuel or maintenance records are added
### 2. Maintenance Scheduling & Reminders
- Auto-calculate next service mileage based on {{service_intervals}} km interval
- Auto-calculate next service date based on monthly interval
- Trigger reminder when vehicle is within 1,000 km or 1 month of due service
- Flag overdue vehicles in red and surface them first on dashboard
- Support multiple service types per vehicle schedule
### 3. Service History Timeline
- Per-vehicle scrollable timeline of all past maintenance
- Each entry: date, mileage, service type, cost (RM), workshop name
- Expandable to show photos and invoice number
- Filter by year or service type
### 4. Fuel Tracking & Efficiency
- Log each refuel: date, station, litres, cost, mileage, driver
- Auto-calculate fuel efficiency: km/litre per fill-up and rolling average
- Monthly fuel cost summary per vehicle
- Recharts bar/line chart comparing fuel efficiency across fleet
- Anomaly detection: flag fill-ups where efficiency drops >20% below vehicle average (possible engine issue or fuel theft)
### 5. Document Expiry Reminders
- Insurance expiry: remind 30 days before
- Road tax expiry: remind 30 days before
- Puspakom inspection: remind 30 days before (vehicles over 5 years old require annual inspection in Malaysia)
- Driver license expiry: remind 60 days before
- Dashboard section listing all upcoming document renewals
### 6. Driver Management
- Driver profile: name, IC number, license number, license class (B/D/E/GDL), license expiry, phone
- View all vehicles assigned to a driver
- License expiry alerts
- Driver linked to fuel records for accountability
### 7. Cost Analytics
- Per-vehicle annual total cost breakdown: maintenance + fuel + estimated insurance
- Monthly cost trend line chart
- Fleet cost comparison bar chart (identify highest-cost vehicles for replacement decision)
- Filter by vehicle type, make, date range
- Export data as CSV
### 8. Maintenance Calendar
- Monthly calendar view showing all upcoming service due dates and document renewals
- Colour-coded: maintenance (blue), insurance (orange), road tax (green), Puspakom (purple)
## Page Structure
`/dashboard` — Fleet overview
- Stat cards: Total Vehicles, Due for Service This Month, Overdue, Monthly Fuel Cost (RM)
- Urgent reminders list (overdue + expiring within 7 days)
- 6-month fuel cost trend chart
- Vehicle status summary table
`/vehicles` — Vehicle list
- Card grid: plate number, type, make/model, current mileage, next service progress bar
- Status badge: Active (green) / Due Soon (yellow) / Overdue (red) / In Workshop (grey)
- Search and filter by type, status, assigned driver
`/vehicles/[id]` — Vehicle detail page
- Full vehicle profile card with photo
- Maintenance schedule section with next-due indicators
- Scrollable service history timeline
- Fuel records table with efficiency chart
- Document expiry dates with countdown badges
- Quick-action buttons: Add Maintenance Record, Add Fuel Record, Update Mileage
`/maintenance` — Maintenance management
- List of all vehicles due or overdue for service, sorted by urgency
- Add maintenance record form (vehicle, service type, date, mileage, cost, workshop, photos)
- Calendar view toggle
`/fuel` — Fuel records
- Add fuel record form
- Fuel efficiency comparison chart across all vehicles
- Monthly fuel spend report with per-vehicle breakdown
`/drivers` — Driver management
- Driver list with license expiry status
- Driver profile page with assigned vehicle and driving history
`/reports` — Cost reports
- Date range selector
- Per-vehicle cost breakdown table
- Export CSV button
`/settings` — System configuration
- Default service interval (km and months)
- Reminder lead time settings
- User/admin management
## UI/UX Specifications
- Top nav: dark background (#0F172A), company name {{company_name}}, white nav links
- Cards: white background, subtle border, generous padding
- Accent colour: yellow #FCD34D for primary CTA buttons and key callouts (use sparingly)
- Status colours: green (ok), yellow (due soon), red (overdue/urgent)
- Vehicle card mileage progress bar: shows km remaining until next service visually
- All costs displayed with RM prefix: RM 1,250.00
- Date format: DD/MM/YYYY (Malaysian convention)
- Fully responsive — drivers use mobile to log fuel on the road
- shadcn/ui components: Card, Table, Badge, Dialog, Sheet, Select, Tabs, Skeleton, Tooltip
## Business Logic Rules
- Mark vehicle "Due Soon" when mileage is within 1,000 km of next service OR within 1 month of next service date
- Mark vehicle "Overdue" when current mileage exceeds next_service_mileage OR current date exceeds next_service_date
- When a fuel record is saved, update vehicles.current_mileage if the new mileage is higher
- When a maintenance record is saved, recalculate next_service_mileage and next_service_date in maintenance_schedules
- Puspakom: auto-determine if vehicle requires annual inspection based on (current year - manufacture year) >= 5
- Fuel anomaly: compare each fill-up efficiency against the vehicle's 90-day rolling average; flag if >20% worse
## Seed Data (supabase/seed.sql)
Insert sample data for immediate demo:
- 5 vehicles: 2 Lorries (Toyota Dyna, Isuzu NLR), 2 Vans (Toyota Hiace, Nissan Urvan), 1 Car (Toyota Vios)
- Malaysian plate numbers: WKL 3847, JHF 2219, BNX 8831, PBD 5540, VDF 1103
- 3 drivers with valid Malaysian IC and GDL/D/B license classes
- 3 maintenance records per vehicle spanning the past 12 months
- 5 fuel records per vehicle with realistic km/litre values
- Active maintenance schedules for all vehicles
- 2 upcoming and 1 overdue reminder to demonstrate dashboard alerts
Begin with the database schema and Supabase configuration, then proceed module by module. Confirm with me after each module before continuing.