Skip to content

Added turborepo and prisma docs #1807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added example 1
  • Loading branch information
D-K-P committed Mar 20, 2025
commit 97861075713a3a4303b8bd0682d98319156c58e4
1 change: 1 addition & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
"pages": [
"guides/example-projects/batch-llm-evaluator",
"guides/example-projects/claude-thinking-chatbot",
"guides/example-projects/turborepo-monorepo-prisma",
"guides/example-projects/realtime-fal-ai",
"guides/example-projects/realtime-csv-importer",
"guides/example-projects/vercel-ai-sdk-image-generator"
Expand Down
117 changes: 117 additions & 0 deletions docs/guides/example-projects/turborepo-monorepo-prisma.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
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."
---

## Overview

These examples demonstrate how to use Prisma and Trigger.dev in a Turborepo monorepo.

<Note>

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.

</Note>

- 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

## Example 1: Turborepo monorepo demo with Trigger.dev and Prisma packages

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.

### GitHub repo

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 repo"
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.
</Card>

### Features

- This monorepo has been created using the [Turborepo CLI](https://turbo.build/repo), following the official [Prisma and Turborepo docs](https://www.prisma.io/docs/guides/turborepo), and then adapted for use with Trigger.dev.
- [pnpm](https://pnpm.io/) has been used as the package manager.
- A tasks package (`@repo/tasks`) using [Trigger.dev](https://trigger.dev) is used to create and execute tasks from an app inside the monorepo.
- A database package (`@repo/db`) using [Prisma ORM](https://www.prisma.io/docs/orm/) is used to interact with the database. You can use any popular Postgres database supported by Prisma, e.g. [Supabase](https://supabase.com/), [Neon](https://neon.tech/), etc.
- A [Next.js](https://nextjs.org/) example app (`apps/web`) to show how to trigger the task via a server action.

### Project structure

```
|
| — 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
```

### Relevant files and code

#### Database package

- Prisma is added as a package in [`/packages/database`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/packages/database/) and exported as `@repo/db` in the [`package.json`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/packages/database/package.json) file.
- The schema is defined in the [`prisma/schema.prisma`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/packages/database/prisma/schema.prisma) file.

#### Tasks package

<Note>

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.

</Note>

- Trigger.dev is added as a package in [`/packages/tasks`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/packages/tasks) and exported as `@repo/tasks` in the [`package.json`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/packages/tasks/package.json) file.
- The [`addNewUser.ts`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/packages/tasks/src/trigger/addNewUser.ts) task adds a new user to the database.
- The [`packages/tasks/src/index.ts`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/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`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/packages/tasks/package.json) file.
- The [`packages/tasks/src/trigger/index.ts`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/packages/tasks/src/trigger/index.ts) file exports the task from the package. Every task must be exported from the package like this.
- The [`trigger.config.ts`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/packages/tasks/trigger.config.ts) file configures the Trigger.dev project settings. This is where the Trigger.dev [Prisma build extension](https://trigger.dev/docs/config/extensions/prismaExtension) is added, which is required to use Prisma in the Trigger.dev task.

<Info>
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](/config/extensions/prismaExtension).

</Info>

#### The Next.js app `apps/web`

- The app is a simple Next.js app using the App Router, that uses the `@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`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/apps/web/package.json) file.
- The task is triggered from a button click in the app in [`page.tsx`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/apps/web/app/page.tsx), which uses a server action in [`/app/api/actions.ts`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/apps/web/app/api/actions.ts) to trigger the task with an example payload.

### Running the example

To run this example, check out the full instructions [in the repo](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package).