mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
docs: update context files with import patterns and recent changes
This commit is contained in:
@@ -2,31 +2,23 @@
|
|||||||
|
|
||||||
## Current Focus
|
## Current Focus
|
||||||
|
|
||||||
Verified no cyclic dependencies exist in the codebase (2024 verification)
|
- Fixing import issues in the VideoArchiver cog
|
||||||
|
- Maintaining relative imports while ensuring compatibility with Red-DiscordBot loading
|
||||||
|
|
||||||
## Recent Analysis (2024)
|
## Recent Changes
|
||||||
|
|
||||||
1. Dependency Structure:
|
- Added fallback to absolute imports in component_manager.py to handle different loading scenarios
|
||||||
- ✅ No cyclic dependencies found
|
- Simplified relative import in core/__init__.py to use correct package structure
|
||||||
- ✅ TYPE_CHECKING used correctly in VideoProcessor
|
- Imports are now more resilient while maintaining relative import patterns
|
||||||
- ✅ Clean handler initialization pattern
|
|
||||||
- ✅ Proper dependency direction maintained
|
|
||||||
|
|
||||||
2. Key Components:
|
## Active Files
|
||||||
- VideoProcessor using late initialization
|
|
||||||
- MessageHandler with clean imports
|
|
||||||
- QueueHandler with proper separation
|
|
||||||
- Utils package properly isolated
|
|
||||||
|
|
||||||
## Architecture Status
|
- videoarchiver/core/component_manager.py
|
||||||
|
- videoarchiver/core/__init__.py
|
||||||
- ✅ Clean dependency structure verified
|
- videoarchiver/processor/__init__.py
|
||||||
- ✅ Proper use of TYPE_CHECKING
|
|
||||||
- ✅ Effective separation of concerns
|
|
||||||
- ✅ Shared functionality properly isolated
|
|
||||||
|
|
||||||
## Next Steps
|
## Next Steps
|
||||||
|
|
||||||
- Continue monitoring for new cyclic dependencies
|
- Monitor package loading behavior
|
||||||
- Consider implementing dependency injection container
|
- Verify imports work in both development and production environments
|
||||||
- Maintain current clean architecture patterns
|
- Consider similar import pattern updates if needed in other modules
|
||||||
|
|||||||
@@ -1,110 +1,60 @@
|
|||||||
# System Patterns
|
# System Patterns
|
||||||
|
|
||||||
## High-Level Architecture
|
## Import Patterns
|
||||||
|
|
||||||
The videoarchiver module is organized into several key components:
|
### Relative Imports
|
||||||
|
|
||||||
- processor: Handles core processing logic
|
- Use relative imports by default to maintain package structure
|
||||||
- queue: Manages video processing queue
|
- Single dot (.) for imports from same directory
|
||||||
- database: Handles data persistence
|
- Double dots (..) for imports from parent directory
|
||||||
- ffmpeg: Manages video processing
|
- Example: `from .base import VideoArchiver`
|
||||||
- utils: Provides utility functions
|
|
||||||
- core: Contains core bot functionality
|
|
||||||
- config: Manages configuration
|
|
||||||
|
|
||||||
## Cyclic Dependencies Analysis
|
### Fallback Import Pattern
|
||||||
|
|
||||||
### Current Dependency Chain (Verified 2024)
|
When loading in different environments (development vs Red-DiscordBot):
|
||||||
|
|
||||||
1. VideoProcessor (core.py)
|
```python
|
||||||
- Uses TYPE_CHECKING for handler imports
|
try:
|
||||||
- Late initialization of handlers
|
# Try relative imports first
|
||||||
- Clean dependency structure with no cycles
|
from ..utils.exceptions import ComponentError
|
||||||
|
except ImportError:
|
||||||
|
# Fall back to absolute imports if relative imports fail
|
||||||
|
from videoarchiver.utils.exceptions import ComponentError
|
||||||
|
```
|
||||||
|
|
||||||
2. MessageHandler (message_handler.py)
|
### Package Structure
|
||||||
- Imports from config, queue, and utils
|
|
||||||
- No circular dependencies detected
|
|
||||||
- Clean dependency structure
|
|
||||||
|
|
||||||
3. QueueHandler (queue_handler.py)
|
- Each module has __init__.py to mark it as a package
|
||||||
- Imports from database, utils, and config
|
- Core package imports are kept simple and direct
|
||||||
- No circular dependencies detected
|
- Avoid circular imports by using proper hierarchy
|
||||||
- Clean dependency structure
|
|
||||||
|
|
||||||
### Mitigation Strategies Used
|
## Component Management
|
||||||
|
|
||||||
1. TYPE_CHECKING conditional imports
|
- Components are loaded in dependency order
|
||||||
- Used effectively in core.py
|
- Each component is registered and tracked
|
||||||
- Prevents runtime circular imports
|
- State changes and errors are logged
|
||||||
- Maintains type safety during development
|
- Health checks ensure system stability
|
||||||
|
|
||||||
2. Late imports
|
## Error Handling
|
||||||
- Used in VideoProcessor.__init__ to avoid circular dependencies
|
|
||||||
- Handlers are imported only when needed
|
|
||||||
|
|
||||||
3. Forward references
|
- Detailed error contexts are maintained
|
||||||
- Type hints use string literals for types that aren't yet defined
|
- Component errors include severity levels
|
||||||
|
- Graceful degradation when possible
|
||||||
|
- Clear error messages for debugging
|
||||||
|
|
||||||
## Core Technical Patterns
|
## Initialization Flow
|
||||||
|
|
||||||
1. Component Initialization Pattern
|
1. Package imports are resolved
|
||||||
- Core processor initializes handlers
|
2. Core components are initialized
|
||||||
- Handlers are loosely coupled through interfaces
|
3. Dependencies are checked and ordered
|
||||||
- Dependencies are injected through constructor
|
4. Components are initialized in dependency order
|
||||||
|
5. Health checks are established
|
||||||
|
6. System enters ready state
|
||||||
|
|
||||||
2. Message Processing Pipeline
|
## Development Patterns
|
||||||
- Message validation
|
|
||||||
- URL extraction
|
|
||||||
- Queue management
|
|
||||||
- Progress tracking
|
|
||||||
|
|
||||||
3. Cleanup Management
|
- Always maintain relative imports where possible
|
||||||
- Staged cleanup process
|
- Use fallback patterns for environment compatibility
|
||||||
- Multiple cleanup strategies
|
- Keep package structure clean and hierarchical
|
||||||
- Resource tracking and monitoring
|
- Document import patterns and their rationale
|
||||||
|
- Test in both development and production environments
|
||||||
## Data Flow
|
|
||||||
|
|
||||||
1. Message Processing Flow
|
|
||||||
- Message received → MessageHandler
|
|
||||||
- Validation → URL Extraction
|
|
||||||
- Queue addition → Processing
|
|
||||||
|
|
||||||
2. Video Processing Flow
|
|
||||||
- Queue item → Download
|
|
||||||
- Processing → Archival
|
|
||||||
- Cleanup → Completion
|
|
||||||
|
|
||||||
## Key Technical Decisions
|
|
||||||
|
|
||||||
1. Dependency Management
|
|
||||||
- Use of TYPE_CHECKING for circular import prevention
|
|
||||||
- Late initialization of components
|
|
||||||
- Clear separation of concerns between handlers
|
|
||||||
|
|
||||||
2. Error Handling
|
|
||||||
- Each component has dedicated error types
|
|
||||||
- Comprehensive error tracking
|
|
||||||
- Graceful degradation
|
|
||||||
|
|
||||||
3. State Management
|
|
||||||
- Clear state transitions
|
|
||||||
- Progress tracking
|
|
||||||
- Health monitoring
|
|
||||||
|
|
||||||
4. Resource Management
|
|
||||||
- Staged cleanup process
|
|
||||||
- Multiple cleanup strategies
|
|
||||||
- Resource tracking
|
|
||||||
|
|
||||||
## Recommendations
|
|
||||||
|
|
||||||
1. Current Structure
|
|
||||||
- The current architecture effectively manages dependencies
|
|
||||||
- No immediate issues requiring refactoring
|
|
||||||
- Clean dependency structure verified
|
|
||||||
|
|
||||||
2. Future Improvements
|
|
||||||
- Consider using dependency injection container
|
|
||||||
- Implement interface segregation for cleaner dependencies
|
|
||||||
- Add more comprehensive health checks
|
|
||||||
|
|||||||
Reference in New Issue
Block a user