{"id":50840018,"url":"https://github.com/vimalyad/elevator-system","last_synced_at":"2026-06-14T06:06:24.087Z","repository":{"id":348074091,"uuid":"1195202788","full_name":"vimalyad/elevator-system","owner":"vimalyad","description":null,"archived":false,"fork":false,"pushed_at":"2026-03-30T16:58:39.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-30T18:28:54.091Z","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-29T11:20:11.000Z","updated_at":"2026-03-30T16:58:43.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/vimalyad/elevator-system","commit_stats":null,"previous_names":["vimalyad/elevator-system"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/vimalyad/elevator-system","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Felevator-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Felevator-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Felevator-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Felevator-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vimalyad","download_url":"https://codeload.github.com/vimalyad/elevator-system/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Felevator-system/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34310810,"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:23.556Z","updated_at":"2026-06-14T06:06:24.080Z","avatar_url":"https://github.com/vimalyad.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Elevator System (LLD)\n\nA highly robust, fully concurrent Low-Level Design (LLD) of an Elevator System implemented in Java.\n\nThis project simulates a real-world elevator environment using advanced concurrency models (Actor Model), design\npatterns, and asynchronous event-driven architecture. It dynamically handles passenger requests, weight limits, and\nemergency interruptions without race conditions or thread blocking.\n\n## 🚀 Key Features\n\n* **True Concurrency (Actor Model):** Each elevator operates on its own dedicated background thread (its \"Motor\"). A\n  central controller queues requests and drops them into the elevators' thread-safe `inboxes`, completely eliminating \"\n  runaway elevator\" race conditions.\n* **Dynamic Dispatch Strategies:** Supports hot-swapping routing algorithms at runtime.\n    * `NearestCarStrategy`: Dispatches the closest available elevator.\n    * `SCANStrategy`: The classic elevator algorithm that sweeps up and down, picking up passengers mid-transit if they\n      are heading in the same direction.\n* **Physical Constraints:** * **Weight Sensors:** Elevators refuse requests if the physical capacity limit (e.g., 800kg)\n  is reached, and trigger observer alarms.\n    * **Maintenance \u0026 Emergencies:** Supports planned downtime (`MAINTENANCE`) and instant, thread-safe emergency\n      halting (`NOT_AVAILABLE`).\n* **Event-Driven Telemetry:** Uses the Observer pattern to broadcast door movements, floor arrivals, alarms, and\n  overload warnings to independent display, logging, and sound systems.\n\n---\n\n## 🏗️ Architecture \u0026 Class Diagram\n\nThe system is built on **SOLID principles**, heavily utilizing **Composition** over inheritance.\n\n*Diagram Key:*\n\n* `\u003c|--` Inheritance (IS-A)\n* `..|\u003e` Realization / Implements\n* `*--` Composition (Strict Ownership / Part-of)\n* `o--` Aggregation (Shared Lifecycle / Has-a)\n* `--\u003e` Directed Association (Knows-about / Uses)\n\n```mermaid\nclassDiagram\n    %% ================= Interfaces =================\n    class IElevator {\n        \u003c\u003cinterface\u003e\u003e\n        +getElevatorId() int\n        +getCurrentFloor() int\n        +setCurrentFloor(int)\n        +getDirection() Direction\n        +setDirection(Direction)\n        +getElevatorStatus() ElevatorStatus\n        +setElevatorStatus(ElevatorStatus)\n        +getDoor() Door\n        +getWeightSensor() WeightSensor\n    }\n\n    class Panel {\n        \u003c\u003cinterface\u003e\u003e\n        +pressButton(Button)\n    }\n\n    class ElevatorPanel {\n        \u003c\u003cinterface\u003e\u003e\n        +getCurrentFloor() int\n        +setCurrentFloor(int)\n        +getDirection() Direction\n        +setDirection(Direction)\n    }\n\n    class Button {\n        \u003c\u003cinterface\u003e\u003e\n        +isPressed() boolean\n        +press()\n        +getDisplayName() String\n        +getType() ButtonType\n        +execute()\n    }\n\n    class DispatchStrategy {\n        \u003c\u003cinterface\u003e\u003e\n        +selectElevator(List~IElevator~, Request) IElevator\n    }\n\n    class ElevatorObserver {\n        \u003c\u003cinterface\u003e\u003e\n        +onFloorArrival(IElevator, int floor)\n        +onDoorStatusChange(IElevator)\n        +onAlarmTriggered(List~IElevator~)\n        +onOverloadWarning(IElevator)\n    }\n\n    %% ================= Models =================\n    class Building {\n        -List~Floor~ floors\n        -List~Elevator~ elevators\n    }\n\n    class Floor {\n        -int floorNumber\n        -ExternalPanel externalPanel\n    }\n\n    class Door {\n        -int doorId\n        -DoorStatus doorStatus\n    }\n\n    class Elevator {\n        -int elevatorId\n        -ElevatorStatus elevatorStatus\n        -int minFloor\n        -int maxFloor\n        -Door door\n        -ElevatorPanel panel\n        -WeightSensor weightSensor\n    }\n\n    class Request {\n        -int sourceFloor\n        -int destinationFloor\n        -Direction direction\n        -RequestType requestType\n    }\n\n    class WeightSensor {\n        -int maxCapacity\n        -int currentWeight\n        -Consumer~IElevator~ onOverload\n        +addWeight(int)\n        +removeWeight(int)\n        +canAccept(int) boolean\n    }\n\n    %% ================= Panels \u0026 Buttons =================\n    class InsidePanel {\n        -List~Button~ buttons\n        -int currentFloor\n        -Direction direction\n    }\n\n    class ExternalPanel {\n        -int panelId\n        -Direction direction\n        -List~IElevator~ elevators\n        -List~Button~ buttons\n    }\n\n    class SimpleButton {\n        -ButtonType type\n        -String displayName\n        -boolean isPressed\n        -Runnable action\n    }\n\n    %% ================= Controllers \u0026 Movers =================\n    class ElevatorController {\n        -List~IElevator~ elevators\n        -DispatchStrategy strategy\n        -ElevatorMover mover\n        -List~ElevatorObserver~ observers\n        -Queue~Request~ requestQueue\n        -ScheduledExecutorService dispatcher\n        +handleRequest(Request)\n        +processQueue()\n        +handleAlarm()\n    }\n\n    class ElevatorMover {\n        -List~ElevatorObserver~ observers\n        -Map~IElevator, Set~Integer~~ inboxes\n        -ExecutorService motorPool\n        +addDestination(IElevator, int)\n        -runMotorLoop(IElevator)\n        +emergencyStop(IElevator)\n    }\n\n    %% ================= Strategies \u0026 Observers =================\n    class NearestCarStrategy { }\n    class SCANStrategy { }\n    \n    class DisplayObserver { }\n    class LoggingObserver { }\n    class SoundObserver { }\n\n    %% ================= Wrappers \u0026 Factories =================\n    class ElevatorSystem {\n        -Building building\n        -ElevatorController controller\n        +requestElevator(int, Direction)\n        +requestFloor(int, int, Direction)\n        +triggerAlarm()\n        +setStrategy(DispatchStrategy)\n        +shutdown()\n    }\n\n    class ElevatorSystemFactory {\n        \u003c\u003cfactory\u003e\u003e\n        +create(...) ElevatorSystem\n    }\n\n    %% ================= Enums =================\n    class Direction { \u003c\u003cenumeration\u003e\u003e UP, DOWN, NOT_MOVING }\n    class ElevatorStatus { \u003c\u003cenumeration\u003e\u003e UP, DOWN, IDLE, NOT_AVAILABLE, MAINTENANCE }\n    class DoorStatus { \u003c\u003cenumeration\u003e\u003e OPEN, CLOSED }\n    class ButtonType { \u003c\u003cenumeration\u003e\u003e UP, DOWN, FLOOR, OPEN_DOOR, CLOSE_DOOR, ALARM }\n    class RequestType { \u003c\u003cenumeration\u003e\u003e INTERNAL, EXTERNAL }\n\n    %% ================= Relationships =================\n    \n    %% Inheritances\n    Elevator ..|\u003e IElevator\n    InsidePanel ..|\u003e ElevatorPanel\n    ExternalPanel ..|\u003e Panel\n    ElevatorPanel --|\u003e Panel\n    SimpleButton ..|\u003e Button\n    NearestCarStrategy ..|\u003e DispatchStrategy\n    SCANStrategy ..|\u003e DispatchStrategy\n    DisplayObserver ..|\u003e ElevatorObserver\n    LoggingObserver ..|\u003e ElevatorObserver\n    SoundObserver ..|\u003e ElevatorObserver\n\n    %% Composition \u0026 Aggregation\n    ElevatorSystem *-- Building\n    ElevatorSystem *-- ElevatorController\n    Building *-- Floor\n    Building *-- Elevator\n    Floor *-- ExternalPanel\n    Elevator *-- InsidePanel\n    Elevator *-- Door\n    Elevator *-- WeightSensor\n    ExternalPanel o-- Button\n    InsidePanel o-- Button\n    \n    %% Controller Dependencies\n    ElevatorController o-- IElevator\n    ElevatorController *-- ElevatorMover\n    ElevatorController --\u003e DispatchStrategy\n    ElevatorController o-- ElevatorObserver\n    ElevatorController o-- Request\n\n    %% Mover \u0026 Sensors\n    ElevatorMover --\u003e IElevator : updates state\n    WeightSensor --\u003e IElevator : triggers overload\n```\n\n---\n\n## 🧩 Design Patterns Applied\n\n1. **Actor Pattern (Concurrency):** `ElevatorMover` spins up one fixed background thread per physical elevator. The\n   `ElevatorController` acts as a dispatcher, dropping requests into concurrent `inboxes` (ConcurrentSkipListSet). This\n   ensures only one thread ever calculates the elevator's physical movement, preventing race conditions.\n2. **Strategy Pattern:** `DispatchStrategy` isolates the mathematical routing logic (`SCAN` vs `NearestCar`), allowing\n   the system to change behavior at runtime based on traffic conditions.\n3. **Observer Pattern:** The system broadcasts state changes (Door opening, Floor arrivals, Alarms, Overloads) to\n   decoupled listeners (`DisplayObserver`, `SoundObserver`, `LoggingObserver`).\n4. **Command Pattern:** UI buttons (`SimpleButton`) encapsulate their behavior within a `Runnable` lambda, allowing the\n   panels to be completely decoupled from the system's execution logic.\n5. **Factory Pattern:** `ElevatorSystemFactory` hides the immense complexity of wiring together doors, panels, buttons,\n   callbacks, threads, and sensors, returning a clean, ready-to-use `ElevatorSystem` API.\n6. **Single Responsibility Principle (SRP):** The `Elevator` class is stripped of heavy logic. Mathematical weight\n   calculations are offloaded to `WeightSensor`, and physical movement is offloaded to `ElevatorMover`.\n\n## ⚙️ How to Run\n\nCompile the package and execute `Main.java`. The main method contains three automated simulation scenarios:\n\n1. **Concurrent Requests** resolving via Nearest Car.\n2. **Mid-Transit Routing** demonstrating the SCAN Algorithm.\n3. **Emergency Halting** demonstrating thread-safe system interrupts.\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimalyad%2Felevator-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvimalyad%2Felevator-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimalyad%2Felevator-system/lists"}