Skip to main content
General
Codebase

Local Development

Learn how to set up your local development environment.

Open MarkdownFull AI corpusFeedback

This guide will help you set up your local development environment for the Pro Next.js Prisma starter kit, including the necessary services like PostgreSQL.

Prerequisites

To run the application locally, you need to have the following:

Start only the services needed for the flow you are testing:

OrderServiceCommandLocal addressRequired
1PostgreSQL 17npm run docker:uplocalhost:5432Yes
2Next.jsnpm run devhttp://localhost:3000Yes
3React Email previewnpm run email:devhttp://localhost:3001Only when editing email templates
4Stripe webhook forwardingnpm run stripe:listenForwards to /api/webhooks/stripeOnly when testing billing events

The Stripe command requires the Stripe CLI and an authenticated Stripe account. Copy the temporary whsec_... value it prints into STRIPE_WEBHOOK_SECRET, then restart Next.js.

Setting Up Local Services

Option 1: Local PostgreSQL Installation

Install PostgreSQL on your machine and create a database:

Terminal
createdb your_database_name

The repository includes a docker-compose.yml file with PostgreSQL 17. It creates a database named database with the password password.

Starting the Services

  1. Start the services using Docker Compose:
Terminal
npm run docker:up
  1. Verify that the services are running:
Terminal
docker compose ps

Environment Configuration

Start from the environment template shipped with the repository:

Terminal
cp .env.example .env

The template already contains the local Docker database URL and NEXT_PUBLIC_SITE_URL. Replace its example BETTER_AUTH_SECRET with a unique value before starting the application:

Generate a Better Auth secret

Generated locally with your browser's cryptographic random number generator. The value is never sent to Achromatic.

Add it to Paste the copied line into your local .env file and use a separately generated value in production.

Optional integrations may remain empty until you test them. Password signup does require RESEND_API_KEY and EMAIL_FROM because new accounts must verify their email. Use the environment variables guide to select complete variable groups for email, Stripe, Google sign-in, AI, storage, Turnstile and Sentry.

Accessing the Services

  • PostgreSQL:
    • Host: localhost
    • Port: 5432
    • Username: postgres
    • Password: password
    • Database: database

Running Database Migrations

After setting up your database, run the migrations:

Terminal
npm run db:migrate:dev

This command will:

  • Create and apply migrations
  • Automatically regenerate Prisma Client

Start Development Server

Start the development server:

Terminal
npm run dev

Your application should now be running at http://localhost:3000 with the local PostgreSQL database.

Troubleshooting

Database Connection Issues

If you're having trouble connecting to PostgreSQL:

  1. Verify the database is running:
Terminal
docker compose ps postgres
  1. Check the logs:
Terminal
docker compose logs postgres
  1. Verify your DATABASE_URL in .env matches your database configuration

Port Already in Use

If port 3000 is already in use, you can change it by setting the PORT environment variable:

Terminal
PORT=3002 npm run dev

Port 3001 is reserved by the included React Email preview command. If you change the application port, also update NEXT_PUBLIC_SITE_URL, OAuth callback URLs and the target used by Stripe webhook forwarding.

Stopping the Services

To stop all services:

Terminal
npm run docker:down

To stop and remove all data (including volumes):

Terminal
docker compose down -v

Additional Resources