s is a user-friendly command-line wrapper around the Linux screen utility. It provides a simpler interface to the powerful but complex screen command, making it more accessible to developers who don't want to remember all the cryptic flags and key combinations.
This project implements Clean Architecture with principles from Domain-Driven Design (DDD). This architectural approach provides several benefits:
- Separation of concerns - Each layer has a specific responsibility
- Dependency rule - Dependencies only point inward
- Testability - Business logic can be tested independently of external systems
- Flexibility - Implementation details can be changed without affecting the core business logic
src/
βββ domain/ # Core business entities and logic
β βββ entities/ # Domain objects
βββ application/ # Application-specific business rules
β βββ ports/ # Interfaces (ports) to external systems
β βββ use_cases/ # Application-specific business logic
βββ infrastructure/ # External adapters and implementations
β βββ adapters/ # Adapters for external tools
β βββ repositories/ # Implementations of repository interfaces
βββ presentation/ # UI layer
β βββ formatters/ # Output formatting
βββ lib.rs # Public API exports
βββ main.rs # Entry point and dependency wiring
The Domain layer contains the core business entities and rules that are independent of any external system.
-
ScreenSession Entity (
domain/entities/screen_session.rs)- Core domain entity representing a screen session
- Has properties like id, name, created_at, and status
- Implements domain-specific behavior related to screen sessions
-
SessionStatus Enum (
domain/entities/screen_session.rs)- Value object representing the possible states of a screen session (Attached, Detached, Unknown)
This layer is isolated from external concerns and does not depend on any other layer.
The Application layer contains use cases and ports (interfaces) that define how the application interacts with the outside world.
-
ScreenRepository Interface (
application/ports/screen_repository.rs)- Defines methods for managing screen sessions (list, create, attach, detach, kill)
- Acts as a port/interface that must be implemented by the infrastructure layer
-
ListScreenSessions Use Case (
application/use_cases/list_screen_sessions.rs)- Defines the business logic for listing screen sessions
- Depends on the ScreenRepository interface, not its implementation
- Single Responsibility: List screen sessions
The Infrastructure layer contains concrete implementations of interfaces defined in the Application layer and adapters for external tools and libraries.
-
ScreenCommand Adapter (
infrastructure/adapters/screen_command.rs)- Adapter for interacting with the Linux
screencommand - Encapsulates the details of command execution
- Adapter for interacting with the Linux
-
ScreenRepositoryImpl (
infrastructure/repositories/screen_repository.rs)- Concrete implementation of the ScreenRepository interface
- Uses the ScreenCommand adapter to interact with the screen utility
- Parses command output into domain entities
The Presentation layer is responsible for formatting and displaying data to the user.
- TableFormatter (
presentation/formatters/table_formatter.rs)- Formats lists of ScreenSession entities into nice tabular output
- Separates display concerns from business logic
The main.rs file acts as a composition root, wiring together all components:
- Creates infrastructure components (ScreenCommand, ScreenRepositoryImpl)
- Creates use cases (ListScreenSessions)
- Coordinates the flow of data between layers
- Handles top-level error display
- User Input β main.rs
- main.rs creates and configures components
- main.rs delegates to appropriate use case
- Use case interacts with repository through interface
- Repository uses adapter to execute actual screen commands
- Repository parses raw output into domain entities
- Use case returns domain entities
- main.rs passes entities to formatter
- Formatter creates user-friendly output
- Output β User
Following Clean Architecture principles, dependencies always point inward:
- Domain layer depends on nothing
- Application layer depends only on Domain layer
- Infrastructure layer depends on Application and Domain layers
- Presentation layer depends on Domain layer
- Main depends on all layers
- Repository Pattern - Abstracts data access behind interfaces
- Adapter Pattern - Adapts external systems to work with our application
- Dependency Injection - Components receive their dependencies rather than creating them
- Use Case Pattern - Encapsulates business logic in single-responsibility classes
- Start with the domain - Define entities and business rules
- Define interfaces - Create or update interfaces in the application layer
- Implement use cases - Add business logic in application layer
- Implement adapters/repositories - Add concrete implementations in infrastructure layer
- Update presentation - Format and display results
- Wire in main.rs - Connect new components
- Add WindowSession entity to domain layer (if needed)
- Add window management methods to ScreenRepository interface
- Create CreateWindow use case in application layer
- Implement window management in ScreenRepositoryImpl
- Add window-specific formatting in presentation layer
- Wire the new use case in main.rs
The application uses Rust's Result type for error handling:
- Infrastructure failures return specific errors
- Each layer can add context to errors
- The main.rs handles top-level error display
- Command-line argument parsing - Add support for command-line arguments
- Configuration - Add support for user configuration
- More screen features - Implement more screen functionality
- Testing - Add unit and integration tests
- Better error messages - Improve error messages and handling
- Documentation - Add more documentation
- Rust - Systems programming language
- Standard Library - For process execution and file I/O
- Screen - Linux utility for terminal session management
This architecture provides a solid foundation for maintainable, testable code with clear separation of concerns. By following these patterns, developers can extend the application while maintaining its architectural integrity.