Architecture overview
The system consists of three primary layers that work together to handle Git operations:Component breakdown
Edge layer: Cloudflare Workers
Your TanStack Start application runs on Cloudflare Workers, deployed globally at the edge for minimal latency. This layer handles: Git Protocol Translation: When you run standard Git commands likegit push or git clone, the requests hit HTTP handlers that implement the Git Smart HTTP protocol. These handlers translate Git’s wire protocol into operations that can be executed against repository storage.
Relevant code in apps/web/src/git/protocol.ts:5-82:
The entire TanStack Start application runs on Cloudflare Workers with zero cold starts and automatic global distribution.
Storage layer: Durable Objects
Each Git repository gets its own isolated Durable Object instance that maintains repository state and handles Git operations. This design provides:- Strong consistency: All operations for a single repository are serialized through one Durable Object
- Stateful operations: The Durable Object maintains an in-memory cache and SQLite-backed storage
- Isolation: Each repository is completely independent with dedicated resources
apps/web/src/do/repo.ts:39-62 shows the initialization:
Metadata layer: Cloudflare D1
Cloudflare D1 (SQLite) stores metadata that needs to be queried efficiently across repositories:- User accounts and authentication data
- Repository metadata (name, description, visibility)
- Issues, pull requests, and comments
- Access control lists and permissions
Request flow
Git push operation
- Client authentication: Git client sends credentials via HTTP Basic Auth
- Protocol negotiation: Worker advertises
git-receive-packcapabilities - Command parsing: Worker parses ref update commands and packfile data from client
- Durable Object routing: Worker routes request to the repository’s Durable Object
- Packfile indexing: Durable Object indexes the packfile and extracts Git objects (see
apps/web/src/do/repo.ts:128-154) - Ref updates: Durable Object validates and applies branch/tag updates
- Status report: Success/failure status is returned to the client
Git clone/pull operation
- Client request: Git client requests specific commits via
git-upload-pack - Ref listing: Durable Object returns available branches and tags
- Negotiation: Client and server negotiate common commits to minimize data transfer
- Object collection: Durable Object walks the commit graph to find required objects (see
apps/web/src/git/service.ts:214-295) - Packfile generation: Objects are packed into an efficient binary format
- Transfer: Packfile is streamed to the client with progress updates
Web UI operation
- User request: Browser requests repository page
- Metadata query: Worker queries D1 for repository information
- Content fetch: Worker calls Durable Object methods for Git data (commits, trees, blobs)
- Caching: Results are cached in the Durable Object for subsequent requests (see
apps/web/src/do/repo.ts:232-242) - Render: Page is rendered and served from the edge
Scalability characteristics
Horizontal scaling: Each repository is isolated in its own Durable Object, allowing unlimited repositories without resource contention. Global distribution: Workers run in 300+ cities worldwide, providing low-latency access regardless of user location. Zero infrastructure management: No servers to provision, patch, or scale. Cloudflare handles all infrastructure concerns. Automatic failover: Durable Objects are automatically migrated if a machine fails, with minimal disruption.The architecture can theoretically support unlimited repositories, with each repository capable of handling concurrent operations through its dedicated Durable Object.
Performance optimization
Gitflare employs several strategies to maintain high performance: Object caching: Frequently accessed Git objects are cached in memory within the Durable Object (seeapps/web/src/git/service.ts:17).
Chunked storage: Large files are split into 512KB chunks for efficient storage and retrieval in SQLite.
Lazy loading: The web interface loads commit history and file contents on-demand rather than preloading entire repositories.
Edge caching: Static assets and public repository data can be cached at the edge using Cloudflare’s cache API.
Security model
Authentication is handled by Better Auth integrated with Cloudflare D1, providing:- Session management
- OAuth integration
- Two-factor authentication support
- API token generation
Next steps
Serverless Git
Learn how Git operations work without traditional servers
Durable Objects
Understand how repository storage works
Storage architecture
Deep dive into the virtualized file system