๐ป Developer Overview & Architecture Tour
Welcome to the TGDCFS Developer Guide! This documentation is written for software engineers who want to understand the inner workings of TGDCFS, add new features, fix bugs, or contribute to the project.
Technical Stack Summaryโ
- Language: Python 3.13+ (strict type annotations with
mypy) - Package Manager: Poetry
- Web & Async Framework: FastAPI, Uvicorn,
uvloop(on Linux) - Protocols:
- Telegram: Telethon (MTProto)
- Discord: discord.py
- SFTP: AsyncSSH
- WebDAV: Custom ASGI WebDAV pipeline (
asgidav/)
- Testing & Quality Assurance:
pytest,pytest-asyncio,mypy,ruff,pre-commit
Codebase Directory Structureโ
tgdcfs/
โโโ main.py # Server entrypoint (Uvicorn + FastAPI + SFTP initialization)
โโโ config-test.yaml # Test configuration file
โโโ demo-config.yaml # Full annotated example config
โโโ pyproject.toml # Dependencies, build metadata, tool settings
โโโ makefile # Quick development commands (make mypy, make ruff)
โโโ tgdcfs/ # Main Python package
โ โโโ config.py # Config loading, schema v2, legacy tgfs translation
โ โโโ backends/ # Backend drivers & store abstractions
โ โ โโโ base.py # IStore interface & StoreCapabilities
โ โ โโโ telegram/ # TelegramStore implementation (Telethon)
โ โ โโโ discord/ # DiscordStore implementation (discord.py)
โ โโโ core/ # Core filesystem domain logic
โ โ โโโ store.py # Store wrapper
โ โ โโโ local_cache.py # LocalCache, StagingWriter, VersionBytes
โ โ โโโ multisource.py # MultiSourceRead parallel scheduler
โ โ โโโ replication.py # Persistent ReplicationQueue & workers
โ โ โโโ backfill.py # Store backfill & promotion logic
โ โ โโโ mirror.py # MirrorGroup & replication dispatch
โ โ โโโ repository/ # File, FileDesc, Metadata repositories
โ โ โโโ model/ # FileVersion, FileRef, Replica data models
โ โโโ crypto/ # AES-256-GCM encryption & Argon2id key derivation
โ โโโ app/ # Protocol servers & web endpoints
โ โ โโโ webdav/ # WebDAV request router & provider
โ โ โโโ sftp/ # AsyncSSH SFTP server & user handling
โ โ โโโ manager/ # Manager REST API endpoints (/api/*)
โ โโโ tasks/ # Task store & async task execution runner
โโโ tests/ # Full test suite
โ โโโ fakes/ # In-memory fake stores for offline testing
โ โโโ test_cache.py # Cache unit tests
โ โโโ test_replication.py # Replication engine unit tests
โ โโโ ... # 57+ unit test modules
โโโ scripts/ # Helper scripts
โ โโโ docker_smoke_check.py # Container smoke test script
โ โโโ measure_transfer.py # Download piece transfer benchmarking tool
โโโ tgdcfs-gh-pages/ # Next.js web frontend & Telegram Mini App
โโโ docusaurus/ # Docusaurus documentation website
Key Core Interfaces & Componentsโ
1. IStore Interface (tgdcfs/backends/base.py)โ
IStore is the foundational abstraction that decouples repository logic from specific cloud backends:
class IStore(Protocol):
key: str
caps: StoreCapabilities
async def send_text(self, text: str) -> int: ...
async def get_text(self, message_id: int) -> Optional[str]: ...
async def upload(self, file_msg: UploadableFileMessage) -> list[SentFileMessage]: ...
async def download(self, message_id: int, begin: int, end: int) -> DownloadFileResp: ...
async def copy_within(self, ids: list[int]) -> list[int]: ...
async def copy_from(self, other: "IStore", ids: list[int]) -> Optional[list[int]]: ...
2. StoreFileContentRepository (tgdcfs/core/repository/)โ
Handles raw byte stream operations, chunking, range slicing, local cache integration, and multi-source read dispatch.
3. ReplicationQueue & ReplicationWorker (tgdcfs/core/replication.py)โ
Provides persistent asynchronous file replication across Telegram and Discord stores, persisting queue items to replication_queue.json.
Next Steps for Developersโ
- ๐ ๏ธ Local Repository Setup โ How to clone, set up Python 3.13+, Poetry, git hooks, and build/test Docker containers locally.
- ๐งช Testing & QA Guide โ Running pytest, typechecking, linting, and offline fake store tests.
- ๐ค Contributing Guidelines โ GitHub fork setup, repository secrets, CI/CD workflow guide, commit conventions, and releases.