1. Architecture & Storage

MyDrive is an enterprise-grade, self-hosted file management and media streaming server built with FastAPI and SQLite WAL mode.

It strictly separates user spaces on disk:

Storage Tree: data/ ├── storage/users/<user_id>/ # Isolated user directory tree ├── uploads_temp/ # Sliced 4MB temporary binary chunks ├── trash/<user_id>/ # Two-stage isolated recycle bin ├── avatars/ # User profile pictures └── mydrive.db # SQLite WAL database (auth, tokens, quotas)

2. Linux VPS / Bare Metal Setup

Deploy directly on any Ubuntu, Debian, Fedora, Arch, or Rocky Linux server:

# 1. Clone repository: git clone https://github.com/dev-hints/mydrive.git cd mydrive # 2. Create Python virtual environment: python3 -m venv venv source venv/bin/activate # 3. Install production dependencies: pip install -r requirements.txt # 4. Configure environment variables: cp .env.example .env nano .env # 5. Launch server: python3 -m app.main

3. Docker & Docker Compose

The included docker-compose.yml sets up persistent storage volumes with non-root container security:

# Launch container in background: docker-compose up -d # Check live logs: docker-compose logs -f # Verify storage health: curl http://localhost:8000/api/health

4. Android Pocket Server (Termux)

Transform an old or spare Android smartphone into a zero-power 24/7 personal cloud server:

# Inside Termux with Debian PRoot: apt update && apt install -y python3 python3-pip git git clone https://github.com/dev-hints/mydrive.git cd mydrive pip3 install -r requirements.txt --break-system-packages python3 -m app.main

5. Chunked Upload Protocol

Traditional multipart HTTP uploads load entire files into system memory, crashing servers on 5GB+ files. MyDrive uses an intelligent chunked upload pipeline:

  1. The frontend splits files into 4MB binary slices.
  2. Each chunk is transmitted via POST /api/upload/chunk with byte offset and total size headers.
  3. The server writes chunks sequentially to disk in data/uploads_temp/.
  4. On completion, the file is assembled and moved to the user's storage directory with verified checksums.
  5. If the network drops, re-uploading checks the existing chunk count and resumes without re-transmitting sent bytes.

6. HTTP 206 Partial Content Streaming

MyDrive implements RFC 7233 byte-range serving. Browsers send:

GET /api/files/stream?path=movie.mp4 HTTP/1.1 Range: bytes=10485760-20971519 HTTP/1.1 206 Partial Content Content-Range: bytes 10485760-20971519/524288000 Content-Length: 10485760 Content-Type: video/mp4

This allows instant forward and backward seeking in multi-hour 4K videos with zero buffering delays.

7. Phone Contacts Sync & vCard

MyDrive provides a built-in contact manager directly in the browser:

  • Native Phone Contact Picker: On mobile Chrome / Edge, tap "Sync Phone Contacts" to use navigator.contacts.select without installing native apps.
  • vCard 3.0/4.0 Support: One-click import and export of .vcf files.
  • CSV Spreadsheets: Export and import contacts with smart column header matching.
  • Actionable Cards: Click-to-call (tel:) and click-to-email (mailto:) links.

8. Enterprise Security & RBAC

  • Argon2id Hashing: Passwords hashed with high-memory cryptographic cost factors.
  • Path Traversal Defense: All file paths pass through resolve_safe_path() which canonicalizes paths with os.path.realpath() to defeat directory traversal (../) and symlink breakout.
  • Double-Submit CSRF: Cryptographically signed tokens validate all POST, PUT, and DELETE operations.
  • HttpOnly Session Cookies: Cookies are invisible to client scripts, neutralizing XSS session hijacking.
  • Brute-Force Lockout: Dynamic rate limiting locks accounts for 15 minutes after 5 consecutive failures.

9. REST API Reference

Method Endpoint Description
POST /api/auth/login Authenticate user and set HttpOnly session cookie
GET /api/files/list List files & folders in directory with metadata
POST /api/upload/chunk Upload a 4MB binary slice of a streaming upload
GET /api/files/stream HTTP 206 Partial Content byte range media stream
POST /api/shares/create Create public or password-protected share token
GET /api/health Server uptime, memory utilization, and storage status