π Tech Stack LayerTechnologyRuntimeNode.jsFrameworkExpress.jsDatabaseMongoDBODMMongooseEnvironment ConfigdotenvDevelopmentnodemon
smart-parking/ βββ src/ β βββ server.js β βββ app.js β βββ config/ β β βββ db.js β βββ models/ β βββ controllers/ β βββ routes/ β βββ middleware/ β βββ utils/ βββ .env βββ .env.example βββ package.json βββ README.md
βοΈ Setup
- Clone the repository bashgit clone https://github.com/your-username/smart-parking-api.git cd smart-parking-api
- Install dependencies bashnpm install
- Configure environment bashcp .env.example .env Edit .env with your values: envPORT=3000 MONGODB_URI=mongodb://localhost:27017/smart_parking NODE_ENV=development
- Run the server bashnpm run dev # Development (with nodemon) npm start # Production
π‘ API Overview Base URL: http://localhost:3000/api π² Slots MethodEndpointDescriptionPOST/slots/initializeInitialize the parking lotGET/slotsView all slots (with filters)DELETE/slots/resetReset the entire system π Vehicles MethodEndpointDescriptionPOST/vehicles/entryVehicle entry β auto slot assignmentPOST/vehicles/exitVehicle exit β duration calculationGET/vehiclesView all currently parked vehiclesGET/vehicles/search?plate=Search by number plate π History MethodEndpointDescriptionGET/historyFull parking historyGET/history?status=Filter by statusGET/history?plate=Filter by number plateGET/history?page=&limit=Paginated results
β¨ Key Features
Smart Slot Allocation β Automatically assigns the nearest available slot Duplicate Prevention β Blocks re-entry of an already-parked vehicle Duration Tracking β Accurate parking time calculation on exit Advanced Filtering β Search and filter across slots, vehicles, and history Pagination β Efficient handling of large datasets Consistent Responses β Uniform API response structure throughout Indexed Queries β MongoDB indexes for high-performance lookups
π Data Models ParkingSlot js{ slotNumber: Number, isOccupied: Boolean, vehicleNumberPlate: String, entryTime: Date } ParkingHistory js{ vehicleNumberPlate: String, slotNumber: Number, entryTime: Date, exitTime: Date, durationMinutes: Number, status: "PARKED" | "EXITED" }
π§ͺ Testing Flow
Initialize the parking lot with slots Park one or more vehicles Check currently occupied slots Exit a vehicle Verify the parking history
No authentication or authorization system No payment or billing logic No real-time updates (WebSocket/SSE) No frontend interface
π License MIT License β free to use, modify, and distribute.