A parking management system built with NestJS and MongoDB that tracks vehicle parking entries, payments, and exits.
- Create parking entries with license plate validation (format: AAA-9999)
- Track parking payment status
- Record vehicle exit times
- View parking history by license plate
- Dockerized deployment with MongoDB
- Up and running on Railway with my own custom DNS (proxied via Cloudflare)! Check out the Test the API section below.
- Framework: NestJS (Node.js)
- Database: MongoDB 7
- Runtime: Node.js 20 (Alpine)
- Containerization: Docker & Docker Compose
- Docker
- Docker Compose
-
Clone the repository.
-
Start the application with Docker Compose:
docker compose up -dThis will:
- Build the NestJS application
- Start MongoDB 7 with health checks
- Create persistent storage for database
- Expose the API on port 3000
- Verify the services are running:
docker compose ps- Stop the application:
docker compose down- Stop and remove data:
docker compose down -vPOST /parking
Content-Type: application/json
{
"plate": "ABC-1234"
}
Response: 201 Created
{
"parkingId": "695e9e44f6f97a164319c0f6"
}GET /parking/:plate
Response: 200 OK
[
{
"id": "695e9e44f6f97a164319c0f6",
"time": "15 minutes",
"paid": false,
"left": false
}
]# use parkingId as param
PUT /parking/:id/pay
Response: 204 No Content# use parkingId as param
PUT /parking/:id/out
Response: 204 No ContentExample workflow:
DISCLAIMER: since it's a free tier serverless deploy, it may take longer than expected for both the server and database to "wake up" and the first request may timeout. Simply try again if that's the case. If running locally with docker compose this should not happen!
To run on your machine with docker compose, simply change the URLs to http://[::]:3000
# 1. Create a parking entry
curl -X POST https://bocchi.codes/parking \
-H "Content-Type: application/json" \
-d '{"plate": "ABC-1234"}'
# 2. Get parking history
curl https://bocchi.codes/parking/ABC-1234
# 3. Mark as paid
curl -X PUT https://bocchi.codes/parking/ABC-1234/pay
# 4. Mark vehicle exit
curl -X PUT https://bocchi.codes/parking/ABC-1234/outAdditionally, there's a health check route to see services status:
curl https://bocchi.codes/parking/health
# or locally
curl http://[::]:3000/health# Unit tests
yarn run test
# Test coverage
yarn run test:covThe application uses a multi-stage Docker build:
- Builder stage: Compiles TypeScript to JavaScript
- Production stage: Runs with minimal dependencies (production-only)