Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(dx): update agents.md file (#12243)

Nimarce3fd8e34c89
diff --git a/AGENTS.md b/AGENTS.md
index d3dbc4c022..4f120998e1 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -1,23 +1,118 @@
# Codex Guidelines for Langfuse
-Langfuse is an **open source LLM engineering** platform for developing, monitoring, evaluating and debugging AI applications. See the README for more details.
+Langfuse is an open source LLM engineering platform for developing, monitoring,
+evaluating, and debugging AI applications.
+Langfuse monorepo guidance for fast, safe code changes.
-## Codebase
-* Nextjs 15 without SSR
-* Typescript 5
-* Tailwind
+## Maintenance Contract
+- `AGENTS.md` is a living document.
+- Update this file in the same PR when monorepo-level architecture, workflows,
+ dependency boundaries, mandatory verification commands, or release/security
+ processes materially change.
+- For package-local material changes, update the package-local `AGENTS.md` in
+ the same PR.
+- If no material guidance changed, do not edit AGENTS files.
-## Linting
-- Run `pnpm run lint` to lint all packages.
-- Fix issues automatically with `pnpm run lint:fix`.
+## Project Structure & Module Organization
+```text
+langfuse/
+β”œβ”€ web/ # Next.js app (UI + tRPC + public REST)
+β”œβ”€ worker/ # Queue consumers and background processing
+β”œβ”€ packages/shared/ # Shared domain, DB, queue contracts, repositories
+β”œβ”€ ee/ # Enterprise package consumed by web
+β”œβ”€ generated/ # Generated API clients (do not hand-edit)
+β”œβ”€ fern/ # API definition sources
+└─ scripts/ # Repo scripts
+```
-## Tests
-- Codex cannot run the test suite because it depends on Docker-based infrastructure that is unavailable in this environment.
-- When writing tests, focus on decoupling each `it` or `test` block to ensure that they can run independently and concurrently. Tests must never depend on the action or outcome of previous or subsequent tests.
-- When writing tests, especially in the __tests__/server directory, ensure that you avoid `pruneDatabase` calls.
+- Package guides:
+ - `web/AGENTS.md`
+ - `worker/AGENTS.md`
+ - `packages/shared/AGENTS.md`
+ - `ee/AGENTS.md`
+- Dependency direction:
+ - `web` -> `@langfuse/shared`, `@langfuse/ee`
+ - `worker` -> `@langfuse/shared`
+ - `@langfuse/ee` -> `@langfuse/shared`
+ - `@langfuse/shared` -> no imports from `web`, `worker`, or `ee`
+- Queue payload schemas and queue-name contracts are owned by
+ `packages/shared/src/server/queues.ts`.
+
+## Build, Test, and Development Commands
+- Install deps: `pnpm install`
+- Dev all packages: `pnpm run dev`
+- Dev web only: `pnpm run dev:web`
+- Dev worker only: `pnpm run dev:worker`
+- Lint all: `pnpm run lint`
+- Typecheck all: `pnpm run typecheck` / `pnpm tc`
+- To try running build, always run `pnpm run build:check` and verify that it succeeds. This does not impact running web servers
+- If you have to rebuild all for testing, run: `pnpm run build`
+- Full reset/bootstrap (destructive): `pnpm run dx`
+
+Minimum verification matrix:
+| Change scope | Minimum verification |
+| --- | --- |
+| `web/**` only | `pnpm --filter web run lint` + targeted web tests |
+| `worker/**` only | `pnpm --filter worker run lint` + targeted worker tests |
+| `packages/shared/**` (non-schema) | `pnpm --filter @langfuse/shared run lint` + one targeted web check + one targeted worker check |
+| `packages/shared/prisma/**` or `packages/shared/clickhouse/**` | `pnpm --filter @langfuse/shared run lint` + `pnpm run db:generate` + targeted web/worker regressions |
+| Public API contract (`web/src/pages/api/public/**`, `web/src/features/public-api/types/**`, `fern/apis/**`) | web lint + targeted server API tests + Fern update/regeneration; never hand-edit `generated/**` |
+| Cross-package refactor (`web` + `worker` + `shared`) | `pnpm run lint` + `pnpm run typecheck` + targeted tests per impacted package |
+
+## Coding Style & Naming Conventions
+- Keep changes scoped; avoid unrelated refactors.
+- Prefer package-local implementation details in package AGENTS files.
+- Do not hand-edit generated/build artifacts:
+ - `generated/*`
+ - `web/.next/*`
+ - `web/.next-check/*`
+ - `*/dist/*`
+ - `packages/shared/prisma/generated/*`
+
+## Testing Guidelines
+- Keep each test independent and parallel-safe.
+- `web/src/__tests__/server`: avoid `pruneDatabase` calls.
+- Client tests contain `....clienttest.ts`
+
+## Commit & Pull Request Guidelines
+- Follow Conventional Commits.
+- Include AGENTS.md updates in the same PR when guidance materially changes.
+- In PR descriptions, list impacted packages and executed verification commands.
+
+## Docs Linking
+- Public API contract changes must update Fern sources in `fern/apis/**` and regenerated outputs; do not hand-edit `generated/**`.
+- Use repo-relative file paths in docs and runbooks.
+- Our docs live in `../langfuse-docs/` which is a different repo. You may always access this.
+
+## Agent-specific Notes
+- Root `AGENTS.md` is monorepo-level only.
+- Package-local runbooks, commands, and entry points belong in package `AGENTS.md` files.
+- Keep guidance DRY: canonicalize to the most specific file.
+
+## Release Channel
+- Release workflow is managed at root (`pnpm run release`).
+- Do not change release/versioning flow without updating this file and impacted package guides.
+
+## GitHub Search
+- use the github cli `gh search issues` to search github.
+
+## GitHub Issues and Pull Requests
+- Placeholder: add issue triage and PR hygiene conventions used by maintainers.
+
+## Security and Configuration Tips
+- Never commit secrets or credentials.
+- Keep examples in `.env*.example` files in sync with required env vars.
+- Follow `SECURITY.md` for vulnerability reporting/handling.
+
+## Troubleshooting
+- Lint/typecheck failures: run `pnpm run lint` and `pnpm run tc`.
+- Schema/client drift: run `pnpm run db:generate`.
+- Local infra issues: run `pnpm run infra:dev:up`; use `pnpm run dx` only when destructive reset is intended.
+
+## Git Notes
+- Do not use destructive git commands (for example `reset --hard`) unless explicitly requested.
+- Do not revert unrelated working-tree changes.
+- Keep commits focused and atomic.
## Cursor Rules
- Additional folder-specific rules live in `.cursor/rules/`.
-
-## Commits
-- Follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) when crafting commit messages.
diff --git a/ee/AGENTS.md b/ee/AGENTS.md
new file mode 100644
index 0000000000..393627ba2c
--- /dev/null
+++ b/ee/AGENTS.md
@@ -0,0 +1,37 @@
+# Codex Guidelines for `ee`
+
+This file covers package-local guidance for this package.
+Use root [AGENTS.md](../AGENTS.md) for monorepo-level rules.
+
+## Purpose
+- Enterprise Edition package consumed by `web` and `worker`.
+- Contains EE-specific logic and licensing-related integrations.
+
+## Maintenance Contract
+- `AGENTS.md` is a living document.
+- Update this file in the same PR when material EE package changes happen:
+ - new/renamed EE entry points
+ - changed EE build/typecheck/lint commands
+ - changed integration contracts consumed by `web` or `worker`
+- If the change impacts monorepo workflows, update root `AGENTS.md` too.
+
+## High-Signal Entry Points
+- Package root exports: `src/index.ts`
+- License check module: `src/ee-license-check/index.ts`
+- Environment parsing: `src/env.ts`
+
+## Quick Commands
+- Dev watch build: `pnpm --filter @langfuse/ee run dev`
+- Lint: `pnpm --filter @langfuse/ee run lint`
+- Lint fix: `pnpm --filter @langfuse/ee run lint:fix`
+- Typecheck: `pnpm --filter @langfuse/ee run typecheck`
+- Build: `pnpm --filter @langfuse/ee run build`
+
+## Integration Notes
+- `ee` depends on `@langfuse/shared`; coordinate shared type changes carefully.
+- Validate downstream usage in `../web/src/ee/*` and `../worker/src/ee/*` when EE
+ exports change.
+
+## Package-Specific Rules
+- Do not hand-edit `dist/*`.
+- Keep EE-only concerns isolated from OSS package code paths.
diff --git a/packages/shared/AGENTS.md b/packages/shared/AGENTS.md
new file mode 100644
index 0000000000..182644a818
--- /dev/null
+++ b/packages/shared/AGENTS.md
@@ -0,0 +1,71 @@
+# Codex Guidelines for `@langfuse/shared`
+
+This file covers package-local guidance for this package.
+Use root [AGENTS.md](../../AGENTS.md) for monorepo-level rules.
+
+## Purpose
+- Shared domain, database, queue, and server utilities used by `web` and
+ `worker`.
+- Primary owner of Postgres schema, ClickHouse schema, and queue payload
+ contracts.
+
+## Maintenance Contract
+- `AGENTS.md` is a living document.
+- Update this file in the same PR for material shared-package changes:
+ - new/renamed schema or migration workflows
+ - new/renamed queue contracts
+ - changed exported surfaces or validation commands
+- Because this package is consumed by both `web` and `worker`, cross-package
+ changes usually require updates in root `AGENTS.md` too.
+
+## High-Signal Entry Points
+- Main exports: `src/index.ts`
+- DB clients and types: `src/db.ts`
+- Server exports: `src/server/index.ts`
+- Domain model types: `src/domain/*`
+- Repository layer: `src/server/repositories/*`
+- Queue payload schemas: `src/server/queues.ts`
+- Queue helpers: `src/server/redis/*`
+- Postgres schema: `prisma/schema.prisma`
+- Prisma migrations: `prisma/migrations/*`
+- ClickHouse migrations: `clickhouse/migrations/{clustered,unclustered}/*`
+- Seeder and support scripts: `scripts/seeder/*`, `clickhouse/scripts/*`
+
+## Quick Commands
+- Dev watch build: `pnpm --filter @langfuse/shared run dev`
+- Lint: `pnpm --filter @langfuse/shared run lint`
+- Lint fix: `pnpm --filter @langfuse/shared run lint:fix`
+- Typecheck: `pnpm --filter @langfuse/shared run typecheck`
+- Build: `pnpm --filter @langfuse/shared run build`
+- Prisma generate: `pnpm --filter @langfuse/shared run db:generate`
+- Prisma migrate (dev): `pnpm --filter @langfuse/shared run db:migrate`
+- ClickHouse reset: `pnpm --filter @langfuse/shared run ch:reset`
+
+## Playbooks
+
+### Postgres schema change
+1. Update `prisma/schema.prisma`.
+2. Add migration in `prisma/migrations/*`.
+3. Regenerate client/types via `db:generate`.
+4. Update affected repository/query code under `src/server/repositories/*`.
+5. Add/adjust `web` and/or `worker` tests for changed behavior.
+
+### ClickHouse schema change
+1. Add migration under `clickhouse/migrations/*`.
+2. Update ClickHouse query/mapping logic in `src/server/clickhouse/*` and
+ related repositories.
+3. Validate ingestion/read path impact in both `web` and `worker`.
+
+### Queue payload contract change
+1. Update zod schemas/types in `src/server/queues.ts`.
+2. Update queue helpers in `src/server/redis/*` if queue names/payload
+ handling changed.
+3. Update producer and consumer code in `web`/`worker`.
+4. Add or update regression tests in affected packages.
+
+## Package-Specific Rules
+- Keep backward compatibility in queue payloads when possible during rolling
+ deployments.
+- Do not hand-edit generated artifacts under `prisma/generated/*` or `dist/*`.
+- Avoid exposing server-only modules through `src/index.ts` if they must remain
+ frontend-safe.
diff --git a/web/AGENTS.md b/web/AGENTS.md
new file mode 100644
index 0000000000..8570cd0a0e
--- /dev/null
+++ b/web/AGENTS.md
@@ -0,0 +1,67 @@
+# Codex Guidelines for `web`
+
+This file covers package-local guidance for this package.
+Use root [AGENTS.md](../AGENTS.md) for monorepo-level rules.
+
+## Purpose
+- Next.js 15 application with UI, tRPC backend, and public REST API routes.
+- Primary package for frontend and most request/response surface changes.
+
+## Maintenance Contract
+- `AGENTS.md` is a living document.
+- Update this file in the same PR when material web-local changes occur:
+ - new/renamed web entry points
+ - new API route families
+ - changed web-specific verification commands
+- If the change also affects monorepo workflows or other packages, update root
+ `AGENTS.md` too.
+
+## High-Signal Entry Points
+- App shell/providers: `src/pages/_app.tsx`
+- tRPC context/procedures: `src/server/api/trpc.ts`
+- tRPC router registry: `src/server/api/root.ts`
+- tRPC routers: `src/server/api/routers/*`, `src/features/*/server/*`
+- Public REST API routes: `src/pages/api/public/*`
+- Feature modules: `src/features/*`
+- Reusable UI components: `src/components/*`
+- Tests:
+ - Server tests: `src/__tests__/server/*.servertest.ts`
+ - Client tests: `src/**/*.clienttest.ts(x)`
+ - E2E: `src/__e2e__/*`
+
+## Quick Commands
+- Dev: `pnpm --filter web run dev`
+- Lint: `pnpm --filter web run lint`
+- Lint fix: `pnpm --filter web run lint:fix`
+- Typecheck: `pnpm --filter web run typecheck`
+- Server tests: `pnpm --filter web run test -- --testPathPatterns="<pattern>"`
+- Client tests: `pnpm --filter web run test-client -- --testPathPatterns="<pattern>"`
+- E2E tests: `pnpm --filter web run test:e2e`
+- Build: `pnpm --filter web run build`
+
+## Playbooks
+
+### Add/Change tRPC endpoint
+1. Implement router/procedure in `src/server/api/routers/*` or
+ `src/features/<feature>/server/*`.
+2. Register in `src/server/api/root.ts`.
+3. Reuse auth/error patterns from `src/server/api/trpc.ts`.
+4. Add/adjust server tests under `src/__tests__/server/*`.
+
+### Add/Change public API endpoint
+1. Add route in `src/pages/api/public/*`.
+2. Define/update contract types in `src/features/public-api/types/*`.
+3. Add/adjust server tests in `src/__tests__/server/*`.
+4. If API contract changed, update Fern source (`../fern/apis/**`) and regenerate
+ outputs (do not hand-edit `../generated/**`).
+
+### Add frontend feature
+1. Prefer `src/features/<feature>/*` for feature-local code.
+2. Put broadly reusable components in `src/components/*`.
+3. Keep server logic near feature server folders when possible.
+
+## Package-Specific Rules
+- Router style is Pages Router-centric; follow existing routing patterns.
+- Keep tests independent; no reliance on test execution order.
+- In `src/__tests__/server`, avoid `pruneDatabase` calls.
+- Do not hand-edit build artifacts: `.next/*`, `.next-check/*`, `dist/*`.
diff --git a/worker/AGENTS.md b/worker/AGENTS.md
new file mode 100644
index 0000000000..28616f4cc2
--- /dev/null
+++ b/worker/AGENTS.md
@@ -0,0 +1,60 @@
+# Codex Guidelines for `worker`
+
+This file covers package-local guidance for this package.
+Use root [AGENTS.md](../AGENTS.md) for monorepo-level rules.
+
+## Purpose
+- Background job processor built on Express + BullMQ.
+- Owns queue consumers, async processors, and operational scripts.
+
+## Maintenance Contract
+- `AGENTS.md` is a living document.
+- Update this file in the same PR for material worker-local changes:
+ - new/renamed queue processors
+ - new worker bootstrapping points
+ - changed worker verification commands
+- If queue contracts or shared workflows change, update root `AGENTS.md` and
+ likely `../packages/shared/AGENTS.md` too.
+
+## High-Signal Entry Points
+- Bootstrap: `src/index.ts`, `src/app.ts`
+- Worker registration/lifecycle: `src/queues/workerManager.ts`
+- Queue processors: `src/queues/*`
+- Feature processors: `src/features/*`
+- Service layer: `src/services/*`
+- Background migrations: `src/backgroundMigrations/*`
+- Tests: `src/__tests__/*`, `src/queues/__tests__/*`
+
+## Quick Commands
+- Dev: `pnpm --filter worker run dev`
+- Lint: `pnpm --filter worker run lint`
+- Lint fix: `pnpm --filter worker run lint:fix`
+- Typecheck: `pnpm --filter worker run typecheck`
+- Tests: `pnpm --filter worker run test -- <file-or-pattern>`
+- Coverage: `pnpm --filter worker run coverage`
+- Build: `pnpm --filter worker run build`
+
+## Queue Playbook (Add/Change Queue Processor)
+1. Update queue schemas/contracts in `../packages/shared/src/server/queues.ts`
+ if payload or queue type changes.
+2. Update queue accessors/helpers in
+ `../packages/shared/src/server/redis/*` when needed.
+3. Implement/update processor in `src/queues/*`.
+4. Register/gate worker in `src/app.ts` (env flags, concurrency, limiter).
+5. Add/adjust tests in `src/__tests__/*` or `src/queues/__tests__/*`.
+
+## Processor Conventions
+- Keep queue handlers idempotent where possible.
+- Preserve metrics/tracing patterns in `workerManager` and queue processors.
+- Prefer explicit env-flag gating in `src/app.ts` for new consumers.
+- Keep queue payload parsing/schema validation centralized in shared contracts.
+
+## Operational Scripts
+- Refill ingestion events: `pnpm --filter worker run refill-ingestion-events`
+- Refill billing event: `pnpm --filter worker run refill-billing-event`
+- Refill queue event: `pnpm --filter worker run refill-queue-event`
+
+## Package-Specific Rules
+- Keep tests independent; no ordering assumptions.
+- Avoid editing `dist/*` directly.
+- Coordinate shared changes with `../packages/shared`.