Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
.env
*.log
npm-debug.log*
dist
.vscode
.DS_Store
coverage
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Campus Cab System

Campus Friday Prayer Cab System described in `docs/PRD.md`. The repo now ships a runnable Express API (Supabase-aware) and
a Vite + React frontend with shadcn-inspired UI primitives.

## Project structure

- `backend/` — Express server exposing health checks, booking creation, mock Razorpay payments, admin demand + allocations,
and QR scan timing rules. Supabase client is initialized via environment variables.
- `frontend/` — Vite + React + Tailwind frontend with shadcn-style components, live booking form, driver scan simulator,
and admin demand/allocation widgets.
- `docs/` — PRD and supporting design docs.

## Getting started

### Backend

```bash
cd backend
cp .env.example .env
npm install
npm run dev
```

The API starts on `http://localhost:4000`. Update the `.env` to point at your Supabase project and set admin credentials.

### Frontend

```bash
cd frontend
cp .env.example .env
npm install
npm run dev
```

The app runs on `http://localhost:5173` and can call the backend using `VITE_API_BASE` (defaults to `http://localhost:4000`).

## Key endpoints

- `GET /health` — basic status.
- `GET /api/bookings/halls` and `/api/bookings/trips` — discover halls and sample trips.
- `POST /api/bookings` — create a confirmed booking (mock payment) and issue a QR token.
- `POST /api/payments/mock` — mock Razorpay payment response (toggle with `MOCK_PAYMENT_MODE`).
- `POST /api/admin/login` — password-only admin sign-in.
- `GET /api/admin/demand` — demand summary derived from created bookings.
- `POST /api/admin/allocations` — simple allocation model that assigns seeded cabs to halls by demand.
- `GET /api/admin/allocations` — view the current allocation set.
- `GET /api/scans/:tripId/rule` — expose scan-direction rules for a trip.
- `POST /api/scans/:tripId/scan` — classify outbound vs return vs no-show using configured return/close times.

## Tech choices

- Backend: Node.js (Express), Supabase client, dotenv, date-fns for scan rules, faker for demo IDs, and morgan for logging.
- Frontend: React 18, Vite, Tailwind, class-variance-authority/tailwind-merge for shadcn-style components.
- Hosting targets: Vercel (frontend) and Azure (backend), with Supabase-managed Postgres/auth.

## Next steps

- Wire Supabase auth (Google for students) and database entities.
- Implement real Razorpay integration and replace mock payment flow.
- Persist bookings/payments/allocations in Supabase and expose QR/passkey validation pages.
9 changes: 9 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PORT=4000
SUPABASE_URL=https://YOUR_PROJECT.supabase.co
SUPABASE_ANON_KEY=your-anon-key
GOOGLE_CLIENT_ID=your-google-client-id.apps.googleusercontent.com
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=changeme
MOCK_PAYMENT_MODE=true
TRIP_RETURN_TIME=2024-01-05T13:30:00.000Z
TRIP_CLOSE_TIME=2024-01-05T14:00:00.000Z
46 changes: 46 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import dotenv from 'dotenv';
import express from 'express';
import cors from 'cors';
import morgan from 'morgan';
import { createClient } from '@supabase/supabase-js';
import healthRouter from './src/routes/health.js';
import bookingRouter from './src/routes/bookings.js';
import paymentsRouter from './src/routes/payments.js';
import adminRouter from './src/routes/admin.js';
import scansRouter from './src/routes/scans.js';
import { loadConfig } from './src/utils/config.js';

dotenv.config();
Comment on lines +10 to +13
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Load .env before importing routes

In backend/index.js the route modules are imported (lines 6–10) before dotenv.config() runs on line 13, but each route module calls loadConfig() at module scope. Because ES module imports execute before the body of this file, those loadConfig() calls see only the bare process environment, so .env values for admin credentials, payment mock mode, and trip timing are silently ignored and defaults are used. Running the API with a .env file will therefore authenticate against admin@example.com/changeme and always enable mock payments regardless of the intended configuration.

Useful? React with 👍 / 👎.


const app = express();
const config = loadConfig();

const supabaseClient = config.supabase.url && config.supabase.key
? createClient(config.supabase.url, config.supabase.key)
: null;

app.set('supabase', supabaseClient);

app.use(cors());
app.use(express.json());
app.use(morgan('dev'));

app.use('/health', healthRouter);
app.use('/api/bookings', bookingRouter);
app.use('/api/payments', paymentsRouter);
app.use('/api/admin', adminRouter);
app.use('/api/scans', scansRouter);

app.get('/api/config/public', (_req, res) => {
res.json({
supabaseUrl: config.supabase.url,
googleClientId: config.googleClientId,
mockPayment: config.payments.mockMode,
});
});

const port = config.port;
app.listen(port, () => {
// eslint-disable-next-line no-console
console.log(`API listening on port ${port}`);
});
Loading