Convertify 2.0 implements Clean Architecture (also known as Hexagonal Architecture or Ports and Adapters), which provides a clear separation of concerns and makes the codebase highly maintainable and testable.
The innermost layer containing business entities and interfaces. This layer has no dependencies on external frameworks or libraries.
VideoFile: Represents a video file with metadataConversionResult: Represents the outcome of a conversionConversionConfig: Configuration for video conversionVideoFormat: Enum for supported formatsConversionStatus: Enum for conversion states
IVideoConverter: Contract for video conversionIFileRepository: Contract for file operationsILogger: Contract for logging
- Custom exception hierarchy for domain errors
Implements the interfaces defined in the domain layer using external libraries and frameworks.
MoviePyVideoConverter: Video conversion using MoviePyFileSystemRepository: File operations using pathlib and Windows APILoguruLogger: Logging using Loguru library
Contains business logic and use cases that orchestrate the domain and infrastructure layers.
VideoConversionService: Orchestrates video conversion with retry logicFileDiscoveryService: Discovers video files in directories
ConvertVideosUseCase: Main use case for batch video conversion
The CLI interface built with Typer and Rich.
Presentation → Application → Domain ← Infrastructure
- Presentation depends on Application
- Application depends on Domain
- Infrastructure depends on Domain
- Domain depends on nothing
This ensures that business logic is independent of external frameworks.
The Container class (src/container.py) manages all dependencies:
container = Container(settings)
use_case = container.convert_videos_use_caseBenefits:
- Easy to swap implementations
- Simplified testing with mocks
- Clear dependency graph
Uses pydantic-settings for type-safe configuration:
- Define settings in
Settingsclass - Load from
.envfile - Validate on startup
- Access via container
- Test each layer independently
- Mock dependencies using fixtures
- Focus on business logic
- Test interaction between layers
- Use real implementations where possible
- Verify end-to-end workflows
tests/
├── conftest.py # Shared fixtures
├── test_entities.py # Domain tests
├── test_file_repository.py # Infrastructure tests
├── test_video_service.py # Application tests
└── test_config.py # Configuration tests
- Repository Pattern: Abstract file operations
- Dependency Injection: Manage dependencies
- Strategy Pattern: Pluggable converters
- Factory Pattern: Create entities
- Protocol Pattern: Define interfaces
- Testability: Easy to mock and test each component
- Maintainability: Clear separation of concerns
- Scalability: Easy to add new features
- Flexibility: Swap implementations without changing business logic
- Independence: Business logic independent of frameworks
Potential improvements enabled by this architecture:
- Multiple Output Formats: Add WebM, AV1, etc.
- Cloud Storage: Add S3, Azure Blob support
- Database Tracking: Store conversion history
- Web Interface: Add FastAPI frontend
- Parallel Processing: True multiprocessing support
- Plugin System: Allow custom converters