: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(product-analytics): seal the product's import boundary (#85553)
Thomas Obermüller1700149de963
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.ymlindex 760825f5c660..6f43f3e27d40 100644--- a/.depot/workflows/ci-backend.yml+++ b/.depot/workflows/ci-backend.yml@@ -848,7 +848,7 @@ jobs:posthog/temporal/*|products/batch_exports/backend/tests/temporal/*|products/tasks/backend/temporal/*|products/signals/backend/emission/*)temporal+=("$f");;- posthog/clickhouse/*|posthog/queries/*|ee/clickhouse/*|products/product_analytics/backend/api/test/*|posthog/api/test/test_insight*|posthog/api/test/dashboards/test_dashboard.py)+ posthog/clickhouse/*|posthog/queries/*|ee/clickhouse/*|products/product_analytics/backend/presentation/test/*|posthog/api/test/test_insight*|posthog/api/test/dashboards/test_dashboard.py)poe+=("$f")core+=("$f");;@@ -2189,7 +2189,7 @@ jobs:if [[ "${{ matrix.compat }}" == "true" ]]; thenfull_targets="$CLICKHOUSE_COMPAT_PYTEST_TARGETS"elif [[ "${{ matrix.person-on-events }}" == "true" ]]; then- full_targets="./posthog/clickhouse/ ./posthog/queries/ ./products/product_analytics/backend/api/test/ ./posthog/api/test/dashboards/test_dashboard.py ee/clickhouse/"+ full_targets="./posthog/clickhouse/ ./posthog/queries/ ./products/product_analytics/backend/presentation/test/ ./posthog/api/test/dashboards/test_dashboard.py ee/clickhouse/"full_ignores+=(--ignore=posthog/hogql_queries --ignore=posthog/hogql)fi# shellcheck disable=SC2086diff --git a/.github/scripts/turbo-discover.js b/.github/scripts/turbo-discover.jsindex 7d7dac53c15e..ca332df4d95f 100644--- a/.github/scripts/turbo-discover.js+++ b/.github/scripts/turbo-discover.js@@ -539,7 +539,7 @@ const DJANGO_SEGMENTS = {include: ['posthog/clickhouse/','posthog/queries/',- 'products/product_analytics/backend/api/test/',+ 'products/product_analytics/backend/presentation/test/','posthog/api/test/dashboards/test_dashboard.py','ee/clickhouse/',],diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex 7448a1bf3629..62a956502ad4 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -781,7 +781,7 @@ jobs:posthog/temporal/*|products/batch_exports/backend/tests/temporal/*|products/tasks/backend/temporal/*|products/signals/backend/emission/*)temporal+=("$f");;- posthog/clickhouse/*|posthog/queries/*|ee/clickhouse/*|products/product_analytics/backend/api/test/*|posthog/api/test/test_insight*|posthog/api/test/dashboards/test_dashboard.py)+ posthog/clickhouse/*|posthog/queries/*|ee/clickhouse/*|products/product_analytics/backend/presentation/test/*|posthog/api/test/test_insight*|posthog/api/test/dashboards/test_dashboard.py)poe+=("$f")core+=("$f");;@@ -3215,7 +3215,7 @@ jobs:if [[ "${{ matrix.compat }}" == "true" ]]; thenfull_targets="$CLICKHOUSE_COMPAT_PYTEST_TARGETS"elif [[ "${{ matrix.person-on-events }}" == "true" ]]; then- full_targets="./posthog/clickhouse/ ./posthog/queries/ ./products/product_analytics/backend/api/test/ ./posthog/api/test/dashboards/test_dashboard.py ee/clickhouse/"+ full_targets="./posthog/clickhouse/ ./posthog/queries/ ./products/product_analytics/backend/presentation/test/ ./posthog/api/test/dashboards/test_dashboard.py ee/clickhouse/"full_ignores+=(--ignore=posthog/hogql_queries --ignore=posthog/hogql)fi# shellcheck disable=SC2086diff --git a/.semgrep/rules/security/idor-team-scoped-models.py b/.semgrep/rules/security/idor-team-scoped-models.pyindex 1b917f903bf9..9b526d531ce8 100644--- a/.semgrep/rules/security/idor-team-scoped-models.py+++ b/.semgrep/rules/security/idor-team-scoped-models.py@@ -2,7 +2,7 @@ from django.shortcuts import get_object_or_404from posthog.models import Notebookfrom products.approvals.backend.models import ChangeRequestfrom products.cohorts.backend.models.cohort import Cohort-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.actions.backend.models.action import Actionfrom posthog.models.personal_api_key import PersonalAPIKeyfrom posthog.models.project import Projectdiff --git a/ee/api/rbac/test/test_access_control.py b/ee/api/rbac/test/test_access_control.pyindex 370d7b358a3a..4a17501d9d54 100644--- a/ee/api/rbac/test/test_access_control.py+++ b/ee/api/rbac/test/test_access_control.py@@ -25,7 +25,7 @@ from products.conversations.backend.models import Ticketfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.warehouse_sources.backend.models import DataWarehouseTable, ExternalDataSourcefrom ee.api.rbac.access_control_settings import _display_model, resources_with_object_access_controlsdiff --git a/ee/api/subscription.py b/ee/api/subscription.pyindex 416db5682f14..a14c2bec22fa 100644--- a/ee/api/subscription.py+++ b/ee/api/subscription.py@@ -63,7 +63,7 @@ from products.exports.backend.temporal.subscriptions.types import (ProcessSubscriptionWorkflowInputs,SubscriptionTriggerType,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.billing.quota_limiting import QuotaLimitingCaches, QuotaResource, is_team_limitedfrom ee.tasks.subscriptions.auto_disable import validate_re_enablediff --git a/ee/api/test/test_insight.py b/ee/api/test/test_insight.pyindex a2fab79d4e29..a9ebdaf9f94a 100644--- a/ee/api/test/test_insight.py+++ b/ee/api/test/test_insight.py@@ -16,7 +16,7 @@ from posthog.test.db_context_capturing import capture_db_queriesfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.api.test.base import APILicensedTestfrom ee.models import DashboardPrivilegediff --git a/ee/api/test/test_subscription.py b/ee/api/test/test_subscription.pyindex f8dfef24c0c6..49f8ac91bd5f 100644--- a/ee/api/test/test_subscription.py+++ b/ee/api/test/test_subscription.py@@ -36,7 +36,7 @@ from products.exports.backend.temporal.subscriptions.types import (ProcessSubscriptionWorkflowInputs,SubscriptionTriggerType,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.api.test.base import APILicensedTestfrom ee.models.rbac.access_control import AccessControldiff --git a/ee/api/test/test_tagged_item.py b/ee/api/test/test_tagged_item.pyindex 56904bb2b163..cb5f21a528ce 100644--- a/ee/api/test/test_tagged_item.py+++ b/ee/api/test/test_tagged_item.py@@ -11,7 +11,7 @@ from posthog.models.tagged_item import TaggedItemfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight# This serializer only tests the business logic of getting and setting of ee descriptions. It uses the dashboard model# as an example, since model specific functionality is already tested in their models' respective serializer tests.diff --git a/ee/hogai/artifacts/handlers/visualization.py b/ee/hogai/artifacts/handlers/visualization.pyindex 8daed5d982cd..ff9154f6b3b5 100644--- a/ee/hogai/artifacts/handlers/visualization.py+++ b/ee/hogai/artifacts/handlers/visualization.py@@ -10,7 +10,7 @@ from posthog.schema import ArtifactContentType, ArtifactSource, VisualizationArtfrom posthog.models import Teamfrom products.posthog_ai.backend.models.assistant import AgentArtifact-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.hogai.artifacts.handlers.base import ArtifactHandler, EnrichmentContext, register_handlerfrom ee.hogai.artifacts.types import (diff --git a/ee/hogai/artifacts/test/test_manager.py b/ee/hogai/artifacts/test/test_manager.pyindex 12876139e457..89dc9a7f8881 100644--- a/ee/hogai/artifacts/test/test_manager.py+++ b/ee/hogai/artifacts/test/test_manager.py@@ -27,7 +27,7 @@ from posthog.schema import ()from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversation-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.hogai.artifacts.manager import ArtifactManagerfrom ee.hogai.artifacts.types import StoredNotebookArtifactContentdiff --git a/ee/hogai/artifacts/types.py b/ee/hogai/artifacts/types.pyindex 0496fa21ee65..b2e2bb0fb735 100644--- a/ee/hogai/artifacts/types.py+++ b/ee/hogai/artifacts/types.py@@ -15,7 +15,7 @@ from posthog.schema import (VisualizationBlock,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass VisualizationRefBlock(BaseModel):diff --git a/ee/hogai/chat_agent/insights/nodes.py b/ee/hogai/chat_agent/insights/nodes.pyindex 588ae95af185..a82089fd9e63 100644--- a/ee/hogai/chat_agent/insights/nodes.py+++ b/ee/hogai/chat_agent/insights/nodes.py@@ -19,7 +19,7 @@ from posthog.schema import ArtifactContentType, ArtifactSource, AssistantToolCalfrom posthog.exceptions_capture import capture_exception-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.hogai.context.insight.query_executor import AssistantQueryExecutorfrom ee.hogai.core.node import AssistantNodediff --git a/ee/hogai/chat_agent/insights/test/test_nodes.py b/ee/hogai/chat_agent/insights/test/test_nodes.pyindex 09d6ec63add7..b8efb684ddd8 100644--- a/ee/hogai/chat_agent/insights/test/test_nodes.py+++ b/ee/hogai/chat_agent/insights/test/test_nodes.py@@ -21,7 +21,7 @@ from posthog.schema import ()from products.posthog_ai.backend.models.assistant import Conversation-from products.product_analytics.backend.models.insight import Insight, InsightViewed+from products.product_analytics.backend.facade.models import Insight, InsightViewedfrom ee.hogai.artifacts.manager import ArtifactManagerfrom ee.hogai.chat_agent.insights.nodes import InsightDict, InsightSearchNode, NoInsightsExceptiondiff --git a/ee/hogai/chat_agent/sql/mixins.py b/ee/hogai/chat_agent/sql/mixins.pyindex e5c52328e70f..345639f09c91 100644--- a/ee/hogai/chat_agent/sql/mixins.py+++ b/ee/hogai/chat_agent/sql/mixins.py@@ -36,7 +36,7 @@ from posthog.models import Teamfrom posthog.models.user import Userfrom posthog.sync import database_sync_to_async-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariablefrom ee.hogai.chat_agent.schema_generator.utils import SchemaGeneratorOutputfrom ee.hogai.core.mixins import AssistantContextMixindiff --git a/ee/hogai/chat_agent/sql/test/test_sql_mixins.py b/ee/hogai/chat_agent/sql/test/test_sql_mixins.pyindex 8eeb982d8862..b49ad58e4232 100644--- a/ee/hogai/chat_agent/sql/test/test_sql_mixins.py+++ b/ee/hogai/chat_agent/sql/test/test_sql_mixins.py@@ -6,7 +6,7 @@ from posthog.schema import ChartDisplayType, DataVisualizationNode, HogQLQueryfrom posthog.sync import database_sync_to_async-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariablefrom ee.hogai.chat_agent.schema_generator.parsers import PydanticOutputParserExceptionfrom ee.hogai.chat_agent.sql.mixins import HogQLGeneratorMixin, SQLSchemaGeneratorOutputdiff --git a/ee/hogai/context/entity_search/context.py b/ee/hogai/context/entity_search/context.pyindex b2b5ab31a8f5..c63df867ca34 100644--- a/ee/hogai/context/entity_search/context.py+++ b/ee/hogai/context/entity_search/context.py@@ -35,7 +35,7 @@ from products.feature_flags.backend.flag_status import ()from products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.surveys.backend.models import Surveyfrom ee.hogai.artifacts.handlers.base import get_handler_for_content_typediff --git a/ee/hogai/context/entity_search/test/test_context.py b/ee/hogai/context/entity_search/test/test_context.pyindex fc6c564a9b66..a535803f4ceb 100644--- a/ee/hogai/context/entity_search/test/test_context.py+++ b/ee/hogai/context/entity_search/test/test_context.py@@ -20,7 +20,7 @@ from products.cohorts.backend.models.cohort import Cohortfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight, InsightViewed+from products.product_analytics.backend.facade.models import Insight, InsightViewedfrom products.surveys.backend.models import Surveyfrom ee.hogai.context import AssistantContextManagerdiff --git a/ee/hogai/context/insight/context.py b/ee/hogai/context/insight/context.pyindex 11ef99d4133f..3882324d9a0e 100644--- a/ee/hogai/context/insight/context.py+++ b/ee/hogai/context/insight/context.py@@ -6,7 +6,7 @@ from posthog.hogql_queries.apply_dashboard_filters import (from posthog.models import Team, Userfrom posthog.sync import database_sync_to_async-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.hogai.context.insight.query_executor import execute_and_format_queryfrom ee.hogai.tool_errors import MaxToolRetryableErrordiff --git a/ee/hogai/eval/ci/max_tools/eval_upsert_dashboard.py b/ee/hogai/eval/ci/max_tools/eval_upsert_dashboard.pyindex 013512e4a2d2..0e8506da5798 100644--- a/ee/hogai/eval/ci/max_tools/eval_upsert_dashboard.py+++ b/ee/hogai/eval/ci/max_tools/eval_upsert_dashboard.py@@ -20,7 +20,7 @@ from posthog.schema import (from products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTilefrom products.posthog_ai.backend.models.assistant import Conversation-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerdiff --git a/ee/hogai/tools/execute_sql/test/test_mcp_tool.py b/ee/hogai/tools/execute_sql/test/test_mcp_tool.pyindex c0d46b53ed0e..6860ef023394 100644--- a/ee/hogai/tools/execute_sql/test/test_mcp_tool.py+++ b/ee/hogai/tools/execute_sql/test/test_mcp_tool.py@@ -7,7 +7,7 @@ from posthog.schema import HogQLNotice, HogQLQueryfrom posthog.models import EventDefinition-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.hogai.tool_errors import MaxToolRetryableErrorfrom ee.hogai.tools.execute_sql.mcp_tool import (diff --git a/ee/hogai/tools/execute_sql/test/test_tool.py b/ee/hogai/tools/execute_sql/test/test_tool.pyindex 8024646951d6..831c8af6b34e 100644--- a/ee/hogai/tools/execute_sql/test/test_tool.py+++ b/ee/hogai/tools/execute_sql/test/test_tool.py@@ -15,7 +15,7 @@ from posthog.schema import ()from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversation-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.hogai.context.context import AssistantContextManagerfrom ee.hogai.tools.execute_sql.tool import ExecuteSQLTool, ExecuteSQLToolArgsdiff --git a/ee/hogai/tools/read_data/test/test_tool.py b/ee/hogai/tools/read_data/test/test_tool.pyindex 2131bf1609aa..c132fee05832 100644--- a/ee/hogai/tools/read_data/test/test_tool.py+++ b/ee/hogai/tools/read_data/test/test_tool.py@@ -37,7 +37,7 @@ from products.data_modeling.backend.facade.models import ()from products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.surveys.backend.models import Surveyfrom products.warehouse_sources.backend.facade.models import (DataWarehouseCredential,diff --git a/ee/hogai/tools/upsert_dashboard/test/test_tool.py b/ee/hogai/tools/upsert_dashboard/test/test_tool.pyindex 3129a30f7fbb..449312b1acd4 100644--- a/ee/hogai/tools/upsert_dashboard/test/test_tool.py+++ b/ee/hogai/tools/upsert_dashboard/test/test_tool.py@@ -27,7 +27,7 @@ from posthog.schema import (from products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile, Textfrom products.posthog_ai.backend.models.assistant import AgentArtifact, Conversation-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.hogai.artifacts.types import ModelArtifactResult, StateArtifactResult, VisualizationWithSourceResultfrom ee.hogai.context.context import AssistantContextManagerdiff --git a/ee/hogai/tools/upsert_dashboard/tool.py b/ee/hogai/tools/upsert_dashboard/tool.pyindex 189549f63252..12d814031e20 100644--- a/ee/hogai/tools/upsert_dashboard/tool.py+++ b/ee/hogai/tools/upsert_dashboard/tool.py@@ -13,7 +13,7 @@ from posthog.utils import pluralizefrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.hogai.artifacts.types import ModelArtifactResult, VisualizationWithSourceResultfrom ee.hogai.context.dashboard.context import DashboardContext, DashboardInsightContextdiff --git a/ee/tasks/subscriptions/subscription_utils.py b/ee/tasks/subscriptions/subscription_utils.pyindex c39b3ee03303..40ea30e2da8b 100644--- a/ee/tasks/subscriptions/subscription_utils.py+++ b/ee/tasks/subscriptions/subscription_utils.py@@ -13,7 +13,7 @@ from posthog.utils import wait_for_parallel_celery_groupfrom products.exports.backend.models.exported_asset import ExportedAssetfrom products.exports.backend.models.subscription import Subscription-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightlogger = structlog.get_logger(__name__)diff --git a/ee/tasks/test/subscriptions/test_email_subscriptions.py b/ee/tasks/test/subscriptions/test_email_subscriptions.pyindex 1fb7bdd8e19a..28ec77309826 100644--- a/ee/tasks/test/subscriptions/test_email_subscriptions.py+++ b/ee/tasks/test/subscriptions/test_email_subscriptions.py@@ -13,7 +13,7 @@ from posthog.tasks.test.utils_email_tests import mock_email_messagesfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.exports.backend.models.exported_asset import ExportedAssetfrom products.exports.backend.models.subscription import Subscription-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.tasks.subscriptions.email_subscriptions import send_email_subscription_reportfrom ee.tasks.test.subscriptions.subscriptions_test_factory import create_subscriptiondiff --git a/ee/tasks/test/subscriptions/test_slack_subscriptions.py b/ee/tasks/test/subscriptions/test_slack_subscriptions.pyindex 58c1e8a9953c..06eeeb8fb86a 100644--- a/ee/tasks/test/subscriptions/test_slack_subscriptions.py+++ b/ee/tasks/test/subscriptions/test_slack_subscriptions.py@@ -16,7 +16,7 @@ from posthog.models.integration import Integrationfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.exports.backend.models.exported_asset import ExportedAssetfrom products.exports.backend.models.subscription import Subscription-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.tasks.subscriptions.slack_subscriptions import (_block_for_asset,diff --git a/ee/tasks/test/subscriptions/test_subscriptions_utils.py b/ee/tasks/test/subscriptions/test_subscriptions_utils.pyindex 1d8cbe394156..9e93ffa007e9 100644--- a/ee/tasks/test/subscriptions/test_subscriptions_utils.py+++ b/ee/tasks/test/subscriptions/test_subscriptions_utils.py@@ -7,7 +7,7 @@ from parameterized import parameterizedfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTilefrom products.exports.backend.models.exported_asset import ExportedAsset-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.tasks.subscriptions.subscription_utils import (ASSET_GENERATION_FAILED_MESSAGE,diff --git a/ee/tasks/test/test_slack.py b/ee/tasks/test/test_slack.pyindex 9bf1849e6c27..fc105ce9e0c7 100644--- a/ee/tasks/test/test_slack.py+++ b/ee/tasks/test/test_slack.py@@ -9,7 +9,7 @@ from posthog.models.sharing_configuration import SharingConfigurationfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.exports.backend.models.exported_asset import ExportedAssetfrom products.exports.backend.models.subscription import Subscription-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.tasks.slack import handle_slack_eventdiff --git a/posthog/admin/test_admin.py b/posthog/admin/test_admin.pyindex 5b537f3531af..970c75316ed9 100644--- a/posthog/admin/test_admin.py+++ b/posthog/admin/test_admin.py@@ -25,7 +25,7 @@ from products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_templates import DashboardTemplatefrom products.dashboards.backend.models.dashboard_tile import Textfrom products.experiments.backend.models.experiment import Experiment, ExperimentSavedMetric-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.product_tours.backend.models import ProductTourfrom products.surveys.backend.models import Surveyfrom products.warehouse_sources.backend.facade.models import DataWarehouseTable, ExternalDataSchemadiff --git a/posthog/api/cohort.py b/posthog/api/cohort.pyindex 4245c6e25167..7a67d8c54cfc 100644--- a/posthog/api/cohort.py+++ b/posthog/api/cohort.py@@ -102,7 +102,7 @@ from products.cohorts.backend.models.util import ()from products.cohorts.backend.models.validation import CohortTypeValidationSerializerfrom products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight# Mirrors SerializedPerson in posthog/queries/actor_base_query.py.diff --git a/posthog/api/file_system/test/test_file_system.py b/posthog/api/file_system/test/test_file_system.pyindex 5893bf604a81..1edd8e19400d 100644--- a/posthog/api/file_system/test/test_file_system.py+++ b/posthog/api/file_system/test/test_file_system.py@@ -38,7 +38,7 @@ from products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.links.backend.models import Linkfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.surveys.backend.models import Surveyfrom ee.models.rbac.access_control import AccessControldiff --git a/posthog/api/file_system/test/test_file_system_shortcut.py b/posthog/api/file_system/test/test_file_system_shortcut.pyindex d199420f7e60..bdf6f49ae962 100644--- a/posthog/api/file_system/test/test_file_system_shortcut.py+++ b/posthog/api/file_system/test/test_file_system_shortcut.py@@ -11,7 +11,7 @@ from posthog.models import Userfrom posthog.models.file_system.file_system_shortcut import FileSystemShortcutfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.models.rbac.access_control import AccessControldiff --git a/posthog/api/my_notifications.py b/posthog/api/my_notifications.pyindex 23669d568e6f..bf6e18ebf6e9 100644--- a/posthog/api/my_notifications.py+++ b/posthog/api/my_notifications.py@@ -19,7 +19,7 @@ from products.cdp.backend.models.hog_functions.hog_function import HogFunctionfrom products.cohorts.backend.models.cohort import Cohortfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.notebooks.backend.facade import api as notebooks-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass MyNotificationsSerializer(serializers.ModelSerializer):diff --git a/posthog/api/search.py b/posthog/api/search.pyindex 2bc4ce355a4b..845af3a92bb1 100644--- a/posthog/api/search.py+++ b/posthog/api/search.py@@ -24,7 +24,7 @@ from products.early_access_features.backend.models import EarlyAccessFeaturefrom products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.surveys.backend.models import Surveyfrom products.workflows.backend.models.hog_flow.hog_flow import HogFlowdiff --git a/posthog/api/sharing.py b/posthog/api/sharing.pyindex 77b004ad2be4..bc8b22f8244b 100644--- a/posthog/api/sharing.py+++ b/posthog/api/sharing.py@@ -79,9 +79,8 @@ from products.feature_flags.backend.persisted_flags import get_dynamic_persistedfrom products.notebooks.backend.facade.content import extract_inline_query_nodes, filter_notebook_content_for_sharingfrom products.notebooks.backend.models import Notebookfrom products.notebooks.backend.presentation.views.notebook import NotebookSerializer-from products.product_analytics.backend.api.insight import InsightSerializer-from products.product_analytics.backend.models.insight import Insight, InsightViewed-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import Insight, InsightVariable, InsightViewed+from products.product_analytics.backend.presentation.insight import InsightSerializerlogger = structlog.get_logger(__name__)diff --git a/posthog/api/sharing_publish_gate.py b/posthog/api/sharing_publish_gate.pyindex 0ff8ef369306..7908e362b930 100644--- a/posthog/api/sharing_publish_gate.py+++ b/posthog/api/sharing_publish_gate.py@@ -27,7 +27,7 @@ from posthog.rbac.user_access_control import UserAccessControl, UserAccessControfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.notebooks.backend.facade.content import extract_inline_query_nodes, extract_referenced_insight_short_idsfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightdef check_can_add_insight_to_shared_dashboard(diff --git a/posthog/api/test/dashboards/test_dashboard.py b/posthog/api/test/dashboards/test_dashboard.pyindex 7de229c645df..939ca4d125e9 100644--- a/posthog/api/test/dashboards/test_dashboard.py+++ b/posthog/api/test/dashboards/test_dashboard.py@@ -52,9 +52,8 @@ from products.dashboards.backend.api.dashboard import (from products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_templates import DashboardTemplatefrom products.dashboards.backend.models.dashboard_tile import ButtonTile, DashboardTile, Text-from products.product_analytics.backend.api.insight import InsightSerializer-from products.product_analytics.backend.models.insight import Insight-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import Insight, InsightVariable+from products.product_analytics.backend.presentation.insight import InsightSerializerfrom ee.models.rbac.access_control import AccessControl@@ -708,7 +707,7 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):)self.assertEqual(response["attr"], "grid_spacing")- @patch("products.product_analytics.backend.api.insight.record_dashboard_cache_outcome")+ @patch("products.product_analytics.backend.presentation.insight.record_dashboard_cache_outcome")@patch("posthog.caching.calculate_results.calculate_for_query_based_insight")def test_update_dashboard_does_not_record_cache_outcomes(self,diff --git a/posthog/api/test/test_cohort.py b/posthog/api/test/test_cohort.pyindex e4f402fac007..d7902753111c 100644--- a/posthog/api/test/test_cohort.py+++ b/posthog/api/test/test_cohort.py@@ -50,7 +50,7 @@ from products.cohorts.backend.models.dependencies import find_behavioral_cohortsfrom products.cohorts.backend.models.util import count_cohort_members, list_cohort_member_idsfrom products.exports.backend.api.test.test_exports import TestExportMixinfrom products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.clickhouse.materialized_columns.analyze import materialize@@ -5231,7 +5231,7 @@ [email protected],@patch("posthog.api.cohort.report_user_action")@patch("posthog.tasks.calculate_cohort.calculate_cohort_ch.delay")def test_cannot_delete_cohort_used_in_insight(self, patch_calculate_cohort, patch_capture):- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insightresponse = self.client.post(f"/api/projects/{self.team.id}/cohorts",@@ -5260,7 +5260,7 @@ [email protected],@patch("posthog.api.cohort.report_user_action")@patch("posthog.tasks.calculate_cohort.calculate_cohort_ch.delay")def test_cannot_delete_cohort_used_in_multiple_insights(self, patch_calculate_cohort, patch_capture):- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insightresponse = self.client.post(f"/api/projects/{self.team.id}/cohorts",@@ -5294,7 +5294,7 @@ [email protected],@patch("posthog.api.cohort.report_user_action")@patch("posthog.tasks.calculate_cohort.calculate_cohort_ch.delay")def test_cannot_delete_cohort_used_in_more_than_five_insights(self, patch_calculate_cohort, patch_capture):- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insightresponse = self.client.post(f"/api/projects/{self.team.id}/cohorts",@@ -5340,7 +5340,7 @@ [email protected],@patch("posthog.api.cohort.report_user_action")@patch("posthog.tasks.calculate_cohort.calculate_cohort_ch.delay")def test_can_delete_cohort_not_used_in_insights(self, patch_calculate_cohort, patch_capture):- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insightresponse = self.client.post(f"/api/projects/{self.team.id}/cohorts",@@ -5370,7 +5370,7 @@ [email protected],@patch("posthog.api.cohort.report_user_action")@patch("posthog.tasks.calculate_cohort.calculate_cohort_ch.delay")def test_cannot_delete_cohort_used_in_breakdown_filter(self, patch_calculate_cohort, patch_capture):- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insightresponse = self.client.post(f"/api/projects/{self.team.id}/cohorts",@@ -5406,7 +5406,7 @@ [email protected],@patch("posthog.api.cohort.report_user_action")@patch("posthog.tasks.calculate_cohort.calculate_cohort_ch.delay")def test_cannot_delete_cohort_used_in_deeply_nested_properties(self, patch_calculate_cohort, patch_capture):- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insightresponse = self.client.post(f"/api/projects/{self.team.id}/cohorts",diff --git a/posthog/api/test/test_file_system.py b/posthog/api/test/test_file_system.pyindex 9e7a1b60ecca..13b797c46741 100644--- a/posthog/api/test/test_file_system.py+++ b/posthog/api/test/test_file_system.py@@ -32,7 +32,7 @@ from products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.links.backend.models import Linkfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.surveys.backend.models import Surveydiff --git a/posthog/api/test/test_personal_api_keys.py b/posthog/api/test/test_personal_api_keys.pyindex 60ed4915b952..805e711b26a8 100644--- a/posthog/api/test/test_personal_api_keys.py+++ b/posthog/api/test/test_personal_api_keys.py@@ -25,7 +25,7 @@ from posthog.models.team.team import Teamfrom posthog.models.user import Userfrom posthog.models.utils import SHA256_HASH_PREFIX, generate_random_token_personal, hash_key_value, mask_key_value-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import InsightErrorTrackingIssue = apps.get_model("error_tracking", "ErrorTrackingIssue")diff --git a/posthog/api/test/test_query.py b/posthog/api/test/test_query.pyindex 2f8b95ac16d4..c8920b85dd41 100644--- a/posthog/api/test/test_query.py+++ b/posthog/api/test/test_query.py@@ -52,7 +52,7 @@ from posthog.models.utils import UUIDTfrom products.event_definitions.backend.models.property_definition import PropertyDefinition, PropertyTypefrom products.managed_warehouse.backend.facade.feature_flags import MANAGED_WAREHOUSE_QUERY_STATUS_LABEL_PREFIX-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariablefrom products.warehouse_sources.backend.facade.models import MANAGED_WAREHOUSE_SOURCE_PREFIX, ExternalDataSourcefrom products.warehouse_sources.backend.facade.types import ExternalDataSourceTypediff --git a/posthog/api/test/test_resource_transfer.py b/posthog/api/test/test_resource_transfer.pyindex 3e1d9c42df44..c96ac08c3aaf 100644--- a/posthog/api/test/test_resource_transfer.py+++ b/posthog/api/test/test_resource_transfer.py@@ -17,7 +17,7 @@ from products.cohorts.backend.models.cohort import Cohortfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTilefrom products.dashboards.backend.models.dashboard_widget import DashboardWidget-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.surveys.backend.models import Surveyfrom ee.models.rbac.access_control import AccessControldiff --git a/posthog/api/test/test_search.py b/posthog/api/test/test_search.pyindex c945982d4f05..a7e6b33b5d8f 100644--- a/posthog/api/test/test_search.py+++ b/posthog/api/test/test_search.py@@ -14,7 +14,7 @@ from products.early_access_features.backend.models import EarlyAccessFeaturefrom products.event_definitions.backend.models.event_definition import EventDefinitionfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.workflows.backend.models.hog_flow.hog_flow import HogFlowfrom ee.models.rbac.access_control import AccessControldiff --git a/posthog/api/test/test_search_match_type_mixin.py b/posthog/api/test/test_search_match_type_mixin.pyindex 9098fb3adc49..5e6f687e1097 100644--- a/posthog/api/test/test_search_match_type_mixin.py+++ b/posthog/api/test/test_search_match_type_mixin.py@@ -8,7 +8,7 @@ from posthog.api.shared import SearchMatchTypeSerializerMixinfrom products.alerts.backend.api.alert import AlertSerializerfrom products.cdp.backend.api.hog_function import HogFunctionMinimalSerializer, HogFunctionSerializerfrom products.dashboards.backend.api.dashboard import DashboardBasicSerializer-from products.product_analytics.backend.api.insight import InsightBasicSerializer, InsightSerializer+from products.product_analytics.backend.presentation.insight import InsightBasicSerializer, InsightSerializerfrom products.product_tours.backend.api.product_tour import ProductTourSerializerfrom products.surveys.backend.api.survey import SurveySerializerdiff --git a/posthog/api/test/test_sharing.py b/posthog/api/test/test_sharing.pyindex 4487085f7261..b41fb0e4f53b 100644--- a/posthog/api/test/test_sharing.py+++ b/posthog/api/test/test_sharing.py@@ -39,7 +39,7 @@ from products.dashboards.backend.models.dashboard_widget import DashboardWidgetfrom products.data_modeling.backend.facade.models import DataWarehouseSavedQueryfrom products.exports.backend.models.exported_asset import ExportedAsset, get_render_access_tokenfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.models.rbac.access_control import AccessControl@@ -1488,7 +1488,7 @@ class TestExportCacheKeyFlow(APIBaseTest):)@patch("posthog.caching.calculate_results.calculate_for_query_based_insight")- @patch("products.product_analytics.backend.api.insight.QueryCache")+ @patch("products.product_analytics.backend.presentation.insight.QueryCache")@mock_exporter_templatedef test_cache_keys_parameter_triggers_direct_cache_lookup(self, mock_query_cache_cls, mock_calculate):"""Test that cache_keys param causes InsightSerializer to use direct cache lookup and skip calculation."""@@ -1505,7 +1505,7 @@ class TestExportCacheKeyFlow(APIBaseTest):mock_calculate.assert_not_called()@patch("posthog.caching.calculate_results.calculate_for_query_based_insight")- @patch("products.product_analytics.backend.api.insight.QueryCache")+ @patch("products.product_analytics.backend.presentation.insight.QueryCache")@mock_exporter_templatedef test_cache_miss_falls_back_to_normal_calculation(self, mock_query_cache_cls, mock_calculate):"""Test that cache miss on expected key falls back to normal calculation."""@@ -1522,7 +1522,7 @@ class TestExportCacheKeyFlow(APIBaseTest):mock_calculate.assert_called_once()@patch("posthog.caching.calculate_results.calculate_for_query_based_insight")- @patch("products.product_analytics.backend.api.insight.QueryCache")+ @patch("products.product_analytics.backend.presentation.insight.QueryCache")@mock_exporter_templatedef test_invalid_cache_keys_param_continues_without_it(self, mock_query_cache_cls, mock_calculate):"""Test that invalid cache_keys parameter is ignored and normal flow continues."""@@ -1542,7 +1542,7 @@ class TestExportCacheKeyFlow(APIBaseTest):])@patch("posthog.caching.calculate_results.calculate_for_query_based_insight")- @patch("products.product_analytics.backend.api.insight.QueryCache")+ @patch("products.product_analytics.backend.presentation.insight.QueryCache")@mock_exporter_templatedef test_public_share_link_cannot_name_the_cache_key_to_read(self, _name: str, path: str, mock_query_cache_cls, mock_calculate@@ -1561,7 +1561,7 @@ class TestExportCacheKeyFlow(APIBaseTest):mock_calculate.assert_called_once()@patch("posthog.caching.calculate_results.calculate_for_query_based_insight")- @patch("products.product_analytics.backend.api.insight.QueryCache")+ @patch("products.product_analytics.backend.presentation.insight.QueryCache")@mock_exporter_templatedef test_cache_key_from_another_team_is_not_served(self, mock_query_cache_cls, mock_calculate):self._cached_entry(mock_query_cache_cls, "another-teams-cached-rows")diff --git a/posthog/api/test/test_sharing_access_token_security.py b/posthog/api/test/test_sharing_access_token_security.pyindex 23aef251ce41..8f30a459a3f3 100644--- a/posthog/api/test/test_sharing_access_token_security.py+++ b/posthog/api/test/test_sharing_access_token_security.py@@ -16,7 +16,7 @@ from posthog.constants import AvailableFeaturefrom posthog.models.sharing_configuration import SharingConfigurationfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass SharingAccessTokenSecurityTest(APIBaseTest):@@ -248,7 +248,7 @@ class SharingAccessTokenSecurityTest(APIBaseTest):Test that variables_override parameter is ignored when using sharing access tokens.Variables only work in HogQL queries, not TrendsQuery."""- from products.product_analytics.backend.models.insight_variable import InsightVariable+ from products.product_analytics.backend.facade.models import InsightVariable# Create an insight variable firstvariable = InsightVariable.objects.create(diff --git a/posthog/api/test/test_tagged_item.py b/posthog/api/test/test_tagged_item.pyindex 1ed865597200..9e1d131a130c 100644--- a/posthog/api/test/test_tagged_item.py+++ b/posthog/api/test/test_tagged_item.py@@ -7,7 +7,7 @@ from posthog.models import ActivityLog, Organization, Tag, Teamfrom posthog.models.tagged_item import TaggedItemfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestTaggedItemSerializerMixin(APIBaseTest):diff --git a/posthog/caching/calculate_results.py b/posthog/caching/calculate_results.pyindex a7740b82166d..52d3740dff5f 100644--- a/posthog/caching/calculate_results.py+++ b/posthog/caching/calculate_results.py@@ -18,7 +18,7 @@ from posthog.schema_migrations.upgrade_manager import upgrade_queryfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight, generate_insight_filters_hash+from products.product_analytics.backend.facade.models import Insight, generate_insight_filters_hashif TYPE_CHECKING:from posthog.caching.insight_result import InsightResultdiff --git a/posthog/caching/test/test_calculate_results.py b/posthog/caching/test/test_calculate_results.pyindex d9e2f249c83e..cca37306f029 100644--- a/posthog/caching/test/test_calculate_results.py+++ b/posthog/caching/test/test_calculate_results.py@@ -18,7 +18,7 @@ from posthog.schema import (from posthog.api.services.query import ExecutionMode, RawCachedQueryResponsefrom posthog.caching.calculate_results import calculate_for_query_based_insight-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestCalculateForQueryBasedInsight(BaseTest):diff --git a/posthog/caching/test/test_warming.py b/posthog/caching/test/test_warming.pyindex c04efbeb7fb3..ade88e0e3ef5 100644--- a/posthog/caching/test/test_warming.py+++ b/posthog/caching/test/test_warming.py@@ -8,7 +8,7 @@ from posthog.exceptions import ClickHouseAtCapacityfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight, InsightViewed+from products.product_analytics.backend.facade.models import Insight, InsightViewedclass TestWarming(APIBaseTest):diff --git a/posthog/caching/warming.py b/posthog/caching/warming.pyindex 0bb1a1e75266..da9da631848d 100644--- a/posthog/caching/warming.py+++ b/posthog/caching/warming.py@@ -31,7 +31,7 @@ from posthog.scoping_audit import skip_team_scope_auditfrom posthog.tasks.utils import CeleryQueuefrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightlogger = structlog.get_logger(__name__)diff --git a/posthog/helpers/dashboard_templates.py b/posthog/helpers/dashboard_templates.pyindex d6c34f783df9..bc95c82c6df5 100644--- a/posthog/helpers/dashboard_templates.py+++ b/posthog/helpers/dashboard_templates.py@@ -15,7 +15,7 @@ from products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_templates import DashboardTemplatefrom products.dashboards.backend.models.dashboard_tile import ButtonTile, DashboardTile, Textfrom products.dashboards.backend.models.dashboard_widget import DashboardWidget-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightif TYPE_CHECKING:from posthog.rbac.user_access_control import UserAccessControldiff --git a/posthog/hogql/ACCESS_CONTROL.md b/posthog/hogql/ACCESS_CONTROL.mdindex 12670a8ca7a4..1a7316db3f2f 100644--- a/posthog/hogql/ACCESS_CONTROL.md+++ b/posthog/hogql/ACCESS_CONTROL.md@@ -212,6 +212,6 @@ The same instance is reused across:- **Schema filtering:** passed into `Database.create_for()`, warmed by `_compute_system_table_access_decision()`, stored as `database.user_access_control`.- **Cache fingerprint:** `QueryRunnerWithHogQLContext.user_access_control` returns `self.database.user_access_control`, so the fingerprint and the schema strip resolve access from the same preloaded rows.- **Print-time row guards:** `build_access_control_guard()` reads `blocked_resource_ids_by_scope` off the same instance.-- **API-level (viewset) access control:** `TeamAndOrgViewSetMixin.user_access_control` (`posthog/api/routing.py`) creates one instance per request, and dashboard rendering passes it down into each tile's query runner (`products/product_analytics/backend/api/insight.py`), so N insights share one access-control fetch.+- **API-level (viewset) access control:** `TeamAndOrgViewSetMixin.user_access_control` (`posthog/api/routing.py`) creates one instance per request, and dashboard rendering passes it down into each tile's query runner (`products/product_analytics/backend/presentation/insight.py`), so N insights share one access-control fetch.When both access-control types are active, a query run makes just one query to `AccessControl` and one to `PropertyAccessControl`.diff --git a/posthog/hogql/autocomplete.py b/posthog/hogql/autocomplete.pyindex 9ed7d5bef555..d020135f67b8 100644--- a/posthog/hogql/autocomplete.py+++ b/posthog/hogql/autocomplete.py@@ -59,7 +59,7 @@ from posthog.models.team.team import Teamfrom posthog.models.user import Userfrom products.event_definitions.backend.models.property_definition import PropertyDefinition-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariablefrom common.hogvm.python.stl import STLfrom common.hogvm.python.stl.bytecode import BYTECODE_STLdiff --git a/posthog/hogql/database/schema/test/test_system_tables.py b/posthog/hogql/database/schema/test/test_system_tables.pyindex ca8f5df6ae34..8429217f0e3d 100644--- a/posthog/hogql/database/schema/test/test_system_tables.py+++ b/posthog/hogql/database/schema/test/test_system_tables.py@@ -48,8 +48,7 @@ from products.exports.backend.models.exported_asset import ExportedAssetfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.logs.backend.models import LogsAlertConfiguration, LogsViewfrom products.notebooks.backend.models import Notebook, ResourceNotebook-from products.product_analytics.backend.models.insight import Insight-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import Insight, InsightVariablefrom products.surveys.backend.models import Survey, SurveyResponseArchivefrom products.warehouse_sources.backend.facade.models import (DataWarehouseTable as DataWarehouseTableModel,diff --git a/posthog/hogql/test/test_autocomplete.py b/posthog/hogql/test/test_autocomplete.pyindex c4ed0f290b20..c62a17cc9af8 100644--- a/posthog/hogql/test/test_autocomplete.py+++ b/posthog/hogql/test/test_autocomplete.py@@ -21,7 +21,7 @@ from posthog.hogql.database.schema.persons import PERSONS_FIELDSfrom products.data_modeling.backend.facade.models import DataWarehouseSavedQueryfrom products.event_definitions.backend.models.property_definition import PropertyDefinition-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariablefrom products.warehouse_sources.backend.facade.models import (DataWarehouseCredential,DataWarehouseTable,diff --git a/posthog/hogql/test/test_metadata.py b/posthog/hogql/test/test_metadata.pyindex e7f6f3beff1e..774f422b5057 100644--- a/posthog/hogql/test/test_metadata.py+++ b/posthog/hogql/test/test_metadata.py@@ -23,7 +23,7 @@ from posthog.hogql.parser import parse_selectfrom posthog.models import EventDefinition, PropertyDefinitionfrom products.cohorts.backend.models.cohort import Cohort-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariablefrom products.warehouse_sources.backend.facade.models import DataWarehouseTable, ExternalDataSchema, ExternalDataSourcefrom products.warehouse_sources.backend.facade.types import ExternalDataSourceTypediff --git a/posthog/hogql/test/test_query.py b/posthog/hogql/test/test_query.pyindex 1cdaaa70f43e..87a0faa9a776 100644--- a/posthog/hogql/test/test_query.py+++ b/posthog/hogql/test/test_query.py@@ -45,7 +45,7 @@ from posthog.uuidt import UUIDT, uuid7from products.cohorts.backend.models.cohort import Cohortfrom products.cohorts.backend.models.util import recalculate_cohortpeople-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariablefrom products.warehouse_sources.backend.facade.models import ExternalDataSourcefrom products.warehouse_sources.backend.facade.types import ExternalDataSourceTypediff --git a/posthog/hogql/variables.py b/posthog/hogql/variables.pyindex f76c23cec4e8..46cab7c1e060 100644--- a/posthog/hogql/variables.py+++ b/posthog/hogql/variables.py@@ -11,7 +11,7 @@ from posthog.hogql.visitor import CloningVisitorfrom posthog.models.team.team import Teamfrom posthog.utils import relative_date_parse-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariableT = TypeVar("T", bound=ast.Expr)diff --git a/posthog/hogql_queries/insights/insight_actors_query_runner.py b/posthog/hogql_queries/insights/insight_actors_query_runner.pyindex 4947bbfbcf7a..41383e7f2c57 100644--- a/posthog/hogql_queries/insights/insight_actors_query_runner.py+++ b/posthog/hogql_queries/insights/insight_actors_query_runner.py@@ -35,9 +35,11 @@ from posthog.models.user import Userfrom posthog.types import InsightActorsQueryNodefrom products.experiments.backend.hogql_queries.experiment_query_runner import ExperimentQueryRunner-from products.product_analytics.backend.hogql_queries.paths.paths_query_runner import PathsQueryRunner-from products.product_analytics.backend.hogql_queries.paths_v2.paths_v2_query_runner import PathsV2QueryRunner-from products.product_analytics.backend.hogql_queries.stickiness.stickiness_query_runner import StickinessQueryRunner+from products.product_analytics.backend.facade.queries import (+ PathsQueryRunner,+ PathsV2QueryRunner,+ StickinessQueryRunner,+)class InsightActorsQueryRunner(AnalyticsQueryRunner[HogQLQueryResponse]):diff --git a/posthog/hogql_queries/legacy_compatibility/flagged_conversion_manager.py b/posthog/hogql_queries/legacy_compatibility/flagged_conversion_manager.pyindex 2ba9b4bf5421..71fd95387c26 100644--- a/posthog/hogql_queries/legacy_compatibility/flagged_conversion_manager.py+++ b/posthog/hogql_queries/legacy_compatibility/flagged_conversion_manager.py@@ -7,7 +7,7 @@ from posthog.exceptions_capture import capture_exceptionfrom .filter_to_query import filter_to_queryif TYPE_CHECKING:- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insight@contextmanagerdiff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.pyindex eb508ddadd32..b15fa0f6c147 100644--- a/posthog/hogql_queries/query_runner.py+++ b/posthog/hogql_queries/query_runner.py@@ -635,7 +635,7 @@ def get_query_runner(user=user,)if kind == "PathsQuery":- from products.product_analytics.backend.hogql_queries.paths.paths_query_runner import PathsQueryRunner+ from products.product_analytics.backend.facade.queries import PathsQueryRunnerreturn PathsQueryRunner(query=cast(PathsQuery | dict[str, Any], query),@@ -647,7 +647,7 @@ def get_query_runner()if kind == "PathsV2Query":- from products.product_analytics.backend.hogql_queries.paths_v2.paths_v2_query_runner import PathsV2QueryRunner+ from products.product_analytics.backend.facade.queries import PathsV2QueryRunnerreturn PathsV2QueryRunner(query=cast(PathsV2Query | dict[str, Any], query),@@ -669,9 +669,7 @@ def get_query_runner(user=user,)if kind == "StickinessQuery":- from products.product_analytics.backend.hogql_queries.stickiness.stickiness_query_runner import (- StickinessQueryRunner,- )+ from products.product_analytics.backend.facade.queries import StickinessQueryRunnerreturn StickinessQueryRunner(query=cast(StickinessQuery | dict[str, Any], query),diff --git a/posthog/hogql_queries/test/test_dashboard_filters_overrides.py b/posthog/hogql_queries/test/test_dashboard_filters_overrides.pyindex 5fcdc05764aa..c1d2603cee49 100644--- a/posthog/hogql_queries/test/test_dashboard_filters_overrides.py+++ b/posthog/hogql_queries/test/test_dashboard_filters_overrides.py@@ -30,8 +30,7 @@ from posthog.hogql_queries.insights.trends.trends_query_runner import TrendsQuerfrom posthog.hogql_queries.query_runner import QueryRunnerfrom posthog.models import Team-from products.product_analytics.backend.hogql_queries.paths.paths_query_runner import PathsQueryRunner-from products.product_analytics.backend.hogql_queries.stickiness.stickiness_query_runner import StickinessQueryRunner+from products.product_analytics.backend.facade.queries import PathsQueryRunner, StickinessQueryRunner_TIME_SERIES = [EventsNode(event="$pageview")]diff --git a/posthog/hogql_queries/test/test_hogql_query_runner.py b/posthog/hogql_queries/test/test_hogql_query_runner.pyindex e36156c3815b..85b791330a57 100644--- a/posthog/hogql_queries/test/test_hogql_query_runner.py+++ b/posthog/hogql_queries/test/test_hogql_query_runner.py@@ -27,7 +27,7 @@ from posthog.hogql_queries.query_runner import ExecutionModefrom posthog.models.utils import UUIDTfrom products.managed_warehouse.backend.facade.feature_flags import MANAGED_WAREHOUSE_QUERY_STATUS_LABEL_PREFIX-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariablefrom products.warehouse_sources.backend.facade.models import MANAGED_WAREHOUSE_SOURCE_PREFIX, ExternalDataSourcefrom products.warehouse_sources.backend.facade.types import ExternalDataSourceTypediff --git a/posthog/hogql_queries/test/test_query_runner.py b/posthog/hogql_queries/test/test_query_runner.pyindex 015faf8bd0ca..cf1c705593d4 100644--- a/posthog/hogql_queries/test/test_query_runner.py+++ b/posthog/hogql_queries/test/test_query_runner.py@@ -1181,9 +1181,7 @@ class TestApplySeriesCustomNames(BaseTest):):from posthog.schema import CachedStickinessQueryResponse, StickinessQuery- from products.product_analytics.backend.hogql_queries.stickiness.stickiness_query_runner import (- StickinessQueryRunner,- )+ from products.product_analytics.backend.facade.queries import StickinessQueryRunnerquery = StickinessQuery(series=[diff --git a/posthog/management/commands/backfill_insights_query_metadata.py b/posthog/management/commands/backfill_insights_query_metadata.pyindex fe11c10ee2bf..3763d8fc90aa 100644--- a/posthog/management/commands/backfill_insights_query_metadata.py+++ b/posthog/management/commands/backfill_insights_query_metadata.py@@ -12,7 +12,7 @@ import structlogfrom posthog.hogql_queries.query_metadata import InsightQueryMetadata-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightlogger = structlog.get_logger(__name__)diff --git a/posthog/management/commands/migrate_retention_show_mean.py b/posthog/management/commands/migrate_retention_show_mean.pyindex 0bfc1709f63b..0fda288226a5 100644--- a/posthog/management/commands/migrate_retention_show_mean.py+++ b/posthog/management/commands/migrate_retention_show_mean.py@@ -1,7 +1,7 @@from django.core.management.base import BaseCommandfrom django.db import transaction-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightdef migrate_show_mean_from_boolean_to_string(batch_size: int, live_run: bool = False) -> None:diff --git a/posthog/middleware.py b/posthog/middleware.pyindex 7fedf71b35d1..d3e9ee16298a 100644--- a/posthog/middleware.py+++ b/posthog/middleware.py@@ -63,7 +63,7 @@ from products.cohorts.backend.models.cohort import Cohortfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom .auth import PersonalAPIKeyAuthenticationdiff --git a/posthog/models/file_system/test/test_file_system.py b/posthog/models/file_system/test/test_file_system.pyindex 36a26f0e651f..a76ba1863c82 100644--- a/posthog/models/file_system/test/test_file_system.py+++ b/posthog/models/file_system/test/test_file_system.py@@ -17,7 +17,7 @@ from products.dashboards.backend.models.dashboard import Dashboardfrom products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestFileSystemModel(TestCase):diff --git a/posthog/models/file_system/test/test_file_system_mixin.py b/posthog/models/file_system/test/test_file_system_mixin.pyindex 2469e34e80ed..9f697423a514 100644--- a/posthog/models/file_system/test/test_file_system_mixin.py+++ b/posthog/models/file_system/test/test_file_system_mixin.py@@ -7,7 +7,7 @@ from products.dashboards.backend.models.dashboard import Dashboardfrom products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestFileSystemSyncMixin(TestCase):diff --git a/posthog/models/file_system/test/test_file_system_view_log.py b/posthog/models/file_system/test/test_file_system_view_log.pyindex f56a94147844..ba58cce40825 100644--- a/posthog/models/file_system/test/test_file_system_view_log.py+++ b/posthog/models/file_system/test/test_file_system_view_log.py@@ -10,7 +10,7 @@ from posthog.models.file_system.file_system_representation import FileSystemReprfrom posthog.models.file_system.file_system_view_log import get_recent_file_system_items, log_file_system_viewfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass FileSystemWithLastViewed(Protocol):diff --git a/posthog/models/file_system/unfiled_file_saver.py b/posthog/models/file_system/unfiled_file_saver.pyindex a0fcb376c35a..dc9a281523d1 100644--- a/posthog/models/file_system/unfiled_file_saver.py+++ b/posthog/models/file_system/unfiled_file_saver.py@@ -20,7 +20,7 @@ from products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.links.backend.models import Linkfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.surveys.backend.models import SurveyMIXIN_MODELS: dict[str, type[FileSystemSyncMixin]] = {diff --git a/posthog/models/product_intent/product_intent.py b/posthog/models/product_intent/product_intent.pyindex 76f57261e979..78aa8818caaa 100644--- a/posthog/models/product_intent/product_intent.py+++ b/posthog/models/product_intent/product_intent.py@@ -24,7 +24,7 @@ from products.dashboards.backend.models.dashboard import Dashboardfrom products.event_definitions.backend.models.event_definition import EventDefinitionfrom products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.product_tours.backend.models import ProductTourfrom products.surveys.backend.models import Surveyfrom products.workflows.backend.models.hog_flow.hog_flow import HogFlowdiff --git a/posthog/models/resource_transfer/test/test_inter_project_transferer.py b/posthog/models/resource_transfer/test/test_inter_project_transferer.pyindex 18aee9ea724c..27582696c966 100644--- a/posthog/models/resource_transfer/test/test_inter_project_transferer.py+++ b/posthog/models/resource_transfer/test/test_inter_project_transferer.py@@ -20,7 +20,7 @@ from products.actions.backend.models.action import Actionfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile, Textfrom products.dashboards.backend.models.dashboard_widget import DashboardWidget-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.surveys.backend.models import Surveydiff --git a/posthog/models/resource_transfer/visitors/insight.py b/posthog/models/resource_transfer/visitors/insight.pyindex d96ccd1c957f..5f7b17d6a86f 100644--- a/posthog/models/resource_transfer/visitors/insight.py+++ b/posthog/models/resource_transfer/visitors/insight.py@@ -32,7 +32,7 @@ class InsightVisitor():@classmethoddef get_model(cls) -> type[models.Model]:- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insightreturn Insightdiff --git a/posthog/models/sharing_configuration.py b/posthog/models/sharing_configuration.pyindex dc577d56450d..c49ae4d8a02f 100644--- a/posthog/models/sharing_configuration.py+++ b/posthog/models/sharing_configuration.py@@ -13,7 +13,7 @@ import structlogfrom posthog.jwt import PosthogJwtAudience, encode_jwt-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightlogger = structlog.get_logger(__name__)diff --git a/posthog/models/test/test_dashboard_tile_model.py b/posthog/models/test/test_dashboard_tile_model.pyindex 67a0eebce1bc..167cf51fd90d 100644--- a/posthog/models/test/test_dashboard_tile_model.py+++ b/posthog/models/test/test_dashboard_tile_model.py@@ -8,7 +8,7 @@ from django.db.utils import IntegrityErrorfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile, Textfrom products.exports.backend.models.exported_asset import ExportedAsset-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestDashboardTileModel(APIBaseTest):diff --git a/posthog/models/test/test_product_intent.py b/posthog/models/test/test_product_intent.pyindex 2eb61ce40864..baea50fcc80e 100644--- a/posthog/models/test/test_product_intent.py+++ b/posthog/models/test/test_product_intent.py@@ -28,7 +28,7 @@ from products.dashboards.backend.models.dashboard import Dashboardfrom products.event_definitions.backend.models.event_definition import EventDefinitionfrom products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.surveys.backend.models import Surveyfrom products.workflows.backend.models.hog_flow.hog_flow import HogFlowdiff --git a/posthog/models/test/test_subscription_activity_log.py b/posthog/models/test/test_subscription_activity_log.pyindex b11fac5816aa..ceef91f632aa 100644--- a/posthog/models/test/test_subscription_activity_log.py+++ b/posthog/models/test/test_subscription_activity_log.py@@ -11,7 +11,7 @@ from posthog.models.activity_logging.activity_log import ActivityLogfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.exports.backend.models.subscription import Subscription-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight@freeze_time("2022-01-01")diff --git a/posthog/models/test/test_subscription_model.py b/posthog/models/test/test_subscription_model.pyindex fcee099ceaef..8897cb9c6e26 100644--- a/posthog/models/test/test_subscription_model.py+++ b/posthog/models/test/test_subscription_model.py@@ -26,7 +26,7 @@ from products.exports.backend.models.subscription import (get_unsubscribe_token,unsubscribe_using_token,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestSubscriptionScheduling:diff --git a/posthog/models/test/test_tagged_item_model.py b/posthog/models/test/test_tagged_item_model.pyindex f3763098838a..7b0542695877 100644--- a/posthog/models/test/test_tagged_item_model.py+++ b/posthog/models/test/test_tagged_item_model.py@@ -7,7 +7,7 @@ from posthog.models import Tag, TaggedItemfrom products.actions.backend.models.action import Actionfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestTaggedItem(BaseTest):diff --git a/posthog/rbac/test/test_user_access_control.py b/posthog/rbac/test/test_user_access_control.pyindex f33529dd6ee1..4e0b015cc78e 100644--- a/posthog/rbac/test/test_user_access_control.py+++ b/posthog/rbac/test/test_user_access_control.py@@ -1151,7 +1151,7 @@ class TestUserAccessControlSpecificAccessLevelForObject(BaseUserAccessControlTesdef test_insight_specific_access_control(self):"""Test insight-specific access controls"""- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insightinsight = Insight.objects.create(team=self.team, created_by=self.other_user)diff --git a/posthog/schema_migrations/upgrade_manager.py b/posthog/schema_migrations/upgrade_manager.pyindex ba7d0153b01d..37136ff3804d 100644--- a/posthog/schema_migrations/upgrade_manager.py+++ b/posthog/schema_migrations/upgrade_manager.py@@ -6,7 +6,7 @@ from posthog.hogql_queries.legacy_compatibility.flagged_conversion_manager imporfrom posthog.schema_migrations.upgrade import upgradeif TYPE_CHECKING:- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insight@contextmanagerdiff --git a/posthog/tasks/alerts/test/test_detector_breakdowns.py b/posthog/tasks/alerts/test/test_detector_breakdowns.pyindex 47acab1895a1..28fd9bfcfea9 100644--- a/posthog/tasks/alerts/test/test_detector_breakdowns.py+++ b/posthog/tasks/alerts/test/test_detector_breakdowns.py@@ -29,7 +29,7 @@ from products.alerts.backend.evaluation.detector import ()from products.alerts.backend.evaluation.dispatcher import check_detector_alertfrom products.alerts.backend.models.alert import AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightdef _make_trend_result(label: str, data: list[float], breakdown_value: str = "") -> dict[str, Any]:diff --git a/posthog/tasks/alerts/test/test_investigation_notifications.py b/posthog/tasks/alerts/test/test_investigation_notifications.pyindex c2a23d85ff11..b4c710321855 100644--- a/posthog/tasks/alerts/test/test_investigation_notifications.py+++ b/posthog/tasks/alerts/test/test_investigation_notifications.py@@ -16,7 +16,7 @@ from posthog.tasks.alerts.investigation_notifications import (from products.alerts.backend.destinations import AlertDeliveryfrom products.alerts.backend.models.alert import AlertCheck, AlertConfiguration, InvestigationStatus-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import InsightNOW = datetime(2026, 5, 4, 12, 0, 0, tzinfo=UTC)diff --git a/posthog/tasks/alerts/test/test_utils.py b/posthog/tasks/alerts/test/test_utils.pyindex e9ec6378aef1..98a382866384 100644--- a/posthog/tasks/alerts/test/test_utils.py+++ b/posthog/tasks/alerts/test/test_utils.py@@ -22,7 +22,7 @@ from posthog.tasks.alerts.utils import (from products.alerts.backend.destinations import ActiveAlertDestinationfrom products.alerts.backend.models.alert import AlertCheck, AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestAlertUtils:diff --git a/posthog/temporal/ai/anomaly_investigation/notebook.py b/posthog/temporal/ai/anomaly_investigation/notebook.pyindex c743c2cdbc93..4ea6452be049 100644--- a/posthog/temporal/ai/anomaly_investigation/notebook.py+++ b/posthog/temporal/ai/anomaly_investigation/notebook.py@@ -14,7 +14,7 @@ from products.notebooks.backend.facade.content import (create_heading_with_text,create_paragraph_with_text,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import InsightVERDICT_LABEL = {"true_positive": "True positive",diff --git a/posthog/temporal/ai/anomaly_investigation/workflow.py b/posthog/temporal/ai/anomaly_investigation/workflow.pyindex ce7793e73c6a..5ba55ce6d1c9 100644--- a/posthog/temporal/ai/anomaly_investigation/workflow.py+++ b/posthog/temporal/ai/anomaly_investigation/workflow.py@@ -39,7 +39,7 @@ from products.notebooks.backend.facade import api as notebooksfrom products.signals.backend.facade import api as signalsif TYPE_CHECKING:- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insightlogger = structlog.get_logger(__name__)diff --git a/posthog/temporal/product_analytics/upgrade_queries_activities.py b/posthog/temporal/product_analytics/upgrade_queries_activities.pyindex 778463e6829f..a21cb47eac39 100644--- a/posthog/temporal/product_analytics/upgrade_queries_activities.py+++ b/posthog/temporal/product_analytics/upgrade_queries_activities.py@@ -11,7 +11,7 @@ from posthog.exceptions_capture import capture_exceptionfrom posthog.schema_migrations import LATEST_VERSIONS, _discover_migrationsfrom posthog.schema_migrations.upgrade import upgrade-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import InsightLOGGER = get_logger(__name__)diff --git a/posthog/temporal/tests/ai/test_anomaly_investigation_notebook.py b/posthog/temporal/tests/ai/test_anomaly_investigation_notebook.pyindex 13bb781e1c2b..57b464e568b5 100644--- a/posthog/temporal/tests/ai/test_anomaly_investigation_notebook.py+++ b/posthog/temporal/tests/ai/test_anomaly_investigation_notebook.py@@ -4,7 +4,7 @@ from posthog.temporal.ai.anomaly_investigation.notebook import NotebookRenderConfrom posthog.temporal.ai.anomaly_investigation.report import InvestigationHypothesis, InvestigationReportfrom products.alerts.backend.models.alert import AlertCheck, AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestAnomalyInvestigationNotebook(BaseTest):diff --git a/posthog/temporal/tests/ai/test_anomaly_investigation_tools.py b/posthog/temporal/tests/ai/test_anomaly_investigation_tools.pyindex f80dc54ed5bd..566d9847c76d 100644--- a/posthog/temporal/tests/ai/test_anomaly_investigation_tools.py+++ b/posthog/temporal/tests/ai/test_anomaly_investigation_tools.py@@ -8,7 +8,7 @@ from posthog.caching.insight_result import InsightResultfrom posthog.temporal.ai.anomaly_investigation.tools import _run_detector_simulationfrom products.alerts.backend.models.alert import AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightdef _trend_result(label: str, data: list[float]) -> dict[str, Any]:diff --git a/posthog/temporal/tests/ai/test_anomaly_investigation_verdict.py b/posthog/temporal/tests/ai/test_anomaly_investigation_verdict.pyindex ed1297b39ca4..b6f334646921 100644--- a/posthog/temporal/tests/ai/test_anomaly_investigation_verdict.py+++ b/posthog/temporal/tests/ai/test_anomaly_investigation_verdict.py@@ -21,7 +21,7 @@ from products.alerts.backend.models.alert import (InvestigationStatus,InvestigationVerdict,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestInvestigationVerdictPersistence(NonAtomicBaseTest):diff --git a/posthog/temporal/tests/product_analytics/test_upgrade_queries_workflow.py b/posthog/temporal/tests/product_analytics/test_upgrade_queries_workflow.pyindex 4305054aad67..84a8a0e37aee 100644--- a/posthog/temporal/tests/product_analytics/test_upgrade_queries_workflow.py+++ b/posthog/temporal/tests/product_analytics/test_upgrade_queries_workflow.py@@ -25,7 +25,7 @@ from posthog.temporal.product_analytics.upgrade_queries_workflow import (UpgradeQueriesWorkflowInputs,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass InsightVizMigration1(SchemaMigration):diff --git a/posthog/temporal/tests/test_alerts_activities.py b/posthog/temporal/tests/test_alerts_activities.pyindex c7dea0a863dd..a896569046e7 100644--- a/posthog/temporal/tests/test_alerts_activities.py+++ b/posthog/temporal/tests/test_alerts_activities.py@@ -55,7 +55,7 @@ from products.alerts.backend.destinations import AlertDeliveryfrom products.alerts.backend.evaluation.contract import AlertExtractionErrorfrom products.alerts.backend.evaluation.validation import THRESHOLD_BOUNDS_REQUIRED_MESSAGEfrom products.alerts.backend.models.alert import AlertCheck, AlertConfiguration, Threshold-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightdef _email_delivery(target: str, at: str = "2026-08-11T00:00:00+00:00") -> AlertDelivery:diff --git a/posthog/temporal/tests/test_alerts_investigation.py b/posthog/temporal/tests/test_alerts_investigation.pyindex a4baa387e528..c3c8f678c481 100644--- a/posthog/temporal/tests/test_alerts_investigation.py+++ b/posthog/temporal/tests/test_alerts_investigation.py@@ -17,7 +17,7 @@ from posthog.schema import AlertStatefrom posthog.temporal.alerts.investigation import claim_investigation_slot, should_trigger_investigationfrom products.alerts.backend.models.alert import AlertCheck, AlertConfiguration, InvestigationStatus-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestShouldTriggerInvestigation(BaseTest):diff --git a/posthog/temporal/tests/test_alerts_workflows.py b/posthog/temporal/tests/test_alerts_workflows.pyindex a81e8d519964..2588819da2e8 100644--- a/posthog/temporal/tests/test_alerts_workflows.py+++ b/posthog/temporal/tests/test_alerts_workflows.py@@ -38,7 +38,7 @@ from posthog.temporal.common.slo_interceptor import SloInterceptorfrom posthog.temporal.tests.test_alerts_activities import _email_deliveryfrom products.alerts.backend.models.alert import AlertCheck, AlertConfiguration, Threshold-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import InsightCHECK_ALERT_ACTIVITIES: list[Callable[..., Any]] = [prepare_alert,diff --git a/posthog/temporal/tests/test_subscriptions_workflows.py b/posthog/temporal/tests/test_subscriptions_workflows.pyindex 34f11a247db3..0e200ec6b1c5 100644--- a/posthog/temporal/tests/test_subscriptions_workflows.py+++ b/posthog/temporal/tests/test_subscriptions_workflows.py@@ -79,7 +79,7 @@ from products.exports.backend.temporal.subscriptions.workflows import (ProcessSubscriptionWorkflow,ScheduleAllSubscriptionsWorkflow,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.tasks.subscriptions.auto_disable import AI_CONSENT_REVOKED_DISABLE_REASON, SLACK_DISCONNECTED_DISABLE_REASONfrom ee.tasks.subscriptions.slack_subscriptions import SlackDeliveryResultdiff --git a/posthog/test/base.py b/posthog/test/base.pyindex e06efd9da9f7..78c260179688 100644--- a/posthog/test/base.py+++ b/posthog/test/base.py@@ -239,7 +239,7 @@ from products.event_definitions.backend.models.property_definition import (DROP_PROPERTY_DEFINITIONS_TABLE_SQL,PROPERTY_DEFINITIONS_TABLE_SQL,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight# Make sure freezegun ignores our utils class that times functions, and heavy optional# deps (e.g. transformers) that can break when freezegun walks sys.modules.diff --git a/posthog/test/playwright_setup_functions.py b/posthog/test/playwright_setup_functions.pyindex a8f87742d8eb..b393f6bcad45 100644--- a/posthog/test/playwright_setup_functions.py+++ b/posthog/test/playwright_setup_functions.py@@ -20,8 +20,7 @@ from posthog.models.utils import hash_key_value, mask_key_valuefrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTilefrom products.experiments.backend.models.experiment import Experiment-from products.product_analytics.backend.models.insight import Insight-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import Insight, InsightVariableclass PlaywrightSetupVariableType(StrEnum):diff --git a/posthog/test/test_middleware.py b/posthog/test/test_middleware.pyindex 32840cbc772a..4a9eeeea6e28 100644--- a/posthog/test/test_middleware.py+++ b/posthog/test/test_middleware.py@@ -35,7 +35,7 @@ from products.actions.backend.models.action import Actionfrom products.cohorts.backend.models.cohort import Cohortfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightdef _social_auth_backend() -> BaseAuth:diff --git a/posthog/test/test_user_permissions.py b/posthog/test/test_user_permissions.pyindex d5fa7f600a83..c53832a6f8b7 100644--- a/posthog/test/test_user_permissions.py+++ b/posthog/test/test_user_permissions.py@@ -10,7 +10,7 @@ from posthog.user_permissions import UserPermissionsfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.models.dashboard_privilege import DashboardPrivilegediff --git a/posthog/user_permissions.py b/posthog/user_permissions.pyindex afc049ecc018..c9e63d798be4 100644--- a/posthog/user_permissions.py+++ b/posthog/user_permissions.py@@ -7,7 +7,7 @@ from posthog.models import Organization, OrganizationMembership, Team, Userfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass UserPermissions:diff --git a/posthog/utils.py b/posthog/utils.pyindex 937f9578b23d..f28b0d5cc54e 100644--- a/posthog/utils.py+++ b/posthog/utils.py@@ -82,7 +82,7 @@ if TYPE_CHECKING:from products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTilefrom products.feature_flags.backend.sdk_cache_provider import HyperCacheFlagProvider- from products.product_analytics.backend.models.insight_variable import InsightVariable+ from products.product_analytics.backend.facade.models import InsightVariableDATERANGE_MAP = {"second": datetime.timedelta(seconds=1),diff --git a/products/actions/backend/api/action.py b/products/actions/backend/api/action.pyindex 6ed53bec37f8..184fc705d978 100644--- a/products/actions/backend/api/action.py+++ b/products/actions/backend/api/action.py@@ -39,7 +39,7 @@ from products.actions.backend.models.action import ACTION_STEP_MATCHING_OPTIONS,from products.cdp.backend.models.hog_functions.hog_function import HogFunctionfrom products.cohorts.backend.models.cohort import Cohortfrom products.experiments.backend.models.experiment import Experiment-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight_PropertyFilterUnion = PolymorphicProxySerializer(component_name="ActionStepPropertyFilter",diff --git a/products/actions/backend/api/test/test_action.py b/products/actions/backend/api/test/test_action.pyindex fb3c3ca3e93d..3e0aab3a9787 100644--- a/products/actions/backend/api/test/test_action.py+++ b/products/actions/backend/api/test/test_action.py@@ -18,7 +18,7 @@ from posthog.models import Tag, Userfrom products.actions.backend.models.action import Actionfrom products.cdp.backend.models.hog_functions.hog_function import HogFunctionfrom products.cohorts.backend.models.cohort import Cohort-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestActionApi(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):diff --git a/products/alerts/backend/api/alert.py b/products/alerts/backend/api/alert.pyindex 60e598689ad5..91680ffbbe47 100644--- a/products/alerts/backend/api/alert.py+++ b/products/alerts/backend/api/alert.py@@ -75,7 +75,7 @@ from products.alerts.backend.insight_alert_state_machine import (apply_unsnooze,)from products.alerts.backend.models.alert import AlertCheck, AlertConfiguration, AlertSubscription, Threshold-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import InsightINSIGHT_ALERT_FIRING_EVENT = "$insight_alert_firing"@@ -504,7 +504,7 @@ class AlertSerializer(SearchMatchTypeSerializerMixin, serializers.ModelSerialize# Deferred: the insight API serializer drags the product-analytics query-runner chain;# keeping it out of module scope lets this module connect its delete receivers at# AppConfig.ready() without pulling that chain onto startup.- from products.product_analytics.backend.api.insight import InsightBasicSerializer # noqa: PLC0415+ from products.product_analytics.backend.presentation.insight import InsightBasicSerializer # noqa: PLC0415data = super().to_representation(instance)data["subscribed_users"] = UserBasicSerializer(instance.subscribed_users.all(), many=True, read_only=True).datadiff --git a/products/alerts/backend/api/test/test_alert.py b/products/alerts/backend/api/test/test_alert.pyindex b2d9fea77c13..2148153f98c0 100644--- a/products/alerts/backend/api/test/test_alert.py+++ b/products/alerts/backend/api/test/test_alert.py@@ -23,7 +23,7 @@ from posthog.models.utils import generate_random_token_personal, hash_key_valuefrom products.alerts.backend.destinations import AlertDeliveryfrom products.alerts.backend.models.alert import AlertCheck, AlertConfiguration, AlertSubscription, Thresholdfrom products.cdp.backend.models.hog_functions.hog_function import HogFunction-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import InsightTEST_DESTINATION_DELIVERY = AlertDelivery(channel="hog_function", target="Eng alerts", template="slack", at="2026-08-11T00:00:00+00:00"diff --git a/products/alerts/backend/evaluation/contract.py b/products/alerts/backend/evaluation/contract.pyindex 41aebfc5690c..321745ddd5a3 100644--- a/products/alerts/backend/evaluation/contract.py+++ b/products/alerts/backend/evaluation/contract.py@@ -9,7 +9,7 @@ from posthog.models.team import Teamfrom posthog.models.user import Userfrom products.alerts.backend.models.alert import AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight@dataclassdiff --git a/products/alerts/backend/evaluation/detector.py b/products/alerts/backend/evaluation/detector.pyindex a3feb5a5e368..af7912381baf 100644--- a/products/alerts/backend/evaluation/detector.py+++ b/products/alerts/backend/evaluation/detector.py@@ -39,7 +39,7 @@ from products.alerts.backend.evaluation.contract import (execution_mode_for_alert,)from products.alerts.backend.models.alert import AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightdef extract_detector_series(diff --git a/products/alerts/backend/evaluation/dispatcher.py b/products/alerts/backend/evaluation/dispatcher.pyindex 0b7148a3e7c8..07dc0f43b523 100644--- a/products/alerts/backend/evaluation/dispatcher.py+++ b/products/alerts/backend/evaluation/dispatcher.py@@ -13,7 +13,7 @@ from products.alerts.backend.evaluation.hogql import HogQLDetectorExtractor, Hogfrom products.alerts.backend.evaluation.metrics import MetricsExtractorfrom products.alerts.backend.evaluation.trends import TrendsExtractorfrom products.alerts.backend.models.alert import AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight# Each insight kind that supports threshold alerts maps to one extractor. The comparator is shared.EXTRACTORS: dict[NodeKind, Extractor] = {diff --git a/products/alerts/backend/evaluation/funnels.py b/products/alerts/backend/evaluation/funnels.pyindex faf62958d2cc..5ebcadc2b607 100644--- a/products/alerts/backend/evaluation/funnels.py+++ b/products/alerts/backend/evaluation/funnels.py@@ -10,7 +10,7 @@ from posthog.tasks.alerts.trends import query_excludes_incomplete_periodsfrom products.alerts.backend.evaluation.contract import AlertExtractionError, ExtractionResult, lookback_intervals_forfrom products.alerts.backend.evaluation.funnel_strategies import strategy_for_vizfrom products.alerts.backend.models.alert import AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightdef _trailing_date_range_override(interval: IntervalType | None, periods: int) -> dict:diff --git a/products/alerts/backend/evaluation/hogql.py b/products/alerts/backend/evaluation/hogql.pyindex 4bb2a0b288e5..9cd6a77ce3e7 100644--- a/products/alerts/backend/evaluation/hogql.py+++ b/products/alerts/backend/evaluation/hogql.py@@ -21,7 +21,7 @@ from products.alerts.backend.evaluation.contract import (zero_sentinel_series,)from products.alerts.backend.models.alert import AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight_HOGQL_SUBJECT = "The SQL insight value"# Any-row alerts fail loud past this many rows: silently truncating could skip the breaching rowdiff --git a/products/alerts/backend/evaluation/metrics.py b/products/alerts/backend/evaluation/metrics.pyindex 1ec5e701c0cd..b3e8a249c53f 100644--- a/products/alerts/backend/evaluation/metrics.py+++ b/products/alerts/backend/evaluation/metrics.py@@ -13,7 +13,7 @@ from products.alerts.backend.evaluation.contract import (zero_sentinel_series,)from products.alerts.backend.models.alert import AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight_SUBJECT = "The metric value"diff --git a/products/alerts/backend/evaluation/test/test_high_frequency_freshness.py b/products/alerts/backend/evaluation/test/test_high_frequency_freshness.pyindex 62f11cdb8e40..b7199b9a8b1e 100644--- a/products/alerts/backend/evaluation/test/test_high_frequency_freshness.py+++ b/products/alerts/backend/evaluation/test/test_high_frequency_freshness.py@@ -27,7 +27,7 @@ from products.alerts.backend.evaluation.funnels import FunnelsExtractorfrom products.alerts.backend.evaluation.hogql import HogQLExtractorfrom products.alerts.backend.evaluation.trends import TrendsExtractorfrom products.alerts.backend.models.alert import AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import InsightALWAYS = ExecutionMode.CALCULATE_BLOCKING_ALWAYSIF_STALE = ExecutionMode.RECENT_CACHE_CALCULATE_BLOCKING_IF_STALEdiff --git a/products/alerts/backend/evaluation/test/test_hogql_extractor_clickhouse.py b/products/alerts/backend/evaluation/test/test_hogql_extractor_clickhouse.pyindex 16558e869217..c95b46f47d57 100644--- a/products/alerts/backend/evaluation/test/test_hogql_extractor_clickhouse.py+++ b/products/alerts/backend/evaluation/test/test_hogql_extractor_clickhouse.py@@ -5,7 +5,7 @@ from posthog.api.services.query import ExecutionModefrom products.alerts.backend.evaluation.hogql import HogQLExtractorfrom products.alerts.backend.models.alert import AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestHogQLExtractorFiltersPlaceholder(APIBaseTest, ClickhouseDestroyTablesMixin):diff --git a/products/alerts/backend/evaluation/trends.py b/products/alerts/backend/evaluation/trends.pyindex aac902f1e285..0a968bf54d36 100644--- a/products/alerts/backend/evaluation/trends.py+++ b/products/alerts/backend/evaluation/trends.py@@ -35,7 +35,7 @@ from products.alerts.backend.evaluation.contract import ()from products.alerts.backend.evaluation.formatting import make_trends_value_formatterfrom products.alerts.backend.models.alert import AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TrendsExtractor:diff --git a/products/alerts/backend/max_tools.py b/products/alerts/backend/max_tools.pyindex 12a1410dbbbe..79185faa8741 100644--- a/products/alerts/backend/max_tools.py+++ b/products/alerts/backend/max_tools.py@@ -26,7 +26,7 @@ from posthog.scopes import APIScopeObjectfrom products.alerts.backend.evaluation.validation import THRESHOLD_BOUNDS_REQUIRED_MESSAGEfrom products.alerts.backend.insight_alert_state_machine import apply_disable, apply_enable, apply_threshold_changefrom products.alerts.backend.models.alert import AlertConfiguration, AlertSubscription, Threshold-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.hogai.artifacts.types import ModelArtifactResultfrom ee.hogai.tool import MaxTooldiff --git a/products/alerts/backend/test_max_tools.py b/products/alerts/backend/test_max_tools.pyindex dc94dc8aff98..5f030a96807c 100644--- a/products/alerts/backend/test_max_tools.py+++ b/products/alerts/backend/test_max_tools.py@@ -15,7 +15,7 @@ from posthog.constants import AvailableFeaturefrom posthog.models import Organization, Teamfrom products.alerts.backend.models.alert import AlertConfiguration, AlertSubscription, Threshold-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom .max_tools import CreateAlertAction, UpdateAlertAction, UpsertAlertTooldiff --git a/products/annotations/backend/api/annotation.py b/products/annotations/backend/api/annotation.pyindex fcc61c79690f..14d7d340521c 100644--- a/products/annotations/backend/api/annotation.py+++ b/products/annotations/backend/api/annotation.py@@ -12,7 +12,7 @@ from posthog.api.shared import UserBasicSerializerfrom products.annotations.backend.models.annotation import Annotationfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass AnnotationSerializer(serializers.ModelSerializer):diff --git a/products/annotations/backend/api/test/test_annotation.py b/products/annotations/backend/api/test/test_annotation.pyindex 1362dad4ef39..0b6e2f0e5598 100644--- a/products/annotations/backend/api/test/test_annotation.py+++ b/products/annotations/backend/api/test/test_annotation.py@@ -15,7 +15,7 @@ from posthog.models import Organization, Team, Userfrom products.annotations.backend.models.annotation import Annotationfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestAnnotation(APIBaseTest, QueryMatchingTest):diff --git a/products/annotations/backend/api/test/test_annotation_activity_logging.py b/products/annotations/backend/api/test/test_annotation_activity_logging.pyindex d791b3530dae..9f358d0c426e 100644--- a/products/annotations/backend/api/test/test_annotation_activity_logging.py+++ b/products/annotations/backend/api/test/test_annotation_activity_logging.py@@ -5,7 +5,7 @@ from posthog.test.activity_log_utils import ActivityLogTestHelperfrom products.annotations.backend.models.annotation import Annotationfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestAnnotationActivityLogging(ActivityLogTestHelper):diff --git a/products/annotations/backend/api/test/test_annotation_context.py b/products/annotations/backend/api/test/test_annotation_context.pyindex a0ef44efebe6..cab7ceaecd3f 100644--- a/products/annotations/backend/api/test/test_annotation_context.py+++ b/products/annotations/backend/api/test/test_annotation_context.py@@ -15,7 +15,7 @@ from products.annotations.backend.api.annotation_context import ()from products.annotations.backend.models.annotation import Annotationfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestAnnotationContext(APIBaseTest):diff --git a/products/architecture.md b/products/architecture.mdindex 2ba23e38102b..9f0d6c70f97b 100644--- a/products/architecture.md+++ b/products/architecture.md@@ -108,8 +108,9 @@ There the class crosses for registration only, core drives only the registry's m**The watched-models allowance** is the one further, deliberately temporary exception, for products whose models are load-bearing substrate that core and sibling products consume and cannot yet stop consuming.Two products hold entries.`warehouse_sources`: core HogQL reads its warehouse table/schema/source models to build queryable tables.-`product_analytics`: `Insight` and `InsightVariable`.+`product_analytics`: `Insight`, `InsightVariable` and `InsightViewed`.Core and seven products (alerts, dashboards, surveys, annotations, exports, customer_analytics, pulse) hold ForeignKeys or M2Ms into `Insight` — dashboard tiles, subscriptions and exported assets, sharing configurations, tagged items — and rely on cascade deletes, relation traversal, reverse relations, and queryset-typed access-control filtering that a frozen contract cannot express.+`InsightViewed` crosses for the view-tracking upsert (`update_or_create`) that shared-insight rendering and the demo generator perform.The dashboards→product_analytics `DashboardTile.insight` FK and `Dashboard.insights` M2M-through cross into the product against §8's direction rule; that coupling is accepted under this entry until dashboards pursues its own isolation.An allowance product's facade may hand out model classes defined under `backend/models/`, provided the whole model surface — `backend/models/` and `backend/migrations/` — stays in the `backend:contract-check` inputs, so any model or migration change still re-runs the full suite.That is the same soundness contract wiring locations have; what it does not buy is isolation — the coupling to core remains, `hogli product:lint` keeps a standing warning on it, and the direction of travel is still facade functions returning contracts.diff --git a/products/customer_analytics/backend/facade/api.py b/products/customer_analytics/backend/facade/api.pyindex 4a2f4eeebff5..985aa770aac3 100644--- a/products/customer_analytics/backend/facade/api.py+++ b/products/customer_analytics/backend/facade/api.py@@ -2354,7 +2354,7 @@ def _customer_journeys_queryset(team_id: int):def insight_belongs_to_team(team_id: int, insight_id: int) -> bool:"""Whether the given insight is in the team — backs the journey serializer's``validate_insight`` (kept as a cheap existence probe so the model stays hidden)."""- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insightreturn Insight.objects.filter(pk=insight_id, team_id=team_id).exists()diff --git a/products/customer_analytics/backend/test/test_facade.py b/products/customer_analytics/backend/test/test_facade.pyindex 776a212711b2..32652b35d7ac 100644--- a/products/customer_analytics/backend/test/test_facade.py+++ b/products/customer_analytics/backend/test/test_facade.py@@ -36,7 +36,7 @@ from products.customer_analytics.backend.models.account import AccountPropertiesfrom products.customer_analytics.backend.models.team_scoped_test_base import TeamScopedTestMixinfrom products.customer_analytics.backend.test.factories import create_accountfrom products.notebooks.backend.models import Notebook, ResourceNotebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestCustomerAnalyticsFacade(BaseTest):diff --git a/products/customer_analytics/backend/test/test_views.py b/products/customer_analytics/backend/test/test_views.pyindex c8864e69d4e8..871e9321ba55 100644--- a/products/customer_analytics/backend/test/test_views.py+++ b/products/customer_analytics/backend/test/test_views.py@@ -48,7 +48,7 @@ from products.customer_analytics.backend.models import ()from products.customer_analytics.backend.test.factories import create_account, create_custom_property_definitionfrom products.notebooks.backend.models import Notebook, ResourceNotebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.warehouse_sources.backend.models.external_data_schema import ExternalDataSchemafrom products.warehouse_sources.backend.models.external_data_source import ExternalDataSourcediff --git a/products/dashboards/backend/api/dashboard.py b/products/dashboards/backend/api/dashboard.pyindex 855ce0f5d088..57c579652c8f 100644--- a/products/dashboards/backend/api/dashboard.py+++ b/products/dashboards/backend/api/dashboard.py@@ -150,7 +150,8 @@ from products.notifications.backend.facade.api import (create_notification,has_been_dispatched,)-from products.product_analytics.backend.api.insight import (+from products.product_analytics.backend.facade.models import Insight, InsightVariable+from products.product_analytics.backend.presentation.insight import (INCLUDE_DASHBOARDS_PARAMETER,DashboardTileBasicSerializer,InsightBasicSerializer,@@ -158,8 +159,6 @@ from products.product_analytics.backend.api.insight import (InsightViewSet,get_insight_type,)-from products.product_analytics.backend.models.insight import Insight-from products.product_analytics.backend.models.insight_variable import InsightVariablefrom ee.hogai.utils.aio import async_to_syncdiff --git a/products/dashboards/backend/api/test/test_dashboard_widgets.py b/products/dashboards/backend/api/test/test_dashboard_widgets.pyindex 13782ec86477..24e663cc3555 100644--- a/products/dashboards/backend/api/test/test_dashboard_widgets.py+++ b/products/dashboards/backend/api/test/test_dashboard_widgets.py@@ -23,7 +23,7 @@ from products.dashboards.backend.models.dashboard_templates import DashboardTempfrom products.dashboards.backend.models.dashboard_tile import DashboardTilefrom products.dashboards.backend.models.dashboard_widget import DashboardWidgetfrom products.dashboards.backend.widget_registry import EXPECTED_WIDGET_TYPES-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightclass TestDashboardWidgets(APIBaseTest):diff --git a/products/dashboards/backend/api/test/test_run_insights.py b/products/dashboards/backend/api/test/test_run_insights.pyindex 93d70cc35f8b..5e2cb9f70176 100644--- a/products/dashboards/backend/api/test/test_run_insights.py+++ b/products/dashboards/backend/api/test/test_run_insights.py@@ -14,8 +14,7 @@ from posthog.models.team import Teamfrom products.dashboards.backend.access import DashboardAccessMethodfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile, Text-from products.product_analytics.backend.models.insight import Insight-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import Insight, InsightVariabledef _trends_query_dict(event: str = "$pageview") -> dict:diff --git a/products/dashboards/backend/models/dashboard_tile.py b/products/dashboards/backend/models/dashboard_tile.pyindex dda5352f64ff..54dffa6ab3b7 100644--- a/products/dashboards/backend/models/dashboard_tile.py+++ b/products/dashboards/backend/models/dashboard_tile.py@@ -161,7 +161,7 @@ class DashboardTile(models.Model):if self.insight is not None:has_no_filters_hash = self.filters_hash is Noneif has_no_filters_hash and self.insight.filters != {}:- from products.product_analytics.backend.models.insight import generate_insight_filters_hash+ from products.product_analytics.backend.facade.models import generate_insight_filters_hashself.filters_hash = generate_insight_filters_hash(self.insight, self.dashboard)diff --git a/products/dashboards/backend/test/test_dashboard_admin.py b/products/dashboards/backend/test/test_dashboard_admin.pyindex 16827819bc35..f7d6c734e638 100644--- a/products/dashboards/backend/test/test_dashboard_admin.py+++ b/products/dashboards/backend/test/test_dashboard_admin.py@@ -9,7 +9,7 @@ from django.test import RequestFactoryfrom products.dashboards.backend.admin.dashboard_admin import DashboardAdminfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightdef _attach_messages(request) -> None:diff --git a/products/data_catalog/backend/logic/drift.py b/products/data_catalog/backend/logic/drift.pyindex 923e917ba4d3..ad04b98a0a1c 100644--- a/products/data_catalog/backend/logic/drift.py+++ b/products/data_catalog/backend/logic/drift.py@@ -14,7 +14,7 @@ from uuid import UUIDfrom posthog.schema_migrations.upgrade import upgrade-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ..models import Metricdiff --git a/products/data_catalog/backend/logic/metrics.py b/products/data_catalog/backend/logic/metrics.pyindex 94dba9331e3a..b9b7f51d5bd8 100644--- a/products/data_catalog/backend/logic/metrics.py+++ b/products/data_catalog/backend/logic/metrics.py@@ -24,7 +24,7 @@ from posthog.models import Team, Userfrom posthog.models.scoping import team_scopefrom posthog.rbac.user_access_control import UserAccessControl-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ..facade.enums import CreatedSource, MetricStatusfrom ..models import METRIC_NAME_REGEX, Metricdiff --git a/products/data_catalog/backend/tests/test_analytics.py b/products/data_catalog/backend/tests/test_analytics.pyindex 17c6a22ff038..4063056cb6c1 100644--- a/products/data_catalog/backend/tests/test_analytics.py+++ b/products/data_catalog/backend/tests/test_analytics.py@@ -12,7 +12,7 @@ from products.data_catalog.backend.logic.exceptions import MetricDriftedfrom products.data_catalog.backend.logic.execution import run_metricfrom products.data_catalog.backend.logic.metrics import approve_metric, upsert_metricfrom products.data_catalog.backend.logic.relationships import propose_relationship-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.warehouse_sources.backend.facade.models import DataWarehouseTable_HOGQL = {"kind": "HogQLQuery", "query": "select count() from events"}diff --git a/products/data_catalog/backend/tests/test_api.py b/products/data_catalog/backend/tests/test_api.pyindex d9b2069f62f4..38926dcb3674 100644--- a/products/data_catalog/backend/tests/test_api.py+++ b/products/data_catalog/backend/tests/test_api.py@@ -34,7 +34,7 @@ from products.data_catalog.backend.presentation.serializers import (MetricRunRequestSerializer,MetricSerializer,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.models.rbac.access_control import AccessControldiff --git a/products/data_catalog/backend/tests/test_information_schema.py b/products/data_catalog/backend/tests/test_information_schema.pyindex d26c13501c09..c6b18f506230 100644--- a/products/data_catalog/backend/tests/test_information_schema.py+++ b/products/data_catalog/backend/tests/test_information_schema.py@@ -39,7 +39,7 @@ from products.data_catalog.backend.models import RelationshipProposal, TableCertfrom products.data_catalog.backend.models.metric import Metricfrom products.data_modeling.backend.facade.models import DataWarehouseSavedQueryfrom products.data_tools.backend.facade.models import DataWarehouseJoin-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.warehouse_sources.backend.facade.models import DataWarehouseTable, ExternalDataSourcefrom products.warehouse_sources.backend.facade.types import ExternalDataSourceTypediff --git a/products/data_catalog/backend/tests/test_logic.py b/products/data_catalog/backend/tests/test_logic.pyindex 7f29180829fe..68ccd9ad01b2 100644--- a/products/data_catalog/backend/tests/test_logic.py+++ b/products/data_catalog/backend/tests/test_logic.py@@ -22,7 +22,7 @@ from products.data_catalog.backend.logic.metrics import ()from products.data_catalog.backend.logic.validation import MAX_DESCRIPTION_LENGTH, validate_metric_definitionfrom products.data_catalog.backend.models import Metric-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.models.rbac.access_control import AccessControldiff --git a/products/data_catalog/evals/seeders.py b/products/data_catalog/evals/seeders.pyindex dcf4dc72939a..b220c54f1fa9 100644--- a/products/data_catalog/evals/seeders.py+++ b/products/data_catalog/evals/seeders.py@@ -68,7 +68,7 @@ from products.data_catalog.evals.constants import (TOP_CUSTOMERS_METRIC_NAME,)from products.data_tools.backend.facade.models import DataWarehouseJoin-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.warehouse_sources.backend.facade.models import DataWarehouseTableif TYPE_CHECKING:diff --git a/products/demo/backend/logic/legacy/app_data_generator.py b/products/demo/backend/logic/legacy/app_data_generator.pyindex baedc57973b5..79af11f19dff 100644--- a/products/demo/backend/logic/legacy/app_data_generator.py+++ b/products/demo/backend/logic/legacy/app_data_generator.py@@ -10,7 +10,7 @@ from posthog.models import EventDefinition, Person, PropertyDefinitionfrom products.actions.backend.models.action import Actionfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom .data_generator import DataGeneratordiff --git a/products/demo/backend/logic/legacy/insight_variables_data_generator.py b/products/demo/backend/logic/legacy/insight_variables_data_generator.pyindex 6dd2737a6c61..3bed1326927c 100644--- a/products/demo/backend/logic/legacy/insight_variables_data_generator.py+++ b/products/demo/backend/logic/legacy/insight_variables_data_generator.py@@ -2,8 +2,7 @@ from posthog.models import Personfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import Insight, InsightVariablefrom .data_generator import DataGeneratordiff --git a/products/demo/backend/logic/legacy/revenue_data_generator.py b/products/demo/backend/logic/legacy/revenue_data_generator.pyindex 2ee0c7f786da..ff407930ddaf 100644--- a/products/demo/backend/logic/legacy/revenue_data_generator.py+++ b/products/demo/backend/logic/legacy/revenue_data_generator.py@@ -10,7 +10,7 @@ from posthog.models import EventDefinition, Person, PropertyDefinitionfrom products.actions.backend.models.action import Actionfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom .data_generator import DataGeneratordiff --git a/products/demo/backend/logic/legacy/web_data_generator.py b/products/demo/backend/logic/legacy/web_data_generator.pyindex 63784958ed39..377ddf9f9f29 100644--- a/products/demo/backend/logic/legacy/web_data_generator.py+++ b/products/demo/backend/logic/legacy/web_data_generator.py@@ -16,7 +16,7 @@ from posthog.models.utils import UUIDTfrom products.actions.backend.models.action import Actionfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom .data_generator import DataGeneratordiff --git a/products/demo/backend/logic/products/hedgebox/matrix.py b/products/demo/backend/logic/products/hedgebox/matrix.pyindex 522aa70ed24b..c5ac1c22a232 100644--- a/products/demo/backend/logic/products/hedgebox/matrix.py+++ b/products/demo/backend/logic/products/hedgebox/matrix.py@@ -81,7 +81,7 @@ from products.experiments.backend.models.experiment import (ExperimentToSavedMetric,)from products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight, InsightViewed+from products.product_analytics.backend.facade.models import Insight, InsightViewedfrom products.warehouse_sources.backend.facade.models import DataWarehouseTable, get_or_create_datawarehouse_credentialfrom .models import HedgeboxAccount, HedgeboxPersondiff --git a/products/endpoints/backend/logic/validation.py b/products/endpoints/backend/logic/validation.pyindex 29ce8fd6974d..bb70ac36b642 100644--- a/products/endpoints/backend/logic/validation.py+++ b/products/endpoints/backend/logic/validation.py@@ -39,7 +39,7 @@ from products.endpoints.backend.models import (_breakdown_property_names,can_materialize_query,)-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariabledef validate_data_freshness(data_freshness_seconds: int | None) -> None:diff --git a/products/endpoints/backend/openapi.py b/products/endpoints/backend/openapi.pyindex f93378463772..b15b5d30dca1 100644--- a/products/endpoints/backend/openapi.py+++ b/products/endpoints/backend/openapi.py@@ -4,7 +4,7 @@ from rest_framework.request import Requestfrom products.endpoints.backend.logic.strategies import InsightEndpointStrategyfrom products.endpoints.backend.models import Endpoint, EndpointVersion, _breakdown_property_names-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariableINSIGHT_VARIABLE_TYPE_TO_OPENAPI: dict[str, dict] = {InsightVariable.Type.STRING: {"type": "string"},diff --git a/products/endpoints/backend/tests/test_endpoint.py b/products/endpoints/backend/tests/test_endpoint.pyindex 76fe82bf7240..647bac451649 100644--- a/products/endpoints/backend/tests/test_endpoint.py+++ b/products/endpoints/backend/tests/test_endpoint.py@@ -21,7 +21,7 @@ from posthog.models.utils import generate_random_token_personal, hash_key_valuefrom products.endpoints.backend.models import Endpoint, EndpointVersionfrom products.endpoints.backend.tests.conftest import create_endpoint_with_version-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariableclass TestEndpoint(ClickhouseTestMixin, APIBaseTest):@@ -1264,7 +1264,7 @@ class TestMaterializationPreview(ClickhouseTestMixin, APIBaseTest):}def _create_endpoint_with_variables(self, name="range-endpoint"):- from products.product_analytics.backend.models.insight_variable import InsightVariable+ from products.product_analytics.backend.facade.models import InsightVariableInsightVariable.objects.create(team=self.team, id="00000000-0000-0000-0000-000000000001", code_name="start_ts", type="String"@@ -1350,7 +1350,7 @@ class TestMaterializationPreview(ClickhouseTestMixin, APIBaseTest):assert endpoint_data.get("materialization", {}).get("status") is Nonedef test_bucket_overrides_stored_on_version(self):- from products.product_analytics.backend.models.insight_variable import InsightVariable+ from products.product_analytics.backend.facade.models import InsightVariableInsightVariable.objects.create(team=self.team, id="00000000-0000-0000-0000-000000000001", code_name="start_ts", type="String"diff --git a/products/endpoints/backend/tests/test_endpoint_execution.py b/products/endpoints/backend/tests/test_endpoint_execution.pyindex edf319b4d4f1..eedcff54521d 100644--- a/products/endpoints/backend/tests/test_endpoint_execution.py+++ b/products/endpoints/backend/tests/test_endpoint_execution.py@@ -18,7 +18,7 @@ from posthog.errors import CHQueryErrorNoCommonTypefrom products.data_modeling.backend.facade.models import DataModelingJob, DataWarehouseSavedQueryfrom products.endpoints.backend.logic.execution import EndpointExecutionServicefrom products.endpoints.backend.tests.conftest import create_endpoint_with_version-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariablefrom products.warehouse_sources.backend.facade.models import DataWarehouseTablediff --git a/products/endpoints/backend/tests/test_openapi_spec.py b/products/endpoints/backend/tests/test_openapi_spec.pyindex 15bce79b64ec..ad8d1a6a53e6 100644--- a/products/endpoints/backend/tests/test_openapi_spec.py+++ b/products/endpoints/backend/tests/test_openapi_spec.py@@ -53,7 +53,7 @@ class TestEndpointOpenAPISpec(ClickhouseTestMixin, APIBaseTest):self.assertEqual(response_schema["properties"]["results"]["type"], "array")def test_openapi_spec_with_variables(self):- from products.product_analytics.backend.models.insight_variable import InsightVariable+ from products.product_analytics.backend.facade.models import InsightVariablevariable = InsightVariable.objects.create(team=self.team,@@ -93,7 +93,7 @@ class TestEndpointOpenAPISpec(ClickhouseTestMixin, APIBaseTest):def test_openapi_spec_marks_hogql_variables_without_default_as_required(self):"""Regression for #54605."""- from products.product_analytics.backend.models.insight_variable import InsightVariable+ from products.product_analytics.backend.facade.models import InsightVariablewith_default = InsightVariable.objects.create(team=self.team,@@ -151,7 +151,7 @@ class TestEndpointOpenAPISpec(ClickhouseTestMixin, APIBaseTest):def test_openapi_spec_keeps_request_body_optional_when_all_variables_have_defaults(self):"""When every HogQL variable has a default value, nothing is required."""- from products.product_analytics.backend.models.insight_variable import InsightVariable+ from products.product_analytics.backend.facade.models import InsightVariablevariable = InsightVariable.objects.create(team=self.team,@@ -211,7 +211,7 @@ class TestEndpointOpenAPISpec(ClickhouseTestMixin, APIBaseTest):self.assertEqual(schema_non_materialized.get("required"), ["$browser"])def test_openapi_spec_variable_types(self):- from products.product_analytics.backend.models.insight_variable import InsightVariable+ from products.product_analytics.backend.facade.models import InsightVariabletest_cases = [(InsightVariable.Type.NUMBER, "number", None),@@ -544,7 +544,7 @@ class TestEndpointOpenAPIRequiredVariables(ClickhouseTestMixin, APIBaseTest):"""Inline HogQL substitutes defaults/NULLs for missing variables — that's a coherentcontract. The OpenAPI spec must not mark inline HogQL variables required, or generatedSDKs would reject calls that are legal at runtime."""- from products.product_analytics.backend.models.insight_variable import InsightVariable+ from products.product_analytics.backend.facade.models import InsightVariableInsightVariable.objects.create(team=self.team,@@ -579,7 +579,7 @@ class TestEndpointOpenAPIRequiredVariables(ClickhouseTestMixin, APIBaseTest):spec must mark every variable required — unlike the inline path, which substitutesdefaults/NULLs and stays optional."""from products.endpoints.backend.openapi import _build_variables_schema- from products.product_analytics.backend.models.insight_variable import InsightVariable+ from products.product_analytics.backend.facade.models import InsightVariablewith_default = InsightVariable.objects.create(team=self.team,diff --git a/products/exports/backend/api/exports.py b/products/exports/backend/api/exports.pyindex 13fa908aa5db..ece9496ca829 100644--- a/products/exports/backend/api/exports.py+++ b/products/exports/backend/api/exports.py@@ -42,7 +42,7 @@ from products.exports.backend.models.exported_asset import (is_valid_session_recording_id,)from products.exports.backend.stuck_exports import STUCK_EXPORT_MESSAGE, is_stuck_export-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight# Full video exports per team per calendar month, tiered by plan.FULL_VIDEO_EXPORTS_LIMIT_BY_TIER: dict[Literal["free", "paid", "enterprise"], int] = {diff --git a/products/exports/backend/api/test/test_exports.py b/products/exports/backend/api/test/test_exports.pyindex e2e2480b8ca5..d47e0c06deba 100644--- a/products/exports/backend/api/test/test_exports.py+++ b/products/exports/backend/api/test/test_exports.py@@ -40,8 +40,8 @@ from products.exports.backend.facade.api import EXPORT_WORKFLOW_TIMEOUTfrom products.exports.backend.models.exported_asset import DATASET_EXPORT_KIND, ExportedAssetfrom products.exports.backend.tasks.failure_handler import FAILURE_TYPE_SYSTEM, FAILURE_TYPE_USERfrom products.exports.backend.tasks.image_exporter import export_image-from products.product_analytics.backend.api.insight import InsightSerializer-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight+from products.product_analytics.backend.presentation.insight import InsightSerializerfrom ee.models.rbac.access_control import AccessControldiff --git a/products/exports/backend/facade/api.py b/products/exports/backend/facade/api.pyindex 368c6e5bad36..85e4941bfd67 100644--- a/products/exports/backend/facade/api.py+++ b/products/exports/backend/facade/api.py@@ -27,7 +27,7 @@ from products.exports.backend.tasks.failure_handler import (InvalidExportContext as InvalidExportContext,RetryableExportError as RetryableExportError,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightlogger = structlog.get_logger(__name__)diff --git a/products/exports/backend/tasks/image_exporter.py b/products/exports/backend/tasks/image_exporter.pyindex c1226607f593..b1b5edfb63f6 100644--- a/products/exports/backend/tasks/image_exporter.py+++ b/products/exports/backend/tasks/image_exporter.py@@ -42,7 +42,7 @@ from products.exports.backend.tasks.failure_handler import (classify_failure_type,)from products.product_analytics.backend.facade.api import map_stale_to_latest-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariablelogger = structlog.get_logger(__name__)diff --git a/products/exports/backend/tasks/test/test_image_exporter.py b/products/exports/backend/tasks/test/test_image_exporter.pyindex cfda8b336934..674b8c40811e 100644--- a/products/exports/backend/tasks/test/test_image_exporter.py+++ b/products/exports/backend/tasks/test/test_image_exporter.py@@ -36,8 +36,7 @@ from products.exports.backend.models.exported_asset import ExportedAssetfrom products.exports.backend.tasks import image_exporterfrom products.exports.backend.tasks.failure_handler import BrowserlessUnavailable, InvalidExportContextfrom products.product_analytics.backend.facade.api import map_stale_to_latest-from products.product_analytics.backend.models.insight import Insight-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import Insight, InsightVariabledef make_insight_result(cache_key: str) -> InsightResult:diff --git a/products/exports/backend/temporal/subscriptions/activities.py b/products/exports/backend/temporal/subscriptions/activities.pyindex cd3277d7513e..54a57cafb7c8 100644--- a/products/exports/backend/temporal/subscriptions/activities.py+++ b/products/exports/backend/temporal/subscriptions/activities.py@@ -42,7 +42,7 @@ from products.exports.backend.temporal.subscriptions.types import (RecipientResult,UpdateDeliveryRecordInputs,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.tasks.subscriptions import _capture_delivery_failed_eventfrom ee.tasks.subscriptions.auto_disable import (diff --git a/products/exports/backend/temporal/subscriptions/ai_subscription/test/test_activities.py b/products/exports/backend/temporal/subscriptions/ai_subscription/test/test_activities.pyindex 90576f162d6a..2a22f5c3c40d 100644--- a/products/exports/backend/temporal/subscriptions/ai_subscription/test/test_activities.py+++ b/products/exports/backend/temporal/subscriptions/ai_subscription/test/test_activities.py@@ -23,7 +23,7 @@ from products.exports.backend.temporal.subscriptions.types import (AI_REPORT_PROMPT_SNAPSHOT_KEY,AI_REPORT_SNAPSHOT_KEY,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight_WINDOW_END_UTC = "2026-06-25T12:00:00+00:00"diff --git a/products/exports/backend/temporal/subscriptions/insight_snapshot.py b/products/exports/backend/temporal/subscriptions/insight_snapshot.pyindex 6fee9ed6d7a1..37eaac49fd18 100644--- a/products/exports/backend/temporal/subscriptions/insight_snapshot.py+++ b/products/exports/backend/temporal/subscriptions/insight_snapshot.py@@ -30,7 +30,7 @@ from products.dashboards.backend.models.dashboard_tile import DashboardTilefrom products.exports.backend.models.subscription import Subscriptionfrom products.exports.backend.temporal.subscriptions.delivery_common import strip_null_bytesfrom products.exports.backend.temporal.subscriptions.types import safe_error_message-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightlogger = structlog.get_logger(__name__)diff --git a/products/exports/backend/temporal/subscriptions/snapshot_activities.py b/products/exports/backend/temporal/subscriptions/snapshot_activities.pyindex db401d03a0f7..7d1b508adf4a 100644--- a/products/exports/backend/temporal/subscriptions/snapshot_activities.py+++ b/products/exports/backend/temporal/subscriptions/snapshot_activities.py@@ -20,7 +20,7 @@ from products.exports.backend.temporal.subscriptions.llm_change_summary import gfrom products.exports.backend.temporal.subscriptions.results_summarizer import build_results_summaryfrom products.exports.backend.temporal.subscriptions.types import SnapshotInsightsInputs, SnapshotInsightsResultfrom products.posthog_ai.backend.models.assistant import CoreMemory-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.billing.quota_limiting import is_team_over_ai_credit_budgetdiff --git a/products/exports/backend/temporal/subscriptions/test_delivery_activities.py b/products/exports/backend/temporal/subscriptions/test_delivery_activities.pyindex 8586cb69b054..b38100a674fa 100644--- a/products/exports/backend/temporal/subscriptions/test_delivery_activities.py+++ b/products/exports/backend/temporal/subscriptions/test_delivery_activities.py@@ -36,7 +36,7 @@ from products.exports.backend.temporal.subscriptions.workflows import (ProcessAISubscriptionWorkflow,ProcessSubscriptionWorkflow,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.tasks.test.subscriptions.subscriptions_test_factory import create_subscriptiondiff --git a/products/exports/backend/temporal/subscriptions/test_snapshot_ai_consent.py b/products/exports/backend/temporal/subscriptions/test_snapshot_ai_consent.pyindex a1d1f431e2e9..cd2720f5405f 100644--- a/products/exports/backend/temporal/subscriptions/test_snapshot_ai_consent.py+++ b/products/exports/backend/temporal/subscriptions/test_snapshot_ai_consent.py@@ -12,7 +12,7 @@ from products.exports.backend.models.subscription import Subscription, Subscriptfrom products.exports.backend.temporal.subscriptions.snapshot_activities import snapshot_subscription_insightsfrom products.exports.backend.temporal.subscriptions.types import SnapshotInsightsInputsfrom products.posthog_ai.backend.models.assistant import CoreMemory-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightpytestmark = [pytest.mark.asyncio, pytest.mark.django_db(transaction=True)]diff --git a/products/exports/backend/temporal/subscriptions/test_snapshot_annotations.py b/products/exports/backend/temporal/subscriptions/test_snapshot_annotations.pyindex 1e21d5b08998..e41a6bc6869a 100644--- a/products/exports/backend/temporal/subscriptions/test_snapshot_annotations.py+++ b/products/exports/backend/temporal/subscriptions/test_snapshot_annotations.py@@ -11,7 +11,7 @@ from parameterized import parameterizedfrom products.annotations.backend.api.annotation_context import resolve_snapshot_date_rangefrom products.annotations.backend.models.annotation import Annotationfrom products.exports.backend.temporal.subscriptions.snapshot_activities import _load_annotations_section-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightdef _snap_with_range(date_from: str | None, date_to: str | None) -> dict:diff --git a/products/exports/backend/temporal/subscriptions/test_snapshot_image_loading.py b/products/exports/backend/temporal/subscriptions/test_snapshot_image_loading.pyindex 9b7743b81753..27dacc866e68 100644--- a/products/exports/backend/temporal/subscriptions/test_snapshot_image_loading.py+++ b/products/exports/backend/temporal/subscriptions/test_snapshot_image_loading.py@@ -9,7 +9,7 @@ from products.exports.backend.temporal.subscriptions.snapshot_activities importSUBSCRIPTION_SUMMARY_IMAGE_SKIPPED,_load_insight_images,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightpytestmark = pytest.mark.django_dbdiff --git a/products/feature_flags/backend/api/test/test_feature_flag.py b/products/feature_flags/backend/api/test/test_feature_flag.pyindex 4f2791a3941f..3f070f722c8e 100644--- a/products/feature_flags/backend/api/test/test_feature_flag.py+++ b/products/feature_flags/backend/api/test/test_feature_flag.py@@ -69,7 +69,7 @@ from products.feature_flags.backend.flag_status import FeatureFlagStatusfrom products.feature_flags.backend.models.feature_flag import FeatureFlag, FeatureFlagDashboardsfrom products.feature_flags.backend.models.team_feature_flags_config import TeamFeatureFlagsConfigfrom products.feature_flags.backend.user_blast_radius import get_user_blast_radius, get_user_blast_radius_persons-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.product_tours.backend.models import ProductTourfrom products.surveys.backend.models import Surveydiff --git a/products/feature_flags/backend/management/commands/delete_feature_flag_usage_insights.py b/products/feature_flags/backend/management/commands/delete_feature_flag_usage_insights.pyindex 9923543f570e..98a8c35cf0e0 100644--- a/products/feature_flags/backend/management/commands/delete_feature_flag_usage_insights.py+++ b/products/feature_flags/backend/management/commands/delete_feature_flag_usage_insights.py@@ -33,7 +33,7 @@ from products.feature_flags.backend.api.feature_flag import (USAGE_DASHBOARD_NAME_PREFIX,)from products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight# Tags each activity-log entry so a sweep's deletions are distinguishable from a user's._JOB_TYPE = "delete_feature_flag_usage_insights"@@ -289,7 +289,7 @@ class Command(BaseCommand):return deletabledef _soft_delete(self, insights: list[_Candidate]) -> None:- """Mirror InsightViewSet.bulk_delete (products/product_analytics/backend/api/insight.py): soft-delete+ """Mirror InsightViewSet.bulk_delete (products/product_analytics/backend/presentation/insight.py): soft-deletethe insights and their tiles, then log each removal as system activity.Three of bulk_delete's steps are deliberately dropped: its alert teardown, because `_keep_ids`diff --git a/products/feature_flags/backend/management/commands/test/test_delete_feature_flag_usage_insights.py b/products/feature_flags/backend/management/commands/test/test_delete_feature_flag_usage_insights.pyindex fcd079e82ada..2950dc3b8ff2 100644--- a/products/feature_flags/backend/management/commands/test/test_delete_feature_flag_usage_insights.py+++ b/products/feature_flags/backend/management/commands/test/test_delete_feature_flag_usage_insights.py@@ -26,7 +26,7 @@ from products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTilefrom products.feature_flags.backend.api.feature_flag import _create_usage_dashboardfrom products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom ee.tasks.test.subscriptions.subscriptions_test_factory import create_subscriptiondiff --git a/products/notebooks/backend/test/test_sharing.py b/products/notebooks/backend/test/test_sharing.pyindex 5647519f8eb4..0a6804fa7b2f 100644--- a/products/notebooks/backend/test/test_sharing.py+++ b/products/notebooks/backend/test/test_sharing.py@@ -16,7 +16,7 @@ from products.notebooks.backend.util import (filter_notebook_content_for_sharing,iter_prosemirror_nodes,)-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightdef _saved_insight_query_node(short_id: str) -> dict[str, Any]:diff --git a/products/posthog_ai/eval_harness/data_setup.py b/products/posthog_ai/eval_harness/data_setup.pyindex 07828d56e66e..228da050a863 100644--- a/products/posthog_ai/eval_harness/data_setup.py+++ b/products/posthog_ai/eval_harness/data_setup.py@@ -24,7 +24,7 @@ from posthog.persons_db import persons_db_connectionfrom products.dashboards.backend.models import Dashboard, DashboardTilefrom products.demo.backend.facade.api import HedgeboxMatrix, MatrixManager, infer_taxonomy_for_teamfrom products.posthog_ai.backend.models.assistant import CoreMemory-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightlogger = logging.getLogger(__name__)diff --git a/products/posthog_ai/eval_harness/seeders/insight.py b/products/posthog_ai/eval_harness/seeders/insight.pyindex fc7aecc00e91..d2145ca1a0dc 100644--- a/products/posthog_ai/eval_harness/seeders/insight.py+++ b/products/posthog_ai/eval_harness/seeders/insight.py@@ -117,7 +117,7 @@ def seed_insight_noise(context: CustomPromptSandboxContext) -> dict[str, Any]:whether the agent found the right one. Synchronous — runs in a workerthread via ``asyncio.to_thread`` from ``base.py:task()``."""- from products.product_analytics.backend.models.insight import Insight+ from products.product_analytics.backend.facade.models import Insightteam_id = context.team_iduser_id = context.user_iddiff --git a/products/product_analytics/backend/api/__init__.py b/products/product_analytics/backend/api/__init__.pydeleted file mode 100644index ef556a5d355f..000000000000--- a/products/product_analytics/backend/api/__init__.py+++ /dev/null@@ -1,8 +0,0 @@-from .insight import InsightViewSet, LegacyInsightViewSet-from .insight_variable import InsightVariableViewSet--__all__ = [- "InsightVariableViewSet",- "InsightViewSet",- "LegacyInsightViewSet",-]diff --git a/products/product_analytics/backend/facade/api.py b/products/product_analytics/backend/facade/api.pyindex 7b0dd0d06225..80b64d6971d0 100644--- a/products/product_analytics/backend/facade/api.py+++ b/products/product_analytics/backend/facade/api.py@@ -6,7 +6,10 @@ functionality from; ``facade.models`` carries the sanctioned model-classcrossings. Functions here stay thin and delegate to ``backend.logic``."""-from products.product_analytics.backend import logic+from typing import Any++from products.product_analytics.backend import insight_test_account_filters, logic+from products.product_analytics.backend.insight_test_account_filters import TestAccountFilterUpdatefrom products.product_analytics.backend.models.insight_variable import InsightVariable@@ -15,6 +18,11 @@ def map_stale_to_latest(stale_variables: dict, latest_variables: list[InsightVarreturn logic.map_stale_to_latest(stale_variables, latest_variables)+def plan_test_account_filter_update(query: Any, *, enabled: bool) -> TestAccountFilterUpdate:+ """Work out how to set the test account filter on an insight, without touching the stored query."""+ return insight_test_account_filters.plan_test_account_filter_update(query, enabled=enabled)++def get_query_specific_instructions(kind: str) -> str:"""Analysis guidance for a query kind, used by LLM insight and subscription summaries."""return logic.get_query_specific_instructions(kind)diff --git a/products/product_analytics/backend/facade/contracts.py b/products/product_analytics/backend/facade/contracts.pynew file mode 100644index 000000000000..cdf099420e34--- /dev/null+++ b/products/product_analytics/backend/facade/contracts.py@@ -0,0 +1,8 @@+"""+Cross-product contracts for product_analytics.++Empty for now: today's crossings are the watched-models allowance classes+(``facade.models``) and the QueryRunner wiring (``facade.queries``). As those+convert to frozen dataclasses per products/architecture.md, the contracts+land here.+"""diff --git a/products/product_analytics/backend/facade/models.py b/products/product_analytics/backend/facade/models.pyindex 95c9eabba26e..5b6a86143d86 100644--- a/products/product_analytics/backend/facade/models.py+++ b/products/product_analytics/backend/facade/models.py@@ -1,17 +1,19 @@"""Model-class wiring for product_analytics.-Re-exports the ``Insight`` and ``InsightVariable`` model classes for-cross-product consumers under the watched-models allowance (MODEL_CROSSINGS):-dashboards, alerts, exports, sharing and other areas hold ForeignKeys or M2Ms-into ``Insight`` and need ORM semantics (relation traversal, cascade deletes,-queryset-typed access-control filtering) that a frozen contract cannot-express. The whole model surface (``backend/models/`` and+Re-exports the ``Insight``, ``InsightVariable`` and ``InsightViewed`` model+classes for cross-product consumers under the watched-models allowance+(MODEL_CROSSINGS): dashboards, alerts, exports, sharing and other areas hold+ForeignKeys or M2Ms into ``Insight`` and need ORM semantics (relation+traversal, cascade deletes, queryset-typed access-control filtering, the+view-tracking ``update_or_create``) that a frozen contract cannot express.+Also carries the model-module helper ``generate_insight_filters_hash``, which+takes model instances. The whole model surface (``backend/models/`` and``backend/migrations/``) stays in the contract-check inputs, so a change tothese classes still runs the full suite."""-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.models.insight import Insight, InsightViewed, generate_insight_filters_hashfrom products.product_analytics.backend.models.insight_variable import InsightVariable-__all__ = ["Insight", "InsightVariable"]+__all__ = ["Insight", "InsightVariable", "InsightViewed", "generate_insight_filters_hash"]diff --git a/products/product_analytics/backend/facade/queries.py b/products/product_analytics/backend/facade/queries.pynew file mode 100644index 000000000000..37c847835aa2--- /dev/null+++ b/products/product_analytics/backend/facade/queries.py@@ -0,0 +1,36 @@+"""+Facade re-exports for product analytics HogQL query runners.++Core's query-runner registry (``posthog/hogql_queries/query_runner.py``) dispatches+on query ``kind`` and constructs these runners by class identity; the paths_v2+presentation imports the segment-to-funnels helpers. The implementations stay in+``backend/hogql_queries/`` (the wiring location, covered by the contract-check+inputs). Runner modules pull the heavy HogQL import chain, so — like+warehouse_sources' pipeline facade — names resolve lazily (PEP 562), keeping the+runners off the ``django.setup()`` path that presentation loads at startup.+"""++_B = "products.product_analytics.backend.hogql_queries."++_LAZY = {+ "PATHS_V2_OTHER": "paths_v2.path_item",+ "PathsQueryRunner": "paths.paths_query_runner",+ "PathsV2QueryRunner": "paths_v2.paths_v2_query_runner",+ "StickinessQueryRunner": "stickiness.stickiness_query_runner",+ "anchored_segment_to_funnels_query": "paths_v2.funnel_converter",+ "edge_to_funnels_query": "paths_v2.funnel_converter",+ "item_label": "paths_v2.path_item",+ "resolve_step_sources": "paths_v2.path_item",+ "step_source_for_event": "paths_v2.path_item",+}++__all__ = sorted(_LAZY)+++def __getattr__(name: str):+ module = _LAZY.get(name)+ if module is None:+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")+ import importlib++ return getattr(importlib.import_module(_B + module), name)diff --git a/products/product_analytics/backend/api/test/__init__.py b/products/product_analytics/backend/presentation/__init__.pysimilarity index 100%rename from products/product_analytics/backend/api/test/__init__.pyrename to products/product_analytics/backend/presentation/__init__.pydiff --git a/products/product_analytics/backend/api/ai_billing.py b/products/product_analytics/backend/presentation/ai_billing.pysimilarity index 100%rename from products/product_analytics/backend/api/ai_billing.pyrename to products/product_analytics/backend/presentation/ai_billing.pydiff --git a/products/product_analytics/backend/api/insight.py b/products/product_analytics/backend/presentation/insight.pysimilarity index 99%rename from products/product_analytics/backend/api/insight.pyrename to products/product_analytics/backend/presentation/insight.pyindex ddb5ef99f180..3c45e42a1d6d 100644--- a/products/product_analytics/backend/api/insight.py+++ b/products/product_analytics/backend/presentation/insight.py@@ -152,15 +152,16 @@ from products.dashboards.backend.access import ()from products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.api.insight_metadata import (+from products.product_analytics.backend.facade.api import map_stale_to_latest, plan_test_account_filter_update+from products.product_analytics.backend.facade.models import Insight, InsightVariable, InsightViewed+from products.product_analytics.backend.presentation.insight_metadata import (InsightMetadataTimeoutError,generate_insight_metadata,)-from products.product_analytics.backend.api.insight_suggestions import get_insight_analysis, get_insight_suggestions-from products.product_analytics.backend.insight_test_account_filters import plan_test_account_filter_update-from products.product_analytics.backend.logic import map_stale_to_latest-from products.product_analytics.backend.models.insight import Insight, InsightViewed-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.presentation.insight_suggestions import (+ get_insight_analysis,+ get_insight_suggestions,+)from common.hogvm.python.utils import HogVMExceptiondiff --git a/products/product_analytics/backend/api/insight_ee.py b/products/product_analytics/backend/presentation/insight_ee.pysimilarity index 84%rename from products/product_analytics/backend/api/insight_ee.pyrename to products/product_analytics/backend/presentation/insight_ee.pyindex fad0b5fdf77d..c16b22bd60bd 100644--- a/products/product_analytics/backend/api/insight_ee.py+++ b/products/product_analytics/backend/presentation/insight_ee.py@@ -4,8 +4,8 @@ from rest_framework.permissions import SAFE_METHODS, BasePermissionfrom rest_framework.request import Requestfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.api.insight import InsightViewSet-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight+from products.product_analytics.backend.presentation.insight import InsightViewSetclass CanEditInsight(BasePermission):diff --git a/products/product_analytics/backend/api/insight_metadata.py b/products/product_analytics/backend/presentation/insight_metadata.pysimilarity index 99%rename from products/product_analytics/backend/api/insight_metadata.pyrename to products/product_analytics/backend/presentation/insight_metadata.pyindex da26db52b65e..dc27d195708f 100644--- a/products/product_analytics/backend/api/insight_metadata.py+++ b/products/product_analytics/backend/presentation/insight_metadata.py@@ -20,7 +20,7 @@ from posthog.event_usage import groupsfrom posthog.llm.completions import hit_openaifrom posthog.models import Team-from products.product_analytics.backend.api.ai_billing import billable_ai_properties+from products.product_analytics.backend.presentation.ai_billing import billable_ai_propertiesclass InsightMetadata(BaseModel):diff --git a/products/product_analytics/backend/api/insight_suggestions.py b/products/product_analytics/backend/presentation/insight_suggestions.pysimilarity index 98%rename from products/product_analytics/backend/api/insight_suggestions.pyrename to products/product_analytics/backend/presentation/insight_suggestions.pyindex eec88e598b91..6ee82abc2cb7 100644--- a/products/product_analytics/backend/api/insight_suggestions.py+++ b/products/product_analytics/backend/presentation/insight_suggestions.py@@ -22,8 +22,8 @@ from posthog.llm.completions import hit_openaifrom posthog.models import Teamfrom products.annotations.backend.api.annotation_context import build_annotations_block, resolve_query_date_range-from products.product_analytics.backend.api.ai_billing import billable_ai_properties-from products.product_analytics.backend.logic import get_query_specific_instructions+from products.product_analytics.backend.facade.api import get_query_specific_instructions+from products.product_analytics.backend.presentation.ai_billing import billable_ai_propertieslogger = structlog.get_logger(__name__)diff --git a/products/product_analytics/backend/api/insight_variable.py b/products/product_analytics/backend/presentation/insight_variable.pysimilarity index 99%rename from products/product_analytics/backend/api/insight_variable.pyrename to products/product_analytics/backend/presentation/insight_variable.pyindex 8941a76e91a5..2a69c15b71e9 100644--- a/products/product_analytics/backend/api/insight_variable.py+++ b/products/product_analytics/backend/presentation/insight_variable.py@@ -10,7 +10,7 @@ from posthog.schema import ProductKeyfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.auth import SharingAccessTokenAuthentication, SharingPasswordProtectedAuthentication-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import InsightVariabledef _scalar_to_str(value: object) -> str | None:diff --git a/products/product_analytics/backend/api/paths_v2.py b/products/product_analytics/backend/presentation/paths_v2.pysimilarity index 97%rename from products/product_analytics/backend/api/paths_v2.pyrename to products/product_analytics/backend/presentation/paths_v2.pyindex 6e21a3e961d2..d2f12ca3ec8b 100644--- a/products/product_analytics/backend/api/paths_v2.py+++ b/products/product_analytics/backend/presentation/paths_v2.py@@ -10,11 +10,9 @@ from posthog.schema import PathsV2AnchorType, PathsV2Item, PathsV2Queryfrom posthog.api.mixins import ValidatedRequest, validated_requestfrom posthog.api.routing import TeamAndOrgViewSetMixin-from products.product_analytics.backend.hogql_queries.paths_v2.funnel_converter import (+from products.product_analytics.backend.facade.queries import (anchored_segment_to_funnels_query,edge_to_funnels_query,-)-from products.product_analytics.backend.hogql_queries.paths_v2.path_item import (item_label,resolve_step_sources,step_source_for_event,diff --git a/products/product_analytics/backend/presentation/test/__init__.py b/products/product_analytics/backend/presentation/test/__init__.pynew file mode 100644index 000000000000..e69de29bb2d1diff --git a/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr b/products/product_analytics/backend/presentation/test/__snapshots__/test_insight.ambrsimilarity index 100%rename from products/product_analytics/backend/api/test/__snapshots__/test_insight.ambrrename to products/product_analytics/backend/presentation/test/__snapshots__/test_insight.ambrdiff --git a/products/product_analytics/backend/api/test/__snapshots__/test_insight_funnels.ambr b/products/product_analytics/backend/presentation/test/__snapshots__/test_insight_funnels.ambrsimilarity index 100%rename from products/product_analytics/backend/api/test/__snapshots__/test_insight_funnels.ambrrename to products/product_analytics/backend/presentation/test/__snapshots__/test_insight_funnels.ambrdiff --git a/products/product_analytics/backend/api/test/test_deprecated_dashboards_field.py b/products/product_analytics/backend/presentation/test/test_deprecated_dashboards_field.pysimilarity index 96%rename from products/product_analytics/backend/api/test/test_deprecated_dashboards_field.pyrename to products/product_analytics/backend/presentation/test/test_deprecated_dashboards_field.pyindex 767f58a8574c..92d52a8fb67c 100644--- a/products/product_analytics/backend/api/test/test_deprecated_dashboards_field.py+++ b/products/product_analytics/backend/presentation/test/test_deprecated_dashboards_field.py@@ -12,8 +12,8 @@ from posthog.models.utils import generate_random_token_personal, hash_key_valuefrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.api.insight import should_serve_deprecated_dashboards_field-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insight+from products.product_analytics.backend.presentation.insight import should_serve_deprecated_dashboards_fielddef _fake_request(authenticator: object | None, query_params: dict[str, str] | None = None) -> MagicMock:diff --git a/products/product_analytics/backend/api/test/test_insight.py b/products/product_analytics/backend/presentation/test/test_insight.pysimilarity index 99%rename from products/product_analytics/backend/api/test/test_insight.pyrename to products/product_analytics/backend/presentation/test/test_insight.pyindex 9b95cb7df15b..6af5610d5259 100644--- a/products/product_analytics/backend/api/test/test_insight.py+++ b/products/product_analytics/backend/presentation/test/test_insight.py@@ -60,8 +60,7 @@ from products.cohorts.backend.models.cohort import Cohortfrom products.dashboards.backend.access import DashboardAccessMethodfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile, Text-from products.product_analytics.backend.models.insight import Insight, InsightViewed-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.models import Insight, InsightVariable, InsightViewedfrom ee.models.rbac.access_control import AccessControl@@ -81,7 +80,7 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):)def test_legacy_insight_endpoints_blocked_with_feature_flag(self, _name: str, path: str) -> None:with patch(- "products.product_analytics.backend.api.insight.feature_enabled_or_false", return_value=True+ "products.product_analytics.backend.presentation.insight.feature_enabled_or_false", return_value=True) as mock_feature_enabled:response = self.client.get(path.format(team_id=self.team.id))@@ -94,7 +93,7 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):def test_creating_legacy_filter_insight_blocked_with_feature_flag(self) -> None:with patch(- "products.product_analytics.backend.api.insight.feature_enabled_or_false", return_value=True+ "products.product_analytics.backend.presentation.insight.feature_enabled_or_false", return_value=True) as mock_feature_enabled:response = self.client.post(f"/api/projects/{self.team.id}/insights/",@@ -113,7 +112,7 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):def test_creating_query_insight_not_blocked_by_legacy_filter_flag(self) -> None:with patch(- "products.product_analytics.backend.api.insight.feature_enabled_or_false", return_value=True+ "products.product_analytics.backend.presentation.insight.feature_enabled_or_false", return_value=True) as mock_feature_enabled:response = self.client.post(f"/api/projects/{self.team.id}/insights/",@@ -503,7 +502,7 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):("forced_refresh", False, "force_blocking", False),])- @patch("products.product_analytics.backend.api.insight.record_dashboard_cache_outcome")+ @patch("products.product_analytics.backend.presentation.insight.record_dashboard_cache_outcome")@patch("posthog.caching.calculate_results.calculate_for_query_based_insight")def test_dashboard_insight_records_cache_outcome(self,@@ -561,7 +560,9 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):patch("posthog.caching.calculate_results.calculate_for_query_based_insight") as calculate_for_query_based_insight,- patch("products.product_analytics.backend.api.insight.record_dashboard_cache_outcome") as record_outcome,+ patch(+ "products.product_analytics.backend.presentation.insight.record_dashboard_cache_outcome"+ ) as record_outcome,):self.client.get(valid_url)calculate_for_query_based_insight.assert_called_once_with(@@ -1596,7 +1597,7 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):),])- @patch("products.product_analytics.backend.api.insight.report_user_action")+ @patch("products.product_analytics.backend.presentation.insight.report_user_action")def test_creating_insight_with_dashboard_fires_tile_added_event(self,_name: str,@@ -1623,7 +1624,7 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):request=ANY,)- @patch("products.product_analytics.backend.api.insight.report_user_action")+ @patch("products.product_analytics.backend.presentation.insight.report_user_action")def test_adding_insight_to_dashboard_fires_tile_added_event(self, mock_report_user_action: mock.Mock) -> None:dashboard_id, _ = self.dashboard_api.create_dashboard({"name": "test"})insight_id, _ = self.dashboard_api.create_insight({"filters": {"insight": "STICKINESS"}})@@ -1639,7 +1640,7 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):request=ANY,)- @patch("products.product_analytics.backend.api.insight.report_user_action")+ @patch("products.product_analytics.backend.presentation.insight.report_user_action")def test_non_web_retrieve_fires_insight_read_event(self, mock_report_user_action: mock.Mock) -> None:insight_id, insight_json = self.dashboard_api.create_insight({"query": DataVisualizationNode(source=HogQLQuery(query="select 1")).model_dump()}@@ -1660,7 +1661,7 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):request=ANY,)- @patch("products.product_analytics.backend.api.insight.report_user_action")+ @patch("products.product_analytics.backend.presentation.insight.report_user_action")def test_removing_insight_from_dashboard_fires_tile_removed_event(self, mock_report_user_action: mock.Mock) -> None:dashboard_id, _ = self.dashboard_api.create_dashboard({"name": "test"})insight_id, _ = self.dashboard_api.create_insight(@@ -1678,7 +1679,7 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):request=ANY,)- @patch("products.product_analytics.backend.api.insight.report_user_action")+ @patch("products.product_analytics.backend.presentation.insight.report_user_action")def test_web_retrieve_does_not_fire_insight_read_event(self, mock_report_user_action: mock.Mock) -> None:insight_id, _ = self.dashboard_api.create_insight({})mock_report_user_action.reset_mock()@@ -5136,7 +5137,7 @@ class TestInsightErrorHandling(ClickhouseTestMixin, APIBaseTest):("HogVMException", "Global variable not found: variables"),])- @patch("products.product_analytics.backend.api.insight.process_query_dict")+ @patch("products.product_analytics.backend.presentation.insight.process_query_dict")def test_trend_returns_400_for_exposed_errors(self, error_type: str, error_message: str, mock_process: mock.MagicMock) -> None:@@ -5168,7 +5169,7 @@ class TestInsightErrorHandling(ClickhouseTestMixin, APIBaseTest):("HogVMException", "Global variable not found: variables"),])- @patch("products.product_analytics.backend.api.insight.process_query_dict")+ @patch("products.product_analytics.backend.presentation.insight.process_query_dict")def test_funnel_returns_400_for_exposed_errors(self, error_type: str, error_message: str, mock_process: mock.MagicMock) -> None:@@ -5344,7 +5345,7 @@ class TestInsightBulkSetTestAccountFilter(ClickhouseTestMixin, APIBaseTest, Querself.assertEqual(self._reloaded_source(needs_change)["filterTestAccounts"], enabled)self.assertEqual(self._reloaded_source(already_set)["filterTestAccounts"], enabled)- @patch("products.product_analytics.backend.api.insight.INSIGHT_BULK_TEST_ACCOUNT_FILTER_BATCH_SIZE", 2)+ @patch("products.product_analytics.backend.presentation.insight.INSIGHT_BULK_TEST_ACCOUNT_FILTER_BATCH_SIZE", 2)def test_covers_every_insight_across_several_batches(self) -> None:insights = [self._create_query_insight(name=f"Trend {n}", filter_test_accounts=False) for n in range(5)]@@ -5444,7 +5445,7 @@ class TestInsightBulkSetTestAccountFilter(ClickhouseTestMixin, APIBaseTest, Quer("a run that flips nothing", True, {"insights_updated": 0, "insights_unchanged": 1}),])- @patch("products.product_analytics.backend.api.insight.report_user_action")+ @patch("products.product_analytics.backend.presentation.insight.report_user_action")def test_reports_the_run_for_analytics(self,_name: str,diff --git a/products/product_analytics/backend/api/test/test_insight_funnels.py b/products/product_analytics/backend/presentation/test/test_insight_funnels.pysimilarity index 100%rename from products/product_analytics/backend/api/test/test_insight_funnels.pyrename to products/product_analytics/backend/presentation/test/test_insight_funnels.pydiff --git a/products/product_analytics/backend/api/test/test_insight_metadata.py b/products/product_analytics/backend/presentation/test/test_insight_metadata.pysimilarity index 99%rename from products/product_analytics/backend/api/test/test_insight_metadata.pyrename to products/product_analytics/backend/presentation/test/test_insight_metadata.pyindex 9d68196ab840..350e8708641e 100644--- a/products/product_analytics/backend/api/test/test_insight_metadata.py+++ b/products/product_analytics/backend/presentation/test/test_insight_metadata.py@@ -8,7 +8,7 @@ from rest_framework import statusfrom posthog.llm.completions import OpenAICompletion-MOCK_PATH = "products.product_analytics.backend.api.insight_metadata.hit_openai"+MOCK_PATH = "products.product_analytics.backend.presentation.insight_metadata.hit_openai"def _completion(content: str) -> OpenAICompletion:diff --git a/products/product_analytics/backend/api/test/test_insight_query.py b/products/product_analytics/backend/presentation/test/test_insight_query.pysimilarity index 99%rename from products/product_analytics/backend/api/test/test_insight_query.pyrename to products/product_analytics/backend/presentation/test/test_insight_query.pyindex e32a8495c705..0ef7364fc39c 100644--- a/products/product_analytics/backend/api/test/test_insight_query.py+++ b/products/product_analytics/backend/presentation/test/test_insight_query.py@@ -8,11 +8,11 @@ from rest_framework import statusfrom posthog import schemafrom posthog.api.test.dashboards import DashboardAPI-from products.product_analytics.backend.api.insight import (+from products.product_analytics.backend.facade.models import Insight+from products.product_analytics.backend.presentation.insight import (AUTO_WRAPPED_INSIGHT_QUERY_KINDS,BARE_RENDERED_INSIGHT_VIZ_SOURCE_KINDS,)-from products.product_analytics.backend.models.insight import Insightfrom ee.api.test.base import LicensedTestMixindiff --git a/products/product_analytics/backend/api/test/test_insight_variable.py b/products/product_analytics/backend/presentation/test/test_insight_variable.pysimilarity index 98%rename from products/product_analytics/backend/api/test/test_insight_variable.pyrename to products/product_analytics/backend/presentation/test/test_insight_variable.pyindex 61dc6a8ab6da..a463e519c531 100644--- a/products/product_analytics/backend/api/test/test_insight_variable.py+++ b/products/product_analytics/backend/presentation/test/test_insight_variable.py@@ -9,9 +9,12 @@ from rest_framework.exceptions import PermissionDeniedfrom posthog.auth import SharingAccessTokenAuthentication-from products.product_analytics.backend.api.insight_variable import InsightVariableSerializer, InsightVariableViewSet-from products.product_analytics.backend.logic import map_stale_to_latest-from products.product_analytics.backend.models.insight_variable import InsightVariable+from products.product_analytics.backend.facade.api import map_stale_to_latest+from products.product_analytics.backend.facade.models import InsightVariable+from products.product_analytics.backend.presentation.insight_variable import (+ InsightVariableSerializer,+ InsightVariableViewSet,+)class TestInsightVariable(APIBaseTest):diff --git a/products/product_analytics/backend/api/test/test_paths_v2.py b/products/product_analytics/backend/presentation/test/test_paths_v2.pysimilarity index 95%rename from products/product_analytics/backend/api/test/test_paths_v2.pyrename to products/product_analytics/backend/presentation/test/test_paths_v2.pyindex 64b3dfad4390..b21af618f29f 100644--- a/products/product_analytics/backend/api/test/test_paths_v2.py+++ b/products/product_analytics/backend/presentation/test/test_paths_v2.py@@ -17,12 +17,12 @@ from posthog.schema import (PathsV2StepSource,)-from products.product_analytics.backend.api.paths_v2 import PathsV2SegmentToFunnelRequestSerializer-from products.product_analytics.backend.hogql_queries.paths_v2.funnel_converter import (+from products.product_analytics.backend.facade.queries import (+ PATHS_V2_OTHER,anchored_segment_to_funnels_query,edge_to_funnels_query,)-from products.product_analytics.backend.hogql_queries.paths_v2.path_item import PATHS_V2_OTHER+from products.product_analytics.backend.presentation.paths_v2 import PathsV2SegmentToFunnelRequestSerializerDATE_RANGE = DateRange(date_from="2023-03-01", date_to="2023-03-31")diff --git a/products/product_analytics/backend/routes.py b/products/product_analytics/backend/routes.pyindex 265de184d93f..66a133b26896 100644--- a/products/product_analytics/backend/routes.py+++ b/products/product_analytics/backend/routes.py@@ -3,10 +3,10 @@ from posthog.api.routing import RouterRegistryfrom posthog.settings import EE_AVAILABLEimport products.alerts.backend.api.alert as alert-from products.product_analytics.backend.api.insight import InsightViewSet-from products.product_analytics.backend.api.insight_ee import EnterpriseInsightsViewSet-from products.product_analytics.backend.api.insight_variable import InsightVariableViewSet-from products.product_analytics.backend.api.paths_v2 import PathsV2ViewSet+from products.product_analytics.backend.presentation.insight import InsightViewSet+from products.product_analytics.backend.presentation.insight_ee import EnterpriseInsightsViewSet+from products.product_analytics.backend.presentation.insight_variable import InsightVariableViewSet+from products.product_analytics.backend.presentation.paths_v2 import PathsV2ViewSetdef register_routes(routers: RouterRegistry) -> None:diff --git a/products/product_analytics/tsconfig.json b/products/product_analytics/tsconfig.jsonnew file mode 100644index 000000000000..fe425d6fcba8--- /dev/null+++ b/products/product_analytics/tsconfig.json@@ -0,0 +1,6 @@+{+ "extends": "../../tsconfig.json",+ "compilerOptions": {+ "composite": true+ }+}diff --git a/products/pulse/backend/api/brief.py b/products/pulse/backend/api/brief.pyindex 3ea0454df48e..d44c40c7c4b4 100644--- a/products/pulse/backend/api/brief.py+++ b/products/pulse/backend/api/brief.py@@ -26,7 +26,7 @@ from posthog.slo.types import SloArea, SloConfig, SloOperationfrom posthog.temporal.common.client import sync_connectfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.pulse.backend.config import WORKFLOW_EXECUTION_TIMEOUTfrom products.pulse.backend.models import BriefConfig, ProductBrieffrom products.pulse.backend.temporal.inputs import GENERATE_BRIEF_WORKFLOW_NAME, GenerateBriefWorkflowInputsdiff --git a/products/pulse/backend/generation/persist.py b/products/pulse/backend/generation/persist.pyindex adb3f704db50..8e3a7efab241 100644--- a/products/pulse/backend/generation/persist.py+++ b/products/pulse/backend/generation/persist.py@@ -11,7 +11,7 @@ from products.annotations.backend.models.annotation import Annotationfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.experiments.backend.models.experiment import Experimentfrom products.exports.backend.models.subscription import Subscription-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.pulse.backend.generation.schemas import BriefOut, BriefSectionOut, OpportunityOutfrom products.pulse.backend.models import Opportunity, ProductBrief, ResourceLink, build_actionfrom products.pulse.backend.sources.base import EvidenceRef, EvidenceType, SourceItem, build_evidence_indexdiff --git a/products/pulse/backend/sources/anchored_dashboards.py b/products/pulse/backend/sources/anchored_dashboards.pyindex 661446fcd6d3..1a2db8a102fe 100644--- a/products/pulse/backend/sources/anchored_dashboards.py+++ b/products/pulse/backend/sources/anchored_dashboards.py@@ -4,7 +4,7 @@ from posthog.models.team import Teamfrom posthog.rbac.user_access_control import UserAccessControlfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.pulse.backend.config import BriefSettingsfrom products.pulse.backend.models import BriefConfigfrom products.pulse.backend.sources.base import SourceItemdiff --git a/products/pulse/backend/sources/anchored_insights.py b/products/pulse/backend/sources/anchored_insights.pyindex 87aeef6a9b46..bd9527acda64 100644--- a/products/pulse/backend/sources/anchored_insights.py+++ b/products/pulse/backend/sources/anchored_insights.py@@ -3,7 +3,7 @@ from django.db.models import QuerySetfrom posthog.models.team import Teamfrom posthog.rbac.user_access_control import UserAccessControl-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.pulse.backend.config import BriefSettingsfrom products.pulse.backend.models import BriefConfigfrom products.pulse.backend.sources.base import SourceItemdiff --git a/products/pulse/backend/sources/resource_health.py b/products/pulse/backend/sources/resource_health.pyindex c8abe810d2d9..9493a9f3d3e0 100644--- a/products/pulse/backend/sources/resource_health.py+++ b/products/pulse/backend/sources/resource_health.py@@ -14,7 +14,7 @@ from posthog.schema_enums import AlertStatefrom products.alerts.backend.models import AlertConfigurationfrom products.exports.backend.models.subscription import SubscriptionDelivery-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.pulse.backend.config import MAX_ITEMS_PER_DETECTOR, STUCK_REFRESH_ATTEMPTSfrom products.pulse.backend.models import BriefConfigfrom products.pulse.backend.sources.base import EvidenceRef, EvidenceType, SourceItem, SourceItemKinddiff --git a/products/pulse/backend/sources/strategy.py b/products/pulse/backend/sources/strategy.pyindex 5e7d91a7ae67..27da85b2cdfe 100644--- a/products/pulse/backend/sources/strategy.py+++ b/products/pulse/backend/sources/strategy.py@@ -10,7 +10,7 @@ from posthog.exceptions_capture import capture_exceptionfrom posthog.models.team import Teamfrom posthog.rbac.user_access_control import UserAccessControl-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.pulse.backend.config import BriefSettingsfrom products.pulse.backend.sources.base import EvidenceRef, EvidenceType, SourceItem, SourceItemKindfrom products.pulse.backend.urls import insight_urldiff --git a/products/pulse/backend/test/test_anchored_dashboards.py b/products/pulse/backend/test/test_anchored_dashboards.pyindex fa6136f0e498..11c4b84ee249 100644--- a/products/pulse/backend/test/test_anchored_dashboards.py+++ b/products/pulse/backend/test/test_anchored_dashboards.py@@ -8,7 +8,7 @@ from posthog.rbac.user_access_control import UserAccessControlfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.pulse.backend.models import BriefConfigfrom products.pulse.backend.sources.anchored_dashboards import AnchoredDashboardsSourcefrom products.pulse.backend.sources.anchored_insights import AnchoredInsightsSourcediff --git a/products/pulse/backend/test/test_anchored_insights.py b/products/pulse/backend/test/test_anchored_insights.pyindex 95ba58e5bb6a..3cae627c7c27 100644--- a/products/pulse/backend/test/test_anchored_insights.py+++ b/products/pulse/backend/test/test_anchored_insights.py@@ -6,7 +6,7 @@ from parameterized import parameterizedfrom posthog.models.scoping import team_scopefrom posthog.rbac.user_access_control import UserAccessControl-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.pulse.backend.config import DEFAULT_BRIEF_SETTINGS, BriefSettingsfrom products.pulse.backend.models import BriefConfigfrom products.pulse.backend.sources.anchored_insights import AnchoredInsightsSourcediff --git a/products/pulse/backend/test/test_api.py b/products/pulse/backend/test/test_api.pyindex 742102ab1614..40df476325cf 100644--- a/products/pulse/backend/test/test_api.py+++ b/products/pulse/backend/test/test_api.py@@ -15,7 +15,7 @@ from posthog.models.team import Teamfrom posthog.rate_limit import AIBurstRateThrottle, AISustainedRateThrottlefrom posthog.slo.types import SloOperation-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.pulse.backend.api.brief import ProductBriefViewSetfrom products.pulse.backend.models import BriefConfig, ProductBriefdiff --git a/products/pulse/backend/test/test_models.py b/products/pulse/backend/test/test_models.pyindex 27c7e99ccc9f..892199fa9e56 100644--- a/products/pulse/backend/test/test_models.py+++ b/products/pulse/backend/test/test_models.py@@ -9,7 +9,7 @@ from parameterized import parameterizedfrom posthog.models.scoping import team_scope-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.pulse.backend.models import (ActionStatus,ActionType,diff --git a/products/pulse/backend/test/test_persist.py b/products/pulse/backend/test/test_persist.pyindex 2872308edaa8..856d2e5689ea 100644--- a/products/pulse/backend/test/test_persist.py+++ b/products/pulse/backend/test/test_persist.py@@ -12,7 +12,7 @@ from posthog.schema_enums import AlertStatefrom products.alerts.backend.models import AlertConfigurationfrom products.exports.backend.models.subscription import Subscription-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.pulse.backend.generation.persist import _fingerprint, persist_brief_outputfrom products.pulse.backend.generation.schemas import BriefOut, BriefSectionOut, OpportunityOutfrom products.pulse.backend.models import (diff --git a/products/pulse/backend/test/test_resource_health_source.py b/products/pulse/backend/test/test_resource_health_source.pyindex 299751a3f332..2397f0fae89d 100644--- a/products/pulse/backend/test/test_resource_health_source.py+++ b/products/pulse/backend/test/test_resource_health_source.py@@ -18,7 +18,7 @@ from products.alerts.backend.models import AlertConfigurationfrom products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTilefrom products.exports.backend.models.subscription import Subscription, SubscriptionDelivery-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.pulse.backend.sources.base import EvidenceRef, EvidenceType, SourceItemfrom products.pulse.backend.sources.resource_health import STUCK_REFRESH_ATTEMPTS, ResourceHealthSourcediff --git a/products/reminders/backend/constants.py b/products/reminders/backend/constants.pyindex 8ec2bf89789a..8e0ee05750a0 100644--- a/products/reminders/backend/constants.py+++ b/products/reminders/backend/constants.py@@ -7,7 +7,7 @@ from products.dashboards.backend.models.dashboard import Dashboardfrom products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.surveys.backend.models import Survey# resource_type -> (model, lookup_field, frontend_path_segment)diff --git a/products/signals/backend/test/test_scout_harness_profile.py b/products/signals/backend/test/test_scout_harness_profile.pyindex 9d60627b535a..8d9759394bfe 100644--- a/products/signals/backend/test/test_scout_harness_profile.py+++ b/products/signals/backend/test/test_scout_harness_profile.py@@ -35,7 +35,7 @@ from products.dashboards.backend.models.dashboard import Dashboardfrom products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlagfrom products.notebooks.backend.models import Notebook-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.signals.backend.models import (SignalProjectProfile,SignalReport,diff --git a/products/slack_app/backend/slack_link_unfurl.py b/products/slack_app/backend/slack_link_unfurl.pyindex 5f0354e3223d..58994749fcf5 100644--- a/products/slack_app/backend/slack_link_unfurl.py+++ b/products/slack_app/backend/slack_link_unfurl.py@@ -19,7 +19,7 @@ from posthog.utils import get_instance_regionfrom products.conversations.backend.models.ticket import Ticketfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.slack_app.backend.services.slack_messages import UNFURL_OPT_OUT_PARAMfrom products.tasks.backend.facade import api as tasks_facadefrom products.tasks.backend.facade.contracts import TaskSlackUnfurlDTOdiff --git a/products/slack_app/backend/tests/test_link_unfurl.py b/products/slack_app/backend/tests/test_link_unfurl.pyindex 0943a68b61f1..f252775c56d9 100644--- a/products/slack_app/backend/tests/test_link_unfurl.py+++ b/products/slack_app/backend/tests/test_link_unfurl.py@@ -20,7 +20,7 @@ from posthog.models.user_integration import UserIntegrationfrom products.conversations.backend.models.ticket import Ticketfrom products.dashboards.backend.models.dashboard import Dashboard-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.slack_app.backend.api import ROUTE_HANDLED_LOCALLY, route_posthog_code_event_to_relevant_regionfrom products.slack_app.backend.models import SlackChannelfrom products.slack_app.backend.services.slack_auth import write_auth_state_okdiff --git a/products/slack_app/backend/tests/test_posthog_code_interactivity.py b/products/slack_app/backend/tests/test_posthog_code_interactivity.pyindex 1baff7c7bfde..96baa00dce7f 100644--- a/products/slack_app/backend/tests/test_posthog_code_interactivity.py+++ b/products/slack_app/backend/tests/test_posthog_code_interactivity.py@@ -25,7 +25,7 @@ from posthog.schema_enums import AlertStatefrom posthog.utils import relative_date_parsefrom products.alerts.backend.models.alert import AlertCheck, AlertConfiguration-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.slack_app.backend.api import (_extract_alert_snooze_hints,_handle_insight_alert_snooze,diff --git a/products/surveys/backend/api/survey.py b/products/surveys/backend/api/survey.pyindex 7da5808d95f7..3a7042f4350a 100644--- a/products/surveys/backend/api/survey.py+++ b/products/surveys/backend/api/survey.py@@ -74,7 +74,7 @@ from products.feature_flags.backend.api.feature_flag import (assert_feature_flag_write_scope,)from products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.surveys.backend.models import MAX_ITERATION_COUNT, Survey, SurveyResponseArchive, ensure_question_idsfrom products.surveys.backend.responses import (SurveyRates,diff --git a/products/surveys/backend/api/test/test_survey.py b/products/surveys/backend/api/test/test_survey.pyindex 6918c7df420b..5ddcbc3147bc 100644--- a/products/surveys/backend/api/test/test_survey.py+++ b/products/surveys/backend/api/test/test_survey.py@@ -30,7 +30,7 @@ from posthog.test.persons import create_personfrom products.actions.backend.models.action import Actionfrom products.cohorts.backend.models.cohort import Cohortfrom products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.product_tours.backend.models import ProductTourfrom products.surveys.backend.api.survey import (get_survey_api_translations,diff --git a/products/surveys/backend/test_max_tools.py b/products/surveys/backend/test_max_tools.pyindex e1d5a1a33bf8..91c21d3468ee 100644--- a/products/surveys/backend/test_max_tools.py+++ b/products/surveys/backend/test_max_tools.py@@ -12,7 +12,7 @@ from langchain_core.runnables import RunnableConfigfrom parameterized import parameterizedfrom products.feature_flags.backend.models.feature_flag import FeatureFlag-from products.product_analytics.backend.models.insight import Insight+from products.product_analytics.backend.facade.models import Insightfrom products.surveys.backend.models import Surveyfrom .max_tools import CreateSurveyTool, EditSurveyTool, SimpleSurveyQuestion, SurveyAnalysisTooldiff --git a/pyproject.toml b/pyproject.tomlindex 0f6aff7a8f54..60d9933c6a7d 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -620,6 +620,26 @@ ignore_imports = ["products.notebooks.backend.presentation.views.notebook -> products.notebooks.backend.sql_v2_state","products.notebooks.backend.presentation.views.notebook -> products.notebooks.backend.temporal.client","products.notebooks.backend.presentation.views.notebook -> products.notebooks.backend.temporal.sql_v2",+ # TODO: product_analytics presentation wave — newly surfaced debt from the backend/api/ →+ # backend/presentation/ rename (same situation as experiments below), not new coupling. The+ # insight viewset renders dashboard tiles, alert state, cohort filters and annotation context+ # in-process; these drain as those products expose facades (or the rendering moves behind+ # product_analytics' own facade). backend:contract-check stays off until this list is empty.+ "products.product_analytics.backend.presentation.insight -> products.alerts.backend.api.alert",+ "products.product_analytics.backend.presentation.insight -> products.alerts.backend.models.alert",+ "products.product_analytics.backend.presentation.insight -> products.cohorts.backend.models.cohort",+ "products.product_analytics.backend.presentation.insight -> products.dashboards.backend.access",+ "products.product_analytics.backend.presentation.insight -> products.dashboards.backend.models.dashboard",+ "products.product_analytics.backend.presentation.insight -> products.dashboards.backend.models.dashboard_tile",+ "products.product_analytics.backend.presentation.insight_ee -> products.dashboards.backend.models.dashboard",+ "products.product_analytics.backend.presentation.insight_suggestions -> products.annotations.backend.api.annotation_context",+ "products.product_analytics.backend.presentation.test.test_insight -> products.alerts.backend.models.alert",+ "products.product_analytics.backend.presentation.test.test_insight -> products.cohorts.backend.models.cohort",+ "products.product_analytics.backend.presentation.test.test_insight -> products.dashboards.backend.access",+ "products.product_analytics.backend.presentation.test.test_insight -> products.dashboards.backend.models.dashboard",+ "products.product_analytics.backend.presentation.test.test_insight -> products.dashboards.backend.models.dashboard_tile",+ "products.product_analytics.backend.presentation.test.test_deprecated_dashboards_field -> products.dashboards.backend.models.dashboard",+ "products.product_analytics.backend.presentation.test.test_deprecated_dashboards_field -> products.dashboards.backend.models.dashboard_tile",# TODO: experiments presentation wave — these were invisible to import-linter until# backend/presentation/ got its package marker, so they are newly surfaced debt, not new# coupling. experiments is not isolated, so nothing was being skipped on their account.diff --git a/tach.toml b/tach.tomlindex 2db6f0332687..7d725f5b64df 100644--- a/tach.toml+++ b/tach.toml@@ -628,6 +628,23 @@ depends_on = []layer = "modules"+# product_analytics — external consumers go through the facade: facade.api for data+# capabilities, facade.queries for the QueryRunner wiring core dispatches on, and+# facade.models for the watched-models allowance crossings (Insight, InsightVariable,+# InsightViewed — see MODEL_CROSSINGS and architecture.md § Wiring couplings).+# presentation.* carries the DRF serializers sharing, dashboards and alerts use to+# render insights in-process — facades must not import DRF, so presentation exposure+# is the sanctioned channel (products.metrics precedent).+[[interfaces]]+expose = [+ "backend\\.facade.*",+ "backend\\.presentation.*",+ "backend\\.routes.*",+]+from = [+ "products.product_analytics",+]+[[modules]]path = "products.product_tours"depends_on = [diff --git a/tools/hogli-commands/hogli_commands/product/isolation.py b/tools/hogli-commands/hogli_commands/product/isolation.pyindex 5de3284dadb6..70d5a1e5b794 100644--- a/tools/hogli-commands/hogli_commands/product/isolation.py+++ b/tools/hogli-commands/hogli_commands/product/isolation.py@@ -486,6 +486,7 @@ MODEL_CROSSINGS: frozenset[tuple[str, str]] = frozenset({("product_analytics", "Insight"),("product_analytics", "InsightVariable"),+ ("product_analytics", "InsightViewed"),("warehouse_sources", "DataWarehouseCredential"),("warehouse_sources", "DataWarehouseTable"),("warehouse_sources", "ExternalDataJob"),diff --git a/tools/snob_backend_test_selection_shadow.py b/tools/snob_backend_test_selection_shadow.pyindex d361489553a0..8237a400ca34 100755--- a/tools/snob_backend_test_selection_shadow.py+++ b/tools/snob_backend_test_selection_shadow.py@@ -610,7 +610,7 @@ _POE_PREFIXES = ("posthog/clickhouse/","posthog/queries/","ee/clickhouse/",- "products/product_analytics/backend/api/test/",+ "products/product_analytics/backend/presentation/test/",)_CORE_IGNORED_PREFIXES = ("posthog/dags/", "common/hogvm/python/test/")