Skip to content

10MinDesign-Invite/10MinDesign

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Turborepo + Prisma ORM starter

This is a example designed to help you quickly set up a Turborepo monorepo with a Next.js app and Prisma ORM. This is a community-maintained example. If you experience a problem, please submit a pull request with a fix. GitHub Issues will be closed.

What's inside?

This turborepo includes the following packages/apps:

Apps and packages

  • web: a Next.js app
  • @repo/eslint-config: eslint configurations (includes eslint-config-next and eslint-config-prettier)
  • @repo/database: Prisma ORM to manage & access your database
  • @repo/typescript-config: tsconfig.jsons used throughout the monorepo

Each package/app is 100% TypeScript.

Utilities

This turborepo has some additional tools already setup for you:

Getting started

Follow these steps to set up and run your Turborepo project with Prisma ORM:

1. Create a Turborepo project

Start by creating a new Turborepo project using the following command:

npx create-turbo@latest -e with-prisma

Choose your desired package manager when prompted and a name for the app (e.g., my-turborepo). This will scaffold a new Turborepo project with Prisma ORM included and dependencies installed.

Navigate to your project directory:

cd ./my-turborepo

2. Setup a local database with Docker Compose

We use Prisma ORM to manage and access our database. As such you will need a database for this project, either locally or hosted in the cloud.

To make this process easier, a docker-compose.yml file is included to setup a MySQL server locally with a new database named turborepo:

Start the MySQL database using Docker Compose:

docker-compose up -d

To change the default database name, update the MYSQL_DATABASE environment variable in the docker-compose.yml file.

3. Setup environment variables

Once the database is ready, copy the .env.example file to the /packages/database and /apps/web directories as .env:

cp .env.example ./packages/database/.env
cp .env.example ./apps/web/.env

This ensures Prisma has access to the DATABASE_URL environment variable, which is required to connect to your database.

If you added a custom database name, or use a cloud based database, you will need to update the DATABASE_URL in your .env accordingly.

4. Migrate your database

Once your database is running, you’ll need to create and apply migrations to set up the necessary tables. Run the database migration command:

# Using npm
npm run db:migrate:dev
Expand for yarn, pnpm or bun
# Using yarn
yarn run db:migrate:dev

# Using pnpm
pnpm run db:migrate:dev

# Using bun
bun run db:migrate:dev

You’ll be prompted to name the migration. Once you provide a name, Prisma will create and apply the migration to your database.

Note: The db:migrate:dev script (located in packages/database/package.json) uses Prisma Migrate under the hood.

For production environments, always push schema changes to your database using the prisma migrate deploy command. You can find an example db:migrate:deploy script in the package.json file of the database package.

5. Seed your database

To populate your database with initial or fake data, use Prisma's seeding functionality.

Update the seed script located at packages/database/src/seed.ts to include any additional data that you want to seed. Once edited, run the seed command:

# Using npm
npm run db:seed
Expand for yarn, pnpm or bun
# Using yarn
yarn run db:seed

# Using pnpm
pnpm run db:seed

# Using bun
bun run db:seed

6. Build your application

To build all apps and packages in the monorepo, run:

# Using npm
npm run build
Expand for yarn, pnpm or bun
# Using yarn
yarn run build

# Using pnpm
pnpm run build

# Using bun
bun run build

7. Start the application

Finally, start your application with:

yarn run dev
Expand for yarn, pnpm or bun
# Using yarn
yarn run dev

# Using pnpm
pnpm run dev

# Using bun
bun run dev

Your app will be running at http://localhost:3000. Open it in your browser to see it in action!

You can also read the official detailed step-by-step guide from Prisma ORM to build a project from scratch using Turborepo and Prisma ORM.

Useful Links

Learn more about the power of Turborepo:

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published