mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 10:51:05 -05:00
2.9 KiB
2.9 KiB
System Patterns
High-Level Architecture
The videoarchiver module is organized into several key components:
- processor: Handles core processing logic
- queue: Manages video processing queue
- database: Handles data persistence
- ffmpeg: Manages video processing
- utils: Provides utility functions
- core: Contains core bot functionality
- config: Manages configuration
Cyclic Dependencies Analysis
Current Dependency Chain
-
VideoProcessor (core.py)
- Imports MessageHandler, QueueHandler, CleanupManager under TYPE_CHECKING
- Creates instances of these handlers in init
-
MessageHandler (message_handler.py)
- Imports ConfigManager, URLExtractor
- No circular imports detected
-
QueueHandler (queue_handler.py)
- Imports utils, database, config_manager
- No circular imports detected
-
CleanupManager (cleanup_manager.py)
- Imports QueueHandler under TYPE_CHECKING
- No problematic circular dependencies
Mitigation Strategies Used
-
TYPE_CHECKING conditional imports
- Used effectively in core.py and cleanup_manager.py
- Prevents runtime circular imports
- Maintains type safety during development
-
Late imports
- Used in VideoProcessor.init to avoid circular dependencies
- Handlers are imported only when needed
-
Forward references
- Type hints use string literals for types that aren't yet defined
Core Technical Patterns
-
Component Initialization Pattern
- Core processor initializes handlers
- Handlers are loosely coupled through interfaces
- Dependencies are injected through constructor
-
Message Processing Pipeline
- Message validation
- URL extraction
- Queue management
- Progress tracking
-
Cleanup Management
- Staged cleanup process
- Multiple cleanup strategies
- Resource tracking and monitoring
Data Flow
-
Message Processing Flow
- Message received → MessageHandler
- Validation → URL Extraction
- Queue addition → Processing
-
Video Processing Flow
- Queue item → Download
- Processing → Archival
- Cleanup → Completion
Key Technical Decisions
-
Dependency Management
- Use of TYPE_CHECKING for circular import prevention
- Late initialization of components
- Clear separation of concerns between handlers
-
Error Handling
- Each component has dedicated error types
- Comprehensive error tracking
- Graceful degradation
-
State Management
- Clear state transitions
- Progress tracking
- Health monitoring
-
Resource Management
- Staged cleanup process
- Multiple cleanup strategies
- Resource tracking
Recommendations
-
Current Structure
- The current architecture effectively manages dependencies
- No immediate issues requiring refactoring
-
Future Improvements
- Consider using dependency injection container
- Implement interface segregation for cleaner dependencies
- Add more comprehensive health checks