| title | Turborepo monorepo with Prisma |
|---|---|
| sidebarTitle | Turborepo monorepo with Prisma |
| description | Two example projects demonstrating how to use Prisma and Trigger.dev in a Turborepo monorepo setup. |
These examples demonstrate two different ways to use Prisma and Trigger.dev in a Turborepo monorepo. They both trigger a task from a Next.js app using a server action, and then use Prisma to add a user to a database table, however they differ in how Trigger.dev is installed and configured.
- Example 1: Turborepo monorepo demo with Trigger.dev and Prisma packages
- Example 2: Turborepo monorepo demo with a Prisma package and Trigger.dev installed in a Next.js app
You can either fork the repos below, or simply check out the project structures and code to get an idea of how to set up Trigger.dev in your own monorepos.
This simple example demonstrates how to use Trigger.dev and Prisma as packages inside a monorepo created with Turborepo. The Trigger.dev task is triggered by a button click in a Next.js app which triggers the task via a server action.
Fork the GitHub repo below to get started with this example project.
<Card title="Check out the Turborepo monorepo demo with Trigger.dev and Prisma packages" icon="GitHub" href="https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package"
Click here to view the full code for this project in our examples repository on GitHub. You can fork it and use it as a starting point for your own project.
- This monorepo has been created using the Turborepo CLI, following the official Prisma and Turborepo docs, and then adapted for use with Trigger.dev.
- pnpm has been used as the package manager.
- A tasks package (
@repo/tasks) using Trigger.dev is used to create and execute tasks from an app inside the monorepo. - A database package (
@repo/db) using Prisma ORM is used to interact with the database. You can use any popular Postgres database supported by Prisma, e.g. Supabase, Neon, etc. - A Next.js example app (
apps/web) to show how to trigger the task via a server action.
Simplified project structure for this example:
|
| — apps/
| | — web/ # Next.js frontend application
| | | — app/ # Next.js app router
| | | | — api/
| | | | | — actions.ts # Server actions for triggering tasks
| | | | — page.tsx # Main page with "Add new user" button
| | | | — layout.tsx # App layout
| | | — package.json # Dependencies including @repo/db and @repo/tasks
| |
| | — docs/ # Documentation app (not fully implemented)
|
| — packages/
| | — database/ # Prisma database package (@repo/db)
| | | — prisma/
| | | | — schema.prisma # Database schema definition
| | | — generated/ # Generated Prisma client (gitignored)
| | | — src/
| | | | — index.ts # Exports from the database package
| | | — package.json # Database package dependencies
| |
| | — tasks/ # Trigger.dev tasks package (@repo/tasks)
| | | — src/
| | | | — index.ts # Exports from the tasks package
| | | | — trigger/
| | | | — index.ts # Exports the tasks
| | | | — addNewUser.ts # Task implementation for adding users
| | | — trigger.config.ts # Trigger.dev configuration
| | | — package.json # Tasks package dependencies
| |
| | — ui/ # UI components package (referenced but not detailed)
|
| — turbo.json # Turborepo configuration
| — package.json # Root package.json with workspace config
- Prisma is added as a package in
/packages/databaseand exported as@repo/dbin thepackage.jsonfile. - The schema is defined in the
prisma/schema.prismafile.
to run pnpm dlx trigger.dev@latest init in a blank packages folder, you have to add a package.json file first, otherwise it will attempt to add Trigger.dev files in the root of your monorepo.
- Trigger.dev is added as a package in
/packages/tasksand exported as@repo/tasksin thepackage.jsonfile. - The
addNewUser.tstask adds a new user to the database. - The
packages/tasks/src/index.tsfile exports values and types from the Trigger.dev SDK, and is exported from the package via thepackage.jsonfile. - The
packages/tasks/src/trigger/index.tsfile exports the task from the package. Every task must be exported from the package like this. - The
trigger.config.tsfile configures the Trigger.dev project settings. This is where the Trigger.dev Prisma build extension is added, which is required to use Prisma in the Trigger.dev task.
- The app is a simple Next.js app using the App Router, that uses the
@repo/dbpackage to interact with the database and the@repo/taskspackage to trigger the task. These are both added as dependencies in thepackage.jsonfile. - The task is triggered from a button click in the app in
page.tsx, which uses a server action in/app/api/actions.tsto trigger the task with an example payload.
To run this example, check out the full instructions in the GitHub repo README file.
This example demonstrates how to use Trigger.dev and Prisma in a monorepo created with Turborepo. Prisma has been added as a package, and Trigger.dev has been installed in a Next.js app. The task is triggered by a button click in the app via a server action.
Fork the GitHub repo below to get started with this example project.
<Card title="Check out the Turborepo monorepo demo with a Prisma package and Trigger.dev installed in a Next.js app" icon="GitHub" href="https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger"
Click here to view the full code for this project in our examples repository on GitHub. You can fork it and use it as a starting point for your own project.
- This monorepo has been created using the Turborepo CLI, following the official Prisma and Turborepo docs, and then adapted for use with Trigger.dev.
- pnpm has been used as the package manager.
- A database package (
@repo/db) using Prisma ORM is used to interact with the database. You can use any popular Postgres database supported by Prisma, e.g. Supabase, Neon, etc. - A Next.js example app (
apps/web) to show how to trigger the task via a server action. - Trigger.dev initialized and an
addNewUsertask created in thewebapp.
Simplified project structure for this example:
|
| — apps/
| | — web/ # Next.js frontend application
| | | — app/ # Next.js app router
| | | | — api/
| | | | | — actions.ts # Server actions for triggering tasks
| | | | — page.tsx # Main page with "Add new user" button
| | | — src/
| | | | — trigger/
| | | | — addNewUser.ts # Task implementation for adding users
| | | — trigger.config.ts # Trigger.dev configuration
| | | — package.json # Dependencies including @repo/db
| |
| | — docs/ # Documentation app
| | — app/
| | — page.tsx # Docs landing page
|
| — packages/
| | — database/ # Prisma database package (@repo/db)
| | | — prisma/
| | | | — schema.prisma # Database schema definition
| |
| | — ui/ # UI components package
|
| — turbo.json # Turborepo configuration
| — package.json # Root package.json with workspace config
- Located in
/packages/database/and exported as@repo/db - Schema defined in
schema.prisma - Provides database access to other packages and apps
- Contains Trigger.dev configuration in
trigger.config.ts - Trigger.dev tasks are defined in
src/trigger/(e.g.,addNewUser.ts) - Demonstrates triggering tasks via server actions in
app/api/actions.ts
To run this example, check out the full instructions in the GitHub repo README file.