Skip to main content

๐Ÿ’ป 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:
  • 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.