Skip to content

Repository files navigation

Communicar Server

Backend API for Communicar, a peer-to-peer car rental platform. Owners list cars; renters search, book, pay, and chat with owners in real time.

The frontend client lives in a separate repository under the CommuniCar Dev Club organization.

Features

  • Auth — email/password signup and login, Google OAuth
  • Cars — geo and availability search, listing details
  • Bookings — create and fetch bookings with Stripe PaymentIntents
  • Profile (/me) — profile, password, avatar uploads (MinIO presigned URLs), saved payment methods, trip history and ratings
  • Owner tools — manage cars, view reservations and stats
  • Messaging — car/booking-linked conversations, text and image messages, read receipts, WebSocket delivery
  • Payments — Stripe setup intents, saved cards, webhooks

Tech Stack

  • Node.js 22, TypeScript, Express 5
  • PostgreSQL, Prisma 7
  • Zod 4 (request validation)
  • Stripe, MinIO (S3-compatible storage)
  • WebSockets (ws)
  • Vitest, Supertest

Architecture

flowchart LR
  Client --> Routes
  Routes --> Controllers
  Controllers --> Services
  Services --> Prisma
  Services --> Stripe
  Services --> MinIO
  Client --> WebSocket
  WebSocket --> Services
Loading

Request flow: Route → Controller → Service → (Mapper) → Prisma

All REST endpoints are prefixed with /api/v1. Success responses use { data, meta: { requestedAt } }. Errors return { code, message, fields? }.

Prerequisites

  • Node.js 22+
  • PostgreSQL (local — not included in Docker Compose)
  • MinIO (via Docker Compose or a local install)
  • Optional: Stripe test keys, Google OAuth client ID

Getting Started

npm ci
cp .env.example .env        # fill in your values
npx prisma generate
npx prisma migrate deploy
npm run db:seed             # requires MinIO running
npm run dev

The API is available at http://localhost:3000/api/v1.

Docker (app + MinIO)

docker compose up

Docker Compose runs the Node app and MinIO. PostgreSQL must run separately — set DATABASE_URL in .env to point at your host database (host.docker.internal on macOS). Compose overrides MINIO_ENDPOINT to minio.

MinIO console: http://localhost:9001 (default credentials: minioadmin / minioadmin).

Environment Variables

Copy .env.example to .env for local development.

Variable Required Default / notes
DATABASE_URL Yes PostgreSQL connection string
JWT_SECRET Prod Falls back to a dev value if unset
PORT No 3000
FRONTEND_URL No CORS origin; http://localhost:5173
STRIPE_SECRET_KEY No Stripe is disabled when absent
STRIPE_WEBHOOK_SECRET No Required only for webhook verification
GOOGLE_CLIENT_ID No Required for Google auth
MINIO_ENDPOINT No localhost
MINIO_PORT No 9000
MINIO_USE_SSL No false
MINIO_ACCESS_KEY No minioadmin
MINIO_SECRET_KEY No minioadmin
MINIO_BUCKET No communicar
MINIO_PRESIGN_EXPIRY_SECONDS No 86400
MINIO_UPLOAD_PRESIGN_EXPIRY_SECONDS No 900

API Overview

Prefix Endpoints
/api/v1/auth POST /login, /signup, /google
/api/v1/cars GET /search, GET /:carId
/api/v1/bookings POST /, GET /:id
/api/v1/me Profile, avatar, payment methods, trips, owner cars and reservations
/api/v1/conversations List, create, delete; messages; mark read
/api/v1/webhooks/stripe Stripe webhook handler
/api/v1/ws/messages WebSocket for real-time messages (JWT auth frame)

Protected routes require a Authorization: Bearer <token> header.

Testing

cp .env.test.example .env.test   # adjust DATABASE_URL if needed
createdb communicar_test          # or equivalent
npm test

Test setup loads .env.test, runs prisma migrate deploy automatically, and strips Stripe keys. Tests use a shared database with per-test truncation (fileParallelism: false).

Script Description
npm test All tests
npm run test:unit Utils and services
npm run test:integration Route integration tests
npm run test:watch Watch mode

Scripts

Script Description
npm run dev Start dev server (nodemon)
npm run build Compile TypeScript to dist/
npm start Run compiled server
npm run db:seed Reset and seed demo data

Project Structure

src/
├── routes/          # Express routers per domain
├── controllers/     # Thin request handlers
├── services/        # Business logic and database access
├── mappers/         # DB record → API shape transforms
├── DTO/             # Zod input/output schemas
├── middleware/      # Auth, validation, error handling
├── lib/             # Prisma, Stripe, MinIO clients
├── ws/              # WebSocket message handler
├── utils/           # Pricing, geo, availability helpers
└── tests/           # Shared test helpers and factories
prisma/
├── schema.prisma
├── migrations/
└── seed.ts
types/               # Inferred types from DTOs

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages