I will implement the backend infrastructure for GitDrive, focusing on a "Multi-Repo" storage strategy where files are stored across multiple GitHub repositories. Authentication will be handled by Supabase Auth, and metadata (file structure, names, sizes) will be stored directly within the Git repositories (e.g., gitdrive-metadata.json), avoiding an external database for file indexing.
- Auth: Supabase Auth (GitHub Provider).
- Storage Backend: GitHub API (REST/GraphQL).
- Data Model (Git-Based):
- Root Repo: A main repository
gitdrive-rootthat acts as the entry point. - Metadata: A
metadata.jsonfile in the root of each repo tracking the virtual file system structure (folders, file references). - Sharding: When a repo nears size limits (e.g., 1GB), a new private repository is created (
gitdrive-storage-001,gitdrive-storage-002) and linked in the metadata.
- Root Repo: A main repository
- API Layer: Next.js API Routes (Server Actions) to bridge the frontend with GitHub APIs.
- Setup: Initialize Supabase client in the Next.js app.
- Config: Configure GitHub OAuth provider in Supabase.
- Middleware: Protect dashboard routes using Next.js Middleware + Supabase Auth.
- Session: Store the GitHub Provider Token (Access Token) securely in the session to make API calls on behalf of the user.
- Service Layer: Create a robust service to handle GitHub interactions.
- Features:
initializeDrive(): Checks/Creates the root repository (gitdrive-root).listFiles(path): Readsmetadata.jsonto return file lists.uploadFile(file, path):- Commits the file blob to the current active storage repo.
- Updates
metadata.jsonin the root repo with the file's pointer (repo name, sha, path).
createFolder(name): Updatesmetadata.json.deleteFile(id): Removes from metadata (and optionally deletes the actual blob).
- Environment Variables: Set up
NEXT_PUBLIC_SUPABASE_URL,NEXT_PUBLIC_SUPABASE_ANON_KEY, andGITHUB_CLIENT_SECRET. - Dashboard Integration: Connect the UI's "File Explorer" to the
listFilesAPI. - Upload Integration: Connect the "Upload" dialog to the
uploadFileAPI.
- Token Scope: Ensure the GitHub token has
reposcope. - Rate Limits: Handle basic rate limiting feedback.
- Concurrency: Basic locking (or optimistic concurrency) for
metadata.jsonupdates to prevent overwrite conflicts.
- Auth: Connect Supabase Auth & Protect Routes.
- Github Service: Build the core logic for repo management and file operations.
- Connect UI: Hook up the frontend components to real data.
- Initialize Next.js project and install dependencies (Shadcn, Lucide)
- Configure GitHub-like theme in Tailwind and CSS variables
- Install required Shadcn UI components
- Implement Login/Signup page
- Implement Dashboard layout (Sidebar, Header)
- Implement File Explorer (Grid/List views) and Upload/Download UI
- Implement Settings page
- Check for linter errors and fix if any
- Complete Implementation
- Refine file upload component (clear template info)
- Verify UI functionality and layout
- Install Supabase SSR and Client libraries
- Configure Supabase Auth Client and Middleware
- Create GitHub Service (API wrapper for Repo/File ops)
- Implement 'Initialize Drive' flow (Create Root Repo)
- Implement File Listing API (Read metadata.json)
- Implement File Upload API (Commit blob + Update metadata)
- Connect Dashboard UI to Real Data
- Implement 'Create Folder' functionality
- Implement 'Delete File/Folder' functionality
- Implement Onboarding Flow (Welcome Screen)