Architecture¶
Overview¶
GmailAutoCleaner follows a modular, CLI-first architecture designed for automation and safety. The system is built in Python, emphasizing separation of concerns, interruptibility, and extensibility. It supports YAML-driven configuration, OAuth2 authentication, and progressive data triage with backup verification.
High-Level Architecture¶
The application follows a functional pipeline architecture, processing data through composed functions. Modules are organized around data transformations and actions:
- CLI Interface: Entry point using
pyt_utils.cli_utilsfor command-line arguments, piping to main pipeline. - Configuration Pipeline: Functions to load, validate, and resolve YAML configuration (email_pools, criteria).
- API Pipeline: Functions for authentication and fetching items (emails/files/photos) from Google services.
- Triage Pipeline: Functions to evaluate items against criteria, categorizing into sensitive/savable/redundant.
- Backup Pipeline: Functions for creating hashable backups, storage, and verification.
- Action Pipeline: Functions to execute actions (delete, backup, ignore) with progress tracking.
- Logging/Reporting Pipeline: Functions for structured logging and generating summaries.
Data Flow (Functional Pipeline)¶
- Initialization: Parse CLI args → Load config → Authenticate → Return config/auth context.
- Data Retrieval: Fetch items pipeline: config → authenticated client → items list.
- Triage: Triage pipeline: items + criteria → categorized items (dict with categories).
- User Oversight (Optional): Display pipeline: categorized items → user confirmation/modification.
- Execution: Action pipeline: categorized items → processed results (backups, deletions).
- Reporting: Report pipeline: results → logs/summaries.
Data is passed as immutable dicts/lists through the pipeline, with functions composing via higher-order functions.
Design Principles¶
- Modularity: Each module has a single responsibility, allowing easy testing and extension.
- Interruptibility: Process can be paused/resumed, with checkpoints for manual intervention.
- Safety: Confirmation prompts, dry-run mode, and rollback support via backups.
- Extensibility: Easy addition of new services or criteria without core changes.
- Automation-Friendly: CLI designed for cronjobs, with minimal user interaction in automated mode.
Technology Stack¶
- Language: Python 3.x
- Libraries:
pyt_utils.cli_utils: CLI wrapper using Fire for command-line interface (build_from_class/function)pyyaml: YAML configurationgoogle-api-python-client: Google API interactionsoauth2client: Authenticationhashlib: Backup hashinglogging: Structured loggingpathlib: File handling- Future UI: Streamlit for smart indexing and visualization of backed up emails/attachments, with search and media viewing capabilities.
Component Interactions (Functional Composition)¶
- CLI args → config_pipeline → auth_pipeline → fetch_pipeline → triage_pipeline → action_pipeline → report_pipeline
- Backup functions composed into action_pipeline for pre/post processing.
- Logging functions injected into each pipeline stage for monitoring.
Security Considerations¶
- OAuth2 tokens stored securely (encrypted).
- Backups encrypted and access-controlled.
- Input validation to prevent malicious YAML.
Scalability¶
- Handles large datasets via pagination and batching in API calls.
- Incremental backups reduce processing time.
- Modular design allows parallel processing if needed.
This architecture ensures the tool is robust, maintainable, and aligned with the requirements for safe, automated cleanup.