Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(devex): clarify where product-owned tooling should live (#64541)

Julian Bezfc2984b34ff5
diff --git a/AGENTS.md b/AGENTS.md
index be10dabc736a..c664df960e47 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -105,7 +105,7 @@ See [.agents/security.md](.agents/security.md) for SQL, HogQL, and semgrep secur
- MCP tools are generated from the same OpenAPI spec — see [implementing MCP tools](docs/published/handbook/engineering/ai/implementing-mcp-tools.md) for the YAML config and codegen workflow
- MCP UI apps (interactive visualizations for tool results) are defined in `products/*/mcp/tools.yaml` under `ui_apps` and auto-generated — see [services/mcp/CONTRIBUTING.md](services/mcp/CONTRIBUTING.md) or use the `implementing-mcp-ui-apps` skill
- When touching a viewset or serializer, ensure schema annotations are present (`@extend_schema` or `@validated_request` on viewset methods, `help_text` on serializer fields) — these flow into generated frontend types and MCP tool schemas
-- New features should live in `products/` — read [products/README.md](products/README.md) for layout and setup. When _creating a new_ product, follow [products/architecture.md](products/architecture.md) (DTOs, facades, isolation)
+- New features should live in `products/` — read [products/README.md](products/README.md) for layout and setup. When _creating a new_ product, follow [products/architecture.md](products/architecture.md) (DTOs, facades, isolation). Code a single product owns — not just backend/frontend, but scripts, CLIs, services, packages, MCP tools, skills — belongs under `products/<product>/`; reserve top-level `tools/`/`services/`/`packages/`/`cli/` for cross-product things
- **Every tenant-data model must have `team_id`** — either as a FK (`models.ForeignKey("posthog.Team", ...)`) or a plain `BigIntegerField` (for multi-DB products). This is the primary tenant isolation boundary. Models without `team_id` must be org-scoped, user-scoped, or instance-global — never silently unscoped. New models should inherit from `TeamScopedRootMixin` (main DB) or `ProductTeamModel` (separate DB) so they start fail-closed — see `posthog/models/scoping/README.md`. CI enforces this via `posthog/models/scoping/baseline_unmigrated.txt`: any new team-scoped model not on a fail-closed manager fails the IDOR coverage check. In serializers, access the team via `self.context["get_team"]()`. When querying a fail-closed model for one team outside request context (Temporal activities, Celery tasks, management commands), use `Model.objects.for_team(team_id)` — not `Model.all_teams.filter(team_id=...)` or `objects.unscoped().filter(...)`; reserve `all_teams`/`unscoped()` for genuinely cross-team access and Django framework internals. Caveat: `for_team(...).get_or_create(...)`/`.create(...)` still need `team_id` passed explicitly — queryset filters don't propagate into row creation
- **Do not add domain-specific fields to the `Team` model.** Use a Team Extension model instead — see `posthog/models/team/README.md` for the pattern and helpers
- **PostHog event capture in Celery tasks:** Do not use `posthoganalytics.capture()` in Celery tasks — events are silently lost. Use `ph_scoped_capture` from `posthog.ph_client` instead (see its docstring for why and usage).
diff --git a/docs/internal/monorepo-layout.md b/docs/internal/monorepo-layout.md
index c043569e60f1..95f7c253b4d0 100644
--- a/docs/internal/monorepo-layout.md
+++ b/docs/internal/monorepo-layout.md
@@ -52,10 +52,15 @@ See [products/README.md](/products/README.md) for how to create products. For ne
#### What a product can own
-Most products are a Django app plus React scenes. Some also own adjacent runtime and tooling — services they deploy, a CLI, packages, a standalone console. Nest those under the product instead of scattering them across top-level dirs:
+Most products are a Django app plus React scenes — and most already carry more: an `mcp/` directory of MCP tool definitions, often a `skills/` directory of agent skills. A product can own anything attributable to it, runtime and tooling alike. Nest it under the product instead of scattering it across top-level dirs:
-- `products/<product>/services/<svc>/`, `.../packages/<lib>/`, a product CLI, and so on. Top-level `services/`, `packages/`, `tools/`, and `cli/` are for things no single product owns.
-- Keep package names (`@posthog/<name>`) independent of location — pnpm resolves by name, so relocating later is a path move with no import churn.
+- `products/<product>/mcp/` — MCP tool definitions (`tools.yaml`) and UI apps (most products)
+- `products/<product>/skills/` — agent skills for the product (many products)
+- `products/<product>/services/<svc>/` — a service or worker the product deploys
+- `products/<product>/packages/<lib>/` — a library or CLI the product owns
+- dev/CI/backfill scripts, benchmarks, audits, fixtures and dummy-data generators, a standalone console — same idea
+
+Top-level `services/`, `packages/`, `tools/`, and `cli/` are for things no single product owns. Keep package names (`@posthog/<name>`) independent of location — pnpm resolves by name, so relocating later is a path move with no import churn.
Nest because tooling boundaries become path-scoped (`products/<product>/**` for CODEOWNERS, CI filters, lint) instead of hand-synced `<product>-*` prefixes. A prefix doing a folder's job is the signal to nest.
diff --git a/products/README.md b/products/README.md
index b96c21c71803..f739b39bbbb1 100644
--- a/products/README.md
+++ b/products/README.md
@@ -48,6 +48,10 @@ products/
hooks/
logics/
generated/ # OpenAPI-generated TypeScript types
+ mcp/ # MCP tool definitions (tools.yaml) and UI apps — most products
+ skills/ # agent skills for the product — many products
+ services/ # optional: a service this product deploys
+ packages/ # optional: a library/CLI this product owns
```
Use `bin/hogli product:bootstrap <name>` to scaffold a new product with this structure.
@@ -101,6 +105,25 @@ This avoids circular imports and keeps migrations/app labels stable.
If backend and frontend need shared schemas, validators, or constants, put them in a `shared/` directory under the product.
Keep shared code minimal to avoid tight coupling.
+## What a product can own
+
+`backend/` and `frontend/` are the core, but a product owns more than that.
+
+Beyond `backend/` + `frontend/` + `manifest.tsx` + `package.json`, most products also carry:
+
+- `mcp/` — MCP tool definitions (`tools.yaml`) and UI apps (the majority of products expose these)
+- `skills/` — agent skills for the product (many products)
+
+And anything else attributable to a single product — nest it here rather than in a top-level dir:
+
+- `services/<svc>/` — a service or worker the product deploys
+- `packages/<lib>/` — a library or CLI the product owns
+- dev/CI/backfill scripts, benchmarks, audits, fixtures and dummy-data generators
+
+Co-locating keeps tooling boundaries (CODEOWNERS, CI filters, lint) on the `products/<product>/**` path instead of hand-synced `<product>-*` prefixes.
+Reserve top-level `tools/`, `services/`, `packages/`, and `cli/` for things no single product owns.
+See [monorepo-layout.md](/docs/internal/monorepo-layout.md) → "What a product can own" for the full rationale and the nest-then-promote rule for shared packages.
+
## Product requirements
- Each high level product should have its own folder.