Skip to content

Conversation

@abbott
Copy link
Owner

@abbott abbott commented Mar 8, 2025

This commit refactors hardn from a procedural codebase to a modern, interface-oriented architecture while improving maintainability, testability, and extensibility.

  • Introduced a layered Clean Architecture separating domain models, application services, infrastructure adapters, and UI.
  • Implemented dependency injection for improved testability and flexibility.
  • Encapsulated external dependencies behind interfaces, enabling mock implementations and multiple environment support.
  • Added unit tests with mocking to verify behavior without external dependencies.
  • Enhanced modularity by clearly organizing domain logic, repositories, application services, and UI.
  • Refactored the menu system while keeping its user experience intact.
  • Used the factory pattern for streamlined component creation and wiring.
  • Improved error handling, logging, and documentation.

This refactoring ensures sustainable long-term maintenance and simplifies future feature development.

abbott added 17 commits March 5, 2025 17:27
This commit introduces the foundation for a full Interface-Oriented
Architecture (IOA) using a hexagonal/ports & adapters pattern. It establishes
a clear separation between domain logic and infrastructure concerns through
well-defined interfaces.

Key additions:
- Domain models: Added User, SSH, Firewall, and DNS models
- Domain services: Created service interfaces with pure business logic
- Port definitions: Defined repository interfaces for infrastructure needs
- Adapters: Implemented adapters for file system, command execution, etc.
- Application services: Added orchestration layer for use cases
- Infrastructure: Service factory for dependency injection

The architecture is designed as vertical slices:
- Completed User Management vertical slice
- Added SSH configuration vertical slice
- Added Firewall configuration vertical slice
- Added DNS configuration vertical slice

This is the first phase in a gradual migration strategy, with feature toggles
for incremental adoption. The new architecture improves testability,
maintainability, and flexibility while enabling easier extension to new
features in the future.

Benefits:
- Clean domain model without infrastructure dependencies
- Proper dependency inversion (dependencies point inward)
- Enhanced testability through interface-based design
- Component isolation for better maintainability
- Flexible implementation swapping without domain changes
This commit refactors the menu system to leverage the Interface-Oriented
Architecture pattern. Rather than directly calling package functions, menus
now operate through the application service layer.

Key changes:
- Create object-oriented MainMenu and UserMenu classes
- Implement MenuManager in application layer for menu operations
- Add menu factory for dependency injection
- Maintain the same UI experience with improved architectural underpinnings

This change enables a gradual transition from the current functional style
to a more maintainable and testable object-oriented approach while preserving
the user experience. Each submenu can now be refactored incrementally while
the system remains fully operational.

Part of the ongoing effort to implement a full hexagonal architecture.
This commit continues the migration to Interface-Oriented Architecture (IOA) by
implementing several key menu components and the package management functionality:

- Create object-oriented menu classes for Firewall, DNS, Linux and Python packages
- Implement domain model and service interface for package management
- Add OSPackageRepository to handle OS-specific package operations
- Update ServiceFactory and MenuFactory to wire dependencies properly
- Extend MenuManager with package management functionality
- Update main menu to use the new menu classes

This change maintains the same UI experience while providing a more maintainable
and testable architecture with clear separation of concerns. The new architecture
can be enabled with the --use-new-arch flag, allowing for incremental adoption.

Part of the ongoing effort to implement a full hexagonal architecture.
Add comprehensive unit tests for all domain service implementations:

- BackupService: Test file operations, cleanup, config management
- UserService: Test user creation, SSH key management, sudo configuration
- SSHService: Test SSH configuration across different OS types
- PackageService: Test package installation and repository management
- LogsService: Test log retrieval and configuration
- FirewallService: Test rule management, profile handling, state management
- EnvironmentService: Test sudo preservation settings
- DNSService: Test nameserver configuration

Each test file implements thorough test coverage using mock repositories
to isolate service logic and verify correct behavior for success paths,
error handling, and edge cases.
@abbott abbott merged commit 6aa62ab into main Mar 8, 2025
4 checks passed
@abbott abbott deleted the refactor/ioa branch March 8, 2025 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants