Skip to content

Commit 5856d6c

Browse files
committed
Added example 2
1 parent 10b375a commit 5856d6c

File tree

1 file changed

+84
-6
lines changed

1 file changed

+84
-6
lines changed

docs/guides/example-projects/turborepo-monorepo-prisma.mdx

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ description: "Two example projects demonstrating how to use Prisma and Trigger.d
66

77
## Overview
88

9-
These examples demonstrate how to use Prisma and Trigger.dev in a Turborepo monorepo.
9+
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.
10+
11+
- Example 1: Turborepo monorepo demo with Trigger.dev and Prisma packages
12+
- Example 2: Turborepo monorepo demo with a Prisma package and Trigger.dev installed in a Next.js app
1013

1114
<Note>
1215

1316
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.
1417

1518
</Note>
1619

17-
- Example 1: Turborepo monorepo demo with Trigger.dev and Prisma packages
18-
- Example 2: Turborepo monorepo demo with a Prisma package and Trigger.dev installed in a Next.js app
19-
2020
## Example 1: Turborepo monorepo demo with Trigger.dev and Prisma packages
2121

2222
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.
@@ -26,7 +26,7 @@ This simple example demonstrates how to use Trigger.dev and Prisma as packages i
2626
Fork the GitHub repo below to get started with this example project.
2727

2828
<Card
29-
title="Check out the Turborepo monorepo demo with Trigger.dev and Prisma packages repo"
29+
title="Check out the Turborepo monorepo demo with Trigger.dev and Prisma packages"
3030
icon="GitHub"
3131
href="https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package"
3232
>
@@ -44,6 +44,8 @@ Fork the GitHub repo below to get started with this example project.
4444

4545
### Project structure
4646

47+
Simplified project structure for this example:
48+
4749
```
4850
|
4951
| — apps/
@@ -114,4 +116,80 @@ You must include the version of Prisma you are using in the `trigger.config.ts`
114116

115117
### Running the example
116118

117-
To run this example, check out the full instructions [in the repo](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package).
119+
To run this example, check out the full instructions [in the GitHub repo README file](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/README.md).
120+
121+
## Example 2: Turborepo monorepo demo with a Prisma package and Trigger.dev installed in a Next.js app
122+
123+
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.
124+
125+
### GitHub repo
126+
127+
Fork the GitHub repo below to get started with this example project.
128+
129+
<Card
130+
title="Check out the Turborepo monorepo demo with a Prisma package and Trigger.dev installed in a Next.js app repo"
131+
icon="GitHub"
132+
href="https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger"
133+
>
134+
Click here to view the full code for this project in our examples repository on GitHub. You can
135+
fork it and use it as a starting point for your own project.
136+
</Card>
137+
138+
### Features
139+
140+
- 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.
141+
- [pnpm](https://pnpm.io/) has been used as the package manager.
142+
- 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.
143+
- A [Next.js](https://nextjs.org/) example app (`apps/web`) to show how to trigger the task via a server action.
144+
- Trigger.dev initialized and an `addNewUser` task created in the `web` app.
145+
146+
### Project structure
147+
148+
Simplified project structure for this example:
149+
150+
```
151+
|
152+
| — apps/
153+
| | — web/ # Next.js frontend application
154+
| | | — app/ # Next.js app router
155+
| | | | — api/
156+
| | | | | — actions.ts # Server actions for triggering tasks
157+
| | | | — page.tsx # Main page with "Add new user" button
158+
| | | — src/
159+
| | | | — trigger/
160+
| | | | — addNewUser.ts # Task implementation for adding users
161+
| | | — trigger.config.ts # Trigger.dev configuration
162+
| | | — package.json # Dependencies including @repo/db
163+
| |
164+
| | — docs/ # Documentation app
165+
| | — app/
166+
| | — page.tsx # Docs landing page
167+
|
168+
| — packages/
169+
| | — database/ # Prisma database package (@repo/db)
170+
| | | — prisma/
171+
| | | | — schema.prisma # Database schema definition
172+
| |
173+
| | — ui/ # UI components package
174+
|
175+
| — turbo.json # Turborepo configuration
176+
| — package.json # Root package.json with workspace config
177+
```
178+
179+
## Relevant files and code
180+
181+
### Database package (`@repo/db`)
182+
183+
- Located in [`/packages/database/`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/packages/database/) and exported as `@repo/db`
184+
- Schema defined in [`schema.prisma`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/packages/database/prisma/schema.prisma)
185+
- Provides database access to other packages and apps
186+
187+
### Next.js app (`apps/web`)
188+
189+
- Contains Trigger.dev configuration in [`trigger.config.ts`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/apps/web/trigger.config.ts)
190+
- Trigger.dev tasks are defined in [`src/trigger/`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/apps/web/src/trigger/) (e.g., [`addNewUser.ts`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/apps/web/src/trigger/addNewUser.ts))
191+
- Demonstrates triggering tasks via server actions in [`app/api/actions.ts`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/apps/web/app/api/actions.ts)
192+
193+
### Running the example
194+
195+
To run this example, check out the full instructions [in the GitHub repo README file](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/README.md).

0 commit comments

Comments
 (0)