Two example projects demonstrating how to use Prisma and Trigger.dev in a Turborepo monorepo setup.
These examples demonstrate two different ways of using Prisma and Trigger.dev in a Turborepo monorepo. In both examples, a task is triggered from a Next.js app using a server action, which uses Prisma to add a user to a database table. The examples differ in how Trigger.dev is installed and configured.
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.
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.
@repo/tasks
) using Trigger.dev is used to create and execute tasks from an app inside the monorepo.@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.apps/web
) to show how to trigger the task via a server action.Simplified project structure for this example:
/packages/database
and exported as @repo/db
in the package.json
file.prisma/schema.prisma
file.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.
/packages/tasks
and exported as @repo/tasks
in the package.json
file.addNewUser.ts
task adds a new user to the database.packages/tasks/src/index.ts
file exports values and types from the Trigger.dev SDK, and is exported from the package via the package.json
file.packages/tasks/src/trigger/index.ts
file exports the task from the package. Every task must be exported from the package like this.trigger.config.ts
file 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.You must include the version of Prisma you are using in the trigger.config.ts
file, otherwise the Prisma build extension will not work. Learn more about our Prisma build extension.
apps/web
@repo/db
package to interact with the database and the @repo/tasks
package to trigger the task. These are both added as dependencies in the package.json
file.page.tsx
, which uses a server action in /app/api/actions.ts
to 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.
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.
@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.apps/web
) to show how to trigger the task via a server action.addNewUser
task created in the web
app.Simplified project structure for this example:
@repo/db
)/packages/database/
and exported as @repo/db
schema.prisma
apps/web
)trigger.config.ts
src/trigger/
(e.g., addNewUser.ts
)app/api/actions.ts
To run this example, check out the full instructions in the GitHub repo README file.