Parking Lot System: Django React fullstack

Parking Lot System Design Specification

Parking Lot System Design Specification

System Overview

  • Purpose: Manage parking operations—entries, exits, payments, reservations, capacity, and reporting.
  • Users: Admins, attendants, and customers.
  • Core Features:
    • Lot management: zones, capacity, pricing rules, operating hours
    • Vehicle lifecycle: entry, session tracking, exit, fee calculation
    • Reservations: pre-booking, penalties
    • Payments: cash/card/manual record, gateway integration-ready
    • Accounts & roles: RBAC
    • Reports: occupancy, revenue, peak times
    • Audit & logs

Architecture

High-level Components

  • Frontend: React SPA with role-based views
  • Backend: Django + Django REST Framework
  • Database: MySQL or MongoDB
  • Auth: JWT-based stateless authentication
  • Deployment: Dockerized services, CI/CD via GitHub Actions

Component Interaction

React calls Django REST APIs → Django applies business rules → Database persists data.

Background tasks handled via Celery + Redis.

Data Model

MySQL Schema

  • ParkingLot: id, name, address, timezone, is_active
  • Zone: id, lot_id, name, capacity, vehicle_type_allowed, is_active
  • PricingRule: id, lot_id, vehicle_type, base_rate, hourly_rate, grace_period_minutes, daily_max, night_rate, effective_from, effective_to
  • Vehicle: id, plate_number, vehicle_type, owner_name, owner_contact
  • ParkingSession: id, lot_id, zone_id, vehicle_id, entry_time, exit_time, status, calculated_fee, payment_status, ticket_number
  • Reservation: id, lot_id, zone_id, vehicle_id, start_time, end_time, status, deposit_amount, no_show_fee
  • Payment: id, session_id, amount, method, transaction_ref, timestamp, status
  • User: id, username, email, password_hash, role, is_active
  • AuditLog: id, user_id, entity_type, entity_id, action, timestamp, changes

MongoDB Schema

  • parking_lots: { _id, name, address, timezone, is_active, zones: [...] }
  • pricing_rules: { _id, lot_id, vehicle_type, base_rate, hourly_rate, ... }
  • vehicles: { _id, plate_number, vehicle_type, owner }
  • sessions: { _id, lot_id, zone_id, vehicle_id, entry_time, exit_time, status, fee }
  • reservations: { _id, lot_id, zone_id, vehicle_id, start_time, end_time, status }
  • payments: { _id, session_id, amount, method, transaction_ref, timestamp, status }
  • users: { _id, username, email, password_hash, role, is_active }
  • audit_logs: { _id, user_id, entity_type, entity_id, action, timestamp, changes }

API Design (Django REST Framework)

Auth

  • POST /api/auth/login
  • POST /api/auth/refresh
  • POST /api/auth/logout

Parking Lots & Zones

  • GET /api/lots
  • POST /api/lots
  • GET /api/lots/{id}
  • PATCH /api/lots/{id}
  • GET /api/lots/{id}/zones
  • POST /api/lots/{id}/zones
  • PATCH /api/zones/{id}

Pricing Rules

  • GET /api/lots/{id}/pricing
  • POST /api/lots/{id}/pricing
  • PATCH /api/pricing/{id}

Vehicles

  • GET /api/vehicles?plate=...
  • POST /api/vehicles
  • PATCH /api/vehicles/{id}

Parking Sessions

  • POST /api/sessions/entry
  • POST /api/sessions/{id}/exit
  • GET /api/sessions?status=ACTIVE
  • GET /api/sessions/{id}

Reservations

  • POST /api/reservations
  • GET /api/reservations
  • PATCH /api/reservations/{id}/cancel

Payments

  • POST /api/payments
  • GET /api/payments?session_id=...

Reports

  • GET /api/reports/occupancy
  • GET /api/reports/revenue
  • GET /api/reports/peak-hours

Audit Logs

  • GET /api/audit

Business Rules

  • Capacity enforcement: Zone capacity must not be exceeded.
  • Pricing calculation: Fee = base_rate + hourly_rate × billable_hours, with grace period and daily cap.

Comments

Popular Posts