Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

TransitOps

A full-stack fleet management platform built for the Odoo Hackathon. TransitOps covers vehicle tracking, driver management, trip dispatch, maintenance workflows, fuel logging, expense tracking, and analytics — all in a TypeScript monorepo.


Table of Contents


Tech Stack

Layer Technology
API Node.js, Express, TypeScript
Frontend Vite, TypeScript (vanilla)
Database PostgreSQL 16
ORM Prisma 5
Auth JWT (access + refresh tokens), bcryptjs
Validation Zod (shared schemas)
Testing Jest, ts-jest
Dev tooling ts-node-dev, concurrently
Infrastructure Docker Compose (Postgres + pgAdmin)

Monorepo Structure

transitops/                        ← monorepo root (run all commands here)
├── apps/
│   ├── api/                       ← Express REST API
│   │   └── src/
│   │       ├── index.ts           ← server entry point (port 4000)
│   │       ├── middleware/        ← auth, error handler, zod validation
│   │       ├── routes/            ← one file per resource
│   │       ├── services/          ← business logic + Prisma queries
│   │       ├── lib/               ← prisma client, error classes
│   │       ├── prisma/
│   │       │   ├── schema.prisma  ← database schema
│   │       │   ├── seed.ts        ← seed script
│   │       │   └── migrations/    ← migration history
│   │       └── __tests__/         ← Jest business-rule unit tests
│   └── web/                       ← Vite frontend (port 5173)
│       └── src/
│           ├── api/               ← typed fetch wrappers per resource
│           ├── auth/              ← login flow
│           ├── components/        ← modal, sidebar, toast, status-badge
│           └── pages/             ← dashboard, vehicles, drivers, trips,
│                                     maintenance, fuel-expenses, reports
├── packages/
│   └── shared-types/              ← enums + Zod schemas shared by API & web
├── docker-compose.yml             ← Postgres 16 + pgAdmin
└── package.json                   ← npm workspaces root

Prerequisites

  • Node.js 20+
  • npm 10+
  • Docker Desktop (for the database)

Getting Started

All commands are run from the transitops/ directory.

1. Start the database

docker compose up -d

This starts:

  • PostgreSQL 16 on port 5432
  • pgAdmin 4 on port 5050

2. Install dependencies

npm install

This installs all workspaces (apps/api, apps/web, packages/shared-types) in one shot.

3. Set up environment variables

Create apps/api/.env — see Environment Variables below.

4. Run migrations

npm run db:migrate

This applies all migrations in apps/api/src/prisma/migrations/ and creates the schema in Postgres.

5. Seed the database

npm run db:seed

6. Start the app

npm run dev

This starts the API and the web frontend concurrently.


Environment Variables

Create the file at apps/api/.env:

# Database
DATABASE_URL="postgresql://transitops:transitops123@localhost:5432/transitops"

# JWT — use two different secrets in production
JWT_ACCESS_SECRET="your-access-token-secret-change-this"
JWT_REFRESH_SECRET="your-refresh-token-secret-change-this"
JWT_ACCESS_EXPIRES_IN="15m"
JWT_REFRESH_EXPIRES_IN="7d"

# Server
PORT=4000
CORS_ORIGIN="http://localhost:5173"

The Docker Compose database credentials (transitops / transitops123) match the DATABASE_URL above — no changes needed for local dev.


Database

Available npm scripts (all run from transitops/)

Command What it does
npm run db:migrate Apply pending migrations (prisma migrate dev)
npm run db:seed Run src/prisma/seed.ts to populate data
npm run db:studio Open Prisma Studio at localhost:5555

Schema models

Model Description
User Authenticated users; linked to a Driver profile for the DRIVER role
Vehicle Fleet vehicles with type, capacity, odometer, status, region
Driver Driver records with license info, safety score, status
Trip Trip lifecycle: DRAFT → DISPATCHED → COMPLETED / CANCELLED
Maintenance Maintenance records (OPEN → IN_PROGRESS → CLOSED)
FuelLog Per-fill-up fuel records linked to a vehicle
Expense General expense ledger; fuel logs auto-create a linked expense

Seed Data

Running npm run db:seed wipes all existing data and inserts:

Users & credentials

Email Password Role
admin@transitops.com Admin123! ADMIN
fleet@transitops.com User123! FLEET_MANAGER
driver@transitops.com User123! DRIVER (→ Alex Johnson)
safety@transitops.com User123! SAFETY_OFFICER
finance@transitops.com User123! FINANCIAL_ANALYST

Plus 20 additional users across all roles (rajan.mehta@transitops.com through tarun.malhotra@transitops.com) — all with password User123! (ADMINs use Admin123!).

Vehicles

Registration Type Status Note
TRK-001 TRUCK AVAILABLE Has a sample fuel log + expense
VAN-002 VAN AVAILABLE
BUS-003 BUS IN_SHOP Edge case — excluded from dispatch
TRK-004 TRUCK RETIRED Edge case — excluded from dispatch

Drivers (edge cases)

Name Status Note
Alex Johnson AVAILABLE Linked to driver@transitops.com
Maria Rodriguez ON_TRIP
Bob Suspended SUSPENDED Must be rejected at dispatch
Eve Expired AVAILABLE License expired 2024 — must be rejected at dispatch

Running the App

# API + Frontend together
npm run dev

