### Project Setup and Development Commands (Bash) Source: https://github.com/nrjdalal/zerostarter/blob/canary/README.md Provides essential bash commands for setting up and running the Zerostarter project. This includes cloning the repository, installing dependencies, configuring environment variables, setting up the database, and starting the development server. These commands are crucial for getting the project running locally. ```bash # Clone the template bunx gitpick https://github.com/nrjdalal/zerostarter/tree/main cd zerostarter # Install dependencies bun install # Set up environment variables (see docs) cp .env.example .env # Set up database bun run db:generate bun run db:migrate # Start development bun dev ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/getting-started/setup.mdx Copies the example environment file to `.env` and lists the variables that need to be configured for server, client, and optional analytics/feedback services. ```bash cp .env.example .env ``` ```dotenv NODE_ENV=local # -------------------- Server variables -------------------- HONO_APP_URL=http://localhost:4000 HONO_TRUSTED_ORIGINS=http://localhost:3000 HONO_RATE_LIMIT=60 # allow 60 req/min (default) and twice that for authenticated users HONO_RATE_LIMIT_WINDOW_MS=60000 # 1 minute (default) # Generate using `openssl rand -base64 32` BETTER_AUTH_SECRET= # Generate at `https://github.com/settings/developers` GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= # Generate at `https://console.cloud.google.com/apis/credentials` GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= # Generate using `bunx pglaunch -k` POSTGRES_URL= # -------------------- Client variables -------------------- NEXT_PUBLIC_APP_URL=http://localhost:3000 NEXT_PUBLIC_API_URL=http://localhost:4000 # Optional: PostHog Analytics (https://zerostarter.dev/docs/manage/analytics) NEXT_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com NEXT_PUBLIC_POSTHOG_KEY= # Optional: User feedback (https://zerostarter.dev/docs/manage/feedback) NEXT_PUBLIC_USERJOT_URL= ``` -------------------------------- ### Install Project Dependencies with Bun Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/getting-started/setup.mdx Installs all necessary project dependencies using the Bun package manager. Includes an alternative command to ignore scripts if installation fails. ```bash bun install # or bun install --ignore-scripts ``` -------------------------------- ### Database Setup with Bun Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/getting-started/setup.mdx Commands to generate the database schema and apply migrations using Bun. Assumes a PostgreSQL server is running. ```bash bun run db:generate bun run db:migrate ``` -------------------------------- ### Bash Script for Project Setup Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/blog/web-development-2026.mdx Provides a sequence of bash commands to clone the ZeroStarter template, install dependencies, set up environment variables, and initialize the database. ```bash # Clone the template bunx gitpick https://github.com/nrjdalal/zerostarter/tree/main cd zerostarter # Install dependencies bun install # Set up environment cp .env.example .env # Edit with your values # Initialize database bun run db:generate bun run db:migrate ``` -------------------------------- ### Run ZeroStarter Application Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/getting-started/setup.mdx Starts the ZeroStarter application using the Bun runtime. This command is used for local development and testing. ```bash bun dev ``` -------------------------------- ### Better Auth Client Setup (React/TypeScript) Source: https://context7.com/nrjdalal/zerostarter/llms.txt Provides frontend authentication client setup for React applications using Better Auth. It includes hooks for session management, organization handling, and examples for signing in via magic link or OAuth. ```typescript // web/next/src/lib/auth/client.ts - Auth client setup import { magicLinkClient, organizationClient } from "better-auth/client/plugins" import { createAuthClient } from "better-auth/react" import { config } from "@/lib/config" export const authClient = createAuthClient({ baseURL: `${config.api.url}/api/auth`, plugins: [magicLinkClient(), organizationClient({ teams: { enabled: true } })], }) // Usage in React components // Magic link sign-in const res = await authClient.signIn.magicLink({ email: "user@example.com", callbackURL: "/dashboard", }) // OAuth sign-in const res = await authClient.signIn.social({ provider: "github", // or "google" callbackURL: "/dashboard", }) // Session hooks const { data: session } = authClient.useSession() const { data: orgs } = authClient.useListOrganizations() const { data: activeOrg } = authClient.useActiveOrganization() // Organization management await authClient.organization.create({ name: "Acme Inc.", slug: "acme-inc" }) await authClient.organization.setActive({ organizationId: "org_123" }) ``` -------------------------------- ### Run ZeroStarter Application with Docker Compose Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/getting-started/setup.mdx Starts the ZeroStarter application and its services using Docker Compose. This is an alternative method for running the application in a containerized environment. ```bash docker compose up ``` -------------------------------- ### Hono API Server Setup and Routes Source: https://context7.com/nrjdalal/zerostarter/llms.txt Sets up the main Hono API server with CORS, logging, rate limiting, and error handling. Defines base routes for health checks and mounts authentication and versioned API routers. Includes example curl commands for testing. ```typescript // api/hono/src/index.ts - Main API server setup import { BUILD_VERSION } from "@packages/env" import { env } from "@packages/env/api-hono" import { Scalar } from "@scalar/hono-api-reference" import { Hono } from "hono" import { cors } from "hono/cors" import { logger } from "hono/logger" import { errorHandler } from "@/lib/error" import { rateLimiterMiddleware } from "@/middlewares" import { authRouter, v1Router } from "@/routers" const app = new Hono() app.use( "*", cors({ origin: env.HONO_TRUSTED_ORIGINS, allowHeaders: ["content-type", "authorization"], allowMethods: ["GET", "OPTIONS", "POST", "PUT"], credentials: true, }), logger(), rateLimiterMiddleware, ) app.onError(errorHandler) app.notFound((c) => c.json({ error: { code: "NOT_FOUND", message: "Not Found" } }, 404)) const routes = app .get("/", (c) => c.json({ data: { version: BUILD_VERSION, environment: env.NODE_ENV } })) .basePath("/api") .get("/health", (c) => c.json({ data: { message: "ok", version: BUILD_VERSION } })) .route("/auth", authRouter) .route("/v1", v1Router) export type AppType = typeof routes export default { port: env.HONO_PORT, fetch: app.fetch } ``` ```bash # Example API requests curl http://localhost:4000/ # Response: {"data":{"version":"0.0.15","environment":"local"}} curl http://localhost:4000/api/health # Response: {"data":{"message":"ok","version":"0.0.15","environment":"local"}} curl http://localhost:4000/api/docs # Opens Scalar API documentation interface ``` -------------------------------- ### Clone ZeroStarter Repository Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/getting-started/setup.mdx Clones the ZeroStarter repository from GitHub using `gitpick`. This command fetches the latest stable release from the `main` branch. ```bash bunx gitpick https://github.com/nrjdalal/zerostarter/tree/main cd zerostarter ``` -------------------------------- ### Conventional Commit examples Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/code-quality.mdx Demonstrates the required format for commit messages and how to denote breaking changes. ```bash feat(auth): add Google OAuth provider fix(api): handle null user in session middleware docs(readme): update installation instructions chore(deps): bump dependencies to latest versions refactor(web): extract form validation into hook # Breaking change example feat!: remove deprecated API endpoints ``` -------------------------------- ### API Session Cookie Example Source: https://context7.com/nrjdalal/zerostarter/llms.txt Demonstrates how to fetch API session information using a valid session cookie with curl. ```bash curl http://localhost:4000/api/v1/session --cookie "better-auth.session_token=..." ``` -------------------------------- ### VS Code Recommended Extensions for ZeroStarter Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/resources/ide-setup.mdx Specifies the recommended VS Code extensions for ZeroStarter, primarily the Oxc extension for linting and formatting. This file ensures a consistent development environment by defining essential tools. ```json { "recommendations": ["oxc.oxc-vscode"] } ``` -------------------------------- ### Custom Skill Structure Example: DB Migration Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/resources/ai-skills.mdx An example of creating a custom AI skill for database migrations using Drizzle. It outlines the directory structure, frontmatter, and workflow steps including creating, reviewing, and applying migrations using specific commands. ```markdown --- name: db-migration description: Creates and runs database migrations. Use when user asks to update database schema. --- # Database Migration Creates type-safe database migrations with Drizzle. ## Workflow ### 1. Create Migration ```bash bun run db:generate ```` ### 2. Review Migration Check the generated SQL in `packages/db/drizzle/` ### 3. Apply Migration ```bash bun run db:migrate ``` ``` -------------------------------- ### Defining Backend Routes with Hono Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/getting-started/type-safe-api.mdx Provides an example of defining backend API routes using Hono. It includes setting up middleware, defining GET and POST endpoints, and handling request data. This snippet is intended for the backend implementation. ```typescript // api/hono/src/routers/v1.ts import { Hono } from "hono" import { authMiddleware } from "@/middlewares" export const v1Router = new Hono() .use("/*", authMiddleware) .get("/session", (c) => { const data = c.get("session") return c.json({ data }) }) .post("/items", async (c) => { const body = await c.req.json() const data = { id: "123", ...body } return c.json({ data }) }) ``` -------------------------------- ### Define New Database Tables Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/database.mdx Example of defining a new table using Drizzle ORM's pgTable helper, including primary keys and foreign key references with cascade deletes. ```typescript import { pgTable, text, timestamp } from "drizzle-orm/pg-core" export const project = pgTable("project", { id: text("id").primaryKey(), name: text("name").notNull(), organizationId: text("organization_id") .notNull() .references(() => organization.id, { onDelete: "cascade" }), createdAt: timestamp("created_at").defaultNow().notNull(), }) ``` -------------------------------- ### Configure OAuth Providers in Better Auth Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/authentication.mdx This snippet shows how to configure GitHub and Google OAuth providers within the Better Auth setup. It requires environment variables for client IDs and secrets. The configuration is typically placed in the main authentication package. ```typescript socialProviders: { github: { clientId: env.GITHUB_CLIENT_ID, clientSecret: env.GITHUB_CLIENT_SECRET, }, google: { clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET, }, } ``` -------------------------------- ### Type-Safe Hono API Client for Next.js Source: https://context7.com/nrjdalal/zerostarter/llms.txt Demonstrates setting up a type-safe API client in Next.js using Hono's `hc` function. It infers types directly from the Hono backend routes, ensuring type safety for API calls. Includes examples of making GET requests and accessing typed data. ```typescript // web/next/src/lib/api/client.ts - Type-safe API client setup import type { AppType } from "@api/hono" import { hc } from "hono/client" import { config } from "@/lib/config" type Client = ReturnType> const hcWithType = (...args: Parameters): Client => hc(...args) const url = config.api.internalUrl ? config.api.internalUrl : config.api.url const honoClient = hcWithType(url, { init: { credentials: "include" }, }) export const apiClient = honoClient.api // Usage examples in React components const response = await apiClient.health.$get() const { data } = await response.json() // data is fully typed: { message: string, version: string, environment: string } const sessionRes = await apiClient.v1.session.$get() const { data: session } = await sessionRes.json() // session is typed with full Session schema ``` -------------------------------- ### VS Code Editor Settings for ZeroStarter Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/resources/ide-setup.mdx Configures VS Code editor settings for ZeroStarter, enabling the Oxc extension as the default formatter and activating format-on-save. This enhances code quality and consistency automatically. ```json { "editor.defaultFormatter": "oxc.oxc-vscode", "editor.formatOnSave": true } ``` -------------------------------- ### Configure Blog Source in Fumadocs Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/blog.mdx Defines the blog content directory within the Fumadocs configuration file. This setup allows the application to locate and process MDX files stored in the specified path. ```typescript export const blog = defineDocs({ dir: "content/blog", }) ``` -------------------------------- ### Hono Authentication and Rate Limiter Middleware Source: https://context7.com/nrjdalal/zerostarter/llms.txt Implements authentication middleware for Hono API routes using Better Auth. It validates sessions, attaches user and session data to context, and applies a user-specific rate limiter. Includes an example of a protected route in `v1.ts` and a bash command to test it. ```typescript // api/hono/src/middlewares/auth.ts - Authentication middleware import type { Session } from "@packages/auth" import { auth } from "@packages/auth" import { env } from "@packages/env/api-hono" import { createMiddleware } from "hono/factory" import { createRateLimiter } from "@/middlewares/rate-limiter" const userRateLimiter = createRateLimiter({ getUserId: (c) => c.get("session")?.userId, limit: env.HONO_RATE_LIMIT * 2, // Authenticated users get double rate limit windowMs: env.HONO_RATE_LIMIT_WINDOW_MS, }) export const authMiddleware = createMiddleware<{ Variables: Session }>(async (c, next) => { const session = await auth.api.getSession({ headers: c.req.raw.headers }) if (!session) { return c.json({ error: { code: "UNAUTHORIZED", message: "Unauthorized" } }, 401) } c.set("session", session.session) c.set("user", session.user) return userRateLimiter(c, next) }) // api/hono/src/routers/v1.ts - Protected route example export const v1Router = new Hono<{ Variables: Session }>() .use("/*", authMiddleware) .get("/session", (c) => c.json({ data: c.get("session") })) .get("/user", (c) => c.json({ data: c.get("user") })) ``` ```bash # Protected endpoint requires authentication curl http://localhost:4000/api/v1/session ``` -------------------------------- ### Accessing Session Data in a Protected Page (TypeScript) Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/dashboard.mdx This example shows how to access authenticated user session data within a protected page component. It imports the `auth` utility and calls `auth.api.getSession()` to retrieve the session object, then displays the user's name. ```typescript import { auth } from "@/lib/auth" export default async function SettingsPage() { const session = await auth.api.getSession() return
Welcome, {session?.user.name}
} ``` -------------------------------- ### Documenting API Routes with Scalar code samples Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/api-conventions.mdx Uses the describeRoute decorator to define API metadata and inject custom code samples into Scalar documentation. The x-codeSamples property allows developers to provide language-specific examples for API consumers. ```typescript describeRoute({ tags: ["v1"], description: "Get session", ...({ "x-codeSamples": [{ lang: "typescript", label: "hono/client", source: "const res = await apiClient.v1.session.$get()\nconst { data } = await res.json()", }], } as object), responses: { ... }, }) ``` -------------------------------- ### Initialize Local PostgreSQL Database Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/database.mdx A command-line utility to instantly spin up a local PostgreSQL database instance for development purposes using bunx. ```bash bunx pglaunch -k ``` -------------------------------- ### Manage Database Migrations and Studio Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/database.mdx CLI commands for generating and applying database migrations using Drizzle Kit, as well as launching Drizzle Studio for data management. ```bash bun run db:generate bun run db:migrate bun run db:studio ``` -------------------------------- ### Conventional Commit Message Examples Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/blog/web-development-2026.mdx Examples of commit messages following the Conventional Commits specification. These messages use a structured format (type(scope): description) to provide clarity on the nature of changes. ```bash feat(auth): add Google OAuth support fix(api): handle null user in session chore(deps): update dependencies refactor(web): extract form validation hook ``` -------------------------------- ### Execute Development and Maintenance Commands Source: https://context7.com/nrjdalal/zerostarter/llms.txt A collection of Bun scripts for managing the development lifecycle, including building, database migrations, code quality checks, and utility tasks. ```bash # Development bun run dev bun run build bun run start bun run check-types # Database bun run db:generate bun run db:migrate bun run db:studio # Code Quality bun run lint bun run format bun run format:check # Utilities bun run clean bun run devtools ``` -------------------------------- ### Initialize Database Client with Drizzle ORM Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/database.mdx Configures the database client using Bun's native SQL driver and Drizzle ORM. It handles environment-specific TLS settings and connection timeouts. ```typescript import { env } from "@packages/env/db" import { drizzle } from "drizzle-orm/bun-sql" import { SQL } from "bun" const client = new SQL({ url: env.POSTGRES_URL, tls: isProduction() ? { rejectUnauthorized: true } : false, connectionTimeout: 10, idleTimeout: 30, maxLifetime: 0, }) export const db = drizzle({ client, schema }) ``` -------------------------------- ### GET /api/v1/session Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/api-conventions.mdx Retrieves the current authenticated session data for the requesting user. ```APIDOC ## GET /api/v1/session ### Description Fetches details about the currently active session. Requires valid authentication via the auth middleware. ### Method GET ### Endpoint /api/v1/session ### Response #### Success Response (200) - **data** (object) - Contains session metadata and user information #### Error Response (401) - **error** (object) - Returned if the session is missing or invalid ``` -------------------------------- ### GET /api/health Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/api-conventions.mdx Health check endpoint used to verify server status and retrieve OpenAPI documentation links. ```APIDOC ## GET /api/health ### Description Returns the health status of the API server and provides links to the OpenAPI specification and documentation UI. ### Method GET ### Endpoint /api/health ### Response #### Success Response (200) - **status** (string) - Current health status of the service - **docs** (string) - URL to the Scalar API documentation UI ``` -------------------------------- ### Configure shadcn/ui Components Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/theming.mdx Configuration file for shadcn/ui components, specifying the style preset and CSS variable usage. ```json { "style": "base-nova", "iconLibrary": "remixicon", "tailwind": { "baseColor": "neutral", "cssVariables": true } } ``` -------------------------------- ### Execute Database Migration Commands Source: https://context7.com/nrjdalal/zerostarter/llms.txt Common CLI commands for managing Drizzle ORM migrations and database inspection. ```bash bun run db:generate # Generate migration files bun run db:migrate # Apply migrations to database bun run db:studio # Open Drizzle Studio GUI ``` -------------------------------- ### GitHub Actions CI Pipeline Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/blog/web-development-2026.mdx A GitHub Actions workflow definition that automates the verification process on every pull request. It installs dependencies, performs security audits, lints the code, and builds the project. ```yaml jobs: checks: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: oven-sh/setup-bun@v2 - run: bun install - run: bun audit --audit-level high - run: bun run lint - run: bun run build ``` -------------------------------- ### Better Auth Server Configuration (TypeScript) Source: https://context7.com/nrjdalal/zerostarter/llms.txt Sets up enterprise-grade authentication with Better Auth, supporting OAuth providers, magic links, and organizations with teams. It integrates with a Drizzle database adapter and includes necessary plugins. ```typescript // packages/auth/src/index.ts - Better Auth setup import { db, account, invitation, member, organization, session, team, teamMember, user, verification } from "@packages/db" import { env } from "@packages/env/auth" import { betterAuth } from "better-auth" import { drizzleAdapter } from "better-auth/adapters/drizzle" import { openAPI as openAPIPlugin, organization as organizationPlugin } from "better-auth/plugins" import { getCookieDomain, getCookiePrefix } from "@/lib/utils" const cookieDomain = getCookieDomain(env.HONO_APP_URL) const cookiePrefix = getCookiePrefix(env.HONO_APP_URL) export const auth = betterAuth({ baseURL: env.HONO_APP_URL, trustedOrigins: env.HONO_TRUSTED_ORIGINS, database: drizzleAdapter(db, { provider: "pg", schema: { account, invitation, member, organization, session, team, teamMember, user, verification }, }), onAPIError: { throw: true }, plugins: [ openAPIPlugin(), organizationPlugin({ teams: { enabled: true } }), ], socialProviders: { github: { clientId: env.GITHUB_CLIENT_ID, clientSecret: env.GITHUB_CLIENT_SECRET, }, google: { clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET, }, }, advanced: { ...(cookiePrefix && { cookiePrefix }), ...(cookieDomain && { crossSubDomainCookies: { enabled: true, domain: cookieDomain } }), }, }) export type Session = typeof auth.$Infer.Session ``` -------------------------------- ### Implement Search API (TypeScript) Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/documentation.mdx Creates a server-side API endpoint for full-text search using Fumadocs core. It indexes page titles, descriptions, URLs, and structured data. ```typescript import { createSearchAPI } from "fumadocs-core/search/server" import { source } from "@/lib/source" export const { GET } = createSearchAPI("advanced", { indexes: source.getPages().map((page) => ({ title: page.data.title, description: page.data.description, url: page.url, id: page.url, structuredData: page.data.structuredData, })), }) ``` -------------------------------- ### Configure Database Connection with Drizzle and Bun Source: https://context7.com/nrjdalal/zerostarter/llms.txt Sets up a singleton database connection using Drizzle ORM and Bun SQL. It handles environment-specific configurations, including connection pooling for production and global singleton instances for development to support Hot Module Replacement (HMR). ```typescript // packages/db/src/index.ts import { env } from "@packages/env/db" import { SQL } from "bun" import type { BunSQLDatabase } from "drizzle-orm/bun-sql" import { drizzle } from "drizzle-orm/bun-sql" import * as schema from "@/schema" type Database = BunSQLDatabase declare global { var db: Database } let db: Database if (env.NODE_ENV === "production") { const client = new SQL(env.POSTGRES_URL, { connectionTimeout: 10, idleTimeout: 30, maxLifetime: 0, tls: { rejectUnauthorized: true }, }) db = drizzle({ client, schema }) } else { if (!global.db) { const client = new SQL(env.POSTGRES_URL) global.db = drizzle({ client, schema }) } db = global.db } export { db } export * from "@/schema" ``` ```typescript // packages/db/drizzle.config.ts import { env } from "@packages/env/db" import { defineConfig } from "drizzle-kit" export default defineConfig({ dialect: "postgresql", dbCredentials: { url: env.POSTGRES_URL }, schema: "src/schema", out: "drizzle", }) ``` -------------------------------- ### Configure Theme Provider Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/theming.mdx Implementation of next-themes ThemeProvider to enable system-aware dark mode switching in a Next.js application. ```typescript {children} ``` -------------------------------- ### Define Environment Variables Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/deployment/docker.mdx Required configuration variables for production deployment, including authentication secrets, database URLs, and service endpoints. ```text NODE_ENV=production # Server variables HONO_APP_URL=http://localhost:4000 HONO_TRUSTED_ORIGINS=http://localhost:3000 BETTER_AUTH_SECRET=your_secret GITHUB_CLIENT_ID=your_github_client_id GITHUB_CLIENT_SECRET=your_github_client_secret GOOGLE_CLIENT_ID=your_google_client_id GOOGLE_CLIENT_SECRET=your_google_client_secret POSTGRES_URL=your_postgres_url # Client variables NEXT_PUBLIC_APP_URL=http://localhost:3000 NEXT_PUBLIC_API_URL=http://localhost:4000 ``` -------------------------------- ### Client-Side Organization Management with Better Auth Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/authentication.mdx Demonstrates how to interact with organization-related features from the client-side using the `authClient`. This includes listing organizations, retrieving the active organization, switching organizations, and creating new ones. ```typescript import { authClient } from "@/lib/auth/client" // List user's organizations const { data: orgs } = authClient.useListOrganizations() // Get active organization const { data: activeOrg } = authClient.useActiveOrganization() // Switch organization await authClient.organization.setActive({ organizationId: "..." }) // Create organization await authClient.organization.create({ name: "Acme Inc.", slug: "acme" }) ``` -------------------------------- ### Fetching Session Data with Type-Safe Client Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/getting-started/type-safe-api.mdx Shows how to retrieve session and user data using a type-safe API client call. This example demonstrates accessing the `auth["get-session"]` endpoint and expecting a typed response containing session and user information. ```typescript import { apiClient } from "@/lib/api/client" // Get current session and user (via Better Auth) const res = await apiClient.auth["get-session"].$get() const data = await res.json() // data is typed as { session: Session, user: User } | null ``` -------------------------------- ### Define API Environment Variables with Zod Schema (TypeScript) Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/blog/web-development-2026.mdx Creates a Zod schema for validating API environment variables using the '@t3-oss/env-core' library. It defines expected types and formats for variables like NODE_ENV, POSTGRES_URL, and PORT, ensuring type safety and early error detection. This setup prevents silent failures due to missing or malformed environment variables. ```typescript import { z } from "zod" import { createEnv } from "@t3-oss/env-core" export const env = createEnv({ server: { NODE_ENV: z.enum(["local", "development", "test", "staging", "production"]), POSTGRES_URL: z.url(), PORT: z.coerce.number().default(4000), TRUSTED_ORIGINS: z.string().transform((s) => s.split(",")), }, runtimeEnv: { NODE_ENV: process.env.NODE_ENV, POSTGRES_URL: process.env.POSTGRES_URL, PORT: process.env.PORT, TRUSTED_ORIGINS: process.env.TRUSTED_ORIGINS, }, }) ``` -------------------------------- ### Configure Application Settings Source: https://context7.com/nrjdalal/zerostarter/llms.txt Centralized configuration object for the Next.js frontend, managing environment variables, API URLs, and application metadata. It includes logic to toggle internal API URLs based on the execution environment. ```typescript import { BUILD_VERSION } from "@packages/env" import { env } from "@packages/env/web-next" const getInternalApiUrl = () => { if (typeof window === "undefined") { return env.INTERNAL_API_URL } return undefined } export const config = { app: { name: "ZeroStarter", description: "A modern, type-safe, and high-performance SaaS starter template.", tagline: "The SaaS Starter", url: env.NEXT_PUBLIC_APP_URL, version: BUILD_VERSION, }, api: { url: env.NEXT_PUBLIC_API_URL, internalUrl: getInternalApiUrl(), }, social: { github: "https://github.com/nrjdalal/zerostarter", }, features: {}, } as const export type Config = typeof config ``` -------------------------------- ### Configure Oxfmt formatting rules Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/code-quality.mdx Sets formatting preferences for the project, including semicolon usage, import sorting, and ignored file patterns. ```jsonc { "$schema": "./node_modules/oxfmt/configuration_schema.json", "semi": false, "experimentalSortImports": {}, "experimentalTailwindcss": {}, "ignorePatterns": ["**/*.lock", ".agents/**", ".claude/**"] } ``` -------------------------------- ### Build and Run Individual Docker Images Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/deployment/docker.mdx Commands to build and execute the Hono API and Next.js frontend containers independently. These commands require a valid .env file in the root directory. ```bash # Backend (Hono API) docker build -f api/hono/Dockerfile -t zerostarter-api . docker run -p 4000:4000 --env-file .env zerostarter-api # Frontend (Next.js) docker build -f web/next/Dockerfile -t zerostarter-web . docker run -p 3000:3000 --env-file .env zerostarter-web ``` -------------------------------- ### Configure Drizzle ORM for PostgreSQL Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/database.mdx Defines the Drizzle Kit configuration file to connect to a PostgreSQL database using environment variables. It specifies the schema location and output directory for generated migrations. ```typescript export default defineConfig({ dialect: "postgresql", dbCredentials: { url: env.POSTGRES_URL }, schema: "src/schema", out: "drizzle", }) ``` -------------------------------- ### Define Documentation Page Order (JSON) Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/documentation.mdx Specifies the order of documentation pages for navigation. The sequence in this JSON array determines how pages are listed in the documentation's sidebar or menu. ```json { "pages": [ "index", "getting-started/architecture", "getting-started/project-structure", "getting-started/type-safe-api", "getting-started/setup", "getting-started/scripts", "getting-started/roadmap", "manage/authentication", "manage/dashboard", "manage/database", "manage/api-conventions", "manage/analytics", "manage/blog", "manage/code-quality", "manage/documentation", "manage/feedback", "manage/environment", "manage/release", "manage/theming", "manage/og-images", "manage/llms-txt", "manage/robots", "manage/sitemap", "deployment/docker", "deployment/vercel", "resources/ai-skills", "resources/ide-setup", "resources/infisical", "contributing" ] } ``` -------------------------------- ### Create Frontend Auth Client with Magic Link (TypeScript) Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/blog/web-development-2026.mdx Initializes a frontend authentication client using Better Auth's React integration and the magic link plugin. This client provides hooks and functions for session management, sign-in, sign-up, and sign-out. It requires the 'better-auth/react' and 'better-auth/client/plugins' packages. ```typescript import { createAuthClient } from "better-auth/react" import { magicLinkClient } from "better-auth/client/plugins" import { config } from "@/config" export const authClient = createAuthClient({ baseURL: `${config.api.url}/api/auth`, plugins: [magicLinkClient()], }) export const { useSession, signIn, signUp, signOut } = authClient ``` -------------------------------- ### Configure Documentation Source (TypeScript) Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/documentation.mdx Defines the source directory for documentation content. This configuration is used by Fumadocs to locate and process MDX files. ```typescript import { defineDocs } from "fumadocs-core/server" export const docs = defineDocs({ dir: "content/docs", }) ``` -------------------------------- ### Configure Better Auth with Multiple Providers (TypeScript) Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/blog/web-development-2026.mdx Sets up the Better Auth library with various social providers like GitHub and Google. It integrates with a database using drizzle-adapter and enables OpenAPI documentation generation. Dependencies include Better Auth, environment variables, and drizzle-adapter. ```typescript import { betterAuth } from "better-auth" import { drizzleAdapter } from "@better-auth/drizzle-adapter" import { openAPI } from "better-auth/plugins" import { env } from "@/env" import { db } from "@/db" import { user, session, account, verification } from "@/schema" export const auth = betterAuth({ baseURL: env.HONO_APP_URL, trustedOrigins: env.HONO_TRUSTED_ORIGINS, database: drizzleAdapter(db, { provider: "pg", schema: { user, session, account, verification }, }), socialProviders: { github: { clientId: env.GITHUB_CLIENT_ID, clientSecret: env.GITHUB_CLIENT_SECRET, }, google: { clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET, }, }, plugins: [openAPI()], // Auto-generated API docs }) ``` -------------------------------- ### Orchestrate Services with Docker Compose Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/deployment/docker.mdx Commands and configuration for running the full stack. The YAML defines the API and Web services with specific build contexts and network environment variables. ```bash docker compose up ``` ```yaml services: api: build: context: . dockerfile: api/hono/Dockerfile env_file: - .env environment: - INTERNAL_API_URL=http://api:4000 ports: - "4000:4000" web: build: context: . dockerfile: web/next/Dockerfile env_file: - .env environment: - INTERNAL_API_URL=http://api:4000 ports: - "3000:3000" ``` -------------------------------- ### Execute manual code quality commands Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/code-quality.mdx Provides CLI commands for manually triggering formatting, linting, and verifying code style. ```bash # Format all files bun run format # Check formatting without changes bun run format:check # Lint all files bun run lint ``` -------------------------------- ### Import Validated Environment Variables Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/environment.mdx Shows how to import the pre-validated environment configuration into specific application modules. ```typescript // api/hono/src/index.ts import { env } from "@packages/env/api-hono" // web/next/src/lib/config.ts import { env } from "@packages/env/web-next" ``` -------------------------------- ### Configure Feedback URL Environment Variable (.env) Source: https://github.com/nrjdalal/zerostarter/blob/canary/web/next/content/docs/manage/feedback.mdx This snippet shows how to add the feedback URL to your project's .env file. It's an optional configuration that enables user feedback collection. Ensure the URL is valid to display the feedback links. ```dotenv # Optional: Manage user feedback `https://zerostarter.dev/docs/manage/feedback` NEXT_PUBLIC_USERJOT_URL= ```