The Application Layer¶
The Application Layer is responsible for orchestration. It defines the Use Cases (the "features" of our application) and coordinates the flow of data between the Domain, the external configurations, the file system, and the notification engine.
Use Cases (src/application/use_cases.py)¶
OrganizeDownloadsUseCase¶
This is the primary pipeline of the application. It takes the injected dependencies (FileSystem, Configuration, Notifier, MimeDetector) and executes the cleanup process.
Execution Flow:
- Loads the configuration (Paths, Rules, Policies).
- Uses the
IFileSystemport to scan the target downloads directory, mapping raw file paths toFileItemdomain models. - For each
FileItem: - Iterates through the registered
Rules(Keywords -> Extensions -> MIME). - If a rule matches, it executes the move via
IFileSystemand records theAction. - If no rules match, it passes the file to the
ArchivePolicy. - If the policy allows archiving, it moves the file to the calculated archive directory.
- Generates a summary of all recorded
Actions. - Invokes the
INotifierport to dispatch an email summary to the user.
Application Interfaces (Ports) (src/application/interfaces.py)¶
Like the Domain layer, the Application layer uses interfaces (ports) to communicate with external systems. This enforces the Dependency Inversion Principle, ensuring the Use Case remains highly testable and loosely coupled to any specific technology (e.g., it shouldn't care if I use local disks, AWS S3, or Google Drive).
IFileSystem¶
Abstracts file operations.
list_files(directory: str)->List[FileItem]move_file(source: str, destination_dir: str, filename: str)->strget_archive_folders(archive_base: str)->List[str]delete_directory(path: str)ensure_directory(path: str)
IConfigProvider¶
Abstracts configuration retrieval.
- get_paths()
- get_rules() -> List[Rule]
- get_archive_policy() -> ArchivePolicy
- get_logging_config()
- get_notifications_config()
INotifier¶
Abstracts the alerting mechanism.
send_summary(summary_data, log_file)