# API only (port 4000)
npm run dev:api

# Frontend only (port 5173)
npm run dev:web

API Reference

Base URL: http://localhost:4000

All routes except /auth/login and /auth/refresh require:

Authorization: Bearer <access_token>

Auth — /auth

Method Path Auth Description
POST /auth/login Public Login; returns accessToken + refreshToken
POST /auth/register ADMIN Create a new user
POST /auth/refresh Public Rotate tokens using a refresh token
POST /auth/logout Any Invalidate refresh token
GET /auth/me Any Get current user profile

Vehicles — /vehicles

Method Path Auth Description
GET /vehicles Any List vehicles (filterable by type, status, region)
GET /vehicles/available Any Only AVAILABLE vehicles (for dispatch dropdowns)
GET /vehicles/:id Any Single vehicle
POST /vehicles ADMIN, FLEET_MANAGER Create vehicle
PATCH /vehicles/:id ADMIN, FLEET_MANAGER Update vehicle
DELETE /vehicles/:id ADMIN Soft-delete vehicle

Drivers — /drivers

Method Path Auth Description
GET /drivers Any List drivers (filterable by status, licenseCategory)
GET /drivers/available Any Only AVAILABLE drivers with valid license
GET /drivers/:id Any Single driver
POST /drivers ADMIN, FLEET_MANAGER Create driver
PATCH /drivers/:id ADMIN, FLEET_MANAGER, SAFETY_OFFICER Update driver
DELETE /drivers/:id ADMIN Soft-delete driver

Trips — /trips

Method Path Auth Description
GET /trips Any List trips (filterable by status, vehicleId, driverId)
GET /trips/:id Any Single trip
POST /trips ADMIN, FLEET_MANAGER Create trip (status: DRAFT)
POST /trips/:id/dispatch ADMIN, FLEET_MANAGER Dispatch trip (enforces all business rules)
POST /trips/:id/complete ADMIN, FLEET_MANAGER, DRIVER Complete trip with actuals
POST /trips/:id/cancel ADMIN, FLEET_MANAGER Cancel trip with reason

Maintenance — /maintenance

Method Path Auth Description
GET /maintenance Any List records (filterable by vehicleId, status, issueType)
GET /maintenance/:id Any Single record
POST /maintenance ADMIN, FLEET_MANAGER, SAFETY_OFFICER Open a new maintenance record
PATCH /maintenance/:id ADMIN, FLEET_MANAGER, SAFETY_OFFICER Update technician / notes
PATCH /maintenance/:id/close ADMIN, FLEET_MANAGER, SAFETY_OFFICER Close record; restores vehicle status

Fuel Logs — /fuel-logs

Method Path Auth Description
GET /fuel-logs Any List fuel logs (filterable by vehicleId, date range)
POST /fuel-logs ADMIN, FLEET_MANAGER, DRIVER Create fuel log (auto-creates linked expense)

Expenses — /expenses

Method Path Auth Description
GET /expenses Any List expenses (filterable by vehicleId, type, date range)
GET /expenses/vehicle/:vehicleId/breakdown Any Cost breakdown by type for a vehicle
POST /expenses ADMIN, FLEET_MANAGER, FINANCIAL_ANALYST Create expense

Analytics — /analytics

Method Path Auth Description
GET /analytics/dashboard Any KPIs — fleet count, active trips, utilisation rate (filterable by type, region)
GET /analytics/reports/fuel-efficiency Any km/litre per vehicle
GET /analytics/reports/operational-cost Any Total cost breakdown per vehicle
GET /analytics/reports/fleet-utilization Any Trip count and distance per vehicle
GET /analytics/reports/export?type=operational-cost Any Download operational cost report as CSV

Health check

GET /health  →  { "status": "ok", "timestamp": "..." }

Business Rules

These are enforced at dispatch (POST /trips/:id/dispatch) and unit-tested in src/__tests__/:

Rule Description
Rule 1 Vehicles with status RETIRED or IN_SHOP cannot be dispatched
Rule 2 Drivers with status SUSPENDED or an expired license cannot be assigned
Rule 3 A vehicle or driver already ON_TRIP cannot be double-booked
Rule 4 Trip cargo weight (cargoKg) must not exceed the vehicle's capacityKg
Rule 5 Closing a maintenance record on a RETIRED vehicle keeps it RETIRED (not AVAILABLE)

Roles & Permissions

Role Key access
ADMIN Full access to everything including user registration and soft-deletes
FLEET_MANAGER Vehicles, drivers, trips, maintenance, fuel logs
DRIVER View trips and vehicles; log fuel; complete trips
SAFETY_OFFICER Drivers (update), maintenance (open/close/update)
FINANCIAL_ANALYST View all data; create expenses

Running Tests

# From transitops/
npm run test

Tests run with Jest in band (--runInBand) against the live database. Make sure your .env is set and the database is running before running tests.

Test files:

  • src/__tests__/business-rules.test.ts — unit tests for dispatch guards (vehicle, driver, cargo)
  • src/__tests__/maintenance-retired.test.ts — ensures RETIRED vehicles stay RETIRED after maintenance close

URLs at a Glance

Service URL
API http://localhost:4000
Web frontend http://localhost:5173
pgAdmin http://localhost:5050 (login: admin@transitops.com / admin123)
Prisma Studio http://localhost:5555 (run npm run db:studio)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages