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 connection (with pgbouncer) |
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 |
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 |
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 |
|---|---|
main | 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
stagingtomainfor 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 testslib/*.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