Developer Guide
Developer Guide
Quick Start (Recommended)
One command starts the entire local development stack:
make dev
This starts: Docker services (PostgreSQL, MinIO), the Cloudflare Worker, the Inngest dev server, runs Prisma migrations, and starts Next.js.
Prerequisites
- Docker (for PostgreSQL and MinIO)
- Node.js and pnpm (
npm install -g pnpm) - Cloudflare Worker repo cloned alongside this project (default:
../datahub-cloudflare-workers)
Setup
-
Clone the repo:
git clone https://github.com/datopian/datahub-next cd datahub-next -
Install dependencies:
pnpm i -
Start the dev stack:
make devThis auto-copies
.env.local.exampleto.envif no.envexists. -
Configure credentials in
.env:NEXT_PUBLIC_AUTH_GITHUB_IDandAUTH_GITHUB_SECRET(GitHub OAuth - get from team)GH_ACCESS_TOKEN(GitHub personal access token for sync and E2E tests)NEXTAUTH_SECRET(any random string for local dev)
-
Visit:
- App: http://localhost:3000
- Dashboard: http://localhost:3000/dashboard
- Inngest: http://localhost:8288
- MinIO Console: http://localhost:9001 (minioadmin/minioadmin)
Press Ctrl+C to stop all services. To also stop Docker:
make dev-down
Make targets
| Command | Description |
|---|---|
make dev | Start full development stack |
make dev-infra | Start Docker services only (Postgres, MinIO) |
make dev-services | Start Worker + Inngest in background |
make dev-down | Stop everything (processes + Docker) |
make db-migrate | Run Prisma migrations |
make db-reset | Reset the database |
make db-studio | Open Prisma Studio |
make help | Show all available targets |
Worker directory override
By default, make dev expects the Cloudflare Worker at ../datahub-cloudflare-workers. Override with:
WORKER_DIR=/path/to/workers make dev
Alternative: Cloud Development Environment
If you prefer not to run local Docker, you can connect to shared cloud resources:
- Copy
.env.example(not.env.local.example) to.env - Obtain cloud credentials from the team (Neon Postgres + R2 bucket)
- Configure
POSTGRES_PRISMA_URL,POSTGRES_URL_NON_POOLING, andS3_*variables - Run
pnpm devdirectly (nomake devneeded)
Environment Variables
See .env.local.example for the full list with comments. Key variables:
| Variable | Required | Description |
|---|---|---|
POSTGRES_PRISMA_URL | Yes | PostgreSQL pooled connection; must include pgbouncer=true (see DEPLOY.md) |
POSTGRES_URL_NON_POOLING | Yes | PostgreSQL direct connection (for migrations) |
NEXTAUTH_URL | Yes | http://localhost:3000 for local dev |
NEXTAUTH_SECRET | Yes | Random secret for NextAuth session encryption |
NEXT_PUBLIC_AUTH_GITHUB_ID | Yes | GitHub OAuth app client ID |
AUTH_GITHUB_SECRET | Yes | GitHub OAuth app secret |
NEXT_PUBLIC_AUTH_GOOGLE_ID | No | Google OAuth client ID; set together with the secret (env validation fails if only one is set). Without both, the Google button is hidden |
AUTH_GOOGLE_SECRET | No | Google OAuth client secret |
GH_ACCESS_TOKEN | For sync/tests | GitHub personal access token |
S3_* | Yes | Storage config (MinIO locally, R2 in prod) |
GH_WEBHOOK_SECRET | For webhooks | GitHub webhook secret |
INNGEST_APP_ID | For Inngest | Inngest app identifier |
POSTHOG_IP_PROJECT_KEY | No | Key of the separate PostHog project that receives raw caller IPs as file_accessed_ip. Its events retention is 1 month, so PostHog's monthly cleanup deletes IPs within 90 days, as the privacy policy states. Unset = IPs are not sent anywhere. Set in Vercel Production only. |
API_KEYS_ENABLED | No | true shows the dashboard's API keys page (/dashboard/api-keys), allows issuing keys, turns on /login?ref= ("get a free API key" links) and adds the DataHub-Notice header to keyless raw-file responses. Default false. Set in Vercel Production and Preview. |
KV_REST_API_URL, KV_REST_API_TOKEN | No | Vercel KV (Upstash) for rate limits (lib/rate-limit.ts): AI SQL generations (20 an hour) and sign-in links (5 an hour), per IP. Unset = no limits. Keys are prefixed with VERCEL_ENV (development when unset). Set in Vercel Production and Preview (separate databases, see DEPLOY.md); not in Development. |
pnpm build also downloads the ASN database to data/asn.mmdb (gitignored), which is used for asn/org on file_accessed. To get it locally, run pnpm asn-db. Without it, those fields are null.
GitHub Webhook Forwarding (Optional)
Only needed for automatic content syncing on push. Manual sync is available via the dashboard "Sync" button.
- Create a webhook channel at smee.io/new
- Install:
npm install --global smee-client - Forward:
smee --url https://smee.io/your_channel_id --target http://127.0.0.1:3000/api/webhook
Stripe Setup (Optional)
For testing subscription/billing features (requires implementing the webhook route first):
- Install Stripe CLI:
brew install stripe-cli - Login:
stripe login(use test mode) - Forward webhooks:
stripe listen --forward-to localhost:3000/api/stripe/webhook - Copy the
whsec_...secret toSTRIPE_WEBHOOK_SECRETin.env - Keep Stripe CLI running while testing subscriptions
Note: The Stripe webhook route (
app/api/stripe/webhook/route.ts) must be implemented before this setup is functional. Currently only Stripe payment links are used.
Branching Strategy
| Branch | Purpose |
|---|---|
production | Production (protected, no direct pushes) |
staging | Staging/testing environment, accepts PRs |
Workflow
- Create feature branch from
staging - Implement changes
- Submit PR to
staging - After review, squash-merge to
staging - Changes are rebased from
stagingontoproductionfor production release
Commit messages follow the Conventional Commits specification.
Testing
Unit Tests (Jest)
# Run all unit tests
pnpm test
# Run in watch mode
pnpm test:watch
Test locations:
lib/__tests__/- Utility function testsserver/api/routers/__tests__/- tRPC router testsapp/**/__tests__/- Route handler tests (Stripe webhook, magic-link handoff)server/__tests__/- Auth config tests (sign-in linking, magic-link rules)lib/*.test.ts- Co-located tests (e.g.,extract-title.test.ts)
E2E Tests (Playwright)
E2E tests require the full dev stack running (make dev) and GH_ACCESS_TOKEN set in .env.
Seeding is handled automatically by Playwright's global setup (e2e/global-setup.ts). It creates a test user, publication, and test posts.
# Run all renderer tests on Chromium
pnpm exec playwright test --project=renderer-chromium
# Run specific test file
pnpm exec playwright test e2e/renderer/dataset-datapackage-json.spec.ts
# Run with UI mode
pnpm exec playwright test --project=renderer-chromium --ui
# Debug mode
pnpm exec playwright test --project=renderer-chromium --debug
# Run on both Chromium and Firefox
pnpm exec playwright test --grep renderer
See e2e/README.md for the full E2E testing guide (CI setup, debugging, test repos).
Lint
pnpm lint
Format
pnpm format:write
Infrastructure
Databases
| Environment | Provider | Name |
|---|---|---|
| Production | Neon/Vercel | datahub-cloud |
| Staging | Neon/Vercel | datahub-cloud-staging |
| Development | Docker | Local PostgreSQL (port 5433) |
Content Storage
| Environment | Provider | Name |
|---|---|---|
| Production | Cloudflare R2 | datahub-cloud |
| Staging | Cloudflare R2 | datahub-cloud-staging |
| Development | Docker MinIO | datahub bucket (port 9000/9001) |
Authentication
GitHub OAuth applications under Datopian account:
- Production:
DataHub Cloud - Staging:
DataHub Cloud - Staging - Development:
DataHub Cloud - Dev