Skip to content

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

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.yml
index 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" ]]; then
full_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=SC2086
diff --git a/.github/scripts/turbo-discover.js b/.github/scripts/turbo-discover.js
index 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.yml
index 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" ]]; then
full_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=SC2086
diff --git a/.semgrep/rules/security/idor-team-scoped-models.py b/.semgrep/rules/security/idor-team-scoped-models.py
index 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_404
from posthog.models import Notebook
from products.approvals.backend.models import ChangeRequest
from products.cohorts.backend.models.cohort import Cohort
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.actions.backend.models.action import Action
from posthog.models.personal_api_key import PersonalAPIKey
from posthog.models.project import Project
diff --git a/ee/api/rbac/test/test_access_control.py b/ee/api/rbac/test/test_access_control.py
index 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 Ticket
from products.dashboards.backend.models.dashboard import Dashboard
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.warehouse_sources.backend.models import DataWarehouseTable, ExternalDataSource
from ee.api.rbac.access_control_settings import _display_model, resources_with_object_access_controls
diff --git a/ee/api/subscription.py b/ee/api/subscription.py
index 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 Insight
from ee.billing.quota_limiting import QuotaLimitingCaches, QuotaResource, is_team_limited
from ee.tasks.subscriptions.auto_disable import validate_re_enable
diff --git a/ee/api/test/test_insight.py b/ee/api/test/test_insight.py
index 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_queries
from products.dashboards.backend.models.dashboard import Dashboard
from 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 Insight
from ee.api.test.base import APILicensedTest
from ee.models import DashboardPrivilege
diff --git a/ee/api/test/test_subscription.py b/ee/api/test/test_subscription.py
index 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 Insight
from ee.api.test.base import APILicensedTest
from ee.models.rbac.access_control import AccessControl
diff --git a/ee/api/test/test_tagged_item.py b/ee/api/test/test_tagged_item.py
index 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 TaggedItem
from products.dashboards.backend.models.dashboard import Dashboard
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
# 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.py
index 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, VisualizationArt
from posthog.models import Team
from 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 Insight
from ee.hogai.artifacts.handlers.base import ArtifactHandler, EnrichmentContext, register_handler
from ee.hogai.artifacts.types import (
diff --git a/ee/hogai/artifacts/test/test_manager.py b/ee/hogai/artifacts/test/test_manager.py
index 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 Insight
from ee.hogai.artifacts.manager import ArtifactManager
from ee.hogai.artifacts.types import StoredNotebookArtifactContent
diff --git a/ee/hogai/artifacts/types.py b/ee/hogai/artifacts/types.py
index 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 Insight
class VisualizationRefBlock(BaseModel):
diff --git a/ee/hogai/chat_agent/insights/nodes.py b/ee/hogai/chat_agent/insights/nodes.py
index 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, AssistantToolCal
from posthog.exceptions_capture import capture_exception
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from ee.hogai.context.insight.query_executor import AssistantQueryExecutor
from ee.hogai.core.node import AssistantNode
diff --git a/ee/hogai/chat_agent/insights/test/test_nodes.py b/ee/hogai/chat_agent/insights/test/test_nodes.py
index 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, InsightViewed
from ee.hogai.artifacts.manager import ArtifactManager
from ee.hogai.chat_agent.insights.nodes import InsightDict, InsightSearchNode, NoInsightsException
diff --git a/ee/hogai/chat_agent/sql/mixins.py b/ee/hogai/chat_agent/sql/mixins.py
index 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 Team
from posthog.models.user import User
from 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 InsightVariable
from ee.hogai.chat_agent.schema_generator.utils import SchemaGeneratorOutput
from ee.hogai.core.mixins import AssistantContextMixin
diff --git a/ee/hogai/chat_agent/sql/test/test_sql_mixins.py b/ee/hogai/chat_agent/sql/test/test_sql_mixins.py
index 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, HogQLQuery
from 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 InsightVariable
from ee.hogai.chat_agent.schema_generator.parsers import PydanticOutputParserException
from ee.hogai.chat_agent.sql.mixins import HogQLGeneratorMixin, SQLSchemaGeneratorOutput
diff --git a/ee/hogai/context/entity_search/context.py b/ee/hogai/context/entity_search/context.py
index 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 FeatureFlag
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.surveys.backend.models import Survey
from ee.hogai.artifacts.handlers.base import get_handler_for_content_type
diff --git a/ee/hogai/context/entity_search/test/test_context.py b/ee/hogai/context/entity_search/test/test_context.py
index 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 Cohort
from products.dashboards.backend.models.dashboard import Dashboard
from products.experiments.backend.models.experiment import Experiment
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, InsightViewed
from products.surveys.backend.models import Survey
from ee.hogai.context import AssistantContextManager
diff --git a/ee/hogai/context/insight/context.py b/ee/hogai/context/insight/context.py
index 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, User
from posthog.sync import database_sync_to_async
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from ee.hogai.context.insight.query_executor import execute_and_format_query
from ee.hogai.tool_errors import MaxToolRetryableError
diff --git a/ee/hogai/eval/ci/max_tools/eval_upsert_dashboard.py b/ee/hogai/eval/ci/max_tools/eval_upsert_dashboard.py
index 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 Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile
from 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 Insight
from ee.hogai.chat_agent import AssistantGraph
from ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointer
diff --git a/ee/hogai/tools/execute_sql/test/test_mcp_tool.py b/ee/hogai/tools/execute_sql/test/test_mcp_tool.py
index 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, HogQLQuery
from posthog.models import EventDefinition
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from ee.hogai.tool_errors import MaxToolRetryableError
from 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.py
index 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 Insight
from ee.hogai.context.context import AssistantContextManager
from ee.hogai.tools.execute_sql.tool import ExecuteSQLTool, ExecuteSQLToolArgs
diff --git a/ee/hogai/tools/read_data/test/test_tool.py b/ee/hogai/tools/read_data/test/test_tool.py
index 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 Experiment
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
from products.surveys.backend.models import Survey
from 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.py
index 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 Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile, Text
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 Insight
from ee.hogai.artifacts.types import ModelArtifactResult, StateArtifactResult, VisualizationWithSourceResult
from ee.hogai.context.context import AssistantContextManager
diff --git a/ee/hogai/tools/upsert_dashboard/tool.py b/ee/hogai/tools/upsert_dashboard/tool.py
index 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 pluralize
from products.dashboards.backend.models.dashboard import Dashboard
from 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 Insight
from ee.hogai.artifacts.types import ModelArtifactResult, VisualizationWithSourceResult
from ee.hogai.context.dashboard.context import DashboardContext, DashboardInsightContext
diff --git a/ee/tasks/subscriptions/subscription_utils.py b/ee/tasks/subscriptions/subscription_utils.py
index 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_group
from products.exports.backend.models.exported_asset import ExportedAsset
from 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
logger = structlog.get_logger(__name__)
diff --git a/ee/tasks/test/subscriptions/test_email_subscriptions.py b/ee/tasks/test/subscriptions/test_email_subscriptions.py
index 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_messages
from products.dashboards.backend.models.dashboard import Dashboard
from products.exports.backend.models.exported_asset import ExportedAsset
from 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
from ee.tasks.subscriptions.email_subscriptions import send_email_subscription_report
from ee.tasks.test.subscriptions.subscriptions_test_factory import create_subscription
diff --git a/ee/tasks/test/subscriptions/test_slack_subscriptions.py b/ee/tasks/test/subscriptions/test_slack_subscriptions.py
index 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 Integration
from products.dashboards.backend.models.dashboard import Dashboard
from products.exports.backend.models.exported_asset import ExportedAsset
from 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
from 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.py
index 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 parameterized
from products.dashboards.backend.models.dashboard import Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile
from 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 Insight
from 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.py
index 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 SharingConfiguration
from products.dashboards.backend.models.dashboard import Dashboard
from products.exports.backend.models.exported_asset import ExportedAsset
from 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
from ee.tasks.slack import handle_slack_event
diff --git a/posthog/admin/test_admin.py b/posthog/admin/test_admin.py
index 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 Dashboard
from products.dashboards.backend.models.dashboard_templates import DashboardTemplate
from products.dashboards.backend.models.dashboard_tile import Text
from 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 Insight
from products.product_tours.backend.models import ProductTour
from products.surveys.backend.models import Survey
from products.warehouse_sources.backend.facade.models import DataWarehouseTable, ExternalDataSchema
diff --git a/posthog/api/cohort.py b/posthog/api/cohort.py
index 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 CohortTypeValidationSerializer
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
# 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.py
index 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 Experiment
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.links.backend.models import Link
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.surveys.backend.models import Survey
from ee.models.rbac.access_control import AccessControl
diff --git a/posthog/api/file_system/test/test_file_system_shortcut.py b/posthog/api/file_system/test/test_file_system_shortcut.py
index 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 User
from posthog.models.file_system.file_system_shortcut import FileSystemShortcut
from products.dashboards.backend.models.dashboard import Dashboard
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from ee.models.rbac.access_control import AccessControl
diff --git a/posthog/api/my_notifications.py b/posthog/api/my_notifications.py
index 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 HogFunction
from products.cohorts.backend.models.cohort import Cohort
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from 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 Insight
class MyNotificationsSerializer(serializers.ModelSerializer):
diff --git a/posthog/api/search.py b/posthog/api/search.py
index 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 EarlyAccessFeature
from products.experiments.backend.models.experiment import Experiment
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.surveys.backend.models import Survey
from products.workflows.backend.models.hog_flow.hog_flow import HogFlow
diff --git a/posthog/api/sharing.py b/posthog/api/sharing.py
index 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_persisted
from products.notebooks.backend.facade.content import extract_inline_query_nodes, filter_notebook_content_for_sharing
from products.notebooks.backend.models import Notebook
from 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 InsightSerializer
logger = structlog.get_logger(__name__)
diff --git a/posthog/api/sharing_publish_gate.py b/posthog/api/sharing_publish_gate.py
index 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, UserAccessContro
from products.dashboards.backend.models.dashboard import Dashboard
from products.notebooks.backend.facade.content import extract_inline_query_nodes, extract_referenced_insight_short_ids
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
def check_can_add_insight_to_shared_dashboard(
diff --git a/posthog/api/test/dashboards/test_dashboard.py b/posthog/api/test/dashboards/test_dashboard.py
index 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 Dashboard
from products.dashboards.backend.models.dashboard_templates import DashboardTemplate
from 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 InsightSerializer
from 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.py
index 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_cohorts
from products.cohorts.backend.models.util import count_cohort_members, list_cohort_member_ids
from products.exports.backend.api.test.test_exports import TestExportMixin
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
from 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 Insight
response = 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 Insight
response = 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 Insight
response = 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 Insight
response = 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 Insight
response = 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 Insight
response = 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.py
index 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 Experiment
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.links.backend.models import Link
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.surveys.backend.models import Survey
diff --git a/posthog/api/test/test_personal_api_keys.py b/posthog/api/test/test_personal_api_keys.py
index 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 Team
from posthog.models.user import User
from 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 Insight
ErrorTrackingIssue = apps.get_model("error_tracking", "ErrorTrackingIssue")
diff --git a/posthog/api/test/test_query.py b/posthog/api/test/test_query.py
index 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 UUIDT
from products.event_definitions.backend.models.property_definition import PropertyDefinition, PropertyType
from 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 InsightVariable
from products.warehouse_sources.backend.facade.models import MANAGED_WAREHOUSE_SOURCE_PREFIX, ExternalDataSource
from products.warehouse_sources.backend.facade.types import ExternalDataSourceType
diff --git a/posthog/api/test/test_resource_transfer.py b/posthog/api/test/test_resource_transfer.py
index 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 Cohort
from products.dashboards.backend.models.dashboard import Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile
from 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 Insight
from products.surveys.backend.models import Survey
from ee.models.rbac.access_control import AccessControl
diff --git a/posthog/api/test/test_search.py b/posthog/api/test/test_search.py
index 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 EarlyAccessFeature
from products.event_definitions.backend.models.event_definition import EventDefinition
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.workflows.backend.models.hog_flow.hog_flow import HogFlow
from ee.models.rbac.access_control import AccessControl
diff --git a/posthog/api/test/test_search_match_type_mixin.py b/posthog/api/test/test_search_match_type_mixin.py
index 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 SearchMatchTypeSerializerMixin
from products.alerts.backend.api.alert import AlertSerializer
from products.cdp.backend.api.hog_function import HogFunctionMinimalSerializer, HogFunctionSerializer
from 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, InsightSerializer
from products.product_tours.backend.api.product_tour import ProductTourSerializer
from products.surveys.backend.api.survey import SurveySerializer
diff --git a/posthog/api/test/test_sharing.py b/posthog/api/test/test_sharing.py
index 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 DashboardWidget
from products.data_modeling.backend.facade.models import DataWarehouseSavedQuery
from products.exports.backend.models.exported_asset import ExportedAsset, get_render_access_token
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from 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_template
def 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_template
def 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_template
def 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_template
def 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_template
def 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.py
index 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 AvailableFeature
from posthog.models.sharing_configuration import SharingConfiguration
from products.dashboards.backend.models.dashboard import Dashboard
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
class 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 first
variable = InsightVariable.objects.create(
diff --git a/posthog/api/test/test_tagged_item.py b/posthog/api/test/test_tagged_item.py
index 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, Team
from posthog.models.tagged_item import TaggedItem
from products.dashboards.backend.models.dashboard import Dashboard
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
class TestTaggedItemSerializerMixin(APIBaseTest):
diff --git a/posthog/caching/calculate_results.py b/posthog/caching/calculate_results.py
index 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_query
from products.dashboards.backend.models.dashboard import Dashboard
from 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_hash
if TYPE_CHECKING:
from posthog.caching.insight_result import InsightResult
diff --git a/posthog/caching/test/test_calculate_results.py b/posthog/caching/test/test_calculate_results.py
index 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, RawCachedQueryResponse
from 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 Insight
class TestCalculateForQueryBasedInsight(BaseTest):
diff --git a/posthog/caching/test/test_warming.py b/posthog/caching/test/test_warming.py
index 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 ClickHouseAtCapacity
from products.dashboards.backend.models.dashboard import Dashboard
from 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, InsightViewed
class TestWarming(APIBaseTest):
diff --git a/posthog/caching/warming.py b/posthog/caching/warming.py
index 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_audit
from posthog.tasks.utils import CeleryQueue
from 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 Insight
logger = structlog.get_logger(__name__)
diff --git a/posthog/helpers/dashboard_templates.py b/posthog/helpers/dashboard_templates.py
index 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 Dashboard
from products.dashboards.backend.models.dashboard_templates import DashboardTemplate
from products.dashboards.backend.models.dashboard_tile import ButtonTile, DashboardTile, Text
from 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 Insight
if TYPE_CHECKING:
from posthog.rbac.user_access_control import UserAccessControl
diff --git a/posthog/hogql/ACCESS_CONTROL.md b/posthog/hogql/ACCESS_CONTROL.md
index 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.py
index 9ed7d5bef555..d020135f67b8 100644
--- a/posthog/hogql/autocomplete.py
+++ b/posthog/hogql/autocomplete.py
@@ -59,7 +59,7 @@ from posthog.models.team.team import Team
from posthog.models.user import User
from 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 InsightVariable
from common.hogvm.python.stl import STL
from common.hogvm.python.stl.bytecode import BYTECODE_STL
diff --git a/posthog/hogql/database/schema/test/test_system_tables.py b/posthog/hogql/database/schema/test/test_system_tables.py
index 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 ExportedAsset
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.logs.backend.models import LogsAlertConfiguration, LogsView
from 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, InsightVariable
from products.surveys.backend.models import Survey, SurveyResponseArchive
from 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.py
index 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_FIELDS
from products.data_modeling.backend.facade.models import DataWarehouseSavedQuery
from 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 InsightVariable
from products.warehouse_sources.backend.facade.models import (
DataWarehouseCredential,
DataWarehouseTable,
diff --git a/posthog/hogql/test/test_metadata.py b/posthog/hogql/test/test_metadata.py
index 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_select
from posthog.models import EventDefinition, PropertyDefinition
from 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 InsightVariable
from products.warehouse_sources.backend.facade.models import DataWarehouseTable, ExternalDataSchema, ExternalDataSource
from products.warehouse_sources.backend.facade.types import ExternalDataSourceType
diff --git a/posthog/hogql/test/test_query.py b/posthog/hogql/test/test_query.py
index 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, uuid7
from products.cohorts.backend.models.cohort import Cohort
from 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 InsightVariable
from products.warehouse_sources.backend.facade.models import ExternalDataSource
from products.warehouse_sources.backend.facade.types import ExternalDataSourceType
diff --git a/posthog/hogql/variables.py b/posthog/hogql/variables.py
index f76c23cec4e8..46cab7c1e060 100644
--- a/posthog/hogql/variables.py
+++ b/posthog/hogql/variables.py
@@ -11,7 +11,7 @@ from posthog.hogql.visitor import CloningVisitor
from posthog.models.team.team import Team
from posthog.utils import relative_date_parse
-from products.product_analytics.backend.models.insight_variable import InsightVariable
+from products.product_analytics.backend.facade.models import InsightVariable
T = 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.py
index 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 User
from posthog.types import InsightActorsQueryNode
from 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.py
index 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_exception
from .filter_to_query import filter_to_query
if TYPE_CHECKING:
- from products.product_analytics.backend.models.insight import Insight
+ from products.product_analytics.backend.facade.models import Insight
@contextmanager
diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.py
index 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 PathsQueryRunner
return 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 PathsV2QueryRunner
return 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 StickinessQueryRunner
return 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.py
index 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 TrendsQuer
from posthog.hogql_queries.query_runner import QueryRunner
from 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.py
index 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 ExecutionMode
from posthog.models.utils import UUIDT
from 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 InsightVariable
from products.warehouse_sources.backend.facade.models import MANAGED_WAREHOUSE_SOURCE_PREFIX, ExternalDataSource
from products.warehouse_sources.backend.facade.types import ExternalDataSourceType
diff --git a/posthog/hogql_queries/test/test_query_runner.py b/posthog/hogql_queries/test/test_query_runner.py
index 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 StickinessQueryRunner
query = StickinessQuery(
series=[
diff --git a/posthog/management/commands/backfill_insights_query_metadata.py b/posthog/management/commands/backfill_insights_query_metadata.py
index 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 structlog
from posthog.hogql_queries.query_metadata import InsightQueryMetadata
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
logger = structlog.get_logger(__name__)
diff --git a/posthog/management/commands/migrate_retention_show_mean.py b/posthog/management/commands/migrate_retention_show_mean.py
index 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 BaseCommand
from django.db import transaction
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
def migrate_show_mean_from_boolean_to_string(batch_size: int, live_run: bool = False) -> None:
diff --git a/posthog/middleware.py b/posthog/middleware.py
index 7fedf71b35d1..d3e9ee16298a 100644
--- a/posthog/middleware.py
+++ b/posthog/middleware.py
@@ -63,7 +63,7 @@ from products.cohorts.backend.models.cohort import Cohort
from products.dashboards.backend.models.dashboard import Dashboard
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from .auth import PersonalAPIKeyAuthentication
diff --git a/posthog/models/file_system/test/test_file_system.py b/posthog/models/file_system/test/test_file_system.py
index 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 Dashboard
from products.experiments.backend.models.experiment import Experiment
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
class 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.py
index 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 Dashboard
from products.experiments.backend.models.experiment import Experiment
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
class 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.py
index 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 FileSystemRepr
from posthog.models.file_system.file_system_view_log import get_recent_file_system_items, log_file_system_view
from products.dashboards.backend.models.dashboard import Dashboard
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
class FileSystemWithLastViewed(Protocol):
diff --git a/posthog/models/file_system/unfiled_file_saver.py b/posthog/models/file_system/unfiled_file_saver.py
index 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 Experiment
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.links.backend.models import Link
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.surveys.backend.models import Survey
MIXIN_MODELS: dict[str, type[FileSystemSyncMixin]] = {
diff --git a/posthog/models/product_intent/product_intent.py b/posthog/models/product_intent/product_intent.py
index 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 Dashboard
from products.event_definitions.backend.models.event_definition import EventDefinition
from products.experiments.backend.models.experiment import Experiment
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
from products.product_tours.backend.models import ProductTour
from products.surveys.backend.models import Survey
from products.workflows.backend.models.hog_flow.hog_flow import HogFlow
diff --git a/posthog/models/resource_transfer/test/test_inter_project_transferer.py b/posthog/models/resource_transfer/test/test_inter_project_transferer.py
index 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 Action
from products.dashboards.backend.models.dashboard import Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile, Text
from 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 Insight
from products.surveys.backend.models import Survey
diff --git a/posthog/models/resource_transfer/visitors/insight.py b/posthog/models/resource_transfer/visitors/insight.py
index 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(
):
@classmethod
def get_model(cls) -> type[models.Model]:
- from products.product_analytics.backend.models.insight import Insight
+ from products.product_analytics.backend.facade.models import Insight
return Insight
diff --git a/posthog/models/sharing_configuration.py b/posthog/models/sharing_configuration.py
index dc577d56450d..c49ae4d8a02f 100644
--- a/posthog/models/sharing_configuration.py
+++ b/posthog/models/sharing_configuration.py
@@ -13,7 +13,7 @@ import structlog
from posthog.jwt import PosthogJwtAudience, encode_jwt
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
logger = structlog.get_logger(__name__)
diff --git a/posthog/models/test/test_dashboard_tile_model.py b/posthog/models/test/test_dashboard_tile_model.py
index 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 IntegrityError
from products.dashboards.backend.models.dashboard import Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile, Text
from 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 Insight
class TestDashboardTileModel(APIBaseTest):
diff --git a/posthog/models/test/test_product_intent.py b/posthog/models/test/test_product_intent.py
index 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 Dashboard
from products.event_definitions.backend.models.event_definition import EventDefinition
from products.experiments.backend.models.experiment import Experiment
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
from products.surveys.backend.models import Survey
from products.workflows.backend.models.hog_flow.hog_flow import HogFlow
diff --git a/posthog/models/test/test_subscription_activity_log.py b/posthog/models/test/test_subscription_activity_log.py
index 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 ActivityLog
from products.dashboards.backend.models.dashboard import Dashboard
from 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.py
index 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 Insight
class TestSubscriptionScheduling:
diff --git a/posthog/models/test/test_tagged_item_model.py b/posthog/models/test/test_tagged_item_model.py
index 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, TaggedItem
from products.actions.backend.models.action import Action
from products.dashboards.backend.models.dashboard import Dashboard
from 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 Insight
class TestTaggedItem(BaseTest):
diff --git a/posthog/rbac/test/test_user_access_control.py b/posthog/rbac/test/test_user_access_control.py
index 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(BaseUserAccessControlTes
def 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 Insight
insight = 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.py
index 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 impor
from posthog.schema_migrations.upgrade import upgrade
if TYPE_CHECKING:
- from products.product_analytics.backend.models.insight import Insight
+ from products.product_analytics.backend.facade.models import Insight
@contextmanager
diff --git a/posthog/tasks/alerts/test/test_detector_breakdowns.py b/posthog/tasks/alerts/test/test_detector_breakdowns.py
index 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_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 Insight
def _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.py
index 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 AlertDelivery
from 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 Insight
NOW = 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.py
index 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 ActiveAlertDestination
from 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 Insight
class TestAlertUtils:
diff --git a/posthog/temporal/ai/anomaly_investigation/notebook.py b/posthog/temporal/ai/anomaly_investigation/notebook.py
index 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 Insight
VERDICT_LABEL = {
"true_positive": "True positive",
diff --git a/posthog/temporal/ai/anomaly_investigation/workflow.py b/posthog/temporal/ai/anomaly_investigation/workflow.py
index 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 notebooks
from products.signals.backend.facade import api as signals
if TYPE_CHECKING:
- from products.product_analytics.backend.models.insight import Insight
+ from products.product_analytics.backend.facade.models import Insight
logger = structlog.get_logger(__name__)
diff --git a/posthog/temporal/product_analytics/upgrade_queries_activities.py b/posthog/temporal/product_analytics/upgrade_queries_activities.py
index 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_exception
from posthog.schema_migrations import LATEST_VERSIONS, _discover_migrations
from posthog.schema_migrations.upgrade import upgrade
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
LOGGER = get_logger(__name__)
diff --git a/posthog/temporal/tests/ai/test_anomaly_investigation_notebook.py b/posthog/temporal/tests/ai/test_anomaly_investigation_notebook.py
index 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 NotebookRenderCon
from posthog.temporal.ai.anomaly_investigation.report import InvestigationHypothesis, InvestigationReport
from 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 Insight
class TestAnomalyInvestigationNotebook(BaseTest):
diff --git a/posthog/temporal/tests/ai/test_anomaly_investigation_tools.py b/posthog/temporal/tests/ai/test_anomaly_investigation_tools.py
index 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 InsightResult
from posthog.temporal.ai.anomaly_investigation.tools import _run_detector_simulation
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
def _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.py
index 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 Insight
class 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.py
index 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 Insight
class InsightVizMigration1(SchemaMigration):
diff --git a/posthog/temporal/tests/test_alerts_activities.py b/posthog/temporal/tests/test_alerts_activities.py
index 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 AlertDelivery
from products.alerts.backend.evaluation.contract import AlertExtractionError
from products.alerts.backend.evaluation.validation import THRESHOLD_BOUNDS_REQUIRED_MESSAGE
from 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 Insight
def _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.py
index 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 AlertState
from posthog.temporal.alerts.investigation import claim_investigation_slot, should_trigger_investigation
from 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 Insight
class TestShouldTriggerInvestigation(BaseTest):
diff --git a/posthog/temporal/tests/test_alerts_workflows.py b/posthog/temporal/tests/test_alerts_workflows.py
index 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 SloInterceptor
from posthog.temporal.tests.test_alerts_activities import _email_delivery
from 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 Insight
CHECK_ALERT_ACTIVITIES: list[Callable[..., Any]] = [
prepare_alert,
diff --git a/posthog/temporal/tests/test_subscriptions_workflows.py b/posthog/temporal/tests/test_subscriptions_workflows.py
index 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 Insight
from ee.tasks.subscriptions.auto_disable import AI_CONSENT_REVOKED_DISABLE_REASON, SLACK_DISCONNECTED_DISABLE_REASON
from ee.tasks.subscriptions.slack_subscriptions import SlackDeliveryResult
diff --git a/posthog/test/base.py b/posthog/test/base.py
index 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.py
index 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_value
from products.dashboards.backend.models.dashboard import Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile
from 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, InsightVariable
class PlaywrightSetupVariableType(StrEnum):
diff --git a/posthog/test/test_middleware.py b/posthog/test/test_middleware.py
index 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 Action
from products.cohorts.backend.models.cohort import Cohort
from products.dashboards.backend.models.dashboard import Dashboard
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
def _social_auth_backend() -> BaseAuth:
diff --git a/posthog/test/test_user_permissions.py b/posthog/test/test_user_permissions.py
index 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 UserPermissions
from products.dashboards.backend.models.dashboard import Dashboard
from 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 Insight
from ee.models.dashboard_privilege import DashboardPrivilege
diff --git a/posthog/user_permissions.py b/posthog/user_permissions.py
index afc049ecc018..c9e63d798be4 100644
--- a/posthog/user_permissions.py
+++ b/posthog/user_permissions.py
@@ -7,7 +7,7 @@ from posthog.models import Organization, OrganizationMembership, Team, User
from products.dashboards.backend.models.dashboard import Dashboard
from 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 Insight
class UserPermissions:
diff --git a/posthog/utils.py b/posthog/utils.py
index 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 Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile
from 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 InsightVariable
DATERANGE_MAP = {
"second": datetime.timedelta(seconds=1),
diff --git a/products/actions/backend/api/action.py b/products/actions/backend/api/action.py
index 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 HogFunction
from products.cohorts.backend.models.cohort import Cohort
from 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.py
index 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, User
from products.actions.backend.models.action import Action
from products.cdp.backend.models.hog_functions.hog_function import HogFunction
from products.cohorts.backend.models.cohort import Cohort
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
class TestActionApi(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
diff --git a/products/alerts/backend/api/alert.py b/products/alerts/backend/api/alert.py
index 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 Insight
INSIGHT_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: PLC0415
data = super().to_representation(instance)
data["subscribed_users"] = UserBasicSerializer(instance.subscribed_users.all(), many=True, read_only=True).data
diff --git a/products/alerts/backend/api/test/test_alert.py b/products/alerts/backend/api/test/test_alert.py
index 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_value
from products.alerts.backend.destinations import AlertDelivery
from products.alerts.backend.models.alert import AlertCheck, AlertConfiguration, AlertSubscription, Threshold
from 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 Insight
TEST_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.py
index 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 Team
from posthog.models.user import User
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
@dataclass
diff --git a/products/alerts/backend/evaluation/detector.py b/products/alerts/backend/evaluation/detector.py
index 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 Insight
def extract_detector_series(
diff --git a/products/alerts/backend/evaluation/dispatcher.py b/products/alerts/backend/evaluation/dispatcher.py
index 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, Hog
from products.alerts.backend.evaluation.metrics import MetricsExtractor
from products.alerts.backend.evaluation.trends import TrendsExtractor
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
# 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.py
index 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_periods
from products.alerts.backend.evaluation.contract import AlertExtractionError, ExtractionResult, lookback_intervals_for
from products.alerts.backend.evaluation.funnel_strategies import strategy_for_viz
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
def _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.py
index 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 row
diff --git a/products/alerts/backend/evaluation/metrics.py b/products/alerts/backend/evaluation/metrics.py
index 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.py
index 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 FunnelsExtractor
from products.alerts.backend.evaluation.hogql import HogQLExtractor
from products.alerts.backend.evaluation.trends import TrendsExtractor
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
ALWAYS = ExecutionMode.CALCULATE_BLOCKING_ALWAYS
IF_STALE = ExecutionMode.RECENT_CACHE_CALCULATE_BLOCKING_IF_STALE
diff --git a/products/alerts/backend/evaluation/test/test_hogql_extractor_clickhouse.py b/products/alerts/backend/evaluation/test/test_hogql_extractor_clickhouse.py
index 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 ExecutionMode
from products.alerts.backend.evaluation.hogql import HogQLExtractor
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
class TestHogQLExtractorFiltersPlaceholder(APIBaseTest, ClickhouseDestroyTablesMixin):
diff --git a/products/alerts/backend/evaluation/trends.py b/products/alerts/backend/evaluation/trends.py
index 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_formatter
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
class TrendsExtractor:
diff --git a/products/alerts/backend/max_tools.py b/products/alerts/backend/max_tools.py
index 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 APIScopeObject
from products.alerts.backend.evaluation.validation import THRESHOLD_BOUNDS_REQUIRED_MESSAGE
from products.alerts.backend.insight_alert_state_machine import apply_disable, apply_enable, apply_threshold_change
from 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 Insight
from ee.hogai.artifacts.types import ModelArtifactResult
from ee.hogai.tool import MaxTool
diff --git a/products/alerts/backend/test_max_tools.py b/products/alerts/backend/test_max_tools.py
index 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 AvailableFeature
from posthog.models import Organization, Team
from 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 Insight
from .max_tools import CreateAlertAction, UpdateAlertAction, UpsertAlertTool
diff --git a/products/annotations/backend/api/annotation.py b/products/annotations/backend/api/annotation.py
index 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 UserBasicSerializer
from products.annotations.backend.models.annotation import Annotation
from products.dashboards.backend.models.dashboard import Dashboard
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
class AnnotationSerializer(serializers.ModelSerializer):
diff --git a/products/annotations/backend/api/test/test_annotation.py b/products/annotations/backend/api/test/test_annotation.py
index 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, User
from products.annotations.backend.models.annotation import Annotation
from products.dashboards.backend.models.dashboard import Dashboard
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
class 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.py
index 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 ActivityLogTestHelper
from products.annotations.backend.models.annotation import Annotation
from products.dashboards.backend.models.dashboard import Dashboard
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
class TestAnnotationActivityLogging(ActivityLogTestHelper):
diff --git a/products/annotations/backend/api/test/test_annotation_context.py b/products/annotations/backend/api/test/test_annotation_context.py
index 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 Annotation
from products.dashboards.backend.models.dashboard import Dashboard
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
class TestAnnotationContext(APIBaseTest):
diff --git a/products/architecture.md b/products/architecture.md
index 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.py
index 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 Insight
return 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.py
index 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 AccountProperties
from products.customer_analytics.backend.models.team_scoped_test_base import TeamScopedTestMixin
from products.customer_analytics.backend.test.factories import create_account
from products.notebooks.backend.models import Notebook, ResourceNotebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
class TestCustomerAnalyticsFacade(BaseTest):
diff --git a/products/customer_analytics/backend/test/test_views.py b/products/customer_analytics/backend/test/test_views.py
index 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_definition
from products.notebooks.backend.models import Notebook, ResourceNotebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.warehouse_sources.backend.models.external_data_schema import ExternalDataSchema
from products.warehouse_sources.backend.models.external_data_source import ExternalDataSource
diff --git a/products/dashboards/backend/api/dashboard.py b/products/dashboards/backend/api/dashboard.py
index 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 InsightVariable
from ee.hogai.utils.aio import async_to_sync
diff --git a/products/dashboards/backend/api/test/test_dashboard_widgets.py b/products/dashboards/backend/api/test/test_dashboard_widgets.py
index 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 DashboardTemp
from products.dashboards.backend.models.dashboard_tile import DashboardTile
from products.dashboards.backend.models.dashboard_widget import DashboardWidget
from 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 Insight
class TestDashboardWidgets(APIBaseTest):
diff --git a/products/dashboards/backend/api/test/test_run_insights.py b/products/dashboards/backend/api/test/test_run_insights.py
index 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 Team
from products.dashboards.backend.access import DashboardAccessMethod
from products.dashboards.backend.models.dashboard import Dashboard
from 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, InsightVariable
def _trends_query_dict(event: str = "$pageview") -> dict:
diff --git a/products/dashboards/backend/models/dashboard_tile.py b/products/dashboards/backend/models/dashboard_tile.py
index 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 None
if 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_hash
self.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.py
index 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 RequestFactory
from products.dashboards.backend.admin.dashboard_admin import DashboardAdmin
from products.dashboards.backend.models.dashboard import Dashboard
from 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 Insight
def _attach_messages(request) -> None:
diff --git a/products/data_catalog/backend/logic/drift.py b/products/data_catalog/backend/logic/drift.py
index 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 UUID
from posthog.schema_migrations.upgrade import upgrade
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from ..models import Metric
diff --git a/products/data_catalog/backend/logic/metrics.py b/products/data_catalog/backend/logic/metrics.py
index 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, User
from posthog.models.scoping import team_scope
from posthog.rbac.user_access_control import UserAccessControl
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from ..facade.enums import CreatedSource, MetricStatus
from ..models import METRIC_NAME_REGEX, Metric
diff --git a/products/data_catalog/backend/tests/test_analytics.py b/products/data_catalog/backend/tests/test_analytics.py
index 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 MetricDrifted
from products.data_catalog.backend.logic.execution import run_metric
from products.data_catalog.backend.logic.metrics import approve_metric, upsert_metric
from 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 Insight
from 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.py
index 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 Insight
from ee.models.rbac.access_control import AccessControl
diff --git a/products/data_catalog/backend/tests/test_information_schema.py b/products/data_catalog/backend/tests/test_information_schema.py
index 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, TableCert
from products.data_catalog.backend.models.metric import Metric
from products.data_modeling.backend.facade.models import DataWarehouseSavedQuery
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 Insight
from products.warehouse_sources.backend.facade.models import DataWarehouseTable, ExternalDataSource
from products.warehouse_sources.backend.facade.types import ExternalDataSourceType
diff --git a/products/data_catalog/backend/tests/test_logic.py b/products/data_catalog/backend/tests/test_logic.py
index 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_definition
from products.data_catalog.backend.models import Metric
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from ee.models.rbac.access_control import AccessControl
diff --git a/products/data_catalog/evals/seeders.py b/products/data_catalog/evals/seeders.py
index 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 Insight
from products.warehouse_sources.backend.facade.models import DataWarehouseTable
if TYPE_CHECKING:
diff --git a/products/demo/backend/logic/legacy/app_data_generator.py b/products/demo/backend/logic/legacy/app_data_generator.py
index 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, PropertyDefinition
from products.actions.backend.models.action import Action
from products.dashboards.backend.models.dashboard import Dashboard
from 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 Insight
from .data_generator import DataGenerator
diff --git a/products/demo/backend/logic/legacy/insight_variables_data_generator.py b/products/demo/backend/logic/legacy/insight_variables_data_generator.py
index 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 Person
from products.dashboards.backend.models.dashboard import Dashboard
from 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, InsightVariable
from .data_generator import DataGenerator
diff --git a/products/demo/backend/logic/legacy/revenue_data_generator.py b/products/demo/backend/logic/legacy/revenue_data_generator.py
index 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, PropertyDefinition
from products.actions.backend.models.action import Action
from products.dashboards.backend.models.dashboard import Dashboard
from 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 Insight
from .data_generator import DataGenerator
diff --git a/products/demo/backend/logic/legacy/web_data_generator.py b/products/demo/backend/logic/legacy/web_data_generator.py
index 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 UUIDT
from products.actions.backend.models.action import Action
from products.dashboards.backend.models.dashboard import Dashboard
from 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 Insight
from .data_generator import DataGenerator
diff --git a/products/demo/backend/logic/products/hedgebox/matrix.py b/products/demo/backend/logic/products/hedgebox/matrix.py
index 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, InsightViewed
from products.warehouse_sources.backend.facade.models import DataWarehouseTable, get_or_create_datawarehouse_credential
from .models import HedgeboxAccount, HedgeboxPerson
diff --git a/products/endpoints/backend/logic/validation.py b/products/endpoints/backend/logic/validation.py
index 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 InsightVariable
def validate_data_freshness(data_freshness_seconds: int | None) -> None:
diff --git a/products/endpoints/backend/openapi.py b/products/endpoints/backend/openapi.py
index f93378463772..b15b5d30dca1 100644
--- a/products/endpoints/backend/openapi.py
+++ b/products/endpoints/backend/openapi.py
@@ -4,7 +4,7 @@ from rest_framework.request import Request
from products.endpoints.backend.logic.strategies import InsightEndpointStrategy
from 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 InsightVariable
INSIGHT_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.py
index 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_value
from products.endpoints.backend.models import Endpoint, EndpointVersion
from 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 InsightVariable
class 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 InsightVariable
InsightVariable.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 None
def 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 InsightVariable
InsightVariable.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.py
index 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 CHQueryErrorNoCommonType
from products.data_modeling.backend.facade.models import DataModelingJob, DataWarehouseSavedQuery
from products.endpoints.backend.logic.execution import EndpointExecutionService
from 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 InsightVariable
from products.warehouse_sources.backend.facade.models import DataWarehouseTable
diff --git a/products/endpoints/backend/tests/test_openapi_spec.py b/products/endpoints/backend/tests/test_openapi_spec.py
index 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 InsightVariable
variable = 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 InsightVariable
with_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 InsightVariable
variable = 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 InsightVariable
test_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 coherent
contract. The OpenAPI spec must not mark inline HogQL variables required, or generated
SDKs 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 InsightVariable
InsightVariable.objects.create(
team=self.team,
@@ -579,7 +579,7 @@ class TestEndpointOpenAPIRequiredVariables(ClickhouseTestMixin, APIBaseTest):
spec must mark every variable required — unlike the inline path, which substitutes
defaults/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 InsightVariable
with_default = InsightVariable.objects.create(
team=self.team,
diff --git a/products/exports/backend/api/exports.py b/products/exports/backend/api/exports.py
index 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.py
index 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_TIMEOUT
from products.exports.backend.models.exported_asset import DATASET_EXPORT_KIND, ExportedAsset
from products.exports.backend.tasks.failure_handler import FAILURE_TYPE_SYSTEM, FAILURE_TYPE_USER
from 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 InsightSerializer
from ee.models.rbac.access_control import AccessControl
diff --git a/products/exports/backend/facade/api.py b/products/exports/backend/facade/api.py
index 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 Insight
logger = structlog.get_logger(__name__)
diff --git a/products/exports/backend/tasks/image_exporter.py b/products/exports/backend/tasks/image_exporter.py
index 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 InsightVariable
logger = 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.py
index 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 ExportedAsset
from products.exports.backend.tasks import image_exporter
from products.exports.backend.tasks.failure_handler import BrowserlessUnavailable, InvalidExportContext
from 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, InsightVariable
def make_insight_result(cache_key: str) -> InsightResult:
diff --git a/products/exports/backend/temporal/subscriptions/activities.py b/products/exports/backend/temporal/subscriptions/activities.py
index 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 Insight
from ee.tasks.subscriptions import _capture_delivery_failed_event
from 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.py
index 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.py
index 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 DashboardTile
from products.exports.backend.models.subscription import Subscription
from products.exports.backend.temporal.subscriptions.delivery_common import strip_null_bytes
from 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 Insight
logger = structlog.get_logger(__name__)
diff --git a/products/exports/backend/temporal/subscriptions/snapshot_activities.py b/products/exports/backend/temporal/subscriptions/snapshot_activities.py
index 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 g
from products.exports.backend.temporal.subscriptions.results_summarizer import build_results_summary
from products.exports.backend.temporal.subscriptions.types import SnapshotInsightsInputs, SnapshotInsightsResult
from 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 Insight
from ee.billing.quota_limiting import is_team_over_ai_credit_budget
diff --git a/products/exports/backend/temporal/subscriptions/test_delivery_activities.py b/products/exports/backend/temporal/subscriptions/test_delivery_activities.py
index 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 Insight
from ee.tasks.test.subscriptions.subscriptions_test_factory import create_subscription
diff --git a/products/exports/backend/temporal/subscriptions/test_snapshot_ai_consent.py b/products/exports/backend/temporal/subscriptions/test_snapshot_ai_consent.py
index 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, Subscript
from products.exports.backend.temporal.subscriptions.snapshot_activities import snapshot_subscription_insights
from products.exports.backend.temporal.subscriptions.types import SnapshotInsightsInputs
from 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 Insight
pytestmark = [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.py
index 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 parameterized
from products.annotations.backend.api.annotation_context import resolve_snapshot_date_range
from products.annotations.backend.models.annotation import Annotation
from 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 Insight
def _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.py
index 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 import
SUBSCRIPTION_SUMMARY_IMAGE_SKIPPED,
_load_insight_images,
)
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
pytestmark = pytest.mark.django_db
diff --git a/products/feature_flags/backend/api/test/test_feature_flag.py b/products/feature_flags/backend/api/test/test_feature_flag.py
index 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 FeatureFlagStatus
from products.feature_flags.backend.models.feature_flag import FeatureFlag, FeatureFlagDashboards
from products.feature_flags.backend.models.team_feature_flags_config import TeamFeatureFlagsConfig
from 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 Insight
from products.product_tours.backend.models import ProductTour
from products.surveys.backend.models import Survey
diff --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.py
index 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 deletable
def _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-delete
the 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.py
index 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 Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile
from products.feature_flags.backend.api.feature_flag import _create_usage_dashboard
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
from ee.tasks.test.subscriptions.subscriptions_test_factory import create_subscription
diff --git a/products/notebooks/backend/test/test_sharing.py b/products/notebooks/backend/test/test_sharing.py
index 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 Insight
def _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.py
index 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_connection
from products.dashboards.backend.models import Dashboard, DashboardTile
from products.demo.backend.facade.api import HedgeboxMatrix, MatrixManager, infer_taxonomy_for_team
from 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 Insight
logger = logging.getLogger(__name__)
diff --git a/products/posthog_ai/eval_harness/seeders/insight.py b/products/posthog_ai/eval_harness/seeders/insight.py
index 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 worker
thread 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 Insight
team_id = context.team_id
user_id = context.user_id
diff --git a/products/product_analytics/backend/api/__init__.py b/products/product_analytics/backend/api/__init__.py
deleted file mode 100644
index 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.py
index 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-class
crossings. 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 TestAccountFilterUpdate
from products.product_analytics.backend.models.insight_variable import InsightVariable
@@ -15,6 +18,11 @@ def map_stale_to_latest(stale_variables: dict, latest_variables: list[InsightVar
return 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.py
new file mode 100644
index 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.py
index 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 to
these 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_hash
from 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.py
new file mode 100644
index 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__.py
similarity index 100%
rename from products/product_analytics/backend/api/test/__init__.py
rename to products/product_analytics/backend/presentation/__init__.py
diff --git a/products/product_analytics/backend/api/ai_billing.py b/products/product_analytics/backend/presentation/ai_billing.py
similarity index 100%
rename from products/product_analytics/backend/api/ai_billing.py
rename to products/product_analytics/backend/presentation/ai_billing.py
diff --git a/products/product_analytics/backend/api/insight.py b/products/product_analytics/backend/presentation/insight.py
similarity index 99%
rename from products/product_analytics/backend/api/insight.py
rename to products/product_analytics/backend/presentation/insight.py
index 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 Dashboard
from 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 HogVMException
diff --git a/products/product_analytics/backend/api/insight_ee.py b/products/product_analytics/backend/presentation/insight_ee.py
similarity index 84%
rename from products/product_analytics/backend/api/insight_ee.py
rename to products/product_analytics/backend/presentation/insight_ee.py
index 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, BasePermission
from rest_framework.request import Request
from 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 InsightViewSet
class CanEditInsight(BasePermission):
diff --git a/products/product_analytics/backend/api/insight_metadata.py b/products/product_analytics/backend/presentation/insight_metadata.py
similarity index 99%
rename from products/product_analytics/backend/api/insight_metadata.py
rename to products/product_analytics/backend/presentation/insight_metadata.py
index 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 groups
from posthog.llm.completions import hit_openai
from 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_properties
class InsightMetadata(BaseModel):
diff --git a/products/product_analytics/backend/api/insight_suggestions.py b/products/product_analytics/backend/presentation/insight_suggestions.py
similarity index 98%
rename from products/product_analytics/backend/api/insight_suggestions.py
rename to products/product_analytics/backend/presentation/insight_suggestions.py
index 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_openai
from posthog.models import Team
from 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_properties
logger = structlog.get_logger(__name__)
diff --git a/products/product_analytics/backend/api/insight_variable.py b/products/product_analytics/backend/presentation/insight_variable.py
similarity index 99%
rename from products/product_analytics/backend/api/insight_variable.py
rename to products/product_analytics/backend/presentation/insight_variable.py
index 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 ProductKey
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.auth import SharingAccessTokenAuthentication, SharingPasswordProtectedAuthentication
-from products.product_analytics.backend.models.insight_variable import InsightVariable
+from products.product_analytics.backend.facade.models import InsightVariable
def _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.py
similarity index 97%
rename from products/product_analytics/backend/api/paths_v2.py
rename to products/product_analytics/backend/presentation/paths_v2.py
index 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, PathsV2Query
from posthog.api.mixins import ValidatedRequest, validated_request
from 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__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr b/products/product_analytics/backend/presentation/test/__snapshots__/test_insight.ambr
similarity index 100%
rename from products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr
rename to products/product_analytics/backend/presentation/test/__snapshots__/test_insight.ambr
diff --git a/products/product_analytics/backend/api/test/__snapshots__/test_insight_funnels.ambr b/products/product_analytics/backend/presentation/test/__snapshots__/test_insight_funnels.ambr
similarity index 100%
rename from products/product_analytics/backend/api/test/__snapshots__/test_insight_funnels.ambr
rename to products/product_analytics/backend/presentation/test/__snapshots__/test_insight_funnels.ambr
diff --git a/products/product_analytics/backend/api/test/test_deprecated_dashboards_field.py b/products/product_analytics/backend/presentation/test/test_deprecated_dashboards_field.py
similarity index 96%
rename from products/product_analytics/backend/api/test/test_deprecated_dashboards_field.py
rename to products/product_analytics/backend/presentation/test/test_deprecated_dashboards_field.py
index 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_value
from products.dashboards.backend.models.dashboard import Dashboard
from 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_field
def _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.py
similarity index 99%
rename from products/product_analytics/backend/api/test/test_insight.py
rename to products/product_analytics/backend/presentation/test/test_insight.py
index 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 Cohort
from products.dashboards.backend.access import DashboardAccessMethod
from products.dashboards.backend.models.dashboard import Dashboard
from 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, InsightViewed
from 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, Quer
self.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.py
similarity index 100%
rename from products/product_analytics/backend/api/test/test_insight_funnels.py
rename to products/product_analytics/backend/presentation/test/test_insight_funnels.py
diff --git a/products/product_analytics/backend/api/test/test_insight_metadata.py b/products/product_analytics/backend/presentation/test/test_insight_metadata.py
similarity index 99%
rename from products/product_analytics/backend/api/test/test_insight_metadata.py
rename to products/product_analytics/backend/presentation/test/test_insight_metadata.py
index 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 status
from 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.py
similarity index 99%
rename from products/product_analytics/backend/api/test/test_insight_query.py
rename to products/product_analytics/backend/presentation/test/test_insight_query.py
index 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 status
from posthog import schema
from 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 Insight
from ee.api.test.base import LicensedTestMixin
diff --git a/products/product_analytics/backend/api/test/test_insight_variable.py b/products/product_analytics/backend/presentation/test/test_insight_variable.py
similarity index 98%
rename from products/product_analytics/backend/api/test/test_insight_variable.py
rename to products/product_analytics/backend/presentation/test/test_insight_variable.py
index 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 PermissionDenied
from 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.py
similarity index 95%
rename from products/product_analytics/backend/api/test/test_paths_v2.py
rename to products/product_analytics/backend/presentation/test/test_paths_v2.py
index 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 PathsV2SegmentToFunnelRequestSerializer
DATE_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.py
index 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 RouterRegistry
from posthog.settings import EE_AVAILABLE
import 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 PathsV2ViewSet
def register_routes(routers: RouterRegistry) -> None:
diff --git a/products/product_analytics/tsconfig.json b/products/product_analytics/tsconfig.json
new file mode 100644
index 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.py
index 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, SloOperation
from posthog.temporal.common.client import sync_connect
from products.dashboards.backend.models.dashboard import Dashboard
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.pulse.backend.config import WORKFLOW_EXECUTION_TIMEOUT
from products.pulse.backend.models import BriefConfig, ProductBrief
from products.pulse.backend.temporal.inputs import GENERATE_BRIEF_WORKFLOW_NAME, GenerateBriefWorkflowInputs
diff --git a/products/pulse/backend/generation/persist.py b/products/pulse/backend/generation/persist.py
index 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 Annotation
from products.dashboards.backend.models.dashboard import Dashboard
from products.experiments.backend.models.experiment import Experiment
from 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
from products.pulse.backend.generation.schemas import BriefOut, BriefSectionOut, OpportunityOut
from products.pulse.backend.models import Opportunity, ProductBrief, ResourceLink, build_action
from products.pulse.backend.sources.base import EvidenceRef, EvidenceType, SourceItem, build_evidence_index
diff --git a/products/pulse/backend/sources/anchored_dashboards.py b/products/pulse/backend/sources/anchored_dashboards.py
index 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 Team
from posthog.rbac.user_access_control import UserAccessControl
from products.dashboards.backend.models.dashboard import Dashboard
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.pulse.backend.config import BriefSettings
from products.pulse.backend.models import BriefConfig
from products.pulse.backend.sources.base import SourceItem
diff --git a/products/pulse/backend/sources/anchored_insights.py b/products/pulse/backend/sources/anchored_insights.py
index 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 QuerySet
from posthog.models.team import Team
from posthog.rbac.user_access_control import UserAccessControl
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.pulse.backend.config import BriefSettings
from products.pulse.backend.models import BriefConfig
from products.pulse.backend.sources.base import SourceItem
diff --git a/products/pulse/backend/sources/resource_health.py b/products/pulse/backend/sources/resource_health.py
index 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 AlertState
from products.alerts.backend.models import AlertConfiguration
from products.exports.backend.models.subscription import SubscriptionDelivery
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.pulse.backend.config import MAX_ITEMS_PER_DETECTOR, STUCK_REFRESH_ATTEMPTS
from products.pulse.backend.models import BriefConfig
from products.pulse.backend.sources.base import EvidenceRef, EvidenceType, SourceItem, SourceItemKind
diff --git a/products/pulse/backend/sources/strategy.py b/products/pulse/backend/sources/strategy.py
index 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_exception
from posthog.models.team import Team
from posthog.rbac.user_access_control import UserAccessControl
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.pulse.backend.config import BriefSettings
from products.pulse.backend.sources.base import EvidenceRef, EvidenceType, SourceItem, SourceItemKind
from products.pulse.backend.urls import insight_url
diff --git a/products/pulse/backend/test/test_anchored_dashboards.py b/products/pulse/backend/test/test_anchored_dashboards.py
index 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 UserAccessControl
from products.dashboards.backend.models.dashboard import Dashboard
from 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 Insight
from products.pulse.backend.models import BriefConfig
from products.pulse.backend.sources.anchored_dashboards import AnchoredDashboardsSource
from products.pulse.backend.sources.anchored_insights import AnchoredInsightsSource
diff --git a/products/pulse/backend/test/test_anchored_insights.py b/products/pulse/backend/test/test_anchored_insights.py
index 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 parameterized
from posthog.models.scoping import team_scope
from posthog.rbac.user_access_control import UserAccessControl
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.pulse.backend.config import DEFAULT_BRIEF_SETTINGS, BriefSettings
from products.pulse.backend.models import BriefConfig
from products.pulse.backend.sources.anchored_insights import AnchoredInsightsSource
diff --git a/products/pulse/backend/test/test_api.py b/products/pulse/backend/test/test_api.py
index 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 Team
from posthog.rate_limit import AIBurstRateThrottle, AISustainedRateThrottle
from posthog.slo.types import SloOperation
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.pulse.backend.api.brief import ProductBriefViewSet
from products.pulse.backend.models import BriefConfig, ProductBrief
diff --git a/products/pulse/backend/test/test_models.py b/products/pulse/backend/test/test_models.py
index 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 parameterized
from posthog.models.scoping import team_scope
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.pulse.backend.models import (
ActionStatus,
ActionType,
diff --git a/products/pulse/backend/test/test_persist.py b/products/pulse/backend/test/test_persist.py
index 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 AlertState
from products.alerts.backend.models import AlertConfiguration
from 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
from products.pulse.backend.generation.persist import _fingerprint, persist_brief_output
from products.pulse.backend.generation.schemas import BriefOut, BriefSectionOut, OpportunityOut
from 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.py
index 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 AlertConfiguration
from products.dashboards.backend.models.dashboard import Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile
from 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 Insight
from products.pulse.backend.sources.base import EvidenceRef, EvidenceType, SourceItem
from products.pulse.backend.sources.resource_health import STUCK_REFRESH_ATTEMPTS, ResourceHealthSource
diff --git a/products/reminders/backend/constants.py b/products/reminders/backend/constants.py
index 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 Dashboard
from products.experiments.backend.models.experiment import Experiment
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from 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.py
index 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 Dashboard
from products.experiments.backend.models.experiment import Experiment
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.notebooks.backend.models import Notebook
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from 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.py
index 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_region
from products.conversations.backend.models.ticket import Ticket
from products.dashboards.backend.models.dashboard import Dashboard
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.slack_app.backend.services.slack_messages import UNFURL_OPT_OUT_PARAM
from products.tasks.backend.facade import api as tasks_facade
from products.tasks.backend.facade.contracts import TaskSlackUnfurlDTO
diff --git a/products/slack_app/backend/tests/test_link_unfurl.py b/products/slack_app/backend/tests/test_link_unfurl.py
index 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 UserIntegration
from products.conversations.backend.models.ticket import Ticket
from products.dashboards.backend.models.dashboard import Dashboard
-from products.product_analytics.backend.models.insight import Insight
+from products.product_analytics.backend.facade.models import Insight
from products.slack_app.backend.api import ROUTE_HANDLED_LOCALLY, route_posthog_code_event_to_relevant_region
from products.slack_app.backend.models import SlackChannel
from products.slack_app.backend.services.slack_auth import write_auth_state_ok
diff --git a/products/slack_app/backend/tests/test_posthog_code_interactivity.py b/products/slack_app/backend/tests/test_posthog_code_interactivity.py
index 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 AlertState
from posthog.utils import relative_date_parse
from 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 Insight
from 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.py
index 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 Insight
from products.surveys.backend.models import MAX_ITERATION_COUNT, Survey, SurveyResponseArchive, ensure_question_ids
from 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.py
index 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_person
from products.actions.backend.models.action import Action
from products.cohorts.backend.models.cohort import Cohort
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
from products.product_tours.backend.models import ProductTour
from 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.py
index 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 RunnableConfig
from parameterized import parameterized
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
from products.surveys.backend.models import Survey
from .max_tools import CreateSurveyTool, EditSurveyTool, SimpleSurveyQuestion, SurveyAnalysisTool
diff --git a/pyproject.toml b/pyproject.toml
index 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.toml
index 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.py
index 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.py
index 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/")