# SwiftWheels Fleet Management System — MongoDB Version

A full-stack web application for managing a fleet of vehicles, drivers, trips, fuel, maintenance, customers, invoices, and payments.

## Stack
- **Frontend**: React.js + Tailwind CSS + Vite + Recharts
- **Backend**: Node.js + Express.js + Mongoose
- **Database**: MongoDB
- **Auth**: JWT-based authentication

## Project Structure
```
swiftwheels-mongodb/
├── backend-project/
│   ├── server.js              # Express entry point
│   ├── config/db.js           # Mongoose connection
│   ├── middleware/auth.js     # JWT middleware
│   ├── models/                # Mongoose schemas
│   │   ├── User.js
│   │   ├── Vehicle.js
│   │   ├── Driver.js
│   │   ├── Customer.js
│   │   ├── Trip.js
│   │   ├── FuelLog.js
│   │   ├── Maintenance.js
│   │   ├── Invoice.js
│   │   ├── Payment.js
│   │   └── GpsTracking.js
│   ├── routes/                # REST API routes
│   └── package.json
└── frontend-project/
    ├── src/
    │   ├── App.jsx            # Routes
    │   ├── context/AuthContext.jsx
    │   ├── hooks/api.js       # Axios instance
    │   ├── components/        # Layout, Modal, StatCard, ConfirmDialog
    │   └── pages/             # Dashboard, Vehicles, Drivers, Trips, Fuel,
    │                          # Maintenance, Customers, Invoices, Payments, Reports
    └── package.json
```

## Setup Instructions

### 1. MongoDB Setup
- Install MongoDB locally or use MongoDB Atlas (cloud)
- For local: start with `mongod`
- For Atlas: copy your connection string

### 2. Backend Setup
```bash
cd backend-project
cp .env.example .env
# Edit .env: set MONGO_URI to your MongoDB connection string
# Example: MONGO_URI=mongodb://localhost:27017/swiftwheels_db
npm install
npm run dev   # runs on port 5000
```

### 3. Frontend Setup
```bash
cd frontend-project
npm install
npm run dev   # runs on port 5173
```

## Quick Start with Demo Data

After starting the backend, create an admin user:
```bash
curl -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"name":"Admin User","email":"admin@swiftwheels.com","password":"admin123","role":"admin"}'
```

Then login at `http://localhost:5173` with:
- Email: `admin@swiftwheels.com`
- Password: `admin123`

## MongoDB Collections
| Collection | Description |
|-----------|-------------|
| users | System users with roles |
| vehicles | Fleet vehicles |
| drivers | Driver records |
| customers | Customer accounts |
| trips | Trip management |
| fuellogs | Fuel consumption tracking |
| maintenances | Service scheduling |
| invoices | Billing documents |
| payments | Payment records |
| gpstrackings | GPS coordinates |

## Roles
| Role | Access |
|------|--------|
| admin | Full system access |
| fleet_manager | Vehicles & drivers |
| dispatcher | Trips & assignments |
| driver | View assigned trips |
| accountant | Invoices & payments |

## Key Differences from MySQL Version
- No schema.sql — MongoDB is schema-less; Mongoose models define structure
- Uses ObjectId references instead of integer foreign keys
- Aggregation pipelines instead of SQL JOINs
- Document-based storage allows flexible fields
- Atlas compatibility out of the box
