How krish120003/zercel works
Project type and purpose
• This is a full‑stack, cloud‑native “Vercel clone” consisting of three core microservices (web, router, builder), shared libraries/packages, and an IaC layer (terraform).
• Purpose: provide GitHub‑driven deployments, build orchestration, dynamic compute, and a browser‑based UI for site provisioning.
File structure
• Top‑level “apps/” folder with three services:
• web (Next.js frontend + API routes + tRPC + server logic)
• router (Node+TypeScript HTTP gateway for real‑time routing of incoming traffic to deployments)
• builder (Node+TypeScript build orchestrator that invokes build jobs and streams logs)
• “packages/” folder with shared ESLint/TS configs and a UI component library.
• “terraform/” for provisioning GCP/Cloudflare/Redis/Postgres infra.
• Monorepo managed with pnpm workspaces and Turbo for generators.
README for additional insights
• High‑level description: automatic GitHub deployments, live build logs, CDN caching, SSL, environment variables, serverless functions.
• Infra services: Eventarc for webhooks, Cloud Run & Batch for compute, Cloud Storage for artifacts, Neon Postgres, Upstash Redis, Artifact Registry.
Main components
a. Web UI service (apps/web)
• Next.js SSR/CSR
• API layer: NextAuth, GitHub webhook endpoint, builder callback, tRPC router
b. Builder service (apps/builder)
• Receives build‑trigger requests
• Orchestrates GCP Batch/Cloud Run job runners
• Pushes static assets to Cloud Storage and Docker images to Artifact Registry
• Streams build logs back to Web UI (via Eventarc or WebSocket)
c. Router service (apps/router)
• Acts as HTTP reverse‐proxy based on hostname/path
• Fetches routing table from Postgres or Redis cache
• Proxies traffic to static assets (Cloud Storage CDN) or serverless endpoints (Cloud Run)
d. Shared state and data stores
• Neon Postgres: stores user accounts, sites, deployments, environment variables
• Upstash Redis: caching routing tables, build status for real‑time updates
e. External integrations
• GitHub (webhooks to Web UI)
• GCP Cloud Storage (static files)
• GCP Artifact Registry (container images)
• GCP Cloud Run & Batch (compute)
• Cloudflare CDN (public ingress)
Relationships and orchestration flows
1. Developer pushes to GitHub → GitHub sends webhook to Web UI’s /api/github/webhook
2. Web UI validates & forwards build request to Builder service (/api/builder/callback)
3. Builder enqueues build job (GCP Batch or Cloud Run job), updates Postgres, caches status in Redis
4. Build jobs run, produce artifacts → upload to Cloud Storage & Artifact Registry
5. Builder streams logs/events back to Web UI (Eventarc → Web UI /api/builder/eventarc)
6. Upon successful build, Builder updates Postgres & invalidates Redis cache
7. Router picks up new route definitions (from Redis or Postgres)
8. End‑user requests arrive at Cloudflare → forwarded to Router → Router proxies to:
• static assets (via CDN origin pointing to Cloud Storage)
• dynamic functions (Cloud Run container for that deployment)
Architectural patterns and design principles
• Microservices: clear separation of concerns among Web, Builder, Router
• Event‑driven: webhook → build events → log streaming
• CQRS‑like: Command path (build requests) vs Query path (runtime routing)
• Shared monorepo for consistency, Turborepo for code‑gen
• IaC with Terraform for reproducibility