How zenhosta/9drive works
Purpose and Entry Points
9Drive is a virtual storage gateway that unifies users’ Google Drive accounts and S3-compatible providers behind a React dashboard and external upload API. The backend is an Express/TypeScript service booted by backend/src/server.ts, composed in backend/src/app.ts; the browser client starts at frontend/src/main.tsx and routes from frontend/src/App.tsx.
API Boundary and Authorization
HTTP routes are organized by domain modules and protected with bearer-JWT authentication or API-key middleware. Authentication includes local credentials, Google OAuth, refresh/logout flows, and OAuth handoff; app/session secrets and provider credentials are encrypted or hashed.
• backend/src/modules/auth/auth.routes.ts
• backend/src/middleware/auth.middleware.ts
• backend/src/middleware/api-key.middleware.ts
Persistent Control Plane
MySQL, accessed through Prisma, is the system of record for users, sessions, connected providers, virtual folder hierarchy, file metadata, share/preview tokens, routing policies, API keys, and audit history. Prisma migrations define the evolving persistence contract, including S3 providers and resumable upload fields.
• backend/prisma/schema.prisma
• backend/src/config/prisma.ts
• backend/prisma/migrations/20260611120000_s3_storage_support/migration.sql
Provider Integration Layer
Google Drive is both an OAuth identity source and storage backend: credentials are stored as encrypted global/provider configuration, connected accounts are managed per user, and Drive contents are synchronized into MySQL metadata. S3-compatible storage is accessed server-side so browser clients never receive storage credentials.
• backend/src/modules/google/google.service.ts
• backend/src/modules/s3/s3.service.ts
• backend/src/modules/connected-accounts/connected-account.routes.ts
Upload Routing and File Lifecycle
Uploads enter through authenticated UI uploads or /api/v1/uploads API-key uploads. The backend streams bytes directly to the selected Google Drive or S3 provider rather than retaining files locally. Routing policies choose a target account/provider by available capacity, round-robin, or priority. File operations then cover listing/search, virtual-folder assignment, rename/move/delete, share links, preview tokens, downloads, and provider streaming.
• backend/src/modules/uploads/upload.routes.ts
• backend/src/modules/files/file.routes.ts
• backend/src/modules/files/stream-google-file.ts
Frontend Workspace
The Vite React single-page application provides protected dashboard pages for files, sharing, quota, activity, provider setup, OAuth completion, and API-key management. A shared API/auth client bridges it to Express; upload state is centralized so progress can persist across dashboard views.
• frontend/src/layouts/DriveLayout.tsx
• frontend/src/lib/api.ts
• frontend/src/context/UploadContext.tsx
Deployment and External Dependencies
Runtime dependencies are Node.js 20+, MySQL 8+, Google OAuth/Drive API, and optionally any S3-compatible endpoint (AWS S3, MinIO, R2, etc.). Docker Compose provisions frontend, backend, and MySQL; the backend applies Prisma migrations and can seed Google configuration at startup. Production frontend is served through Nginx.
• docker-compose.yml
• backend/Dockerfile
• frontend/nginx.conf
Main entry points: app.ts API composition · schema.prisma MySQL control plane · google.service.ts Provider adapters · file.routes.ts File lifecycle API
Components 19
React Workspace
- React SPA · Dashboard and external-upload user interface.
frontend/src/main.tsx - Dashboard routes
frontend/src/App.tsx - Drive workspace
frontend/src/layouts/DriveLayout.tsx - API and auth client
frontend/src/lib/api.ts - Upload state · Keeps upload progress across dashboard views.
frontend/src/context/UploadContext.tsx
Gateway Backend
- Express service
backend/src/server.ts - API composition
backend/src/app.ts - Auth and OAuth · Local login, Google OAuth, refresh, logout, and handoff.
backend/src/modules/auth/auth.routes.ts - JWT and API-key guard
backend/src/middleware/auth.middleware.ts - API-key uploads
backend/src/middleware/api-key.middleware.ts - File lifecycle API · Files, folders, sharing, preview, download, and streaming.
backend/src/modules/files/file.routes.ts - Upload routing · Selects provider targets and streams upload bytes.
backend/src/modules/uploads/upload.routes.ts - Provider adapters · Server-side Google Drive and S3 access.
backend/src/modules/google/google.service.ts
Control Plane
- MySQL control plane · System of record for identities, metadata, policies, tokens, and audit history.
backend/prisma/schema.prisma - S3 persistence migration · Adds S3 provider and resumable-upload persistence.
backend/prisma/migrations/20260611120000_s3_storage_support/migration.sql
External Providers
- Google OAuth and Drive
- S3-compatible storage · AWS S3, MinIO, R2, or compatible endpoint.
Deployment
- Docker Compose · Provisions frontend, backend, and MySQL.
docker-compose.yml - Nginx
frontend/nginx.conf
Connections 27
- React SPA → Dashboard routes: boots
- Dashboard routes → Drive workspace: protected pages
- Drive workspace → Upload state: shares progress
- React SPA → API and auth client: calls API
- API and auth client → Express service: HTTPS
- Express service → API composition: hosts
- API composition → Auth and OAuth: auth endpoints
- API composition → JWT and API-key guard: protects routes
- JWT and API-key guard → File lifecycle API: authorizes UI operations
- API-key uploads → Upload routing: authorizes external uploads
- API composition → API-key uploads: upload API
- API composition → Upload routing: upload routes
- API composition → File lifecycle API: file routes
- Auth and OAuth → MySQL control plane: sessions and credentials
- Auth and OAuth → Google OAuth and Drive: OAuth
- File lifecycle API → MySQL control plane: metadata and tokens
- Upload routing → MySQL control plane: routing policies and quota
- Upload routing → Provider adapters: stream bytes
- File lifecycle API → Provider adapters: provider operations
- Provider adapters → Google OAuth and Drive: Drive API
- Provider adapters → S3-compatible storage: S3 API
- Provider adapters → MySQL control plane: connected accounts and sync
- S3 persistence migration → MySQL control plane: evolves schema
- Docker Compose → Express service: runs backend
- Docker Compose → MySQL control plane: runs database
- Docker Compose → Nginx: runs frontend
- Nginx → React SPA: serves production build