Design a Package Installer System with dependencies
Problem Statement
Design the Low-Level Design (LLD) for a Package Installer System, similar to how tools like npm, pip, apt, or Maven work.
The system manages software packages, their versions, and dependencies between them.
It should handle installing, uninstalling, and resolving dependencies while preventing cyclic or conflicting installs.
The focus is on object-oriented class design and dependency resolution logic — not on actual file downloads or OS-level execution.
🎯 Goal
Design a Package Installer System that can:
✅ Functional Requirements
1. Package Management
Example:
1
2Package A depends on B and C
3Package B depends on DWhen installing A → system must install D, then B, then C, then A.
2. Installation
Example:
1
2install(A)
3A depends on B, C
4B depends on D
5=> Install D → B → C → A3. Uninstallation
Example:
1
2If A depends on B and user tries to remove B:
3→ Prevent removal since A still needs it.4. Dependency Resolution
5. State Management
6. Commands (APIs)
⚙️ Non-Functional Requirements
🧱 Key Classes to Design
ClassResponsibility
Package
Represents a software package (name, version, dependencies).
Dependency
Represents a link between two packages.
PackageRepository
Stores available packages and their dependency metadata.
InstalledPackageRegistry
Tracks currently installed packages and dependents.
DependencyResolver
Handles dependency graph traversal and topological sorting.
PackageInstaller
Orchestrates installation and uninstallation logic.
DependencyGraph
Represents the graph structure of package dependencies.
CycleDetector
Detects cyclic dependencies.
🧩 Suggested Class Structure
1
2Package
3 ├── String name
4 ├── String version
5 ├── List<String> dependencies
6
7DependencyGraph
8 ├── Map<String, List<String>> adjacencyList
9 ├── addEdge(String pkg, String dependency)
10 ├── List<String> topologicalSort()
11 ├── boolean hasCycle()
12
13PackageRepository
14 ├── Map<String, Package> availablePackages
15 ├── getPackage(String name)
16
17InstalledPackageRegistry
18 ├── Set<String> installedPackages
19 ├── Map<String, Set<String>> dependencyMap
20 ├── addPackage(String pkg)
21 ├── removePackage(String pkg)
22 ├── boolean isInstalled(String pkg)
23
24DependencyResolver
25 ├── List<String> resolveInstallOrder(String pkg)
26 ├── boolean detectCycle()
27
28PackageInstaller
29 ├── PackageRepository repo
30 ├── InstalledPackageRegistry registry
31 ├── DependencyResolver resolver
32 ├── void install(String pkg)
33 ├── void uninstall(String pkg)
34 ├── void listInstalled()🔄 Example Flow
📥 Installation Example
Input
1
2Package A → depends on B, C
3Package B → depends on D
4Package C → no dependencies
5Package D → no dependenciesCommand
1
2install(A)Process
Output
1
2Installing D
3Installing B
4Installing C
5Installing A🗑️ Uninstallation Example
Command
1
2uninstall(B)Output
1
2Cannot uninstall B — still required by A🧠 Design Patterns
⚡ Possible Extensions
🧾 Example Scenario
1
2repo.addPackage(A, dependencies=[B, C])
3repo.addPackage(B, dependencies=[D])
4repo.addPackage(C, dependencies=[])
5repo.addPackage(D, dependencies=[])
6
7installer.install("A")Output
1
2Installing D
3Installing B
4Installing C
5Installing A
6Installation complete.✅ Final Summary:
Design a Package Installer System (LLD) that: