{"id":50840067,"url":"https://github.com/vimalyad/multi-level-parking-lot-system","last_synced_at":"2026-06-14T06:06:36.597Z","repository":{"id":346421103,"uuid":"1189563953","full_name":"vimalyad/multi-level-parking-lot-system","owner":"vimalyad","description":null,"archived":false,"fork":false,"pushed_at":"2026-03-23T19:52:33.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-24T17:48:29.821Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vimalyad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-23T12:57:35.000Z","updated_at":"2026-03-23T19:52:37.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/vimalyad/multi-level-parking-lot-system","commit_stats":null,"previous_names":["vimalyad/multi-level-parking-lot-system"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/vimalyad/multi-level-parking-lot-system","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Fmulti-level-parking-lot-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Fmulti-level-parking-lot-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Fmulti-level-parking-lot-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Fmulti-level-parking-lot-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vimalyad","download_url":"https://codeload.github.com/vimalyad/multi-level-parking-lot-system/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Fmulti-level-parking-lot-system/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34310813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-14T06:06:35.884Z","updated_at":"2026-06-14T06:06:36.587Z","avatar_url":"https://github.com/vimalyad.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🅿️ Multilevel Parking Lot System (Low-Level Design)\n\nA robust, highly scalable, and modular object-oriented design for a multilevel parking lot. This system is engineered to\nhandle multiple entry gates, dynamic slot assignments based on distance, vehicle type compatibility, and extensible\npricing models.\n\n## ✨ Core Features\n\n* **Multi-Gate Distance Optimization:** Automatically assigns the *nearest* available compatible slot based on the\n  specific entry gate the vehicle arrives at.\n* **Smart Slot Upgrades:** Implements compatibility rules where smaller vehicles can occupy larger slots if their\n  preferred slots are full (e.g., a Two-Wheeler can park in a Medium or Large slot).\n* **Fair Billing System:** Calculates parking fees based on the *allocated slot type*, not the vehicle type, ensuring\n  fair usage of real estate.\n* **High Performance:** Utilizes customized `TreeSet` data structures backed by Red-Black Trees. Finding the optimal slot and updating its availability across $G$ multiple gates operates at a highly efficient **$O(G \\log N)$** time complexity, ensuring the system remains responsive even with thousands of parking spaces.\n\n---\n\n## 🏗️ Architecture \u0026 Approach\n\nThis system strictly adheres to **SOLID** principles and utilizes the **Strategy Design Pattern** to prevent the\n`ParkingLot` service from becoming a bloated \"God Object.\"\n\n### 1. Separation of Concerns\n\nThe codebase is divided into clear layers:\n\n* **Models (Entities):** Pure data carriers (`Vehicle`, `Gate`, `Slot`, `Ticket`).\n* **Strategies (Business Logic):** Interchangeable rules for assignment and pricing.\n* **Service (Orchestrator):** The `ParkingLot` class simply holds the state and delegates complex decisions to the\n  injected strategies.\n\n### 2. The Strategy Pattern\n\nBy abstracting the core logic into interfaces, the system is highly extensible (Open/Closed Principle):\n\n* **`SlotAssignmentStrategy`**: Currently implemented as `NearestSlotStrategy`. If a future requirement demands VIP\n  parking (where VIPs get premium slots regardless of distance), we simply create a `VipSlotStrategy` without modifying\n  existing code.\n* **`PricingStrategy`**: Currently implemented as `HourlyPricingStrategy`. This can easily be swapped for a\n  `FlatRatePricingStrategy` or `SurgePricingStrategy` during holidays.\n\n### 3. The \"Nearest Slot\" Engine (`TreeSet`)\n\nFinding the nearest slot out of thousands could be an $O(N)$ bottleneck. To solve this, the system pre-computes\ndistances:\n\n* Each `Gate` maintains its own `Map\u003cSlotType, TreeSet\u003cSlot\u003e\u003e`.\n* The `TreeSet` is initialized with a custom `Comparator` that sorts slots by their geometric distance to *that specific\n  gate* (calculating floor and position deltas).\n* **Result:** When a vehicle enters, finding the optimal slot is an **$O(\\log N)$** operation (`treeSet.first()`). Because we must prevent double-booking, updating this state across all $G$ gates takes **$O(G \\log N)$** time.\n\n---\n\n## 📊 UML Class Diagram\n\n```mermaid\nclassDiagram\n    %% Core Service\n    class ParkingLot {\n        -Map~String, Gate~ gates\n        -Map~String, Map~SlotType, TreeSet~Slot~~~ availableSlotsPerGate\n        -Map~String, Ticket~ activeTickets\n        -SlotAssignmentStrategy assignmentStrategy\n        -PricingStrategy pricingStrategy\n        +addGate(Gate)\n        +addSlot(Slot)\n        +park(Vehicle, long, SlotType, String): Ticket\n        +exit(String, long): double\n        +status(): Map~SlotType, Integer~\n    }\n\n    %% Strategies\n    class SlotAssignmentStrategy {\n        \u003c\u003cinterface\u003e\u003e\n        +assignSlot(Vehicle, SlotType, Gate, Map) Slot\n    }\n\n    class NearestSlotStrategy {\n        -Map~VehicleType, List~SlotType~~ compatibilityMap\n        +assignSlot(Vehicle, SlotType, Gate, Map) Slot\n    }\n\n    class PricingStrategy {\n        \u003c\u003cinterface\u003e\u003e\n        +calculateBill(Ticket, long) double\n    }\n\n    class HourlyPricingStrategy {\n        -Map~SlotType, Double~ hourlyRates\n        +calculateBill(Ticket, long) double\n    }\n\n    %% Enums\n    class VehicleType {\n        \u003c\u003cenumeration\u003e\u003e\n        TWO_WHEELER\n        CAR\n        BUS\n    }\n\n    class SlotType {\n        \u003c\u003cenumeration\u003e\u003e\n        SMALL\n        MEDIUM\n        LARGE\n    }\n\n    %% Models\n    class Vehicle {\n        -String licensePlate\n        -VehicleType type\n    }\n\n    class Gate {\n        -String id\n        -int floor\n        -int position\n    }\n\n    class Slot {\n        -String id\n        -SlotType type\n        -int floor\n        -int position\n    }\n\n    class Ticket {\n        -String ticketId\n        -Vehicle vehicle\n        -Slot allocatedSlot\n        -long entryTime\n    }\n\n    %% Relationships\n    ParkingLot --\u003e SlotAssignmentStrategy : Uses\n    ParkingLot --\u003e PricingStrategy : Uses\n    SlotAssignmentStrategy \u003c|.. NearestSlotStrategy : Implements\n    PricingStrategy \u003c|.. HourlyPricingStrategy : Implements\n    \n    ParkingLot \"1\" *-- \"*\" Gate : Manages\n    ParkingLot \"1\" *-- \"*\" Slot : Manages\n    ParkingLot \"1\" *-- \"*\" Ticket : Manages\n    \n    Ticket --\u003e Vehicle : Contains\n    Ticket --\u003e Slot : Contains\n    Slot --\u003e SlotType : Uses\n    Vehicle --\u003e VehicleType : Uses\n```\n\n---\n\n## 📁 Project Structure\n\n```text\nsrc/\n├── enums/\n│   ├── SlotType.java\n│   └── VehicleType.java\n├── models/\n│   ├── Gate.java\n│   ├── Slot.java\n│   ├── Ticket.java\n│   └── Vehicle.java\n├── strategy/\n│   ├── PricingStrategy.java\n│   ├── HourlyPricingStrategy.java\n│   ├── SlotAssignmentStrategy.java\n│   └── NearestSlotStrategy.java\n├── service/\n│   └── ParkingLot.java\n└── Main.java\n```\n\n---\n\n## 🚀 How to Run\n\n1. Clone the repository to your local machine.\n2. Ensure you have Java Development Kit (JDK) 8 or higher installed.\n3. Compile the Java files:\n   ```bash\n   javac src/*.java\n   ```\n4. Execute the Main runner class:\n   ```bash\n   java -cp src Main\n   ```\n\nThe `Main.java` file contains a pre-built simulation that demonstrates adding physical infrastructure (Gates and Slots), processing various vehicle arrivals (including automated slot upgrades), and calculating exits and billing.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimalyad%2Fmulti-level-parking-lot-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvimalyad%2Fmulti-level-parking-lot-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimalyad%2Fmulti-level-parking-lot-system/lists"}