-
Notifications
You must be signed in to change notification settings - Fork 0
Initialize Express/React scaffolding #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheShahnawaaz
wants to merge
3
commits into
database-lld
Choose a base branch
from
codex/understand-project-structure-and-components
base: database-lld
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
|
||
| 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}`); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
backend/index.jsthe route modules are imported (lines 6–10) beforedotenv.config()runs on line 13, but each route module callsloadConfig()at module scope. Because ES module imports execute before the body of this file, thoseloadConfig()calls see only the bare process environment, so.envvalues for admin credentials, payment mock mode, and trip timing are silently ignored and defaults are used. Running the API with a.envfile will therefore authenticate againstadmin@example.com/changemeand always enable mock payments regardless of the intended configuration.Useful? React with 👍 / 👎.