How zaantoru/p2p-ui works
Purpose and entry points
1816 is a peer-to-peer car and motorcycle rental platform. A React/Vite client serves renter and role-specific staff workflows; a Fastify API owns booking, payment, operations, notifications, and telemetry persistence. Client startup is src/main.jsx → src/App.jsx; API startup is server/src/index.js. Vite proxies browser /api and /uploads traffic to the API.
Client application and role workspaces
The SPA provides vehicle discovery, detail, checkout, chat, notifications, and dashboards for renter, host, operations, management, and admin roles. Authentication state is centralized before protected API interactions, while dashboard selection reflects server-issued roles.
• src/context/AuthContext.jsx
• src/pages/Checkout/Checkout.jsx
• src/pages/Dashboard/Renter/RenterDashboard.jsx
• src/pages/Dashboard/Operations/OperationsDashboard.jsx
• src/pages/Dashboard/Admin/AdminDashboard.jsx
API boundary, identity, and authorization
Fastify routes expose the domain API. JWT authentication and role guards form the principal boundary between the SPA and protected booking, operational, financial, and fleet actions. Uploads are served separately for vehicle and workflow evidence.
• server/src/index.js
• server/src/routes/auth.js
• server/src/middleware/auth.js
• server/src/middleware/roleGuard.js
• server/src/routes/uploads.js
Booking lifecycle and availability control
Bookings progress through approval, payment-required, scheduled/booked, ongoing, and completed states. Route handlers coordinate availability, workflow state, and notifications; overlap/hold logic prevents conflicting reservations. Late status and fee calculation are modeled separately from booking status.
• server/src/routes/bookings.js
• server/src/routes/operations.js
• server/src/utils/bookingOverlap.js
• server/src/utils/lateFees.js
• server/src/services/lateReturnMonitor.js
Payments, receipts, and payment policy
The platform supports manually verified GCash/Maya evidence, with a fixed PHP 1 test-reservation policy after approval. It also contains PayMongo checkout/webhook integration, receipt generation, payment-method management, and refund eligibility/policy rules.
• server/src/routes/payments.js
• server/src/routes/paymentMethods.js
• server/src/routes/paymongoWebhooks.js
• server/src/services/paymongoService.js
• server/src/services/receiptService.js
Evidence-led rental operations
Operational routes manage pre-handover and post-return condition checks, required renter sign-off, and completion. Identity and requirements endpoints support renter verification and required booking documentation; stored uploads are an important persistence boundary.
• server/src/routes/conditionChecks.js
• server/src/routes/identity.js
• server/src/routes/requirements.js
• server/uploads/vehicle-photos
Fleet, telemetry, and communications
Vehicle inventory is managed through the vehicle API and host workflows. MQTT/GNSS telemetry is ingested for registered IoT devices, with a staff-only simulation path outside production. The API also supports direct messages, in-app notifications, booking reminders, and email delivery.
• server/src/routes/vehicles.js
• server/src/routes/telemetry.js
• server/src/services/telemetryService.js
• server/src/routes/messages.js
• server/src/services/mailService.js
Persistence and infrastructure
PostgreSQL is the system of record, accessed through the DB configuration and evolved by ordered SQL migrations tracked in schema_migrations. Runtime dependencies include Node.js/Fastify, PostgreSQL, JWT, MQTT broker connectivity, PayMongo, and local upload storage.
• server/src/config/db.js
• server/db/schema.sql
• server/db/migrations/001_operations_upgrade.sql
• server/db/migrations/004_paymongo_checkout_webhooks.sql
• server/scripts/migrate.js
Main entry points: bookings.js Booking lifecycle · index.js API server · auth.js Auth and access control · main.jsx SPA entry and router
Components 21
React SPA
- SPA entry and router
src/main.jsx - Authentication state · Centralizes identity before protected API calls.
src/context/AuthContext.jsx - Role workspaces · Renter, operations, and admin dashboards select server-issued roles.
src/pages/Dashboard/Renter/RenterDashboard.jsx - Checkout
src/pages/Checkout/Checkout.jsx
Fastify API
- API server · Serves domain routes and proxied uploads.
server/src/index.js - Auth and access control · JWT authentication and role guards protect domain actions.
server/src/middleware/auth.js - Booking lifecycle · Coordinates approval, payment, scheduling, ongoing, and completion states.
server/src/routes/bookings.js - Availability control · Prevents conflicting reservations and holds.
server/src/utils/bookingOverlap.js - Rental operations · Manages handover, return workflow, and completion.
server/src/routes/operations.js - Late return monitoring · Separates late status and fee calculation from booking state.
server/src/services/lateReturnMonitor.js - Payments and policy · Handles manual evidence, test-reservation policy, refunds, and methods.
server/src/routes/payments.js - PayMongo integration · Creates checkout sessions and processes webhooks.
server/src/services/paymongoService.js - Identity and condition evidence · Captures verification, requirements, condition checks, and sign-off.
server/src/routes/conditionChecks.js - Fleet inventory
server/src/routes/vehicles.js - Telemetry ingestion · Ingests GNSS data for registered IoT devices.
server/src/services/telemetryService.js - Messaging and notifications · Supports direct messages, reminders, in-app notifications, and email.
server/src/routes/messages.js
Persistence
- PostgreSQL
server/src/config/db.js - Schema migrations · Ordered migrations are tracked in schema_migrations.
server/scripts/migrate.js - Local upload storage · Stores vehicle photos and workflow evidence.
server/uploads/vehicle-photos
External services
- MQTT broker
- PayMongo
Connections 23
- SPA entry and router → Authentication state
- SPA entry and router → Role workspaces
- SPA entry and router → Checkout
- Authentication state → API server: protected API requests
- Role workspaces → API server: staff and renter workflows
- Checkout → API server: booking and payment
- API server → Auth and access control: authenticates and authorizes
- Auth and access control → Booking lifecycle: guards access
- Auth and access control → Rental operations: guards access
- Auth and access control → Payments and policy: guards access
- Booking lifecycle → Availability control: checks overlap and holds
- Booking lifecycle → Payments and policy: requires payment after approval
- Booking lifecycle → Rental operations: drives rental workflow
- Booking lifecycle → Late return monitoring: monitors active rentals
- Rental operations → Identity and condition evidence: requires condition evidence
- Identity and condition evidence → Local upload storage: stores evidence
- Fleet inventory → Local upload storage: stores vehicle photos
- Payments and policy → PayMongo integration: checkout and webhook processing
- PayMongo integration → PayMongo: payment API
- Telemetry ingestion → MQTT broker: ingests device telemetry
- Booking lifecycle → Messaging and notifications: booking notifications
- API server → PostgreSQL: domain persistence
- Schema migrations → PostgreSQL: evolves schema