Next.js 16 habit tracker with Better Auth + Drizzle (SQLite/libSQL).
- Install dependencies
npm install- Configure
.env
BETTER_AUTH_SECRETBETTER_AUTH_URLNEXT_PUBLIC_BETTER_AUTH_URLDB_FILE_NAME(example:file:local.db)MAIL_FROMRESEND_API_KEY(required in production)- Optional local React Email relay:
REACT_EMAIL_API_URL(example:http://127.0.0.1:5000/api/send) - Optional Sentry:
SENTRY_DSN,NEXT_PUBLIC_SENTRY_DSN,SENTRY_ORG,SENTRY_PROJECT,SENTRY_AUTH_TOKEN - Optional request logging flag:
REQUEST_LOGGING_ENABLED=1 - Optional providers:
GOOGLE_*,FACEBOOK_*,MICROSOFT_* - Optional admin IDs:
BETTER_AUTH_ADMIN_USER_IDS - Optional infra key:
BETTER_AUTH_API_KEY
- Run migrations
npm run db:migrate- Start app
npm run dev- Generate migration:
npm run db:generate - Apply migrations:
npm run db:migrate - Backup DB:
npm run db:backup - Restore DB (destructive):
npm run db:restore -- --from backups/<file>.db --yes - Restore drill + integrity check:
npm run db:restore:test
Backup config via env:
DB_BACKUP_DIR(defaultbackups)DB_BACKUP_PREFIX(defaulthabits)DB_BACKUP_KEEP_COUNT(default30)
- Integration/auth tests (Vitest):
npm test - Browser E2E (Playwright):
npm run test:e2e - Full suite:
npm run test:all
First-time Playwright setup:
npx playwright install chromiumSentry is wired via:
sentry.server.config.tssentry.edge.config.tsinstrumentation-client.tsinstrumentation.tsnext.config.ts(withSentryConfig)
Set DSNs and project env vars in production to enable tracking.
Structured request logs are emitted for:
- proxy auth guard requests (
src/proxy.ts) - Better Auth route handler (
src/app/api/auth/[...all]/route.ts) - health endpoint (
src/app/api/health/route.ts)
Enable/disable with REQUEST_LOGGING_ENABLED.
- Health endpoint:
GET /api/health(returns200when DB is reachable,503otherwise). - Configure your uptime provider (Better Stack, UptimeRobot, Pingdom, etc.) to monitor
/api/health. - Configure Sentry alert rules for:
- new issues in production
- spike in error rate
- throughput drop / transaction latency threshold
GitHub Actions workflow is provided at:
.github/workflows/ci.yml
Pipeline runs:
npm cinpm run db:migratenpm run lintnpm testnpm run test:e2enpm run build
/login/signup/forgot-password/reset-password/verify-email/dashboard(protected)/accept-invitation/[invitationId]
Better Auth handler is mounted at /api/auth/[...all].