You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .cursor/rules/executing-commands.mdc
+16-2Lines changed: 16 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -6,5 +6,19 @@ alwaysApply: true
6
6
Almost all commands in the monorepo should be executed when `pnpm run ...` from the root of the monorepo. For example, running tests for the `@internal/run-engine` internal package:
7
7
8
8
```
9
-
pnpm run test --filter @internal/run-engine
10
-
```
9
+
pnpm run dev --filter webapp
10
+
```
11
+
12
+
But often, when running tests, it's better to `cd` into the directory and then run tests:
Copy file name to clipboardExpand all lines: .cursor/rules/repo.mdc
+1-15Lines changed: 1 addition & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -3,18 +3,4 @@ description: understanding the structure of the monorepo
3
3
globs:
4
4
alwaysApply: true
5
5
---
6
-
This is a pnpm 8.15.5 monorepo that uses turborepo [turbo.json](mdc:turbo.json). The following workspaces are relevant:
7
-
8
-
- <root>/apps/webapp is a remix app that is the main API and dashboard for trigger.dev
9
-
- <root>/packages/trigger-sdk is the `@trigger.dev/sdk` main SDK package
10
-
- <root>/packages/cli-v3 is the `trigger.dev` CLI package
11
-
- <root>/packages/core is the `@trigger.dev/core` package that is shared across the SDK and other packages
12
-
- <root>/packages/build defines the types and prebuilt build extensions for trigger.dev
13
-
- <root>/packages/react-hooks defines some useful react hooks like our realtime hooks
14
-
- <root>/internal-packages/* are packages that are used internally only, not published, and usually they have a tsc build step and are used in the webapp
15
-
- <root>/references/* are test workspaces that we use to write and test the system. Not quite e2e tests or automated, but just a useful place to help develop new features
16
-
- <root>/docs is our trigger.dev/docs mintlify documentation site
17
-
18
-
Other things in the monorepo to note:
19
-
20
-
The [Dockerfile](mdc:docker/Dockerfile) is the one that creates the main trigger.dev published image, and the [docker-compose.yml](mdc:docker/docker-compose.yml) is the file we run locally to start postgresql, redis, and electric when we are doing local development. The [CONTRIBUTING.md](mdc:CONTRIBUTING.md) file defines the steps it takes for OSS contributors to start contributing.
6
+
We've documented the structure of our monorepo here: [repo.md](mdc:ai/references/repo.md)
The main trigger.dev webapp, which powers it's API and dashboard and makes up the docker image that is produced as an OSS image, is a Remix 2.1.0 app that uses an express server, written in TypeScript. The following subsystems are either included in the webapp or are used by the webapp in another part of the monorepo:
10
8
11
9
- `@trigger.dev/database` exports a Prisma 5.4.1 client that is used extensively in the webapp to access a PostgreSQL instance. The schema file is [schema.prisma](mdc:internal-packages/database/prisma/schema.prisma)
12
10
- `@trigger.dev/core` is a published package and is used to share code between the `@trigger.dev/sdk` and the webapp. It includes functionality but also a load of Zod schemas for data validation. When importing from `@trigger.dev/core` in the webapp, we never import the root `@trigger.dev/core` path, instead we favor one of the subpath exports that you can find in [package.json](mdc:packages/core/package.json)
11
+
- `@internal/run-engine` has all the code needed to trigger a run and take it through it's lifecycle to completion.
12
+
- `@internal/redis-worker` is a custom redis based background job/worker system that's used in the webapp and also used inside the run engine.
13
+
14
+
## Environment variables and testing
15
+
16
+
In the webapp, all environment variables are accessed through the `env` export of [env.server.ts](mdc:apps/webapp/app/env.server.ts), instead of directly accessing `process.env`.
17
+
18
+
Ideally, the `env.server.ts` file would never be imported into a test file, either directly or indirectly. Tests should only imported classes and functions from a file matching `app/**/*.ts` of the webapp, and that file should not use environment variables, everything should be passed through as options instead. This "service/configuration" separation is important, and can be seen in a few places in the code for examples:
19
+
20
+
- [realtimeClient.server.ts](mdc:apps/webapp/app/services/realtimeClient.server.ts) is the testable service, and [realtimeClientGlobal.server.ts](mdc:apps/webapp/app/services/realtimeClientGlobal.server.ts) is the configuration
21
+
22
+
Also for writing tests in the webapp, checkout our [tests.md](mdc:ai/references/tests.md) guide
23
+
24
+
## Legacy run engine vs Run Engine 2.0
25
+
26
+
We originally the Trigger.dev "Run Engine" not as a single system, but just spread out all over the codebase, with no real separate or encapsulation. And we didn't even call it a "Run Engine". With Run Engine 2.0, we've completely rewritten big parts of the way the system works, and moved it over to an internal package called `@internal/run-engine`. So we've retroactively named the previous run engine "Legacy run engine". We're focused almost exclusively now on moving to Run Engine 2.0 and will be deprecating and removing the legacy run engine code eventually.
27
+
28
+
## Where to look for code
29
+
30
+
- The trigger API endpoint is [api.v1.tasks.$taskId.trigger.ts](mdc:apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts)
31
+
- The batch trigger API endpoint is [api.v1.tasks.batch.ts](mdc:apps/webapp/app/routes/api.v1.tasks.batch.ts)
32
+
- Setup code for the prisma client is in [db.server.ts](mdc:apps/webapp/app/db.server.ts)
33
+
- The run engine is configured in [runEngine.server.ts](mdc:apps/webapp/app/v3/runEngine.server.ts)
34
+
- All the "services" that are found in app/v3/services/**/*.server.ts
35
+
- The code for the TaskEvent data, which is the otel data sent from tasks to our servers, is in both the [eventRepository.server.ts](mdc:apps/webapp/app/v3/eventRepository.server.ts) and also the [otlpExporter.server.ts](mdc:apps/webapp/app/v3/otlpExporter.server.ts). The otel endpoints which are hit from production and development otel exporters is [otel.v1.logs.ts](mdc:apps/webapp/app/routes/otel.v1.logs.ts) and [otel.v1.traces.ts](mdc:apps/webapp/app/routes/otel.v1.traces.ts)
36
+
- We use "presenters" to move more complex loader code into a class, and you can find those are app/v3/presenters/**/*.server.ts
This is a pnpm 8.15.5 monorepo that uses turborepo @turbo.json. The following workspaces are relevant
4
+
5
+
## Apps
6
+
7
+
- <root>/apps/webapp is a remix app that is the main API and dashboard for trigger.dev
8
+
- <root>/apps/supervisor is a node.js app that handles the execution of built tasks, interaction with the webapp through internal "engine" APIs, as well as interfacing with things like docker or kubernetes, to execute the code.
9
+
10
+
## Public Packages
11
+
12
+
- <root>/packages/trigger-sdk is the `@trigger.dev/sdk` main SDK package.
13
+
- <root>/packages/cli-v3 is the `trigger.dev` CLI package. See our [CLI dev command](https://trigger.dev/docs/cli-dev.md) and [Deployment](https://trigger.dev/docs/deployment/overview.md) docs for more information.
14
+
- <root>/packages/core is the `@trigger.dev/core` package that is shared across the SDK and other packages
15
+
- <root>/packages/build defines the types and prebuilt build extensions for trigger.dev. See our [build extensions docs](https://trigger.dev/docs/config/extensions/overview.md) for more information.
16
+
- <root>/packages/react-hooks defines some useful react hooks like our realtime hooks. See our [Realtime hooks](https://trigger.dev/docs/frontend/react-hooks/realtime.md) and our [Trigger hooks](https://trigger.dev/docs/frontend/react-hooks/triggering.md) for more information.
17
+
18
+
## Internal Packages
19
+
20
+
- <root>/internal-packages/\* are packages that are used internally only, not published, and usually they have a tsc build step and are used in the webapp
21
+
- <root>/internal-packages/database is the `@trigger.dev/database` package that exports a prisma client, has the schema file, and exports a few other helpers.
22
+
- <root>/internal-packages/run-engine is the `@internal/run-engine` package that is "Run Engine 2.0" and handles moving a run all the way through it's lifecycle
23
+
- <root>/internal-packages/redis-worker is the `@internal/redis-worker` package that implements a custom background job/worker sytem powered by redis for offloading work to the background, used in the webapp and also in the Run Engine 2.0.
24
+
- <root>/internal-packages/redis is the `@internal/redis` package that exports Redis types and the `createRedisClient` function to unify how we create redis clients in the repo. It's not used everywhere yet, but it's the preferred way to create redis clients from now on.
25
+
- <root>/internal-packages/testcontainers is the `@internal/testcontainers` package that exports a few useful functions for spinning up local testcontainers when writing vitest tests. See our [tests.md](./tests.md) file for more information.
26
+
- <root>/internal-packages/zodworker is the `@internal/zodworker` package that implements a wrapper around graphile-worker that allows us to use zod to validate our background jobs. We are moving away from using graphile-worker as our background job system, replacing it with our own redis-worker package.
27
+
28
+
## References
29
+
30
+
- <root>/references/\* are test workspaces that we use to write and test the system. Not quite e2e tests or automated, but just a useful place to help develop new features
31
+
32
+
## Other
33
+
34
+
- <root>/docs is our trigger.dev/docs mintlify documentation site
35
+
- <root>/docker/Dockerfile is the one that creates the main trigger.dev published image
36
+
- <root>/docker/docker-compose.yml is the file we run locally to start postgresql, redis, and electric when we are doing local development. You can run it with `pnpm run docker`
37
+
- <root>/CONTRIBUTING.md defines the steps it takes for OSS contributors to start contributing.
0 commit comments