Core architecture principles
The application separates concerns into distinct layers:- Handler Router - Central entry point that routes URLs to site-specific handlers
- Site Handlers - Pluggable strategies for each supported manga site
- Utilities - Shared functionality for downloads, PDF generation, and file management
- Interfaces - Multiple frontends (web, desktop, Discord) that consume the same core
Strategy Pattern implementation
Each manga site implements theBaseSiteHandler abstract class, which defines two key methods:
core/sites/base.py
The Strategy Pattern allows you to add support for new manga sites by simply creating a new handler class that implements
BaseSiteHandler. No changes to the core routing logic are required.Handler routing system
Theprocess_entry function in core/handler.py acts as the central router. It receives a URL and delegates processing to the appropriate site handler:
core/handler.py
How routing works
- Parse the hostname from the provided URL
- Iterate through all registered handlers
- Check if the hostname matches any supported domain
- Delegate to the first matching handler’s
process()method - Return an error if no handler matches
Handlers are instantiated once and reused for all requests (stateless design). This improves performance and reduces memory overhead.
Core package structure
Thecore package exposes a single public interface for all consumers:
core/__init__.py
Three interface model
The architecture supports multiple frontends that all consume the same core:Web interface
FastAPI server with WebSocket support for real-time progress updates. Located inweb_server.py.
Features:
- Real-time log streaming
- Progress tracking
- Cancellation support
- PDF file serving
Desktop interface
Tkinter-based GUI application providing a native desktop experience. Features:- File dialogs
- Local folder management
- Automatic PDF opening
- Visual progress bars
Discord bot
Discord bot that allows users to download manga directly in Discord servers. Features:- Command-based interface
- PDF upload to Discord
- Per-user rate limiting
- Server-wide usage tracking
Component interaction flow
Here’s how components work together during a typical download:Callback system details
Callback system details
The architecture uses three callback functions for interface communication:
log_callback(msg: str)- Send status messages to the usercheck_cancel() -> bool- Allow users to cancel long-running operationsprogress_callback(current: int, total: int)- Update download progress
Adding a new site handler
To add support for a new manga site:- Create a new file in
core/sites/(e.g.,mysite.py) - Implement the
BaseSiteHandlerabstract class - Add your handler to
core/sites/__init__.py - Register it in the
HANDLERSlist incore/handler.py
Example handler
Configuration system
Global configuration is managed throughcore/config.py:
core/config.py
Benefits of this architecture
Extensibility - Add new sites without touching existing code Maintainability - Clear separation of concerns makes debugging easier Reusability - Single core serves multiple interfaces Testability - Each handler can be tested independently Flexibility - Interfaces can customize behavior through configurationNext steps
Security features
Learn about SSRF prevention, path traversal protection, and DoS mitigation
Async downloads
Understand how concurrent downloads work with asyncio and aiohttp