Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

ralph(M9-CLEANUP-001): packages/db shrinks to its final surface now that V1 is gone

ralph97f03a84a93b
diff --git a/apps/api/e2e/lib.ts b/apps/api/e2e/lib.ts
index 37787c861..b339d2c68 100644
--- a/apps/api/e2e/lib.ts
+++ b/apps/api/e2e/lib.ts
@@ -4,7 +4,8 @@
* fixtures, polling, and a tiny check/report framework.
*/
-import { ClientType, chQuery, db, getClientByIdCached } from '@openpanel/db';
+import { getClientByIdCached } from '@openpanel/core';
+import { ClientType, chQuery, db } from '@openpanel/db';
import { getRedisCache } from '@openpanel/redis';
// ── Config ──────────────────────────────────────────────────────────────────
diff --git a/apps/api/scripts/test.ts b/apps/api/scripts/test.ts
index 08fe47e7e..5492dfcc3 100644
--- a/apps/api/scripts/test.ts
+++ b/apps/api/scripts/test.ts
@@ -1,5 +1,5 @@
-import { type IClickhouseEvent, ch, createEvent } from '@openpanel/db';
-import { formatClickhouseDate } from '@openpanel/db';
+import { type IClickhouseEvent, createEvent } from '@openpanel/core';
+import { ch, formatClickhouseDate } from '@openpanel/db';
import { v4 as uuid } from 'uuid';
async function main() {
diff --git a/apps/start/src/components/events/event-list-item.tsx b/apps/start/src/components/events/event-list-item.tsx
index 5908d70b2..b56045a65 100644
--- a/apps/start/src/components/events/event-list-item.tsx
+++ b/apps/start/src/components/events/event-list-item.tsx
@@ -1,4 +1,4 @@
-import type { IServiceEvent, IServiceEventMinimal } from '@openpanel/db';
+import type { IServiceEvent, IServiceEventMinimal } from '@openpanel/core';
import { Link } from '@tanstack/react-router';
import { SerieIcon } from '../report-chart/common/serie-icon';
import { EventIcon } from './event-icon';
diff --git a/apps/start/src/components/events/table/columns.tsx b/apps/start/src/components/events/table/columns.tsx
index fd560bff6..2d7649864 100644
--- a/apps/start/src/components/events/table/columns.tsx
+++ b/apps/start/src/components/events/table/columns.tsx
@@ -1,4 +1,4 @@
-import type { IServiceEvent } from '@openpanel/db';
+import type { IServiceEvent } from '@openpanel/core';
import type { ColumnDef } from '@tanstack/react-table';
import { ColumnCreatedAt } from '@/components/column-created-at';
import { EventIcon } from '@/components/events/event-icon';
diff --git a/apps/start/src/components/events/table/index.tsx b/apps/start/src/components/events/table/index.tsx
index c545ee802..105961e03 100644
--- a/apps/start/src/components/events/table/index.tsx
+++ b/apps/start/src/components/events/table/index.tsx
@@ -1,4 +1,4 @@
-import type { IServiceEvent } from '@openpanel/db';
+import type { IServiceEvent } from '@openpanel/core';
import type { UseInfiniteQueryResult } from '@tanstack/react-query';
import type { Table } from '@tanstack/react-table';
import { getCoreRowModel, useReactTable } from '@tanstack/react-table';
diff --git a/apps/start/src/components/events/table/item.tsx b/apps/start/src/components/events/table/item.tsx
index f50ee3247..789bfcbfc 100644
--- a/apps/start/src/components/events/table/item.tsx
+++ b/apps/start/src/components/events/table/item.tsx
@@ -5,7 +5,7 @@ import { pushModal } from '@/modals';
import { cn } from '@/utils/cn';
import { formatTimeAgoOrDateTime } from '@/utils/date';
import { getProfileName } from '@/utils/getters';
-import type { IServiceEvent } from '@openpanel/db';
+import type { IServiceEvent } from '@openpanel/core';
import { memo } from 'react';
import { Skeleton } from '../../skeleton';
import { EventIcon } from '../event-icon';
diff --git a/apps/start/src/components/grafana-grid.tsx b/apps/start/src/components/grafana-grid.tsx
index 4b4232ccd..b5dc0951e 100644
--- a/apps/start/src/components/grafana-grid.tsx
+++ b/apps/start/src/components/grafana-grid.tsx
@@ -1,4 +1,4 @@
-import type { IServiceReport } from '@openpanel/db';
+import type { IServiceReport } from '@openpanel/core';
import { useMemo } from 'react';
import { Responsive, WidthProvider } from 'react-grid-layout';
diff --git a/apps/start/src/components/groups/table/columns.tsx b/apps/start/src/components/groups/table/columns.tsx
index 87d7fedcf..97acbdc5b 100644
--- a/apps/start/src/components/groups/table/columns.tsx
+++ b/apps/start/src/components/groups/table/columns.tsx
@@ -3,7 +3,7 @@ import { ColumnCreatedAt } from '@/components/column-created-at';
import { Badge } from '@/components/ui/badge';
import { Link } from '@tanstack/react-router';
import type { ColumnDef } from '@tanstack/react-table';
-import type { IServiceGroup } from '@openpanel/db';
+import type { IServiceGroup } from '@openpanel/core';
export type IServiceGroupWithStats = IServiceGroup & {
memberCount: number;
diff --git a/apps/start/src/components/groups/table/index.tsx b/apps/start/src/components/groups/table/index.tsx
index bbf19534f..c6fd36c60 100644
--- a/apps/start/src/components/groups/table/index.tsx
+++ b/apps/start/src/components/groups/table/index.tsx
@@ -1,4 +1,4 @@
-import type { IServiceGroup } from '@openpanel/db';
+import type { IServiceGroup } from '@openpanel/core';
import type { UseQueryResult } from '@tanstack/react-query';
import type { PaginationState, Table, Updater } from '@tanstack/react-table';
import { getCoreRowModel, useReactTable } from '@tanstack/react-table';
diff --git a/apps/start/src/components/mock-event-list.tsx b/apps/start/src/components/mock-event-list.tsx
index 9bf67045c..adab5ad43 100644
--- a/apps/start/src/components/mock-event-list.tsx
+++ b/apps/start/src/components/mock-event-list.tsx
@@ -2,7 +2,7 @@ import { EventListItem } from '@/components/events/event-list-item';
import { AnimatePresence, motion } from 'framer-motion';
import { useEffect, useState } from 'react';
-import type { IServiceEventMinimal } from '@openpanel/db';
+import type { IServiceEventMinimal } from '@openpanel/core';
const useWebEventGenerator = () => {
const [events, setEvents] = useState<IServiceEventMinimal[]>([]);
diff --git a/apps/start/src/components/notifications/table/columns.tsx b/apps/start/src/components/notifications/table/columns.tsx
index 4831c5b75..d2ca48047 100644
--- a/apps/start/src/components/notifications/table/columns.tsx
+++ b/apps/start/src/components/notifications/table/columns.tsx
@@ -7,7 +7,7 @@ import { ProjectLink } from '@/components/links';
import { SerieIcon } from '@/components/report-chart/common/serie-icon';
import { createHeaderColumn } from '@/components/ui/data-table/data-table-helpers';
import type { RouterOutputs } from '@/trpc/client';
-import type { INotificationPayload } from '@openpanel/db';
+import type { INotificationPayload } from '@openpanel/core';
function getEventFromPayload(payload: INotificationPayload | null) {
if (payload?.type === 'event') {
diff --git a/apps/start/src/components/onboarding/connect-web.tsx b/apps/start/src/components/onboarding/connect-web.tsx
index a1b4a9dee..c67c40262 100644
--- a/apps/start/src/components/onboarding/connect-web.tsx
+++ b/apps/start/src/components/onboarding/connect-web.tsx
@@ -1,4 +1,4 @@
-import type { IServiceClient } from '@openpanel/db';
+import type { IServiceClient } from '@openpanel/core';
import { frameworks } from '@openpanel/sdk-info';
import { CopyIcon, PlugIcon } from 'lucide-react';
import { Button } from '../ui/button';
diff --git a/apps/start/src/components/onboarding/onboarding-verify-listener.tsx b/apps/start/src/components/onboarding/onboarding-verify-listener.tsx
index 0360e1a3c..10839f53f 100644
--- a/apps/start/src/components/onboarding/onboarding-verify-listener.tsx
+++ b/apps/start/src/components/onboarding/onboarding-verify-listener.tsx
@@ -1,4 +1,4 @@
-import type { IServiceEvent } from '@openpanel/db';
+import type { IServiceEvent } from '@openpanel/core';
import { CheckCircle2Icon, CheckIcon, Loader2 } from 'lucide-react';
import { cn } from '@/utils/cn';
import { timeAgo } from '@/utils/date';
diff --git a/apps/start/src/components/onboarding/verify-faq.tsx b/apps/start/src/components/onboarding/verify-faq.tsx
index b4f73fcd4..247f2c7a1 100644
--- a/apps/start/src/components/onboarding/verify-faq.tsx
+++ b/apps/start/src/components/onboarding/verify-faq.tsx
@@ -1,4 +1,4 @@
-import type { IServiceProjectWithClients } from '@openpanel/db';
+import type { IServiceProjectWithClients } from '@openpanel/core';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { GlobeIcon, KeyIcon, UserIcon } from 'lucide-react';
import { toast } from 'sonner';
diff --git a/apps/start/src/components/organization/billing-plan-picker.tsx b/apps/start/src/components/organization/billing-plan-picker.tsx
index 80ac819ba..14a3dd36b 100644
--- a/apps/start/src/components/organization/billing-plan-picker.tsx
+++ b/apps/start/src/components/organization/billing-plan-picker.tsx
@@ -1,4 +1,4 @@
-import type { IServiceOrganization } from '@openpanel/db';
+import type { IServiceOrganization } from '@openpanel/core';
import type { IPolarProduct } from '@openpanel/payments';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import {
diff --git a/apps/start/src/components/organization/billing-prompt.tsx b/apps/start/src/components/organization/billing-prompt.tsx
index 33392a3f4..c1055eafd 100644
--- a/apps/start/src/components/organization/billing-prompt.tsx
+++ b/apps/start/src/components/organization/billing-prompt.tsx
@@ -1,4 +1,4 @@
-import type { IServiceOrganization } from '@openpanel/db';
+import type { IServiceOrganization } from '@openpanel/core';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { CheckIcon } from 'lucide-react';
import { useEffect } from 'react';
diff --git a/apps/start/src/components/organization/billing-usage.tsx b/apps/start/src/components/organization/billing-usage.tsx
index 786e8a397..2d6b393f8 100644
--- a/apps/start/src/components/organization/billing-usage.tsx
+++ b/apps/start/src/components/organization/billing-usage.tsx
@@ -1,5 +1,5 @@
import { sum } from '@openpanel/common';
-import type { IServiceOrganization } from '@openpanel/db';
+import type { IServiceOrganization } from '@openpanel/core';
import { useQuery } from '@tanstack/react-query';
import { Loader2Icon } from 'lucide-react';
import {
diff --git a/apps/start/src/components/organization/billing.tsx b/apps/start/src/components/organization/billing.tsx
index d956a18b7..933cab89c 100644
--- a/apps/start/src/components/organization/billing.tsx
+++ b/apps/start/src/components/organization/billing.tsx
@@ -1,4 +1,4 @@
-import type { IServiceOrganization } from '@openpanel/db';
+import type { IServiceOrganization } from '@openpanel/core';
import { getSubscriptionStateMeta } from '@openpanel/payments/subscription-state-meta';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { differenceInDays } from 'date-fns';
diff --git a/apps/start/src/components/organization/cancel-subscription-flow.tsx b/apps/start/src/components/organization/cancel-subscription-flow.tsx
index eb45b0d75..91cca91c0 100644
--- a/apps/start/src/components/organization/cancel-subscription-flow.tsx
+++ b/apps/start/src/components/organization/cancel-subscription-flow.tsx
@@ -1,4 +1,4 @@
-import type { IServiceOrganization } from '@openpanel/db';
+import type { IServiceOrganization } from '@openpanel/core';
import type { ICancellationReason } from '@openpanel/validation';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { CheckIcon } from 'lucide-react';
diff --git a/apps/start/src/components/organization/edit-organization.tsx b/apps/start/src/components/organization/edit-organization.tsx
index 990426adb..235f09051 100644
--- a/apps/start/src/components/organization/edit-organization.tsx
+++ b/apps/start/src/components/organization/edit-organization.tsx
@@ -9,7 +9,7 @@ import { toast } from 'sonner';
import type { z } from 'zod';
import { Combobox } from '@/components/ui/combobox';
-import type { IServiceOrganization } from '@openpanel/db';
+import type { IServiceOrganization } from '@openpanel/core';
import { zEditOrganization } from '@openpanel/validation';
const validator = zEditOrganization;
diff --git a/apps/start/src/components/organization/organization.tsx b/apps/start/src/components/organization/organization.tsx
index d063e92bf..b6303fb51 100644
--- a/apps/start/src/components/organization/organization.tsx
+++ b/apps/start/src/components/organization/organization.tsx
@@ -1,4 +1,4 @@
-import type { IServiceOrganization } from '@openpanel/db';
+import type { IServiceOrganization } from '@openpanel/core';
import EditOrganization from './edit-organization';
interface OrganizationProps {
diff --git a/apps/start/src/components/organization/yearly-switch-prompt.tsx b/apps/start/src/components/organization/yearly-switch-prompt.tsx
index bab8973d9..114fb8f07 100644
--- a/apps/start/src/components/organization/yearly-switch-prompt.tsx
+++ b/apps/start/src/components/organization/yearly-switch-prompt.tsx
@@ -1,4 +1,4 @@
-import type { IServiceOrganization } from '@openpanel/db';
+import type { IServiceOrganization } from '@openpanel/core';
import { useQuery } from '@tanstack/react-query';
import { differenceInMonths } from 'date-fns';
import { useEffect, useState } from 'react';
diff --git a/apps/start/src/components/overview/overview-constants.tsx b/apps/start/src/components/overview/overview-constants.tsx
index 1cd9c209a..72945a4ed 100644
--- a/apps/start/src/components/overview/overview-constants.tsx
+++ b/apps/start/src/components/overview/overview-constants.tsx
@@ -1,4 +1,4 @@
-import type { IGetTopGenericInput } from '@openpanel/db';
+import type { IGetTopGenericInput } from '@openpanel/core';
export const OVERVIEW_COLUMNS_NAME: Record<
IGetTopGenericInput['column'],
diff --git a/apps/start/src/components/overview/overview-top-generic-modal.tsx b/apps/start/src/components/overview/overview-top-generic-modal.tsx
index 0ff17593e..9e7ef60f8 100644
--- a/apps/start/src/components/overview/overview-top-generic-modal.tsx
+++ b/apps/start/src/components/overview/overview-top-generic-modal.tsx
@@ -1,7 +1,7 @@
import { useEventQueryFilters } from '@/hooks/use-event-query-filters';
import { useTRPC } from '@/integrations/trpc/react';
-import type { IGetTopGenericInput } from '@openpanel/db';
+import type { IGetTopGenericInput } from '@openpanel/core';
import { useQuery } from '@tanstack/react-query';
import { ChevronRightIcon } from 'lucide-react';
import { SerieIcon } from '../report-chart/common/serie-icon';
diff --git a/apps/start/src/components/profiles/profile-metrics.tsx b/apps/start/src/components/profiles/profile-metrics.tsx
index 6558c4ee6..9f6b038de 100644
--- a/apps/start/src/components/profiles/profile-metrics.tsx
+++ b/apps/start/src/components/profiles/profile-metrics.tsx
@@ -1,4 +1,4 @@
-import type { IProfileMetrics } from '@openpanel/db';
+import type { IProfileMetrics } from '@openpanel/core';
import { OverviewMetricCard } from '@/components/overview/overview-metric-card';
type Props = {
diff --git a/apps/start/src/components/profiles/profile-properties.tsx b/apps/start/src/components/profiles/profile-properties.tsx
index 16528729d..54ab1a50f 100644
--- a/apps/start/src/components/profiles/profile-properties.tsx
+++ b/apps/start/src/components/profiles/profile-properties.tsx
@@ -4,7 +4,7 @@ import { cn } from '@/utils/cn';
import { formatDateTime } from '@/utils/date';
import { parseAsStringEnum, useQueryState } from 'nuqs';
-import type { IServiceEvent, IServiceProfile } from '@openpanel/db';
+import type { IServiceEvent, IServiceProfile } from '@openpanel/core';
import { FullPageEmptyState } from '../full-page-empty-state';
import { WidgetButtons, WidgetHead } from '../overview/overview-widget';
diff --git a/apps/start/src/components/profiles/table/columns.tsx b/apps/start/src/components/profiles/table/columns.tsx
index b37b0671c..a6f1e59f6 100644
--- a/apps/start/src/components/profiles/table/columns.tsx
+++ b/apps/start/src/components/profiles/table/columns.tsx
@@ -1,4 +1,4 @@
-import type { IServiceProfile } from '@openpanel/db';
+import type { IServiceProfile } from '@openpanel/core';
import type { ColumnDef } from '@tanstack/react-table';
import { ProfileAvatar } from '../profile-avatar';
import { ColumnCreatedAt } from '@/components/column-created-at';
diff --git a/apps/start/src/components/profiles/table/index.tsx b/apps/start/src/components/profiles/table/index.tsx
index de1623e7a..4882ecb11 100644
--- a/apps/start/src/components/profiles/table/index.tsx
+++ b/apps/start/src/components/profiles/table/index.tsx
@@ -1,4 +1,4 @@
-import type { IServiceProfile } from '@openpanel/db';
+import type { IServiceProfile } from '@openpanel/core';
import type { UseQueryResult } from '@tanstack/react-query';
import { useNavigate } from '@tanstack/react-router';
import type { PaginationState, Table, Updater } from '@tanstack/react-table';
diff --git a/apps/start/src/components/project-mapper.tsx b/apps/start/src/components/project-mapper.tsx
index 92002a171..2d5476fa3 100644
--- a/apps/start/src/components/project-mapper.tsx
+++ b/apps/start/src/components/project-mapper.tsx
@@ -8,7 +8,7 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
-import type { IServiceProject } from '@openpanel/db';
+import type { IServiceProject } from '@openpanel/core';
import { PlusIcon, XIcon } from 'lucide-react';
import type {
Control,
diff --git a/apps/start/src/components/project-selector.tsx b/apps/start/src/components/project-selector.tsx
index 89fed538e..ba14eef18 100644
--- a/apps/start/src/components/project-selector.tsx
+++ b/apps/start/src/components/project-selector.tsx
@@ -1,4 +1,4 @@
-import type { IServiceOrganization } from '@openpanel/db';
+import type { IServiceOrganization } from '@openpanel/core';
import { Link, useRouter } from '@tanstack/react-router';
import {
Building2Icon,
diff --git a/apps/start/src/components/projects/project-card.tsx b/apps/start/src/components/projects/project-card.tsx
index a8b026bd6..10e7eef17 100644
--- a/apps/start/src/components/projects/project-card.tsx
+++ b/apps/start/src/components/projects/project-card.tsx
@@ -3,7 +3,7 @@ import { useTRPC } from '@/integrations/trpc/react';
import { useQuery } from '@tanstack/react-query';
import { Link } from '@tanstack/react-router';
-import type { IServiceProject } from '@openpanel/db';
+import type { IServiceProject } from '@openpanel/core';
import { cn } from '@/utils/cn';
import { SettingsIcon, TrendingDownIcon, TrendingUpIcon } from 'lucide-react';
diff --git a/apps/start/src/components/report-chart/report-editor.tsx b/apps/start/src/components/report-chart/report-editor.tsx
index af7bbeb16..c27e1a613 100644
--- a/apps/start/src/components/report-chart/report-editor.tsx
+++ b/apps/start/src/components/report-chart/report-editor.tsx
@@ -1,4 +1,4 @@
-import type { IServiceReport } from '@openpanel/db';
+import type { IServiceReport } from '@openpanel/core';
import { GanttChartSquareIcon, ShareIcon } from 'lucide-react';
import { useEffect } from 'react';
import EditReportName from '../report/edit-report-name';
diff --git a/apps/start/src/components/sessions/replay/index.tsx b/apps/start/src/components/sessions/replay/index.tsx
index 70fec16da..7d02bdd9b 100644
--- a/apps/start/src/components/sessions/replay/index.tsx
+++ b/apps/start/src/components/sessions/replay/index.tsx
@@ -1,4 +1,4 @@
-import type { IServiceEvent } from '@openpanel/db';
+import type { IServiceEvent } from '@openpanel/core';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { Maximize2, Minimize2 } from 'lucide-react';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
diff --git a/apps/start/src/components/sessions/replay/replay-event-feed.tsx b/apps/start/src/components/sessions/replay/replay-event-feed.tsx
index 03fcf4da7..5d938e50e 100644
--- a/apps/start/src/components/sessions/replay/replay-event-feed.tsx
+++ b/apps/start/src/components/sessions/replay/replay-event-feed.tsx
@@ -1,7 +1,7 @@
import { useCurrentTime, useReplayContext } from '@/components/sessions/replay/replay-context';
import { ReplayEventItem } from '@/components/sessions/replay/replay-event-item';
import { ScrollArea } from '@/components/ui/scroll-area';
-import type { IServiceEvent } from '@openpanel/db';
+import type { IServiceEvent } from '@openpanel/core';
import { useEffect, useMemo, useRef } from 'react';
import { BrowserChrome } from './browser-chrome';
import { getEventOffsetMs } from './replay-utils';
diff --git a/apps/start/src/components/sessions/replay/replay-event-item.tsx b/apps/start/src/components/sessions/replay/replay-event-item.tsx
index 28a0102b8..712ef13ef 100644
--- a/apps/start/src/components/sessions/replay/replay-event-item.tsx
+++ b/apps/start/src/components/sessions/replay/replay-event-item.tsx
@@ -1,6 +1,6 @@
import { EventIcon } from '@/components/events/event-icon';
import { cn } from '@/lib/utils';
-import type { IServiceEvent } from '@openpanel/db';
+import type { IServiceEvent } from '@openpanel/core';
function formatTime(date: Date | string): string {
const d = date instanceof Date ? date : new Date(date);
diff --git a/apps/start/src/components/sessions/replay/replay-timeline.tsx b/apps/start/src/components/sessions/replay/replay-timeline.tsx
index 33a9a3f56..81bc22701 100644
--- a/apps/start/src/components/sessions/replay/replay-timeline.tsx
+++ b/apps/start/src/components/sessions/replay/replay-timeline.tsx
@@ -5,7 +5,7 @@ import {
TooltipProvider,
TooltipTrigger,
} from '@/components/ui/tooltip';
-import type { IServiceEvent } from '@openpanel/db';
+import type { IServiceEvent } from '@openpanel/core';
import { AnimatePresence, motion } from 'framer-motion';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
diff --git a/apps/start/src/components/sessions/replay/replay-utils.ts b/apps/start/src/components/sessions/replay/replay-utils.ts
index 415ebae23..f7f3860a2 100644
--- a/apps/start/src/components/sessions/replay/replay-utils.ts
+++ b/apps/start/src/components/sessions/replay/replay-utils.ts
@@ -1,4 +1,4 @@
-import type { IServiceEvent } from '@openpanel/db';
+import type { IServiceEvent } from '@openpanel/core';
export function getEventOffsetMs(
event: IServiceEvent,
diff --git a/apps/start/src/components/sessions/table/columns.tsx b/apps/start/src/components/sessions/table/columns.tsx
index 249450c53..c0f49bfd1 100644
--- a/apps/start/src/components/sessions/table/columns.tsx
+++ b/apps/start/src/components/sessions/table/columns.tsx
@@ -1,5 +1,5 @@
import { round } from '@openpanel/common';
-import type { IServiceSession } from '@openpanel/db';
+import type { IServiceSession } from '@openpanel/core';
import type { ColumnDef } from '@tanstack/react-table';
import { Video } from 'lucide-react';
import { ColumnCreatedAt } from '@/components/column-created-at';
diff --git a/apps/start/src/components/sessions/table/index.tsx b/apps/start/src/components/sessions/table/index.tsx
index 26b7c1619..b26068675 100644
--- a/apps/start/src/components/sessions/table/index.tsx
+++ b/apps/start/src/components/sessions/table/index.tsx
@@ -35,7 +35,7 @@ const usePersistentColumnVisibility = (columns: any[]) => {
};
};
-import type { IServiceSession } from '@openpanel/db';
+import type { IServiceSession } from '@openpanel/core';
import { useNavigate } from '@tanstack/react-router';
import type { Table } from '@tanstack/react-table';
import { getCoreRowModel, useReactTable } from '@tanstack/react-table';
diff --git a/apps/start/src/components/settings/delete-organization.tsx b/apps/start/src/components/settings/delete-organization.tsx
index 39afd112d..54219b143 100644
--- a/apps/start/src/components/settings/delete-organization.tsx
+++ b/apps/start/src/components/settings/delete-organization.tsx
@@ -3,7 +3,7 @@ import { Button } from '@/components/ui/button';
import { Widget, WidgetBody, WidgetHead } from '@/components/widget';
import { handleError, useTRPC } from '@/integrations/trpc/react';
import { pushModal } from '@/modals';
-import type { IServiceOrganization } from '@openpanel/db';
+import type { IServiceOrganization } from '@openpanel/core';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { addHours, format, startOfHour } from 'date-fns';
import { TrashIcon } from 'lucide-react';
diff --git a/apps/start/src/components/settings/delete-project.tsx b/apps/start/src/components/settings/delete-project.tsx
index 2a60c1486..c2f1aa9f5 100644
--- a/apps/start/src/components/settings/delete-project.tsx
+++ b/apps/start/src/components/settings/delete-project.tsx
@@ -3,7 +3,7 @@ import { Button } from '@/components/ui/button';
import { Widget, WidgetBody, WidgetHead } from '@/components/widget';
import { handleError, useTRPC } from '@/integrations/trpc/react';
import { showConfirm } from '@/modals';
-import type { IServiceProjectWithClients } from '@openpanel/db';
+import type { IServiceProjectWithClients } from '@openpanel/core';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useRouter } from '@tanstack/react-router';
import { addHours, format, startOfHour } from 'date-fns';
diff --git a/apps/start/src/components/settings/edit-project-details.tsx b/apps/start/src/components/settings/edit-project-details.tsx
index efebce109..7defd3851 100644
--- a/apps/start/src/components/settings/edit-project-details.tsx
+++ b/apps/start/src/components/settings/edit-project-details.tsx
@@ -9,7 +9,7 @@ import { Switch } from '@/components/ui/switch';
import { Widget, WidgetBody, WidgetHead } from '@/components/widget';
import { handleError, useTRPC } from '@/integrations/trpc/react';
import { zodResolver } from '@hookform/resolvers/zod';
-import type { IServiceProjectWithClients } from '@openpanel/db';
+import type { IServiceProjectWithClients } from '@openpanel/core';
import { zProject } from '@openpanel/validation';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { SaveIcon } from 'lucide-react';
diff --git a/apps/start/src/components/settings/members/columns.tsx b/apps/start/src/components/settings/members/columns.tsx
index 915725665..47a058d47 100644
--- a/apps/start/src/components/settings/members/columns.tsx
+++ b/apps/start/src/components/settings/members/columns.tsx
@@ -9,7 +9,7 @@ import { ColumnCreatedAt } from '@/components/column-created-at';
import { Badge } from '@/components/ui/badge';
import { createActionColumn } from '@/components/ui/data-table/data-table-helpers';
import { pushModal } from '@/modals';
-import type { IServiceMember } from '@openpanel/db';
+import type { IServiceMember } from '@openpanel/core';
export function useColumns() {
const columns: ColumnDef<IServiceMember>[] = [
diff --git a/apps/start/src/components/settings/members/index.tsx b/apps/start/src/components/settings/members/index.tsx
index a23ca81bc..30cc45c2a 100644
--- a/apps/start/src/components/settings/members/index.tsx
+++ b/apps/start/src/components/settings/members/index.tsx
@@ -1,4 +1,4 @@
-import type { IServiceMember } from '@openpanel/db';
+import type { IServiceMember } from '@openpanel/core';
import { DataTable } from '@/components/ui/data-table/data-table';
import { DataTableToolbar } from '@/components/ui/data-table/data-table-toolbar';
diff --git a/apps/start/src/components/sidebar-project-menu.tsx b/apps/start/src/components/sidebar-project-menu.tsx
index 8738bc72b..c0f7e59d8 100644
--- a/apps/start/src/components/sidebar-project-menu.tsx
+++ b/apps/start/src/components/sidebar-project-menu.tsx
@@ -1,4 +1,4 @@
-import type { IServiceDashboards } from '@openpanel/db';
+import type { IServiceDashboards } from '@openpanel/core';
import { useNavigate } from '@tanstack/react-router';
import { AnimatePresence, motion } from 'framer-motion';
import {
diff --git a/apps/start/src/components/sidebar.tsx b/apps/start/src/components/sidebar.tsx
index 114796f63..9f4c4d649 100644
--- a/apps/start/src/components/sidebar.tsx
+++ b/apps/start/src/components/sidebar.tsx
@@ -1,4 +1,4 @@
-import type { IServiceOrganization } from '@openpanel/db';
+import type { IServiceOrganization } from '@openpanel/core';
import { useQuery } from '@tanstack/react-query';
import { Link, useLocation, useParams } from '@tanstack/react-router';
import { MenuIcon, SparklesIcon, XIcon } from 'lucide-react';
diff --git a/apps/start/src/components/ui/key-value-grid.tsx b/apps/start/src/components/ui/key-value-grid.tsx
index 01180dd42..e8299ae38 100644
--- a/apps/start/src/components/ui/key-value-grid.tsx
+++ b/apps/start/src/components/ui/key-value-grid.tsx
@@ -4,7 +4,7 @@ import { camelCaseToWords } from '@/utils/casing';
import { clipboard } from '@/utils/clipboard';
import { cn } from '@/utils/cn';
import { formatDateTime, formatTime } from '@/utils/date';
-import type { IServiceEvent } from '@openpanel/db';
+import type { IServiceEvent } from '@openpanel/core';
import { isToday } from 'date-fns';
import { CopyIcon } from 'lucide-react';
import { SerieIcon } from '../report-chart/common/serie-icon';
diff --git a/apps/start/src/modals/Instructions.tsx b/apps/start/src/modals/Instructions.tsx
index ba183a098..126ece295 100644
--- a/apps/start/src/modals/Instructions.tsx
+++ b/apps/start/src/modals/Instructions.tsx
@@ -9,7 +9,7 @@ import {
} from '@/components/ui/sheet';
import { ExternalLinkIcon, XIcon } from 'lucide-react';
-import type { IServiceClient } from '@openpanel/db';
+import type { IServiceClient } from '@openpanel/core';
import type { frameworks } from '@openpanel/sdk-info';
import { popModal } from '.';
diff --git a/apps/start/src/modals/create-invite.tsx b/apps/start/src/modals/create-invite.tsx
index 5b851bca8..c1a4de663 100644
--- a/apps/start/src/modals/create-invite.tsx
+++ b/apps/start/src/modals/create-invite.tsx
@@ -19,7 +19,7 @@ import type { z } from 'zod';
import { ProjectAccessGrants } from '@/components/settings/project-access-grants';
import { useTRPC } from '@/integrations/trpc/react';
-import type { IServiceProject } from '@openpanel/db';
+import type { IServiceProject } from '@openpanel/core';
import { zInviteUser } from '@openpanel/validation';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
diff --git a/apps/start/src/modals/edit-client.tsx b/apps/start/src/modals/edit-client.tsx
index c88fe41cd..c039eb391 100644
--- a/apps/start/src/modals/edit-client.tsx
+++ b/apps/start/src/modals/edit-client.tsx
@@ -10,7 +10,7 @@ import { useForm } from 'react-hook-form';
import { toast } from 'sonner';
import { z } from 'zod';
-import type { IServiceClient } from '@openpanel/db';
+import type { IServiceClient } from '@openpanel/core';
import { popModal } from '.';
import { ModalContent, ModalHeader } from './Modal/Container';
diff --git a/apps/start/src/modals/edit-dashboard.tsx b/apps/start/src/modals/edit-dashboard.tsx
index 557f463ca..8131fc301 100644
--- a/apps/start/src/modals/edit-dashboard.tsx
+++ b/apps/start/src/modals/edit-dashboard.tsx
@@ -10,7 +10,7 @@ import { useForm } from 'react-hook-form';
import { toast } from 'sonner';
import { z } from 'zod';
-import type { IServiceDashboard } from '@openpanel/db';
+import type { IServiceDashboard } from '@openpanel/core';
import { popModal } from '.';
import { ModalContent, ModalHeader } from './Modal/Container';
diff --git a/apps/start/src/modals/edit-group.tsx b/apps/start/src/modals/edit-group.tsx
index 851a3a3d8..e4015f74c 100644
--- a/apps/start/src/modals/edit-group.tsx
+++ b/apps/start/src/modals/edit-group.tsx
@@ -1,5 +1,5 @@
import { zodResolver } from '@hookform/resolvers/zod';
-import type { IServiceGroup } from '@openpanel/db';
+import type { IServiceGroup } from '@openpanel/core';
import { zUpdateGroup } from '@openpanel/validation';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { PlusIcon, Trash2Icon } from 'lucide-react';
diff --git a/apps/start/src/modals/edit-member.tsx b/apps/start/src/modals/edit-member.tsx
index e8c36fdca..bd5af023b 100644
--- a/apps/start/src/modals/edit-member.tsx
+++ b/apps/start/src/modals/edit-member.tsx
@@ -7,7 +7,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useState } from 'react';
import { toast } from 'sonner';
-import type { IServiceMember } from '@openpanel/db';
+import type { IServiceMember } from '@openpanel/core';
import type { IProjectAccessGrant } from '@openpanel/validation';
import { popModal } from '.';
diff --git a/apps/start/src/modals/edit-reference.tsx b/apps/start/src/modals/edit-reference.tsx
index f2cc58b27..ad2a18d2e 100644
--- a/apps/start/src/modals/edit-reference.tsx
+++ b/apps/start/src/modals/edit-reference.tsx
@@ -10,7 +10,7 @@ import { Controller, useForm } from 'react-hook-form';
import { toast } from 'sonner';
import { z } from 'zod';
-import type { IServiceReference } from '@openpanel/db';
+import type { IServiceReference } from '@openpanel/core';
import { popModal } from '.';
import { ModalContent, ModalHeader } from './Modal/Container';
diff --git a/apps/start/src/modals/event-details.tsx b/apps/start/src/modals/event-details.tsx
index 11e2854f0..fe07643de 100644
--- a/apps/start/src/modals/event-details.tsx
+++ b/apps/start/src/modals/event-details.tsx
@@ -1,4 +1,4 @@
-import type { IClickhouseEvent, IServiceEvent } from '@openpanel/db';
+import type { IClickhouseEvent, IServiceEvent } from '@openpanel/core';
import { useSuspenseQuery } from '@tanstack/react-query';
import { FilterIcon, XIcon } from 'lucide-react';
import { omit } from 'ramda';
diff --git a/apps/start/src/modals/select-billing-plan.tsx b/apps/start/src/modals/select-billing-plan.tsx
index e5ee1e885..f18469970 100644
--- a/apps/start/src/modals/select-billing-plan.tsx
+++ b/apps/start/src/modals/select-billing-plan.tsx
@@ -1,4 +1,4 @@
-import type { IServiceOrganization } from '@openpanel/db';
+import type { IServiceOrganization } from '@openpanel/core';
import type { IPolarProduct } from '@openpanel/payments';
import { useState } from 'react';
import { popModal } from '.';
diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.references.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.references.tsx
index 7e3b8e640..5461bffe0 100644
--- a/apps/start/src/routes/_app.$organizationId.$projectId.references.tsx
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.references.tsx
@@ -20,7 +20,7 @@ import { useTRPC } from '@/integrations/trpc/react';
import { pushModal, showConfirm } from '@/modals';
import { formatDate, formatDateTime } from '@/utils/date';
import { PAGE_TITLES, createProjectTitle } from '@/utils/title';
-import type { IServiceReference } from '@openpanel/db';
+import type { IServiceReference } from '@openpanel/core';
import {
keepPreviousData,
useMutation,
diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.sessions_.$sessionId.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.sessions_.$sessionId.tsx
index 81e049822..3be8da025 100644
--- a/apps/start/src/routes/_app.$organizationId.$projectId.sessions_.$sessionId.tsx
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.sessions_.$sessionId.tsx
@@ -1,4 +1,4 @@
-import type { IServiceEvent, IServiceSession } from '@openpanel/db';
+import type { IServiceEvent, IServiceSession } from '@openpanel/core';
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
import { createFileRoute, Link } from '@tanstack/react-router';
import { EventIcon } from '@/components/events/event-icon';
diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.settings._tabs.tracking.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.settings._tabs.tracking.tsx
index dbebd244c..e51e46b31 100644
--- a/apps/start/src/routes/_app.$organizationId.$projectId.settings._tabs.tracking.tsx
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.settings._tabs.tracking.tsx
@@ -1,4 +1,4 @@
-import type { IServiceClient } from '@openpanel/db';
+import type { IServiceClient } from '@openpanel/core';
import { frameworks } from '@openpanel/sdk-info';
import { useQuery } from '@tanstack/react-query';
import { createFileRoute } from '@tanstack/react-router';
diff --git a/apps/start/src/utils/getters.ts b/apps/start/src/utils/getters.ts
index 411dc9448..b8e294fc4 100644
--- a/apps/start/src/utils/getters.ts
+++ b/apps/start/src/utils/getters.ts
@@ -1,4 +1,4 @@
-import type { IServiceProfile } from '@openpanel/db';
+import type { IServiceProfile } from '@openpanel/core';
export type GetProfileNameProps = Partial<
Pick<
diff --git a/packages/core/package.json b/packages/core/package.json
index 39387f0ca..c44823651 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -38,6 +38,7 @@
"@openpanel/db": "workspace:*",
"@openpanel/email": "workspace:*",
"@openpanel/payments": "workspace:*",
+ "@openpanel/queue": "workspace:*",
"@openpanel/redis": "workspace:*",
"@openpanel/validation": "workspace:*",
"@oslojs/crypto": "^1.0.1",
diff --git a/packages/core/src/buffers/lazy-db-buffers.ts b/packages/core/src/buffers/lazy-db-buffers.ts
index 8ea0b3140..3f9d1f747 100644
--- a/packages/core/src/buffers/lazy-db-buffers.ts
+++ b/packages/core/src/buffers/lazy-db-buffers.ts
@@ -1,12 +1,10 @@
-// The seven buffer singletons are built once by @openpanel/db's src/buffers
-// (the V1 delegate — see that file's header) and, once V2 owns boot, handed
-// to AppDeps by createBuffers directly. Until then, every core module that
-// needs a buffer ahead of that boot wiring reaches it through THIS one
-// dynamic import() — see session.service.ts's loadProfileService comment:
-// rolldown cannot finalize a dynamic-import cycle when apps/api or
-// apps/worker bundles the workspace and 2+ separate call sites each reopen
-// the same core -> @openpanel/db -> core edge (db/buffers imports
-// `createBuffers` from the core barrel). One edge, one file.
+// The seven buffer singletons are built once by @openpanel/queue's
+// src/buffers.ts (moved from @openpanel/db, M9-CLEANUP-001 — see that file's
+// header for why @openpanel/queue and not here) and, once V2 owns boot,
+// handed to AppDeps by createBuffers directly. Until then, every core module
+// that needs a buffer ahead of that boot wiring reaches it through THIS one
+// dynamic import() — one edge, one file, same reasoning as
+// session.service.ts's loadProfileService comment.
export function loadDbBuffers() {
- return import('@openpanel/db/src/buffers');
+ return import('@openpanel/queue/src/buffers');
}
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 1fe340aa9..14fcfeff1 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -565,9 +565,11 @@ export { emailCategories } from './modules/email/email.constants';
// "R,S,C") — packages/trpc's routers, apps/api's export controller, is-bot
// hook and profile controller, apps/worker's incoming-event job and the
// assistant/mcp tools call these directly, the same way V1 reaches every
-// other dissolved service here. packages/db keeps re-export shims for all
-// three files (the buffers' row types and cohort.service's profileSearchSql
-// still resolve through them).
+// other dissolved service here. `packages/db`'s re-export shims for these
+// three files are gone (M9-CLEANUP-001) — every caller now imports this
+// barrel directly, and `profileSearchSql` (cohort.service's one addition atop
+// the shim) moved to profile/src/profile.sql.ts alongside its sibling
+// `profileSearchCondition`.
export type {
EventListSelect,
GetEventListOptions,
@@ -705,12 +707,14 @@ export {
upsertIntegration,
} from './modules/integration/integration.service';
// Dissolved from @openpanel/db's services/notification.service.ts (M6-005,
-// "rules + dispatch stay together") — packages/trpc's notification router,
-// packages/db's own enqueue orchestration (createNotification et al, which
-// stays there — see that file's header for why) and apps/worker's
-// notification job all call these directly, the same way V1 reaches every
-// other dissolved service here. packages/db/src/services/notification.service.ts
-// stays a re-export shim for the pieces that moved.
+// "rules + dispatch stay together") — packages/trpc's notification router
+// and apps/worker's notification job call these directly, the same way V1
+// reaches every other dissolved service here. `createNotification` /
+// `triggerNotification` / `checkNotificationRulesForEvent` /
+// `checkNotificationRulesForSessionEnd` — the BullMQ-producer orchestration
+// around a rule match — moved to `@openpanel/queue/src/notification-dispatch.ts`
+// (M9-CLEANUP-001, packages/db's final-surface shrink), not here: core still
+// cannot import `@openpanel/queue` back without a real package cycle.
export type {
INotificationPayload,
INotificationRuleCached,
@@ -1035,9 +1039,9 @@ export {
// (M7-001, ADR-008's module map: session owns "R,S,J") — packages/trpc's
// session router, the assistant/mcp tools and apps/worker's thin delegates
// call these directly, the same way V1 reaches every other dissolved service
-// here. packages/db keeps re-export shims for both files. The `sessions`
-// queue's own job and the reaper/vacuum cron fragments are registered in
-// jobs.registry.ts, not exported.
+// here. `packages/db`'s re-export shims for both files are gone
+// (M9-CLEANUP-001). The `sessions` queue's own job and the reaper/vacuum cron
+// fragments are registered in jobs.registry.ts, not exported.
export type {
GetSessionListOptions,
IClickhouseSession,
@@ -1148,13 +1152,12 @@ export {
// SessionManager to manage.
//
// Loaded via dynamic import, NOT a static re-export, for the same reason
-// `getChatApp`/`runFilterCommand` above are: `mcp.service` reaches
-// `@openpanel/db` (auth's client lookup, every analytics tool), and
-// `@openpanel/db/src/buffers/index.ts` already imports `@openpanel/core`
-// eagerly. A static export here would make this barrel's own evaluation
-// re-enter `@openpanel/db` mid-evaluation — observed as a `PagesService` TDZ
-// ReferenceError two modules away, in a tool file that never otherwise runs
-// at import time.
+// `getChatApp`/`runFilterCommand` above are: `mcp.service` reaches this same
+// barrel (auth's client lookup, every analytics tool, all moved onto
+// `@openpanel/core` directly since M9-CLEANUP-001). A static export here
+// would make this barrel's own evaluation re-enter itself mid-evaluation —
+// observed as a `PagesService` TDZ ReferenceError two modules away, in a tool
+// file that never otherwise runs at import time.
let _mcp: Promise<typeof import('./modules/mcp/mcp.service')> | undefined;
function loadMcp() {
if (!_mcp) {
diff --git a/packages/core/src/modules/assistant/assistant.routes.ts b/packages/core/src/modules/assistant/assistant.routes.ts
index 8ee4a88ee..e9b741e99 100644
--- a/packages/core/src/modules/assistant/assistant.routes.ts
+++ b/packages/core/src/modules/assistant/assistant.routes.ts
@@ -17,14 +17,13 @@
// unconsumed `request` so it can re-read the body itself.
//
// Everything below is dynamically imported, not statically — index.ts's
-// header explains why a static import of `@openpanel/db` or
-// `./assistant.service` here would race `@openpanel/db`'s own circular
-// `buffers/base-buffer.ts` -> `@openpanel/core` import.
+// header explains why a static import of this barrel or `./assistant.service`
+// here would race this module's own evaluation.
import { defineRoutes } from '../../http/define';
-function loadDb() {
- return import('@openpanel/db');
+function loadCore() {
+ return import('@openpanel/core');
}
function loadAssistant() {
return import('./assistant.service');
@@ -65,7 +64,7 @@ export const assistantRoutes = defineRoutes((app) =>
// A brand-new chat (no row yet) falls through to the agent handler,
// whose `ConversationStore.load()` returns null.
if (route === 'conversations' && routeId) {
- const { getConversationById } = await loadDb();
+ const { getConversationById } = await loadCore();
const conv = await getConversationById(routeId);
if (conv && conv.userId !== userId) {
return status(404, { message: 'Conversation not found' });
@@ -92,7 +91,7 @@ export const assistantRoutes = defineRoutes((app) =>
getOrganizationByProjectIdCached,
getProjectAccess,
getSettingsForProject,
- } = await loadDb();
+ } = await loadCore();
const [access, organization, settings] = await Promise.all([
getProjectAccess({ projectId, userId }),
getOrganizationByProjectIdCached(projectId),
diff --git a/packages/core/src/modules/assistant/src/filter-command.ts b/packages/core/src/modules/assistant/src/filter-command.ts
index 8ba9fb740..d3d1c41d6 100644
--- a/packages/core/src/modules/assistant/src/filter-command.ts
+++ b/packages/core/src/modules/assistant/src/filter-command.ts
@@ -16,7 +16,7 @@ import {
getTrafficBreakdownCore,
listEventNamesCore,
resolveDateRange as resolveDateRangeCore,
-} from '@openpanel/db';
+} from '@openpanel/core';
import {
type IChartEventFilter,
type IChartRange,
diff --git a/packages/core/src/modules/assistant/src/report-runner.ts b/packages/core/src/modules/assistant/src/report-runner.ts
index fcbc4a5c4..187ed1d02 100644
--- a/packages/core/src/modules/assistant/src/report-runner.ts
+++ b/packages/core/src/modules/assistant/src/report-runner.ts
@@ -23,7 +23,7 @@ import {
getFunnel,
getReportById,
getSettingsForProject,
-} from '@openpanel/db';
+} from '@openpanel/core';
function reportUrl(
organizationId: string,
diff --git a/packages/core/src/modules/assistant/src/tools/base.ts b/packages/core/src/modules/assistant/src/tools/base.ts
index 67bc2da4d..39d843c9b 100644
--- a/packages/core/src/modules/assistant/src/tools/base.ts
+++ b/packages/core/src/modules/assistant/src/tools/base.ts
@@ -15,7 +15,7 @@ import {
listReportsCore,
queryEventsCore,
querySessionsCore,
-} from '@openpanel/db';
+} from '@openpanel/core';
import { zReportInput } from '@openpanel/validation';
import { z } from 'zod';
import { runReport, runReportFromConfig } from '../report-runner';
diff --git a/packages/core/src/modules/assistant/src/tools/dashboard.ts b/packages/core/src/modules/assistant/src/tools/dashboard.ts
index 4489fa793..405a425e2 100644
--- a/packages/core/src/modules/assistant/src/tools/dashboard.ts
+++ b/packages/core/src/modules/assistant/src/tools/dashboard.ts
@@ -6,7 +6,7 @@ import {
getFunnel,
getReportsByDashboardId,
getSettingsForProject,
-} from '@openpanel/db';
+} from '@openpanel/core';
import type { IChartRange, IInterval } from '@openpanel/validation';
import { z } from 'zod';
import { chatTool, dashboardUrl } from './helpers';
diff --git a/packages/core/src/modules/assistant/src/tools/events.ts b/packages/core/src/modules/assistant/src/tools/events.ts
index b504ab396..52a7252bf 100644
--- a/packages/core/src/modules/assistant/src/tools/events.ts
+++ b/packages/core/src/modules/assistant/src/tools/events.ts
@@ -2,7 +2,7 @@ import {
getEventPropertyValuesCore,
listEventPropertiesCore,
queryEventsCore,
-} from '@openpanel/db';
+} from '@openpanel/core';
import { z } from 'zod';
import {
chatTool,
diff --git a/packages/core/src/modules/assistant/src/tools/groups.ts b/packages/core/src/modules/assistant/src/tools/groups.ts
index 9a1c21c7e..ac8cc4f25 100644
--- a/packages/core/src/modules/assistant/src/tools/groups.ts
+++ b/packages/core/src/modules/assistant/src/tools/groups.ts
@@ -3,7 +3,7 @@ import {
getGroupCore,
getGroupMemberProfiles,
queryEventsCore,
-} from '@openpanel/db';
+} from '@openpanel/core';
import { z } from 'zod';
import { chatTool, dashboardUrl, truncateRows } from './helpers';
diff --git a/packages/core/src/modules/assistant/src/tools/helpers.ts b/packages/core/src/modules/assistant/src/tools/helpers.ts
index c8be502b2..e48d394f0 100644
--- a/packages/core/src/modules/assistant/src/tools/helpers.ts
+++ b/packages/core/src/modules/assistant/src/tools/helpers.ts
@@ -6,7 +6,7 @@ import {
import {
getDatesFromRange,
resolveDateRange as resolveDateRangeCore,
-} from '@openpanel/db';
+} from '@openpanel/core';
import type { IChartEventFilter, IChartRange } from '@openpanel/validation';
import type { z } from 'zod';
import type { ChatAgentContext, PageContext } from '../context';
diff --git a/packages/core/src/modules/assistant/src/tools/pages.ts b/packages/core/src/modules/assistant/src/tools/pages.ts
index 8fc1d5ce9..8fa6bc975 100644
--- a/packages/core/src/modules/assistant/src/tools/pages.ts
+++ b/packages/core/src/modules/assistant/src/tools/pages.ts
@@ -3,7 +3,7 @@ import {
getPageConversionsCore,
getPagePerformanceCore,
getTopPagesCore,
-} from '@openpanel/db';
+} from '@openpanel/core';
import { z } from 'zod';
import {
chatTool,
diff --git a/packages/core/src/modules/assistant/src/tools/profile.ts b/packages/core/src/modules/assistant/src/tools/profile.ts
index c43703247..e5c50aa5e 100644
--- a/packages/core/src/modules/assistant/src/tools/profile.ts
+++ b/packages/core/src/modules/assistant/src/tools/profile.ts
@@ -5,7 +5,7 @@ import {
getProfileSessionsCore,
getProfileWithEvents,
queryEventsCore,
-} from '@openpanel/db';
+} from '@openpanel/core';
import { z } from 'zod';
import { chatTool, dashboardUrl, truncateRows } from './helpers';
diff --git a/packages/core/src/modules/assistant/src/tools/report.ts b/packages/core/src/modules/assistant/src/tools/report.ts
index 889b1d622..6eadb084d 100644
--- a/packages/core/src/modules/assistant/src/tools/report.ts
+++ b/packages/core/src/modules/assistant/src/tools/report.ts
@@ -1,4 +1,4 @@
-import { listEventPropertiesCore } from '@openpanel/db';
+import { listEventPropertiesCore } from '@openpanel/core';
import type { IReportInput } from '@openpanel/validation';
import { z } from 'zod';
import { runReportFromConfig } from '../report-runner';
diff --git a/packages/core/src/modules/assistant/src/tools/seo.ts b/packages/core/src/modules/assistant/src/tools/seo.ts
index a8fb5ded5..47aae48e7 100644
--- a/packages/core/src/modules/assistant/src/tools/seo.ts
+++ b/packages/core/src/modules/assistant/src/tools/seo.ts
@@ -7,7 +7,7 @@ import {
gscGetQueryOpportunitiesCore,
gscGetTopPagesCore,
gscGetTopQueriesCore,
-} from '@openpanel/db';
+} from '@openpanel/core';
import { z } from 'zod';
import { chatTool, resolveDateRange, truncateRows } from './helpers';
diff --git a/packages/core/src/modules/assistant/src/tools/session.ts b/packages/core/src/modules/assistant/src/tools/session.ts
index 3dff771bd..53971caea 100644
--- a/packages/core/src/modules/assistant/src/tools/session.ts
+++ b/packages/core/src/modules/assistant/src/tools/session.ts
@@ -1,8 +1,8 @@
import {
+ getSessionById,
queryEventsCore,
querySessionsCore,
- sessionService,
-} from '@openpanel/db';
+} from '@openpanel/core';
import { z } from 'zod';
import { chatTool, dashboardUrl, truncateRows } from './helpers';
@@ -18,7 +18,7 @@ export const getSessionFull = chatTool(
async ({ sessionId }, context) => {
const id = sessionId || context.pageContext?.ids?.sessionId || '';
const [session, events] = await Promise.all([
- sessionService.byId(id, context.projectId),
+ getSessionById(id, context.projectId),
queryEventsCore({
projectId: context.projectId,
sessionId: id,
@@ -106,7 +106,7 @@ export const getSimilarSessions = chatTool(
},
async ({ sessionId, limit }, context) => {
const id = sessionId || context.pageContext?.ids?.sessionId || '';
- const session = await sessionService.byId(id, context.projectId);
+ const session = await getSessionById(id, context.projectId);
const similar = await querySessionsCore({
projectId: context.projectId,
@@ -147,7 +147,7 @@ export const compareSessionToTypical = chatTool(
},
async ({ sessionId }, context) => {
const id = sessionId || context.pageContext?.ids?.sessionId || '';
- const session = await sessionService.byId(id, context.projectId);
+ const session = await getSessionById(id, context.projectId);
// Sample recent sessions to compute project averages.
const sample = await querySessionsCore({
@@ -216,7 +216,7 @@ export const getSessionReferrerContext = chatTool(
},
async ({ sessionId }, context) => {
const id = sessionId || context.pageContext?.ids?.sessionId || '';
- const session = await sessionService.byId(id, context.projectId);
+ const session = await getSessionById(id, context.projectId);
if (!(session.referrer || session.referrerName)) {
return {
@@ -260,7 +260,7 @@ export const getSessionReplaySummary = chatTool(
},
async ({ sessionId }, context) => {
const id = sessionId || context.pageContext?.ids?.sessionId || '';
- const session = await sessionService.byId(id, context.projectId);
+ const session = await getSessionById(id, context.projectId);
return {
session_id: id,
available: session.hasReplay ?? false,
diff --git a/packages/core/src/modules/auth/auth.service.ts b/packages/core/src/modules/auth/auth.service.ts
index 7564c1671..22d02cd87 100644
--- a/packages/core/src/modules/auth/auth.service.ts
+++ b/packages/core/src/modules/auth/auth.service.ts
@@ -173,7 +173,7 @@ function loadAuthSession() {
}
function loadRegistration() {
- return import('@openpanel/db/src/services/registration.service');
+ return import('@openpanel/core');
}
function loadShare() {
diff --git a/packages/core/src/modules/chart/chart.rpc.ts b/packages/core/src/modules/chart/chart.rpc.ts
index 4ca06f326..8e5220aa0 100644
--- a/packages/core/src/modules/chart/chart.rpc.ts
+++ b/packages/core/src/modules/chart/chart.rpc.ts
@@ -11,7 +11,7 @@
// saved report, and the request renders that report (the caller may only move
// the date window). `resolveShare` is that middleware, inlined.
-import type { IServiceReport } from '@openpanel/db/src/services/reports.service';
+import type { IServiceReport } from '@openpanel/core';
import {
type IReportInput,
zChartEventFilter,
@@ -53,7 +53,7 @@ function loadAccessChecks() {
}
function loadReportsService() {
- return import('@openpanel/db/src/services/reports.service');
+ return import('@openpanel/core');
}
function requireLogin(userId: string | null | undefined): string {
diff --git a/packages/core/src/modules/chart/chart.service.ts b/packages/core/src/modules/chart/chart.service.ts
index 863112680..7a26cc352 100644
--- a/packages/core/src/modules/chart/chart.service.ts
+++ b/packages/core/src/modules/chart/chart.service.ts
@@ -16,8 +16,8 @@
import {
getChartPrevStartEndDate,
getChartStartEndDate,
-} from '@openpanel/db/src/services/date.service';
-import type { IServiceReport } from '@openpanel/db/src/services/reports.service';
+} from '@openpanel/core';
+import type { IServiceReport } from '@openpanel/core';
import type {
FinalChart,
IChartEventFilter,
@@ -175,7 +175,7 @@ const FIXED_FILTER_PROPERTIES = [
];
function loadReportsService() {
- return import('@openpanel/db/src/services/reports.service');
+ return import('@openpanel/core');
}
async function getProfilesInBatches(
diff --git a/packages/core/src/modules/chart/conversion.service.ts b/packages/core/src/modules/chart/conversion.service.ts
index a7a0f2875..6505efe29 100644
--- a/packages/core/src/modules/chart/conversion.service.ts
+++ b/packages/core/src/modules/chart/conversion.service.ts
@@ -21,7 +21,7 @@ import { runQuery } from './src/run-query';
// Lazy: packages/db's reports.service imports the funnel shim, which points
// back here — a static import would close the cycle at module load.
function loadReportsService() {
- return import('@openpanel/db/src/services/reports.service');
+ return import('@openpanel/core');
}
/** Default funnel window, in hours, when the report does not set one. */
diff --git a/packages/core/src/modules/chart/funnel.service.ts b/packages/core/src/modules/chart/funnel.service.ts
index f67b6cec1..4529567a8 100644
--- a/packages/core/src/modules/chart/funnel.service.ts
+++ b/packages/core/src/modules/chart/funnel.service.ts
@@ -29,7 +29,7 @@ import { runQuery } from './src/run-query';
// Lazy: packages/db's reports.service imports the funnel shim, which points
// back here — a static import would close the cycle at module load.
function loadReportsService() {
- return import('@openpanel/db/src/services/reports.service');
+ return import('@openpanel/core');
}
export {
diff --git a/packages/core/src/modules/chart/src/access.ts b/packages/core/src/modules/chart/src/access.ts
index 3d8985453..1ec67b626 100644
--- a/packages/core/src/modules/chart/src/access.ts
+++ b/packages/core/src/modules/chart/src/access.ts
@@ -8,8 +8,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/chart/src/engine/execute.ts b/packages/core/src/modules/chart/src/engine/execute.ts
index 61084e465..738bc25a5 100644
--- a/packages/core/src/modules/chart/src/engine/execute.ts
+++ b/packages/core/src/modules/chart/src/engine/execute.ts
@@ -1,4 +1,4 @@
-import { getChartPrevStartEndDate } from '@openpanel/db/src/services/date.service';
+import { getChartPrevStartEndDate } from '@openpanel/core';
import type { FinalChart, IReportInput } from '@openpanel/validation';
import {
getOrganizationSubscriptionChartEndDate,
diff --git a/packages/core/src/modules/chart/src/engine/normalize.ts b/packages/core/src/modules/chart/src/engine/normalize.ts
index f20dfe92a..28b3c6bc1 100644
--- a/packages/core/src/modules/chart/src/engine/normalize.ts
+++ b/packages/core/src/modules/chart/src/engine/normalize.ts
@@ -1,5 +1,5 @@
import { alphabetIds } from '@openpanel/constants';
-import { getChartStartEndDate } from '@openpanel/db/src/services/date.service';
+import { getChartStartEndDate } from '@openpanel/core';
import type {
IChartEvent,
IReportInput,
@@ -15,7 +15,7 @@ export type NormalizedInput = IReportInputWithDates & {
// `mergeGlobalFilters` belongs to the report module (its own task); until it
// moves, reach V1's copy lazily — reports.service imports prisma at load.
function loadGlobalFilterMerge() {
- return import('@openpanel/db/src/services/reports.service').then(
+ return import('@openpanel/core').then(
(m) => m.mergeGlobalFilters
);
}
diff --git a/packages/core/src/modules/chart/src/funnel.sql.test.ts b/packages/core/src/modules/chart/src/funnel.sql.test.ts
index b6a5f2dc3..b25faf1e1 100644
--- a/packages/core/src/modules/chart/src/funnel.sql.test.ts
+++ b/packages/core/src/modules/chart/src/funnel.sql.test.ts
@@ -46,7 +46,7 @@ let buildFunnelBase: typeof import('../funnel.service').buildFunnelBase;
let funnelChartQuery: typeof import('./funnel.sql').funnelChartQuery;
let funnelProfilesQuery: typeof import('./funnel.sql').funnelProfilesQuery;
let funnelStepConditions: typeof import('./funnel.sql').funnelStepConditions;
-let onlyReportEvents: typeof import('@openpanel/db/src/services/reports.service').onlyReportEvents;
+let onlyReportEvents: typeof import('@openpanel/core').onlyReportEvents;
const PROJECT_ID = 'test-sql-validation';
const START = '2026-04-14 00:00:00';
@@ -147,7 +147,7 @@ beforeAll(async () => {
({ funnelChartQuery, funnelProfilesQuery, funnelStepConditions } =
await import('./funnel.sql'));
({ onlyReportEvents } = await import(
- '@openpanel/db/src/services/reports.service'
+ '@openpanel/core'
));
});
diff --git a/packages/core/src/modules/client/src/access.ts b/packages/core/src/modules/client/src/access.ts
index b4444d963..28c7ac8f5 100644
--- a/packages/core/src/modules/client/src/access.ts
+++ b/packages/core/src/modules/client/src/access.ts
@@ -9,11 +9,11 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
+} from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
import { getProjectById } from '../../project/project.service';
-export { getClientAccess } from '@openpanel/db/src/services/access.service';
+export { getClientAccess } from '@openpanel/core';
const checks = createAccessChecks({
getProjectAccess,
diff --git a/packages/core/src/modules/cohort/cohort.service.ts b/packages/core/src/modules/cohort/cohort.service.ts
index a7c455a28..e49f59bc2 100644
--- a/packages/core/src/modules/cohort/cohort.service.ts
+++ b/packages/core/src/modules/cohort/cohort.service.ts
@@ -33,7 +33,7 @@
// mutations and its cron fragment).
import type { ClickHouseSettings } from '@clickhouse/client';
-import type { IServiceProfile } from '@openpanel/db/src/services/profile.service';
+import type { IServiceProfile } from '@openpanel/core';
import type { IChartEventFilter } from '@openpanel/validation';
import sqlstring from 'sqlstring';
import type { ServiceDeps } from '../../services';
@@ -785,7 +785,7 @@ export async function listCohortMemberProfiles({
const { chQuery } = await loadChClient();
const { buildFilterWhere } = await import('../chart/src/table-filter-where');
const { getProfiles, profileSearchSql } = await import(
- '@openpanel/db/src/services/profile.service'
+ '../profile/profile.service'
);
const offset = Math.max(0, (cursor ?? 0) * take);
diff --git a/packages/core/src/modules/cohort/src/access.ts b/packages/core/src/modules/cohort/src/access.ts
index de4a4168e..b82a18072 100644
--- a/packages/core/src/modules/cohort/src/access.ts
+++ b/packages/core/src/modules/cohort/src/access.ts
@@ -7,8 +7,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/conversation/conversation.rpc.ts b/packages/core/src/modules/conversation/conversation.rpc.ts
index 3aca98310..f1873dd89 100644
--- a/packages/core/src/modules/conversation/conversation.rpc.ts
+++ b/packages/core/src/modules/conversation/conversation.rpc.ts
@@ -35,7 +35,7 @@ function loadAccessChecks() {
}
function loadOrganizationService() {
- return import('@openpanel/db/src/services/organization.service');
+ return import('@openpanel/core');
}
function requireLogin(userId: string | null | undefined): string {
diff --git a/packages/core/src/modules/conversation/src/access.ts b/packages/core/src/modules/conversation/src/access.ts
index de4a4168e..b82a18072 100644
--- a/packages/core/src/modules/conversation/src/access.ts
+++ b/packages/core/src/modules/conversation/src/access.ts
@@ -7,8 +7,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/dashboard/dashboard.service.ts b/packages/core/src/modules/dashboard/dashboard.service.ts
index 5143e5b82..e87bc3523 100644
--- a/packages/core/src/modules/dashboard/dashboard.service.ts
+++ b/packages/core/src/modules/dashboard/dashboard.service.ts
@@ -28,7 +28,7 @@ function loadDb() {
}
function loadIdService() {
- return import('@openpanel/db/src/services/id.service').then((m) => m.getId);
+ return import('@openpanel/core').then((m) => m.getId);
}
export async function getDashboardById(id: string, projectId: string) {
diff --git a/packages/core/src/modules/dashboard/src/access.ts b/packages/core/src/modules/dashboard/src/access.ts
index 315315e48..a080240fc 100644
--- a/packages/core/src/modules/dashboard/src/access.ts
+++ b/packages/core/src/modules/dashboard/src/access.ts
@@ -8,8 +8,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/event/event.rpc.ts b/packages/core/src/modules/event/event.rpc.ts
index 3de8312d9..58adbfcfb 100644
--- a/packages/core/src/modules/event/event.rpc.ts
+++ b/packages/core/src/modules/event/event.rpc.ts
@@ -53,9 +53,9 @@ function loadAccessChecks() {
function loadPagesRuntime() {
return Promise.all([
- import('@openpanel/db/src/services/organization.service'),
- import('@openpanel/db/src/services/date.service'),
- import('@openpanel/db/src/services/pages.service'),
+ import('@openpanel/core'),
+ import('@openpanel/core'),
+ import('@openpanel/core'),
]).then(
([
{ getSettingsForProject },
diff --git a/packages/core/src/modules/event/event.service.ts b/packages/core/src/modules/event/event.service.ts
index 31d453f7d..226c23e40 100644
--- a/packages/core/src/modules/event/event.service.ts
+++ b/packages/core/src/modules/event/event.service.ts
@@ -111,7 +111,7 @@ function loadFilterCompiler() {
}
function loadLookback() {
- return import('@openpanel/db/src/services/lookback');
+ return import('@openpanel/core');
}
// Lazy: session.service → session-end → this module is a static chain, and a
@@ -124,7 +124,7 @@ function loadSessionService() {
}
function loadDateService() {
- return import('@openpanel/db/src/services/date.service');
+ return import('@openpanel/core');
}
export type IImportedEvent = Omit<
diff --git a/packages/core/src/modules/event/src/access.ts b/packages/core/src/modules/event/src/access.ts
index 9b407436e..e3dff4359 100644
--- a/packages/core/src/modules/event/src/access.ts
+++ b/packages/core/src/modules/event/src/access.ts
@@ -8,8 +8,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/event/src/create-event-id.test.ts b/packages/core/src/modules/event/src/create-event-id.test.ts
index 3ef9bde34..07aebc392 100644
--- a/packages/core/src/modules/event/src/create-event-id.test.ts
+++ b/packages/core/src/modules/event/src/create-event-id.test.ts
@@ -7,16 +7,16 @@ import { afterAll, beforeAll, describe, expect, mock, test } from 'bun:test';
const add = mock((_event: { id: string }) => undefined);
-const actualBuffers = await import('@openpanel/db/src/buffers');
+const actualBuffers = await import('@openpanel/queue/src/buffers');
const realBuffers = { ...actualBuffers };
-mock.module('@openpanel/db/src/buffers', () => ({
+mock.module('@openpanel/queue/src/buffers', () => ({
...realBuffers,
eventBuffer: { add },
botBuffer: { add: mock(() => undefined) },
}));
afterAll(() => {
- mock.module('@openpanel/db/src/buffers', () => realBuffers);
+ mock.module('@openpanel/queue/src/buffers', () => realBuffers);
});
let createEvent: typeof import('../event.service').createEvent;
diff --git a/packages/core/src/modules/export/export.routes.ts b/packages/core/src/modules/export/export.routes.ts
index 9ed94ae7f..4b3212684 100644
--- a/packages/core/src/modules/export/export.routes.ts
+++ b/packages/core/src/modules/export/export.routes.ts
@@ -32,7 +32,7 @@ import type {
GetEventListOptions,
IGetTopGenericInput,
TrafficColumn,
-} from '@openpanel/db';
+} from '@openpanel/core';
import {
zChartEvent,
zChartEventFilter,
@@ -43,9 +43,10 @@ import { z } from 'zod';
import type { ClientType } from '../../http/client-auth';
import { defineRoutes } from '../../http/define';
import { parseQueryStringTransform } from '../../http/query';
+import { loadDbBuffers } from '../../buffers/lazy-db-buffers';
import { HttpError } from '../../shared/errors';
import {
- loadDb,
+ loadCore,
resolveExportProjectId,
resolveInsightsDateRange,
resolveInsightsProjectId,
@@ -174,7 +175,7 @@ export const exportRoutes = defineRoutes((app) =>
// is undefined and JSON drops it.
throw new HttpError(resolved.message, { status: resolved.status });
}
- const { getEventList, getEventsCount } = await loadDb();
+ const { getEventList, getEventsCount } = await loadCore();
const {
limit,
page: rawPage,
@@ -240,7 +241,7 @@ export const exportRoutes = defineRoutes((app) =>
// is undefined and JSON drops it.
throw new HttpError(resolved.message, { status: resolved.status });
}
- const { ChartEngine, getSettingsForProject } = await loadDb();
+ const { ChartEngine, getSettingsForProject } = await loadCore();
const { timezone } = await getSettingsForProject(resolved.projectId);
const { events, series, ...rest } = query;
@@ -324,7 +325,7 @@ async function getOverviewGeneric(
) {
const projectId = await resolveInsightsProjectId(client, params);
const { getChartStartEndDate, getSettingsForProject, overviewService } =
- await loadDb();
+ await loadCore();
const { timezone } = await getSettingsForProject(projectId);
const { startDate, endDate } = getChartStartEndDate(query, timezone);
return overviewService.getTopGeneric({
@@ -508,7 +509,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { getAnalyticsOverviewCore } = await loadDb();
+ const { getAnalyticsOverviewCore } = await loadCore();
return getAnalyticsOverviewCore({
projectId,
startDate,
@@ -531,7 +532,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/active_users',
async ({ params, query, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { getRollingActiveUsersCore } = await loadDb();
+ const { getRollingActiveUsersCore } = await loadCore();
return getRollingActiveUsersCore({ projectId, days: query.days });
},
{
@@ -548,7 +549,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/retention',
async ({ params, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { getWeeklyRetentionSeriesCore } = await loadDb();
+ const { getWeeklyRetentionSeriesCore } = await loadCore();
return getWeeklyRetentionSeriesCore(projectId);
},
{
@@ -564,7 +565,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/retention/cohort',
async ({ params, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { getRetentionCohortCore } = await loadDb();
+ const { getRetentionCohortCore } = await loadCore();
return getRetentionCohortCore(projectId);
},
{
@@ -584,7 +585,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { getTopPagesCore } = await loadDb();
+ const { getTopPagesCore } = await loadCore();
return getTopPagesCore({ projectId, startDate, endDate });
},
{
@@ -606,7 +607,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { getEntryExitPagesCore } = await loadDb();
+ const { getEntryExitPagesCore } = await loadCore();
return getEntryExitPagesCore({
projectId,
startDate,
@@ -632,7 +633,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { getPagePerformanceCore } = await loadDb();
+ const { getPagePerformanceCore } = await loadCore();
return getPagePerformanceCore({
projectId,
startDate,
@@ -656,7 +657,7 @@ export const insightsRoutes = defineRoutes((app) =>
async ({ params, query, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
const { getChartStartEndDate, getSettingsForProject, overviewService } =
- await loadDb();
+ await loadCore();
const { timezone } = await getSettingsForProject(projectId);
const { startDate, endDate } = getChartStartEndDate(query, timezone);
return overviewService.getMetrics({
@@ -683,7 +684,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/live',
async ({ params, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { eventBuffer } = await loadDb();
+ const { eventBuffer } = await loadDbBuffers();
return { visitors: await eventBuffer.getActiveVisitorCount(projectId) };
},
{
@@ -700,7 +701,7 @@ export const insightsRoutes = defineRoutes((app) =>
async ({ params, query, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
const { getChartStartEndDate, getSettingsForProject, overviewService } =
- await loadDb();
+ await loadCore();
const { timezone } = await getSettingsForProject(projectId);
const { startDate, endDate } = getChartStartEndDate(query, timezone);
return overviewService.getTopPages({
@@ -982,7 +983,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { getFunnelCore } = await loadDb();
+ const { getFunnelCore } = await loadCore();
return getFunnelCore({
projectId,
startDate,
@@ -1010,7 +1011,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { getTrafficBreakdownCore } = await loadDb();
+ const { getTrafficBreakdownCore } = await loadCore();
return getTrafficBreakdownCore({
projectId,
startDate,
@@ -1036,7 +1037,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { getTrafficBreakdownCore } = await loadDb();
+ const { getTrafficBreakdownCore } = await loadCore();
return getTrafficBreakdownCore({
projectId,
startDate,
@@ -1063,7 +1064,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { getTrafficBreakdownCore } = await loadDb();
+ const { getTrafficBreakdownCore } = await loadCore();
return getTrafficBreakdownCore({
projectId,
startDate,
@@ -1089,7 +1090,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { getUserFlowCore } = await loadDb();
+ const { getUserFlowCore } = await loadCore();
return getUserFlowCore({ projectId, startDate, endDate, ...query });
},
{
@@ -1107,7 +1108,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/engagement',
async ({ params, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { getEngagementCore } = await loadDb();
+ const { getEngagementCore } = await loadCore();
return getEngagementCore(projectId);
},
{
@@ -1123,7 +1124,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/events',
async ({ params, query, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { queryEventsCore } = await loadDb();
+ const { queryEventsCore } = await loadCore();
return queryEventsCore({ projectId, ...query });
},
{
@@ -1141,7 +1142,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/events/names',
async ({ params, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { listEventNamesCore } = await loadDb();
+ const { listEventNamesCore } = await loadCore();
return listEventNamesCore(projectId);
},
{
@@ -1157,7 +1158,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/events/properties',
async ({ params, query, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { listEventPropertiesCore } = await loadDb();
+ const { listEventPropertiesCore } = await loadCore();
return listEventPropertiesCore({
projectId,
eventName: query.eventName,
@@ -1177,7 +1178,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/events/property_values',
async ({ params, query, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { getEventPropertyValuesCore } = await loadDb();
+ const { getEventPropertyValuesCore } = await loadCore();
return getEventPropertyValuesCore({ projectId, ...query });
},
{
@@ -1194,7 +1195,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/profiles',
async ({ params, query, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { findProfilesCore } = await loadDb();
+ const { findProfilesCore } = await loadCore();
return findProfilesCore({ projectId, ...query });
},
{
@@ -1211,7 +1212,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/profiles/:profileId',
async ({ params, query, client, status }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { getProfileWithEvents } = await loadDb();
+ const { getProfileWithEvents } = await loadCore();
const result = await getProfileWithEvents(
projectId,
params.profileId,
@@ -1239,7 +1240,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/profiles/:profileId/sessions',
async ({ params, query, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { getProfileSessionsCore } = await loadDb();
+ const { getProfileSessionsCore } = await loadCore();
return getProfileSessionsCore(projectId, params.profileId, query.limit);
},
{
@@ -1256,7 +1257,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/profiles/:profileId/metrics',
async ({ params, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { getProfileMetricsCore } = await loadDb();
+ const { getProfileMetricsCore } = await loadCore();
return getProfileMetricsCore({
projectId,
profileId: params.profileId,
@@ -1275,7 +1276,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/sessions',
async ({ params, query, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { querySessionsCore } = await loadDb();
+ const { querySessionsCore } = await loadCore();
return querySessionsCore({ projectId, ...query });
},
{
@@ -1292,7 +1293,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/groups/types',
async ({ params, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { listGroupTypesCore } = await loadDb();
+ const { listGroupTypesCore } = await loadCore();
return listGroupTypesCore(projectId);
},
{
@@ -1308,7 +1309,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/groups',
async ({ params, query, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { findGroupsCore } = await loadDb();
+ const { findGroupsCore } = await loadCore();
return findGroupsCore({ projectId, ...query });
},
{
@@ -1325,7 +1326,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/groups/:groupId',
async ({ params, query, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { getGroupCore } = await loadDb();
+ const { getGroupCore } = await loadCore();
return getGroupCore({
projectId,
groupId: params.groupId,
@@ -1346,7 +1347,7 @@ export const insightsRoutes = defineRoutes((app) =>
'/insights/:projectId/reports/:reportId/data',
async ({ params, client }) => {
const projectId = await resolveInsightsProjectId(client, params);
- const { getReportDataCore } = await loadDb();
+ const { getReportDataCore } = await loadCore();
return getReportDataCore({
projectId,
reportId: params.reportId,
@@ -1370,7 +1371,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { gscGetOverviewCore } = await loadDb();
+ const { gscGetOverviewCore } = await loadCore();
return gscGetOverviewCore({
projectId,
startDate,
@@ -1397,7 +1398,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { gscGetTopPagesCore } = await loadDb();
+ const { gscGetTopPagesCore } = await loadCore();
return gscGetTopPagesCore({
projectId,
startDate,
@@ -1423,7 +1424,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { gscGetPageDetailsCore } = await loadDb();
+ const { gscGetPageDetailsCore } = await loadCore();
return gscGetPageDetailsCore({
projectId,
startDate,
@@ -1449,7 +1450,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { gscGetTopQueriesCore } = await loadDb();
+ const { gscGetTopQueriesCore } = await loadCore();
return gscGetTopQueriesCore({
projectId,
startDate,
@@ -1475,7 +1476,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { gscGetQueryDetailsCore } = await loadDb();
+ const { gscGetQueryDetailsCore } = await loadCore();
return gscGetQueryDetailsCore({
projectId,
startDate,
@@ -1501,7 +1502,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { gscGetQueryOpportunitiesCore } = await loadDb();
+ const { gscGetQueryOpportunitiesCore } = await loadCore();
return gscGetQueryOpportunitiesCore({
projectId,
startDate,
@@ -1528,7 +1529,7 @@ export const insightsRoutes = defineRoutes((app) =>
projectId,
query
);
- const { gscGetCannibalizationCore } = await loadDb();
+ const { gscGetCannibalizationCore } = await loadCore();
return gscGetCannibalizationCore({ projectId, startDate, endDate });
},
{
diff --git a/packages/core/src/modules/export/export.service.ts b/packages/core/src/modules/export/export.service.ts
index 11294486e..8f5fea665 100644
--- a/packages/core/src/modules/export/export.service.ts
+++ b/packages/core/src/modules/export/export.service.ts
@@ -7,16 +7,17 @@
// apps/api/src/controllers/{export,insights}.controller.ts. No new query
// logic: every resolution here already existed in V1's controllers.
//
-// `@openpanel/db` is reached through `loadDb()`, not a static import:
-// `export.routes.ts` mounts into `rest.routes.ts`, which `index.ts` — this
-// package's curated barrel — imports. A static import here would make
-// importing `@openpanel/core` from ANYWHERE eagerly evaluate the whole of
-// `@openpanel/db` (every service, `packages/queue`'s still-V1 `getRedisQueue`
-// included), which is exactly the "core ↔ db is an import cycle" hazard
-// session.service.ts and event.service.ts already document — just reached via
-// a different, much more central, file this time. A route body only pays for
-// `@openpanel/db` when it actually runs, same reason `event.rpc.ts`'s
-// `loadPagesRuntime()` exists.
+// This barrel (`@openpanel/core`) is reached through `loadCore()`, not a
+// static import: `export.routes.ts` mounts into `rest.routes.ts`, which
+// `index.ts` — this package's curated barrel — imports. A static import here
+// would make importing `@openpanel/core` from ANYWHERE eagerly re-enter this
+// same barrel mid-evaluation — the "core imports itself" hazard
+// session.service.ts and event.service.ts already document for their own
+// lazy loaders — just reached via a different, much more central, file this
+// time. A route body only pays for it when it actually runs, same reason
+// `event.rpc.ts`'s `loadPagesRuntime()` exists. `@openpanel/db` (just the
+// Prisma client) is cheap enough to load the same way, kept separate so a
+// caller that only needs `db` doesn't pull in the rest.
import type { IChartRange } from '@openpanel/validation';
import type { AuthenticatedClient } from '../../http/client-auth';
@@ -25,6 +26,10 @@ export function loadDb() {
return import('@openpanel/db');
}
+export function loadCore() {
+ return import('@openpanel/core');
+}
+
export type ProjectIdResolution =
| { ok: true; projectId: string }
| { ok: false; status: 400 | 403 | 404; message: string };
@@ -84,7 +89,7 @@ export async function resolveInsightsProjectId(
client: AuthenticatedClient,
params: { projectId?: string }
): Promise<string> {
- const { resolveClientProjectId } = await loadDb();
+ const { resolveClientProjectId } = await loadCore();
return resolveClientProjectId({
clientType: client.type === 'root' ? 'root' : 'read',
clientProjectId: client.projectId,
@@ -102,7 +107,7 @@ export async function resolveInsightsDateRange(
data: { startDate?: string; endDate?: string; range?: IChartRange }
): Promise<{ startDate: string; endDate: string }> {
const { getChartStartEndDate, getSettingsForProject, resolveDateRange } =
- await loadDb();
+ await loadCore();
if (!data.range || data.startDate) {
return resolveDateRange(data.startDate, data.endDate);
}
diff --git a/packages/core/src/modules/group/src/access.ts b/packages/core/src/modules/group/src/access.ts
index 9b407436e..e3dff4359 100644
--- a/packages/core/src/modules/group/src/access.ts
+++ b/packages/core/src/modules/group/src/access.ts
@@ -8,8 +8,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/gsc/gsc.service.test.ts b/packages/core/src/modules/gsc/gsc.service.test.ts
index 14e0aa846..ea96d4e6c 100644
--- a/packages/core/src/modules/gsc/gsc.service.test.ts
+++ b/packages/core/src/modules/gsc/gsc.service.test.ts
@@ -173,27 +173,19 @@ mock.module('../auth/auth.service', () => ({
}));
const getSettingsForProject = mock(async () => ({ timezone: 'UTC' }));
-// Spread the real module — see the clickhouse/client mock above for why a
-// partial factory here is a process-wide hazard, not a local one.
-const actualOrganizationService = await import(
- '@openpanel/db/src/services/organization.service'
-);
-mock.module('@openpanel/db/src/services/organization.service', () => ({
- ...actualOrganizationService,
- getSettingsForProject,
-}));
-
const getChartStartEndDate = mock(() => ({
startDate: '2026-09-01T00:00:00.000Z',
endDate: '2026-09-03T00:00:00.000Z',
}));
// Spread the real module — see the clickhouse/client mock above for why a
-// partial factory here is a process-wide hazard, not a local one.
-const actualDateService = await import(
- '@openpanel/db/src/services/date.service'
-);
-mock.module('@openpanel/db/src/services/date.service', () => ({
- ...actualDateService,
+// partial factory here is a process-wide hazard, not a local one. The
+// organization/date loaders both resolve through this same specifier now
+// (M9-CLEANUP-001) — one mock.module call, not two, or the second replaces
+// the whole module and drops the first override.
+const actualCore = await import('@openpanel/core');
+mock.module('@openpanel/core', () => ({
+ ...actualCore,
+ getSettingsForProject,
getChartStartEndDate,
}));
diff --git a/packages/core/src/modules/gsc/gsc.service.ts b/packages/core/src/modules/gsc/gsc.service.ts
index 96d02426c..9049c4f32 100644
--- a/packages/core/src/modules/gsc/gsc.service.ts
+++ b/packages/core/src/modules/gsc/gsc.service.ts
@@ -774,10 +774,10 @@ export async function resolveGscDateRange(
input: GscDateRangeInput
): Promise<{ startDate: string; endDate: string }> {
const { getSettingsForProject } = await import(
- '@openpanel/db/src/services/organization.service'
+ '@openpanel/core'
);
const { getChartStartEndDate } = await import(
- '@openpanel/db/src/services/date.service'
+ '@openpanel/core'
);
const { timezone } = await getSettingsForProject(projectId);
const { startDate, endDate } = getChartStartEndDate(
diff --git a/packages/core/src/modules/gsc/src/access.ts b/packages/core/src/modules/gsc/src/access.ts
index de4a4168e..b82a18072 100644
--- a/packages/core/src/modules/gsc/src/access.ts
+++ b/packages/core/src/modules/gsc/src/access.ts
@@ -7,8 +7,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/import/import.routes.ts b/packages/core/src/modules/import/import.routes.ts
index 3ad652519..cc1e14a9e 100644
--- a/packages/core/src/modules/import/import.routes.ts
+++ b/packages/core/src/modules/import/import.routes.ts
@@ -20,7 +20,7 @@
// guards on exactly this (apps/api/src/controllers/import.controller.ts:17-18),
// ported verbatim.
-import type { IClickhouseEvent } from '@openpanel/db';
+import type { IClickhouseEvent } from '@openpanel/core';
import { z } from 'zod';
import { defineRoutes } from '../../http/define';
import { insertRawEventsBatch } from './import.service';
diff --git a/packages/core/src/modules/import/import.service.ts b/packages/core/src/modules/import/import.service.ts
index 0a6b22836..c05221e23 100644
--- a/packages/core/src/modules/import/import.service.ts
+++ b/packages/core/src/modules/import/import.service.ts
@@ -20,7 +20,7 @@
import { createHash } from 'node:crypto';
import { toDots } from '@openpanel/common';
-import type { IClickhouseEvent, IClickhouseProfile } from '@openpanel/db';
+import type { IClickhouseEvent, IClickhouseProfile } from '@openpanel/core';
import type { Prisma } from '@openpanel/db/src/prisma-client';
import { createLogger, type ILogger } from '../../clients/logger';
import type { Logger } from '../../logger';
diff --git a/packages/core/src/modules/import/src/access.ts b/packages/core/src/modules/import/src/access.ts
index de4a4168e..b82a18072 100644
--- a/packages/core/src/modules/import/src/access.ts
+++ b/packages/core/src/modules/import/src/access.ts
@@ -7,8 +7,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/import/src/base-provider.ts b/packages/core/src/modules/import/src/base-provider.ts
index 056ff20f5..66e1e695e 100644
--- a/packages/core/src/modules/import/src/base-provider.ts
+++ b/packages/core/src/modules/import/src/base-provider.ts
@@ -1,4 +1,4 @@
-import type { IClickhouseEvent } from '@openpanel/db';
+import type { IClickhouseEvent } from '@openpanel/core';
import type { BaseRawEvent, ErrorContext, ImportJobMetadata } from './types';
export abstract class BaseImportProvider<
diff --git a/packages/core/src/modules/import/src/providers/amplitude.ts b/packages/core/src/modules/import/src/providers/amplitude.ts
index 2a1e1bfa5..f27a9ac7f 100644
--- a/packages/core/src/modules/import/src/providers/amplitude.ts
+++ b/packages/core/src/modules/import/src/providers/amplitude.ts
@@ -5,8 +5,8 @@ import { createBrotliDecompress, createGunzip } from 'node:zlib';
import { isSameDomain, parsePath, toDots } from '@openpanel/common';
// Deep imports, not @openpanel/db's full barrel — see umami.ts's header.
import { formatClickhouseDate } from '@openpanel/db/src/clickhouse/client';
-import type { IClickhouseEvent } from '@openpanel/db/src/services/event.service';
-import type { IClickhouseProfile } from '@openpanel/db/src/services/profile.service';
+import type { IClickhouseEvent } from '@openpanel/core';
+import type { IClickhouseProfile } from '@openpanel/core';
import unzipper from 'unzipper';
import { z } from 'zod';
import type { Logger } from '../../../../logger';
diff --git a/packages/core/src/modules/import/src/providers/mixpanel.ts b/packages/core/src/modules/import/src/providers/mixpanel.ts
index de8976608..204594538 100644
--- a/packages/core/src/modules/import/src/providers/mixpanel.ts
+++ b/packages/core/src/modules/import/src/providers/mixpanel.ts
@@ -2,8 +2,8 @@ import { randomUUID } from 'node:crypto';
import { isSameDomain, parsePath, toDots } from '@openpanel/common';
// Deep imports, not @openpanel/db's full barrel — see umami.ts's header.
import { formatClickhouseDate } from '@openpanel/db/src/clickhouse/client';
-import type { IClickhouseEvent } from '@openpanel/db/src/services/event.service';
-import type { IClickhouseProfile } from '@openpanel/db/src/services/profile.service';
+import type { IClickhouseEvent } from '@openpanel/core';
+import type { IClickhouseProfile } from '@openpanel/core';
import { z } from 'zod';
import type { Logger } from '../../../../logger';
import {
diff --git a/packages/core/src/modules/import/src/providers/umami.ts b/packages/core/src/modules/import/src/providers/umami.ts
index 6022de72d..c660334bd 100644
--- a/packages/core/src/modules/import/src/providers/umami.ts
+++ b/packages/core/src/modules/import/src/providers/umami.ts
@@ -9,7 +9,7 @@ import { isSameDomain, parsePath, toDots } from '@openpanel/common';
// pino-pretty transport at import time — fatal under bun:test's
// `--isolate` worker threads (AGENTS.md's eager-barrel-chain hazard).
import { formatClickhouseDate } from '@openpanel/db/src/clickhouse/client';
-import type { IClickhouseEvent } from '@openpanel/db/src/services/event.service';
+import type { IClickhouseEvent } from '@openpanel/core';
import { parse } from 'csv-parse';
import { assocPath } from 'ramda';
import { z } from 'zod';
diff --git a/packages/core/src/modules/import/src/types.ts b/packages/core/src/modules/import/src/types.ts
index 5f7c466fe..89221b090 100644
--- a/packages/core/src/modules/import/src/types.ts
+++ b/packages/core/src/modules/import/src/types.ts
@@ -1,4 +1,4 @@
-import type { IServiceImportedEventPayload } from '@openpanel/db';
+import type { IServiceImportedEventPayload } from '@openpanel/core';
export interface ImportConfig {
projectId: string;
diff --git a/packages/core/src/modules/ingest/src/incoming-event-handler.ts b/packages/core/src/modules/ingest/src/incoming-event-handler.ts
index 0a1aaeac0..c7165e444 100644
--- a/packages/core/src/modules/ingest/src/incoming-event-handler.ts
+++ b/packages/core/src/modules/ingest/src/incoming-event-handler.ts
@@ -113,7 +113,7 @@ export async function loadIncomingEventDeps(
const [{ sessionBuffer }, { db }, notifications] = await Promise.all([
loadDbBuffers(),
import('@openpanel/db/src/prisma-client'),
- import('@openpanel/db/src/services/notification.service'),
+ import('@openpanel/queue/src/notification-dispatch'),
]);
return {
logger,
diff --git a/packages/core/src/modules/insight/insight.rpc.ts b/packages/core/src/modules/insight/insight.rpc.ts
index baa439b4d..5e25f7b98 100644
--- a/packages/core/src/modules/insight/insight.rpc.ts
+++ b/packages/core/src/modules/insight/insight.rpc.ts
@@ -123,7 +123,7 @@ export const insightRouter = createTRPCRouter({
// @openpanel/db's internals until it does.
const { db } = await import('@openpanel/db/src/prisma-client');
const { getSegmentDailySeriesCore, getTrafficBreakdownCore } =
- await import('@openpanel/db/src/services/overview.service');
+ await import('@openpanel/core');
const insight = await db.projectInsight.findUniqueOrThrow({
where: { id: insightId },
diff --git a/packages/core/src/modules/insight/insight.service.ts b/packages/core/src/modules/insight/insight.service.ts
index aa5e83483..3344e6117 100644
--- a/packages/core/src/modules/insight/insight.service.ts
+++ b/packages/core/src/modules/insight/insight.service.ts
@@ -400,7 +400,7 @@ async function buildDigestData(
// `overview` hasn't moved to core yet — deep-imported like the rest of
// @openpanel/db's internals until it does.
const { getAnalyticsOverviewCore } = await import(
- '@openpanel/db/src/services/overview.service'
+ '@openpanel/core'
);
const [cur, prev] = await Promise.all([
diff --git a/packages/core/src/modules/insight/src/access.ts b/packages/core/src/modules/insight/src/access.ts
index de4a4168e..b82a18072 100644
--- a/packages/core/src/modules/insight/src/access.ts
+++ b/packages/core/src/modules/insight/src/access.ts
@@ -7,8 +7,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/insight/src/referrer-spikes.ts b/packages/core/src/modules/insight/src/referrer-spikes.ts
index 1166471b1..719cabd62 100644
--- a/packages/core/src/modules/insight/src/referrer-spikes.ts
+++ b/packages/core/src/modules/insight/src/referrer-spikes.ts
@@ -6,7 +6,7 @@ import {
import { clix } from '@openpanel/db/src/clickhouse/query-builder';
// `overview` hasn't moved to core yet (a later wave) — deep-imported like the
// rest of @openpanel/db's internals until it does.
-import { overviewService } from '@openpanel/db/src/services/overview.service';
+import { overviewService } from '@openpanel/core';
import type { IChartEventFilter, IInterval } from '@openpanel/validation';
// Spike detection thresholds. Conservative defaults — markers should be rare
diff --git a/packages/core/src/modules/integration/src/access.ts b/packages/core/src/modules/integration/src/access.ts
index 12efcfeac..2ff2c18f9 100644
--- a/packages/core/src/modules/integration/src/access.ts
+++ b/packages/core/src/modules/integration/src/access.ts
@@ -8,8 +8,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
@@ -24,4 +24,4 @@ export const requireOrganizationAdmin = checks.requireOrganizationAdmin;
// `assertIntegrationAccess`'s read-branch on a legacy org-wide row needs bare
// membership, not the admin gate — re-exported raw, same as
// packages/trpc/src/access.ts does for V1's integration router.
-export { getOrganizationAccess } from '@openpanel/db/src/services/access.service';
+export { getOrganizationAccess } from '@openpanel/core';
diff --git a/packages/core/src/modules/mcp/mcp.service.test.ts b/packages/core/src/modules/mcp/mcp.service.test.ts
index c2009c952..c2dbad406 100644
--- a/packages/core/src/modules/mcp/mcp.service.test.ts
+++ b/packages/core/src/modules/mcp/mcp.service.test.ts
@@ -67,10 +67,10 @@ mock.module('../../clients/logger', () => ({
const mockGetClientByIdCached = mock();
const actualClientsService = await import(
- '@openpanel/db/src/services/clients.service'
+ '@openpanel/core'
);
const realClientsService = { ...actualClientsService };
-mock.module('@openpanel/db/src/services/clients.service', () => ({
+mock.module('@openpanel/core', () => ({
...realClientsService,
getClientByIdCached: mockGetClientByIdCached,
}));
@@ -104,7 +104,7 @@ mock.module('@openpanel/db/src/prisma-client', () => ({
afterAll(() => {
mock.module('../../clients/logger', () => realLogger);
mock.module(
- '@openpanel/db/src/services/clients.service',
+ '@openpanel/core',
() => realClientsService
);
mock.module('@openpanel/redis', () => realRedis);
diff --git a/packages/core/src/modules/mcp/src/auth.test.ts b/packages/core/src/modules/mcp/src/auth.test.ts
index 3ce8c0d83..4a33d6985 100644
--- a/packages/core/src/modules/mcp/src/auth.test.ts
+++ b/packages/core/src/modules/mcp/src/auth.test.ts
@@ -31,9 +31,9 @@ const noopLogger = {
// sharing this process (bun:test only isolates modules per file under
// `--isolate`; see AGENTS.md).
const actualClientsService = await import(
- '@openpanel/db/src/services/clients.service'
+ '@openpanel/core'
);
-mock.module('@openpanel/db/src/services/clients.service', () => ({
+mock.module('@openpanel/core', () => ({
...actualClientsService,
getClientByIdCached: mockGetClientByIdCached,
}));
diff --git a/packages/core/src/modules/mcp/src/auth.ts b/packages/core/src/modules/mcp/src/auth.ts
index 7e488d7a5..b0c5f1835 100644
--- a/packages/core/src/modules/mcp/src/auth.ts
+++ b/packages/core/src/modules/mcp/src/auth.ts
@@ -1,5 +1,6 @@
import { createHash } from 'node:crypto';
-import { ClientType, getClientByIdCached } from '@openpanel/db';
+import { getClientByIdCached } from '@openpanel/core';
+import { ClientType } from '@openpanel/db';
import { getCache } from '@openpanel/redis';
import { createLogger } from '../../../clients/logger';
import { verifyPassword } from '../../../shared/crypto';
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/active-users.ts b/packages/core/src/modules/mcp/src/tools/analytics/active-users.ts
index ed72d578f..0422dff76 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/active-users.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/active-users.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getRetentionSeries, getRollingActiveUsers } from '@openpanel/db';
+import { getRetentionSeries, getRollingActiveUsers } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/engagement.test.ts b/packages/core/src/modules/mcp/src/tools/analytics/engagement.test.ts
index ea3628f06..1bb5102d6 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/engagement.test.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/engagement.test.ts
@@ -6,19 +6,13 @@ const mockGetRetentionLastSeenSeries = mock();
// '@openpanel/db' barrel — a whole-barrel replacement would drop every other
// export the barrel carries for any other file sharing this process
// (bun:test only isolates modules per file under `--isolate`; see AGENTS.md).
-const actualRetentionService = await import(
- '@openpanel/db/src/services/retention.service'
-);
-mock.module('@openpanel/db/src/services/retention.service', () => ({
- ...actualRetentionService,
+// The retention/project loaders both resolve through this same specifier now
+// (M9-CLEANUP-001) — one mock.module call, not two, or the second replaces
+// the whole module and drops the first override.
+const actualCore = await import('@openpanel/core');
+mock.module('@openpanel/core', () => ({
+ ...actualCore,
getRetentionLastSeenSeries: mockGetRetentionLastSeenSeries,
-}));
-
-const actualProjectService = await import(
- '@openpanel/db/src/services/project.service'
-);
-mock.module('@openpanel/db/src/services/project.service', () => ({
- ...actualProjectService,
resolveClientProjectId: mock(
({ clientProjectId }: { clientProjectId: string }) =>
Promise.resolve(clientProjectId)
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/engagement.ts b/packages/core/src/modules/mcp/src/tools/analytics/engagement.ts
index a6bafeb7f..5b4df1746 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/engagement.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/engagement.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getRetentionLastSeenSeries } from '@openpanel/db';
+import { getRetentionLastSeenSeries } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/event-names.ts b/packages/core/src/modules/mcp/src/tools/analytics/event-names.ts
index e5d4f2553..f452827eb 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/event-names.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/event-names.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getTopEventNames } from '@openpanel/db';
+import { getTopEventNames } from '@openpanel/core';
import type { McpAuthContext } from '../../auth';
import {
projectIdSchema,
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/events.ts b/packages/core/src/modules/mcp/src/tools/analytics/events.ts
index ee26d4954..9b0cbbec1 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/events.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/events.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { queryEventsCore } from '@openpanel/db';
+import { queryEventsCore } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/funnel.ts b/packages/core/src/modules/mcp/src/tools/analytics/funnel.ts
index d33c19b06..56e5463f4 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/funnel.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/funnel.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getFunnelCore } from '@openpanel/db';
+import { getFunnelCore } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/groups.ts b/packages/core/src/modules/mcp/src/tools/analytics/groups.ts
index ef6e8c0a4..d55e5c9dc 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/groups.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/groups.ts
@@ -4,7 +4,7 @@ import {
getGroupList,
getGroupMemberProfiles,
getGroupTypes,
-} from '@openpanel/db';
+} from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/overview.ts b/packages/core/src/modules/mcp/src/tools/analytics/overview.ts
index 7ea59f843..dcd9925d9 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/overview.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/overview.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getAnalyticsOverviewCore } from '@openpanel/db';
+import { getAnalyticsOverviewCore } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/page-conversions.test.ts b/packages/core/src/modules/mcp/src/tools/analytics/page-conversions.test.ts
index 581c03248..15121e32d 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/page-conversions.test.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/page-conversions.test.ts
@@ -6,19 +6,13 @@ const mockGetPageConversionsCore = mock();
// '@openpanel/db' barrel — a whole-barrel replacement would drop every other
// export the barrel carries for any other file sharing this process
// (bun:test only isolates modules per file under `--isolate`; see AGENTS.md).
-const actualPagesService = await import(
- '@openpanel/db/src/services/pages.service'
-);
-mock.module('@openpanel/db/src/services/pages.service', () => ({
- ...actualPagesService,
+// The pages/project loaders both resolve through this same specifier now
+// (M9-CLEANUP-001) — one mock.module call, not two, or the second replaces
+// the whole module and drops the first override.
+const actualCore = await import('@openpanel/core');
+mock.module('@openpanel/core', () => ({
+ ...actualCore,
getPageConversionsCore: mockGetPageConversionsCore,
-}));
-
-const actualProjectService = await import(
- '@openpanel/db/src/services/project.service'
-);
-mock.module('@openpanel/db/src/services/project.service', () => ({
- ...actualProjectService,
resolveClientProjectId: mock(
({ clientProjectId }: { clientProjectId: string }) =>
Promise.resolve(clientProjectId)
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/page-conversions.ts b/packages/core/src/modules/mcp/src/tools/analytics/page-conversions.ts
index a049689f4..23513e1bc 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/page-conversions.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/page-conversions.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getPageConversionsCore } from '@openpanel/db';
+import { getPageConversionsCore } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/page-performance.test.ts b/packages/core/src/modules/mcp/src/tools/analytics/page-performance.test.ts
index 123c674a6..4b8a638dd 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/page-performance.test.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/page-performance.test.ts
@@ -9,14 +9,20 @@ const mockGetSettingsForProject = mock(() =>
// '@openpanel/db' barrel — a whole-barrel replacement would drop every other
// export the barrel carries for any other file sharing this process
// (bun:test only isolates modules per file under `--isolate`; see AGENTS.md).
-const actualPagesService = await import(
- '@openpanel/db/src/services/pages.service'
-);
-mock.module('@openpanel/db/src/services/pages.service', () => ({
- ...actualPagesService,
+// The pages/organization/project loaders all resolve through this same
+// specifier now (M9-CLEANUP-001) — one mock.module call, not three, or each
+// later call replaces the whole module and drops the earlier overrides.
+const actualCore = await import('@openpanel/core');
+mock.module('@openpanel/core', () => ({
+ ...actualCore,
PagesService: mock().mockImplementation(() => ({
getTopPages: mockGetTopPages,
})),
+ getSettingsForProject: mockGetSettingsForProject,
+ resolveClientProjectId: mock(
+ ({ clientProjectId }: { clientProjectId: string }) =>
+ Promise.resolve(clientProjectId)
+ ),
}));
const actualClickhouseClient = await import(
@@ -27,25 +33,6 @@ mock.module('@openpanel/db/src/clickhouse/client', () => ({
ch: {},
}));
-const actualOrganizationService = await import(
- '@openpanel/db/src/services/organization.service'
-);
-mock.module('@openpanel/db/src/services/organization.service', () => ({
- ...actualOrganizationService,
- getSettingsForProject: mockGetSettingsForProject,
-}));
-
-const actualProjectService = await import(
- '@openpanel/db/src/services/project.service'
-);
-mock.module('@openpanel/db/src/services/project.service', () => ({
- ...actualProjectService,
- resolveClientProjectId: mock(
- ({ clientProjectId }: { clientProjectId: string }) =>
- Promise.resolve(clientProjectId)
- ),
-}));
-
let registerPagePerformanceTools: typeof import('./page-performance').registerPagePerformanceTools;
beforeAll(async () => {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/page-performance.ts b/packages/core/src/modules/mcp/src/tools/analytics/page-performance.ts
index 6e6d71207..e82fc145b 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/page-performance.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/page-performance.ts
@@ -1,5 +1,6 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { ch, getSettingsForProject, PagesService } from '@openpanel/db';
+import { getSettingsForProject, PagesService } from '@openpanel/core';
+import { ch } from '@openpanel/db';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/pages.ts b/packages/core/src/modules/mcp/src/tools/analytics/pages.ts
index 82005b304..63c13ed0e 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/pages.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/pages.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getEntryExitPagesCore, getTopPagesCore } from '@openpanel/db';
+import { getEntryExitPagesCore, getTopPagesCore } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/profile-metrics.ts b/packages/core/src/modules/mcp/src/tools/analytics/profile-metrics.ts
index acf41f785..f5ece3c36 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/profile-metrics.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/profile-metrics.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getProfileMetrics } from '@openpanel/db';
+import { getProfileMetrics } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/profiles.test.ts b/packages/core/src/modules/mcp/src/tools/analytics/profiles.test.ts
index 9c5cb434d..507cdd469 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/profiles.test.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/profiles.test.ts
@@ -40,11 +40,11 @@ afterAll(() => {
}));
});
-let findProfilesCore: typeof import('@openpanel/db/src/services/profile.service').findProfilesCore;
+let findProfilesCore: typeof import('@openpanel/core').findProfilesCore;
beforeAll(async () => {
({ findProfilesCore } = await import(
- '@openpanel/db/src/services/profile.service'
+ '@openpanel/core'
));
});
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/profiles.ts b/packages/core/src/modules/mcp/src/tools/analytics/profiles.ts
index dd16c4d1f..8ee759068 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/profiles.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/profiles.ts
@@ -3,7 +3,7 @@ import {
findProfilesCore,
getProfileSessionsCore,
getProfileWithEvents,
-} from '@openpanel/db';
+} from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import { dashboardBaseUrl, profileUrl } from '../dashboard-links';
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/property-values.ts b/packages/core/src/modules/mcp/src/tools/analytics/property-values.ts
index 15643f2f0..e798a128f 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/property-values.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/property-values.ts
@@ -1,5 +1,6 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { ch, clix, EVENT_COLUMNS, TABLE_NAMES } from '@openpanel/db';
+import { EVENT_COLUMNS } from '@openpanel/core';
+import { ch, clix, TABLE_NAMES } from '@openpanel/db';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/reports.ts b/packages/core/src/modules/mcp/src/tools/analytics/reports.ts
index dc4a3d845..efd83bfc0 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/reports.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/reports.ts
@@ -2,13 +2,13 @@ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import {
AggregateChartEngine,
ChartEngine,
- db,
getChartStartEndDate,
getFunnel,
getReportById,
getReportsByDashboardId,
getSettingsForProject,
-} from '@openpanel/db';
+} from '@openpanel/core';
+import { db } from '@openpanel/db';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import { dashboardBaseUrl } from '../dashboard-links';
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/retention.ts b/packages/core/src/modules/mcp/src/tools/analytics/retention.ts
index 7b17ff1c8..172c81c97 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/retention.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/retention.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getRetentionCohortCore } from '@openpanel/db';
+import { getRetentionCohortCore } from '@openpanel/core';
import type { McpAuthContext } from '../../auth';
import {
projectIdSchema,
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/sessions.ts b/packages/core/src/modules/mcp/src/tools/analytics/sessions.ts
index 0e77d174d..a10540dae 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/sessions.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/sessions.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { querySessionsCore } from '@openpanel/db';
+import { querySessionsCore } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import { dashboardBaseUrl } from '../dashboard-links';
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/traffic.ts b/packages/core/src/modules/mcp/src/tools/analytics/traffic.ts
index 07860e9a9..ad7492b8d 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/traffic.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/traffic.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getTrafficBreakdownCore, type TrafficColumn } from '@openpanel/db';
+import { getTrafficBreakdownCore, type TrafficColumn } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/analytics/user-flow.ts b/packages/core/src/modules/mcp/src/tools/analytics/user-flow.ts
index 197361fce..bf72f88bf 100644
--- a/packages/core/src/modules/mcp/src/tools/analytics/user-flow.ts
+++ b/packages/core/src/modules/mcp/src/tools/analytics/user-flow.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getUserFlowCore } from '@openpanel/db';
+import { getUserFlowCore } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/dashboard-management.test.ts b/packages/core/src/modules/mcp/src/tools/dashboard-management.test.ts
index 735dcadb5..ee3f4cdb6 100644
--- a/packages/core/src/modules/mcp/src/tools/dashboard-management.test.ts
+++ b/packages/core/src/modules/mcp/src/tools/dashboard-management.test.ts
@@ -38,19 +38,14 @@ mock.module('@openpanel/db/src/prisma-client', () => ({
db: mockDb,
}));
-const actualDashboardService = await import(
- '@openpanel/db/src/services/dashboard.service'
-);
-mock.module('@openpanel/db/src/services/dashboard.service', () => ({
- ...actualDashboardService,
+// The dashboard/project/id loaders all resolve through this same
+// @openpanel/core specifier now (M9-CLEANUP-001) — one mock.module call, not
+// three, or each later call replaces the whole module and drops the earlier
+// overrides.
+const actualCore = await import('@openpanel/core');
+mock.module('@openpanel/core', () => ({
+ ...actualCore,
getDashboardById: mockGetDashboardById,
-}));
-
-const actualProjectService = await import(
- '@openpanel/db/src/services/project.service'
-);
-mock.module('@openpanel/db/src/services/project.service', () => ({
- ...actualProjectService,
getProjectById: mockGetProjectById,
resolveClientProjectId: mock(
({
@@ -61,11 +56,6 @@ mock.module('@openpanel/db/src/services/project.service', () => ({
inputProjectId?: string;
}) => Promise.resolve(clientProjectId ?? inputProjectId)
),
-}));
-
-const actualIdService = await import('@openpanel/db/src/services/id.service');
-mock.module('@openpanel/db/src/services/id.service', () => ({
- ...actualIdService,
getId: mockGetId,
}));
diff --git a/packages/core/src/modules/mcp/src/tools/dashboard-management.ts b/packages/core/src/modules/mcp/src/tools/dashboard-management.ts
index 5bce23ca5..140bd615e 100644
--- a/packages/core/src/modules/mcp/src/tools/dashboard-management.ts
+++ b/packages/core/src/modules/mcp/src/tools/dashboard-management.ts
@@ -1,11 +1,6 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import {
- db,
- getDashboardById,
- getId,
- getProjectById,
- Prisma,
-} from '@openpanel/db';
+import { getDashboardById, getId, getProjectById } from '@openpanel/core';
+import { db, Prisma } from '@openpanel/db';
import { zReport } from '@openpanel/validation';
import { z } from 'zod';
import type { McpAuthContext } from '../auth';
diff --git a/packages/core/src/modules/mcp/src/tools/gsc/cannibalization.ts b/packages/core/src/modules/mcp/src/tools/gsc/cannibalization.ts
index 28964b882..2767395fb 100644
--- a/packages/core/src/modules/mcp/src/tools/gsc/cannibalization.ts
+++ b/packages/core/src/modules/mcp/src/tools/gsc/cannibalization.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getGscCannibalization } from '@openpanel/db';
+import { getGscCannibalization } from '@openpanel/core';
import type { McpAuthContext } from '../../auth';
import {
projectIdSchema,
diff --git a/packages/core/src/modules/mcp/src/tools/gsc/overview.ts b/packages/core/src/modules/mcp/src/tools/gsc/overview.ts
index 4d0c2778c..9d7dd6972 100644
--- a/packages/core/src/modules/mcp/src/tools/gsc/overview.ts
+++ b/packages/core/src/modules/mcp/src/tools/gsc/overview.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getGscOverview } from '@openpanel/db';
+import { getGscOverview } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/gsc/pages.ts b/packages/core/src/modules/mcp/src/tools/gsc/pages.ts
index a089604b6..553ac92db 100644
--- a/packages/core/src/modules/mcp/src/tools/gsc/pages.ts
+++ b/packages/core/src/modules/mcp/src/tools/gsc/pages.ts
@@ -1,5 +1,5 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import { getGscPageDetails, getGscPages } from '@openpanel/db';
+import { getGscPageDetails, getGscPages } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/gsc/queries.ts b/packages/core/src/modules/mcp/src/tools/gsc/queries.ts
index 70d68a618..38abaf8ab 100644
--- a/packages/core/src/modules/mcp/src/tools/gsc/queries.ts
+++ b/packages/core/src/modules/mcp/src/tools/gsc/queries.ts
@@ -1,6 +1,6 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
-import type { GscQueryOpportunity } from '@openpanel/db';
-import { getGscQueries, getGscQueryDetails } from '@openpanel/db';
+import type { GscQueryOpportunity } from '@openpanel/core';
+import { getGscQueries, getGscQueryDetails } from '@openpanel/core';
import { z } from 'zod';
import type { McpAuthContext } from '../../auth';
import {
diff --git a/packages/core/src/modules/mcp/src/tools/shared.test.ts b/packages/core/src/modules/mcp/src/tools/shared.test.ts
index 60db42798..23a1e2eec 100644
--- a/packages/core/src/modules/mcp/src/tools/shared.test.ts
+++ b/packages/core/src/modules/mcp/src/tools/shared.test.ts
@@ -6,7 +6,7 @@ import {
it,
setSystemTime,
} from 'bun:test';
-import { resolveClientProjectId } from '@openpanel/db';
+import { resolveClientProjectId } from '@openpanel/core';
import type { McpAuthContext } from '../auth';
import { MAX_RESPONSE_CHARS, resolveDateRange, table, toText } from './shared';
diff --git a/packages/core/src/modules/mcp/src/tools/shared.ts b/packages/core/src/modules/mcp/src/tools/shared.ts
index ef8cf0513..a6283834a 100644
--- a/packages/core/src/modules/mcp/src/tools/shared.ts
+++ b/packages/core/src/modules/mcp/src/tools/shared.ts
@@ -1,4 +1,4 @@
-import { resolveClientProjectId } from '@openpanel/db';
+import { resolveClientProjectId } from '@openpanel/core';
import { z } from 'zod';
import { createLogger } from '../../../../clients/logger';
import type { McpAuthContext } from '../auth';
diff --git a/packages/core/src/modules/notification/notification.service.ts b/packages/core/src/modules/notification/notification.service.ts
index 8b8cd2c85..76be0596f 100644
--- a/packages/core/src/modules/notification/notification.service.ts
+++ b/packages/core/src/modules/notification/notification.service.ts
@@ -21,7 +21,7 @@
// would spawn a pino-pretty transport worker thread per test file).
import { stripLeadingAndTrailingSlashes } from '@openpanel/common';
-import type { IServiceCreateEventPayload, IServiceEvent } from '@openpanel/db';
+import type { IServiceCreateEventPayload, IServiceEvent } from '@openpanel/core';
import type { Integration, Prisma } from '@openpanel/db/src/prisma-client';
import { cacheable } from '@openpanel/redis';
import type { IChartEvent, IChartEventFilter } from '@openpanel/validation';
diff --git a/packages/core/src/modules/notification/src/access.ts b/packages/core/src/modules/notification/src/access.ts
index de4a4168e..b82a18072 100644
--- a/packages/core/src/modules/notification/src/access.ts
+++ b/packages/core/src/modules/notification/src/access.ts
@@ -7,8 +7,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/onboarding/onboarding.rpc.ts b/packages/core/src/modules/onboarding/onboarding.rpc.ts
index 3d889152b..cc8cbde40 100644
--- a/packages/core/src/modules/onboarding/onboarding.rpc.ts
+++ b/packages/core/src/modules/onboarding/onboarding.rpc.ts
@@ -26,7 +26,7 @@ import {
} from './onboarding.service';
function loadOrganizationAccess() {
- return import('@openpanel/db/src/services/access.service');
+ return import('@openpanel/core');
}
function requireLogin(userId: string | null | undefined): string {
diff --git a/packages/core/src/modules/onboarding/onboarding.service.ts b/packages/core/src/modules/onboarding/onboarding.service.ts
index 43b217ffa..1243d2c05 100644
--- a/packages/core/src/modules/onboarding/onboarding.service.ts
+++ b/packages/core/src/modules/onboarding/onboarding.service.ts
@@ -39,7 +39,7 @@ function loadDb() {
}
function loadIdService() {
- return import('@openpanel/db/src/services/id.service');
+ return import('@openpanel/core');
}
export async function canSkipOnboarding(
diff --git a/packages/core/src/modules/organization/organization.service.ts b/packages/core/src/modules/organization/organization.service.ts
index 963e5d240..a6f2b9322 100644
--- a/packages/core/src/modules/organization/organization.service.ts
+++ b/packages/core/src/modules/organization/organization.service.ts
@@ -200,7 +200,7 @@ export async function connectUserToOrganization({
}) {
const db = await loadDb();
const { getOrganizationAccess, getProjectAccess } = await import(
- '@openpanel/db/src/services/access.service'
+ '@openpanel/core'
);
// Use primary since before this we might have just created the invite
diff --git a/packages/core/src/modules/organization/src/access.ts b/packages/core/src/modules/organization/src/access.ts
index 600ad06bd..007a09b95 100644
--- a/packages/core/src/modules/organization/src/access.ts
+++ b/packages/core/src/modules/organization/src/access.ts
@@ -8,11 +8,11 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
-export { getOrganizationAccess } from '@openpanel/db/src/services/access.service';
+export { getOrganizationAccess } from '@openpanel/core';
const checks = createAccessChecks({
getProjectAccess,
diff --git a/packages/core/src/modules/overview/overview.rpc.ts b/packages/core/src/modules/overview/overview.rpc.ts
index 3941f78cd..dcc1c8324 100644
--- a/packages/core/src/modules/overview/overview.rpc.ts
+++ b/packages/core/src/modules/overview/overview.rpc.ts
@@ -21,7 +21,7 @@ import { validateOverviewShareAccess } from '../share/share.service';
import {
getChartPrevStartEndDate,
getChartStartEndDate,
-} from '@openpanel/db/src/services/date.service';
+} from '@openpanel/core';
import {
type IChartRange,
pageContextSchema,
diff --git a/packages/core/src/modules/overview/src/access.ts b/packages/core/src/modules/overview/src/access.ts
index 667861497..25f45b905 100644
--- a/packages/core/src/modules/overview/src/access.ts
+++ b/packages/core/src/modules/overview/src/access.ts
@@ -8,8 +8,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/profile/profile.service.ts b/packages/core/src/modules/profile/profile.service.ts
index 9246bcb5e..c3ffdcab2 100644
--- a/packages/core/src/modules/profile/profile.service.ts
+++ b/packages/core/src/modules/profile/profile.service.ts
@@ -43,7 +43,7 @@ import {
profileValuesQuery,
} from './src/profile.sql';
-export { profileSearchCondition } from './src/profile.sql';
+export { profileSearchCondition, profileSearchSql } from './src/profile.sql';
const PROFILES_CACHE_SECONDS = 60 * 5;
const PROPERTY_KEYS_CACHE_SECONDS = 60;
diff --git a/packages/core/src/modules/profile/src/access.ts b/packages/core/src/modules/profile/src/access.ts
index 9b407436e..e3dff4359 100644
--- a/packages/core/src/modules/profile/src/access.ts
+++ b/packages/core/src/modules/profile/src/access.ts
@@ -8,8 +8,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/profile/src/profile.sql.ts b/packages/core/src/modules/profile/src/profile.sql.ts
index b44b6fc28..e442222d4 100644
--- a/packages/core/src/modules/profile/src/profile.sql.ts
+++ b/packages/core/src/modules/profile/src/profile.sql.ts
@@ -14,6 +14,7 @@
// binds as `Array(String)`, a literal list to the planner.
import { type SqlFragment, sql } from '@openpanel/db/src/clickhouse/sql';
+import sqlstring from 'sqlstring';
import {
type CompiledFilterClauses,
compiledFilterFragments,
@@ -78,6 +79,29 @@ export function profileSearchCondition(
return sql`(${sql.join(perToken, ' AND ')})`;
}
+/**
+ * String-SQL twin of `profileSearchCondition`, for the one caller
+ * (cohort.service.ts's `getCohortProfiles`) that still composes a V1 text
+ * query rather than a `sql` fragment. Ported from
+ * packages/db/src/services/profile.service.ts (M9-CLEANUP-001) — goes with
+ * that query when it moves onto the `sql` tag.
+ */
+export function profileSearchSql(search: string | null | undefined): string | null {
+ const tokens = (search ?? '')
+ .trim()
+ .split(SEARCH_TOKEN_SEPARATOR)
+ .filter(Boolean)
+ .slice(0, SEARCH_MAX_TOKENS);
+ if (tokens.length === 0) {
+ return null;
+ }
+ const perToken = tokens.map((token) => {
+ const like = sqlstring.escape(`%${token}%`);
+ return `(id ILIKE ${like} OR email ILIKE ${like} OR first_name ILIKE ${like} OR last_name ILIKE ${like} OR concat(first_name, ' ', last_name) ILIKE ${like})`;
+ });
+ return `(${perToken.join(' AND ')})`;
+}
+
export function profileMetricsQuery(query: {
profileId: string;
projectId: string;
diff --git a/packages/core/src/modules/project/project.service.test.ts b/packages/core/src/modules/project/project.service.test.ts
index de2a0b955..84af94852 100644
--- a/packages/core/src/modules/project/project.service.test.ts
+++ b/packages/core/src/modules/project/project.service.test.ts
@@ -173,7 +173,7 @@ mock.module('@openpanel/db/src/prisma-client', () => ({
db: { project, report, member },
}));
-mock.module('@openpanel/db/src/services/id.service', () => ({
+mock.module('@openpanel/core', () => ({
getId: async (_table: string, name: string) => `${name}-slug`,
}));
diff --git a/packages/core/src/modules/project/project.service.ts b/packages/core/src/modules/project/project.service.ts
index 5b151a815..f7391e74d 100644
--- a/packages/core/src/modules/project/project.service.ts
+++ b/packages/core/src/modules/project/project.service.ts
@@ -51,7 +51,7 @@ function loadChClient() {
}
function loadIdService() {
- return import('@openpanel/db/src/services/id.service').then((m) => m.getId);
+ return import('@openpanel/core').then((m) => m.getId);
}
export async function getProjectById(id: string) {
diff --git a/packages/core/src/modules/project/src/access.ts b/packages/core/src/modules/project/src/access.ts
index f2b341396..5cd8ce212 100644
--- a/packages/core/src/modules/project/src/access.ts
+++ b/packages/core/src/modules/project/src/access.ts
@@ -10,14 +10,14 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
+} from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
import { getProjectById } from '../project.service';
export {
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
+} from '@openpanel/core';
const checks = createAccessChecks({
getProjectAccess,
diff --git a/packages/core/src/modules/realtime/realtime.routes.ts b/packages/core/src/modules/realtime/realtime.routes.ts
index ab6fff376..69a2cff9b 100644
--- a/packages/core/src/modules/realtime/realtime.routes.ts
+++ b/packages/core/src/modules/realtime/realtime.routes.ts
@@ -37,7 +37,7 @@ import {
} from './realtime.service';
// Dynamic, not a static top-level import: `./src/access` reaches
-// `@openpanel/db/src/services/project.service`, which re-exports from
+// `@openpanel/core`, which re-exports from
// `@openpanel/core`'s own barrel (`index.ts`) — and this file IS part of that
// barrel's eager chain (`rest.routes.ts` -> `dashboardRoutes`). A static
// import here closes the cycle mid-evaluation (a `getProjectAccess` TDZ
diff --git a/packages/core/src/modules/realtime/realtime.service.test.ts b/packages/core/src/modules/realtime/realtime.service.test.ts
index 85353cbb8..5da102ab6 100644
--- a/packages/core/src/modules/realtime/realtime.service.test.ts
+++ b/packages/core/src/modules/realtime/realtime.service.test.ts
@@ -27,15 +27,15 @@ const eventBuffer = {
// mock below. Snapshotted into a plain object BEFORE mocking: the live
// import binding would reflect the mock too once `mock.module` below swaps
// the specifier, making a same-binding "restore" a no-op.
-const actualBuffers = await import('@openpanel/db/src/buffers');
+const actualBuffers = await import('@openpanel/queue/src/buffers');
const realBuffers = { ...actualBuffers };
-mock.module('@openpanel/db/src/buffers', () => ({
+mock.module('@openpanel/queue/src/buffers', () => ({
...realBuffers,
eventBuffer,
}));
afterAll(() => {
- mock.module('@openpanel/db/src/buffers', () => realBuffers);
+ mock.module('@openpanel/queue/src/buffers', () => realBuffers);
});
const subscribeToPublishedEvent = mock(
diff --git a/packages/core/src/modules/realtime/src/access.ts b/packages/core/src/modules/realtime/src/access.ts
index a72831bb7..3a00981ac 100644
--- a/packages/core/src/modules/realtime/src/access.ts
+++ b/packages/core/src/modules/realtime/src/access.ts
@@ -14,14 +14,14 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
export {
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
+} from '@openpanel/core';
const checks = createAccessChecks({
getProjectAccess,
diff --git a/packages/core/src/modules/reference/reference.service.test.ts b/packages/core/src/modules/reference/reference.service.test.ts
index 43e4eb130..7704817a7 100644
--- a/packages/core/src/modules/reference/reference.service.test.ts
+++ b/packages/core/src/modules/reference/reference.service.test.ts
@@ -102,15 +102,15 @@ mock.module('@openpanel/db/src/prisma-client', () => ({
}));
const getSettingsForProject = mock(async () => ({ timezone: 'UTC' }));
-mock.module('@openpanel/db/src/services/organization.service', () => ({
- getSettingsForProject,
-}));
-
const getChartStartEndDate = mock(() => ({
startDate: '2026-08-25 00:00:00',
endDate: '2026-09-01 23:59:59',
}));
-mock.module('@openpanel/db/src/services/date.service', () => ({
+// Both loaders (date.service + organization.service) resolve through the
+// same @openpanel/core specifier now (M9-CLEANUP-001) — one mock.module call,
+// not two, or the second silently drops the first's override.
+mock.module('@openpanel/core', () => ({
+ getSettingsForProject,
getChartStartEndDate,
}));
diff --git a/packages/core/src/modules/reference/reference.service.ts b/packages/core/src/modules/reference/reference.service.ts
index 15178605a..374cbed28 100644
--- a/packages/core/src/modules/reference/reference.service.ts
+++ b/packages/core/src/modules/reference/reference.service.ts
@@ -25,11 +25,11 @@ function loadDb() {
}
function loadDateService() {
- return import('@openpanel/db/src/services/date.service');
+ return import('@openpanel/core');
}
function loadOrganizationService() {
- return import('@openpanel/db/src/services/organization.service');
+ return import('@openpanel/core');
}
export async function getReferenceById(id: string): Promise<Reference | null> {
diff --git a/packages/core/src/modules/reference/src/access.ts b/packages/core/src/modules/reference/src/access.ts
index 6b3a1661f..37255f63d 100644
--- a/packages/core/src/modules/reference/src/access.ts
+++ b/packages/core/src/modules/reference/src/access.ts
@@ -8,11 +8,11 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
-export { getProjectAccess } from '@openpanel/db/src/services/access.service';
+export { getProjectAccess } from '@openpanel/core';
const checks = createAccessChecks({
getProjectAccess,
diff --git a/packages/core/src/modules/report/report.service.ts b/packages/core/src/modules/report/report.service.ts
index 5f2a53386..abf149313 100644
--- a/packages/core/src/modules/report/report.service.ts
+++ b/packages/core/src/modules/report/report.service.ts
@@ -9,7 +9,7 @@ import type {
Report as DbReport,
ReportLayout,
} from '@openpanel/db/src/prisma-client';
-import { getChartStartEndDate } from '@openpanel/db/src/services/date.service';
+import { getChartStartEndDate } from '@openpanel/core';
import type {
IChartBreakdown,
IChartEventFilter,
diff --git a/packages/core/src/modules/report/src/access.ts b/packages/core/src/modules/report/src/access.ts
index 315315e48..a080240fc 100644
--- a/packages/core/src/modules/report/src/access.ts
+++ b/packages/core/src/modules/report/src/access.ts
@@ -8,8 +8,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/session/session.service.ts b/packages/core/src/modules/session/session.service.ts
index 336dbe060..9a2488bbe 100644
--- a/packages/core/src/modules/session/session.service.ts
+++ b/packages/core/src/modules/session/session.service.ts
@@ -58,11 +58,11 @@ function loadFilterCompiler() {
}
function loadLookback() {
- return import('@openpanel/db/src/services/lookback');
+ return import('@openpanel/core');
}
function loadDateService() {
- return import('@openpanel/db/src/services/date.service');
+ return import('@openpanel/core');
}
export interface IClickhouseSession {
diff --git a/packages/core/src/modules/session/src/access.ts b/packages/core/src/modules/session/src/access.ts
index 1b99a6d3e..b67cf8a8e 100644
--- a/packages/core/src/modules/session/src/access.ts
+++ b/packages/core/src/modules/session/src/access.ts
@@ -8,8 +8,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/session/src/session-end.ts b/packages/core/src/modules/session/src/session-end.ts
index 22e45e7eb..9a592b56d 100644
--- a/packages/core/src/modules/session/src/session-end.ts
+++ b/packages/core/src/modules/session/src/session-end.ts
@@ -110,7 +110,7 @@ export interface SessionEndDeps extends SessionRuntime {
notifications: {
getRules(projectId: string): Promise<INotificationRuleCached[]>;
hasFunnelRules(rules: INotificationRuleCached[]): boolean;
- /** Stays in @openpanel/db — it enqueues through @openpanel/queue. */
+ /** Lives in @openpanel/queue — it enqueues through the notification queue. */
checkFunnelRules(events: IServiceEvent[]): Promise<unknown>;
};
}
@@ -128,7 +128,7 @@ export async function loadSessionEndDeps(
import('@openpanel/db/src/clickhouse/client'),
loadDbBuffers(),
import('../../notification/notification.service'),
- import('@openpanel/db/src/services/notification.service'),
+ import('@openpanel/queue/src/notification-dispatch'),
]);
return {
...runtime,
diff --git a/packages/core/src/modules/session/src/session-reaper.ts b/packages/core/src/modules/session/src/session-reaper.ts
index 4d5c2b738..9053424a6 100644
--- a/packages/core/src/modules/session/src/session-reaper.ts
+++ b/packages/core/src/modules/session/src/session-reaper.ts
@@ -1,6 +1,6 @@
// Ported from apps/worker/src/jobs/cron.session-reaper.ts (M7-001).
-import type { IServiceCreateEventPayload } from '@openpanel/db/src/services/event.service';
+import type { IServiceCreateEventPayload } from '@openpanel/core';
import type { Logger } from '../../../logger';
import type { IClickhouseSession } from '../session.service';
import type { SessionRuntime } from './runtime';
diff --git a/packages/core/src/modules/share/share.service.test.ts b/packages/core/src/modules/share/share.service.test.ts
index 9d17e8807..5f64ccb6e 100644
--- a/packages/core/src/modules/share/share.service.test.ts
+++ b/packages/core/src/modules/share/share.service.test.ts
@@ -173,9 +173,6 @@ mock.module('@openpanel/db/src/prisma-client', () => ({
const getDashboardById = mock(async (id: string, projectId: string) =>
id === 'dash_missing' ? null : { id, projectId, name: 'Main' }
);
-mock.module('@openpanel/db/src/services/dashboard.service', () => ({
- getDashboardById,
-}));
const getReportById = mock(async (id: string) =>
id === 'report_missing'
@@ -187,17 +184,20 @@ const transformReport = mock((report: unknown) => ({
transformed: true,
}));
const getReportsByDashboardId = mock(async () => [{ id: 'report_1' }]);
-mock.module('@openpanel/db/src/services/reports.service', () => ({
- getReportById,
- transformReport,
- getReportsByDashboardId,
-}));
const getProjectAccess = mock(
async ({ userId }: { userId: string; projectId: string }) =>
userId === 'member' ? { level: 'read' } : null
);
-mock.module('@openpanel/db/src/services/access.service', () => ({
+
+// The access/dashboard/reports loaders all resolve through the same
+// @openpanel/core specifier now (M9-CLEANUP-001) — one mock.module call, not
+// three, or each later call silently drops the earlier ones' overrides.
+mock.module('@openpanel/core', () => ({
+ getDashboardById,
+ getReportById,
+ transformReport,
+ getReportsByDashboardId,
getProjectAccess,
}));
diff --git a/packages/core/src/modules/share/share.service.ts b/packages/core/src/modules/share/share.service.ts
index 9f47a92d2..98dd76bc1 100644
--- a/packages/core/src/modules/share/share.service.ts
+++ b/packages/core/src/modules/share/share.service.ts
@@ -30,15 +30,15 @@ function loadDb() {
}
function loadAccessService() {
- return import('@openpanel/db/src/services/access.service');
+ return import('@openpanel/core');
}
function loadDashboardService() {
- return import('@openpanel/db/src/services/dashboard.service');
+ return import('@openpanel/core');
}
function loadReportsService() {
- return import('@openpanel/db/src/services/reports.service');
+ return import('@openpanel/core');
}
// -----------------------------------------------------------------------
diff --git a/packages/core/src/modules/share/src/access.ts b/packages/core/src/modules/share/src/access.ts
index 18ce81d56..4b5b53194 100644
--- a/packages/core/src/modules/share/src/access.ts
+++ b/packages/core/src/modules/share/src/access.ts
@@ -8,8 +8,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/subscription/src/access.ts b/packages/core/src/modules/subscription/src/access.ts
index d9f12fa60..5c5d9292d 100644
--- a/packages/core/src/modules/subscription/src/access.ts
+++ b/packages/core/src/modules/subscription/src/access.ts
@@ -9,8 +9,8 @@ import {
canWriteProject,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db/src/services/access.service';
-import { getProjectById } from '@openpanel/db/src/services/project.service';
+} from '@openpanel/core';
+import { getProjectById } from '@openpanel/core';
import { createAccessChecks } from '../../../shared/access';
const checks = createAccessChecks({
diff --git a/packages/core/src/modules/subscription/subscription.service.ts b/packages/core/src/modules/subscription/subscription.service.ts
index 539e6e1bd..2c7ed9dc9 100644
--- a/packages/core/src/modules/subscription/subscription.service.ts
+++ b/packages/core/src/modules/subscription/subscription.service.ts
@@ -18,7 +18,7 @@
// worker thread per test file); `./src/access.ts` needs the same treatment
// because it calls `createAccessChecks({ canWriteProject, ... })` at ITS OWN
// top level; a static import here would reach into
-// @openpanel/db/src/services/access.service as soon as anything imports
+// @openpanel/core as soon as anything imports
// @openpanel/core's barrel (this module is a static re-export there, not a
// lazy one), which broke a vitest suite that partially mocks that module
// (packages/trpc/src/routers/share.test.ts) with no `canWriteProject` export
diff --git a/packages/db/index.ts b/packages/db/index.ts
index b065e0251..22cb91d5e 100644
--- a/packages/db/index.ts
+++ b/packages/db/index.ts
@@ -1,39 +1,10 @@
-export * from './src/buffers';
export * from './src/clickhouse/client';
+// `clix` (query-builder.ts) and `createSqlBuilder` (sql-builder.ts) are dead
+// per ADR-013, but 7 live call sites across @openpanel/core still import
+// them directly and have not been converted onto the `sql` tag yet — see
+// M9-CLEANUP-001's report. Deleting these two ahead of that conversion is
+// BLOCKED, not done.
export * from './src/clickhouse/query-builder';
-export * from './src/encryption';
-export * from './src/engine';
-export * from './src/gsc';
export * from './src/prisma-client';
-export * from './src/services/access.service';
-export * from './src/services/auth-session.service';
-export * from './src/services/chart.service';
-export * from './src/services/clients.service';
-export * from './src/services/conversation.service';
-export * from './src/services/conversion.service';
-export * from './src/services/dashboard.service';
-export * from './src/services/date.service';
-export * from './src/services/event.service';
-export * from './src/services/filter-where.service';
-export * from './src/services/funnel.service';
-export * from './src/services/group.service';
-export * from './src/services/gsc.service';
-export * from './src/services/id.service';
-export * from './src/services/notification.service';
-export * from './src/services/organization.service';
-export * from './src/services/overview.service';
-export * from './src/services/pages.service';
-export * from './src/services/profile.service';
-export * from './src/services/project.service';
-export * from './src/services/reference.service';
-export * from './src/services/registration.service';
-export * from './src/services/reports.service';
-export * from './src/services/retention.service';
-export * from './src/services/salt.service';
-export * from './src/services/sankey.service';
-export * from './src/services/session.service';
-export * from './src/services/share.service';
-export * from './src/services/user.service';
-export * from './src/session-context';
export * from './src/sql-builder';
export * from './src/types';
diff --git a/packages/db/package.json b/packages/db/package.json
index ddbe52d66..5ff088d1d 100644
--- a/packages/db/package.json
+++ b/packages/db/package.json
@@ -17,8 +17,6 @@
"dependencies": {
"@clickhouse/client": "^1.18.5",
"@hyperdx/node-opentelemetry": "catalog:",
- "@openpanel/common": "workspace:*",
- "@openpanel/constants": "workspace:*",
"@openpanel/core": "workspace:*",
"@openpanel/json": "workspace:*",
"@openpanel/payments": "workspace:*",
@@ -26,24 +24,17 @@
"@openpanel/redis": "workspace:*",
"@openpanel/validation": "workspace:*",
"@prisma/client": "^6.14.0",
- "fast-deep-equal": "^3.1.3",
"jiti": "^2.4.1",
- "mathjs": "^12.3.2",
"pino": "catalog:",
"pino-pretty": "catalog:",
"prisma-json-types-generator": "^3.1.1",
- "ramda": "^0.29.1",
"sqlstring": "^2.3.3",
- "superjson": "^1.13.3",
- "uuid": "^9.0.1",
"zod": "catalog:"
},
"devDependencies": {
"@openpanel/tsconfig": "workspace:*",
"@types/node": "catalog:",
- "@types/ramda": "^0.29.6",
"@types/sqlstring": "^2.3.2",
- "@types/uuid": "^9.0.8",
"prisma": "^6.14.0",
"typescript": "catalog:"
}
diff --git a/packages/db/scripts/check-sessions.ts b/packages/db/scripts/check-sessions.ts
index 1a1cc8d7a..b05b89972 100644
--- a/packages/db/scripts/check-sessions.ts
+++ b/packages/db/scripts/check-sessions.ts
@@ -11,10 +11,10 @@
// pnpm with-env tsx scripts/check-sessions.ts --hours 48
import { getSafeJson } from '@openpanel/json';
+import type { IClickhouseSession } from '@openpanel/core';
import { sessionsQueue } from '@openpanel/queue';
import { getRedisCache } from '@openpanel/redis';
import { ch } from '../src/clickhouse/client';
-import type { IClickhouseSession } from '../src/services/session.service';
const DEADMAN_MS = Number.parseInt(
process.env.SESSION_REAPER_WALLCLOCK_DEADMAN_MS || String(30 * 60 * 1000),
diff --git a/packages/db/scripts/migrate-sessions.ts b/packages/db/scripts/migrate-sessions.ts
index ca991a023..baf33da6d 100644
--- a/packages/db/scripts/migrate-sessions.ts
+++ b/packages/db/scripts/migrate-sessions.ts
@@ -24,13 +24,13 @@
// `events.incoming-event` after deploy; keep `sessions` paused until step 7
// (drain-old-session-jobs.ts) finishes.
+import type { IClickhouseSession } from '@openpanel/core';
import { getSafeJson } from '@openpanel/json';
import {
type EventsQueuePayloadCreateSessionEnd,
sessionsQueue,
} from '@openpanel/queue';
import { getRedisCache } from '@openpanel/redis';
-import type { IClickhouseSession } from '../src/services/session.service';
const sessionKey = (projectId: string, deviceId: string) =>
`session:${projectId}:${deviceId}`;
diff --git a/packages/db/src/buffers/index.ts b/packages/db/src/buffers/index.ts
deleted file mode 100644
index ac967c71f..000000000
--- a/packages/db/src/buffers/index.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-// The seven buffers live in @openpanel/core now (M8-001):
-// packages/core/src/buffers/*. They are no longer module singletons there —
-// `createBuffers(deps)` builds them once and V2's main.ts hangs the result on
-// `AppDeps.buffers` (ADR-007). This file is the V1 delegate: one call to that
-// factory, its instances re-exported under the names apps/api, apps/worker,
-// packages/trpc and core's own lazy `import('@openpanel/db/src/buffers')`
-// call sites already use. Both boots therefore share ONE set of buffers and
-// one set of Redis lists.
-import { createBuffers } from '@openpanel/core';
-import { cronQueue } from '@openpanel/queue';
-import { createLogger } from '../logger';
-
-const buffers = createBuffers({
- // packages/db's own pino, exactly as each buffer built it before the move —
- // same `LOG_PREFIX-<name>-<NODE_ENV>` service name on every line.
- createLogger: (name) => createLogger({ name }),
- // ADR-005's BullMQ escape hatch: pausing `cron` from bull-board halts all
- // buffer flushing, preserved deliberately (docs/ANSWERS.md §3: "known!").
- isCronPaused: () => cronQueue.isPaused(),
-});
-
-export const eventBuffer = buffers.event;
-export const profileBuffer = buffers.profile;
-export const botBuffer = buffers.bot;
-export const sessionBuffer = buffers.session;
-export const profileBackfillBuffer = buffers.profileBackfill;
-export const replayBuffer = buffers.replay;
-export const groupBuffer = buffers.group;
-
-export type {
- IClickhouseSessionReplayChunk,
- ProfileBackfillEntry,
- SessionIngestResult,
-} from '@openpanel/core';
-export { SESSION_TIMEOUT_MS } from '@openpanel/core';
diff --git a/packages/db/src/encryption.ts b/packages/db/src/encryption.ts
deleted file mode 100644
index 56149c983..000000000
--- a/packages/db/src/encryption.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-// At-rest encryption lives in @openpanel/core so it can be shared by clients
-// (e.g. the object-store adapters) that can't depend on db. Re-exported here
-// for existing `@openpanel/db` importers (GSC tokens, TOTP). Same key
-// (ENCRYPTION_KEY) and same format as before — no data migration.
-export { decrypt, encrypt } from '@openpanel/core';
diff --git a/packages/db/src/engine/index.ts b/packages/db/src/engine/index.ts
deleted file mode 100644
index bb75ead24..000000000
--- a/packages/db/src/engine/index.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-// The chart engine lives in @openpanel/core now (M7-003). Re-exported here
-// for existing `@openpanel/db` importers (apps/api's export controller,
-// reports.service, core's mcp/assistant tools) — same shape as
-// packages/db/src/services/chart.service.ts.
-export type { ConcreteSeries, Plan, SeriesDefinition } from '@openpanel/core';
-export {
- AggregateChartEngine,
- ChartEngine,
- evaluateFormula,
- executeAggregateChart,
- executeChart,
- InvalidFormulaError,
- isValidFormula,
-} from '@openpanel/core';
diff --git a/packages/db/src/gsc.ts b/packages/db/src/gsc.ts
deleted file mode 100644
index 3adbd1268..000000000
--- a/packages/db/src/gsc.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-// The GSC OAuth token lifecycle, the Search Console API client and its
-// ClickHouse read/write live in @openpanel/core now (M5-002). Re-exported
-// here for existing `@openpanel/db` importers (packages/mcp's gsc tools) —
-// same shape as packages/db/src/encryption.ts since M4-006.
-export type { GscCannibalizedQuery, GscSite } from '@openpanel/core';
-export {
- getGscCannibalization,
- getGscOverview,
- getGscPageDetails,
- getGscPages,
- getGscQueries,
- getGscQueryDetails,
- listGscSites,
- syncGscData,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/access.service.ts b/packages/db/src/services/access.service.ts
index 38c81ea05..9c51f1f96 100644
--- a/packages/db/src/services/access.service.ts
+++ b/packages/db/src/services/access.service.ts
@@ -1,9 +1,13 @@
// The concrete project/organization/client access lookups live in
// @openpanel/core now (M8-005): packages/core/src/shared/access-lookups.ts.
-// Re-exported here for existing `@openpanel/db` importers (packages/trpc's
-// access.ts, apps/api's app.ts + live.controller.ts, and the ~28 core
-// modules' own `src/access.ts` files that deep-import this exact specifier)
-// — same shape as event.service.ts since M7-002.
+//
+// Kept here as a deep-path-only re-export (NOT part of packages/db's index.ts
+// barrel — that shrank to the final surface at M9-CLEANUP-001) solely because
+// the controller's protected `verification/contracts/auth/
+// group-b-project-access.mts` hard-imports this exact path
+// ('packages/db/src/services/access.service.ts') to exercise ADR-011
+// benchmark 2's getProjectAccess golden table. Every real importer in this
+// repo now reaches these functions through `@openpanel/core` directly.
export {
canWriteProject,
getClientAccess,
diff --git a/packages/db/src/services/auth-session.service.ts b/packages/db/src/services/auth-session.service.ts
deleted file mode 100644
index 39755a18f..000000000
--- a/packages/db/src/services/auth-session.service.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-// The Postgres-backed login session CRUD lives in @openpanel/core now
-// (M8-005): packages/core/src/modules/auth/src/login-session.ts. Re-exported
-// here for existing `@openpanel/db` importers (apps/api's app.ts) — same
-// shape as packages/db/src/services/chart.service.ts since M7-003.
-export type { SessionValidationResult } from '@openpanel/core';
-export {
- createDemoSession,
- createSession,
- EMPTY_SESSION,
- invalidateSession,
- validateSessionToken,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/chart.service.ts b/packages/db/src/services/chart.service.ts
deleted file mode 100644
index 633def545..000000000
--- a/packages/db/src/services/chart.service.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-// The chart service — field resolution, the event filter compiler, the chart
-// statements and the engine — lives in @openpanel/core now (M7-003).
-// Re-exported here for existing `@openpanel/db` importers (packages/trpc's
-// chart router, funnel/conversion/sankey/retention/overview services) — same
-// shape as packages/db/src/services/organization.service.ts since M6-001.
-export type {
- AggregateChartSqlInput,
- ChartSqlInput,
- CohortMetadata,
- FilterTableScope,
-} from '@openpanel/core';
-export {
- buildAllCohortsLabelExpr,
- buildAllCohortsMembershipQuery,
- buildCohortMembershipQuery,
- buildInlineCohortJoin,
- collectBreakdownCohortIds,
- collectProfilePropertyKeys,
- extractCohortId,
- fetchCohortsMetadata,
- fetchProjectCohorts,
- getAggregateChartSql,
- getChartSql,
- getCohortAlias,
- getCohortCteName,
- getEventFiltersWhereClause,
- getGroupPropertySelect,
- getGroupPropertySql,
- getProfilePropertySelect,
- getSelectPropertyKey,
- isAllCohortsBreakdown,
- isKnownEventField,
- normalizeEventField,
- profilePropertiesCteSelect,
- rewriteProfilePropertyRefs,
- transformPropertyKey,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/clients.service.ts b/packages/db/src/services/clients.service.ts
deleted file mode 100644
index 074f9fb48..000000000
--- a/packages/db/src/services/clients.service.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-// The client service lives in @openpanel/core now (M6-002). Re-exported
-// here for existing `@openpanel/db` importers (apps/api/src/utils/auth.ts,
-// core's mcp module) — same shape as
-// packages/db/src/services/organization.service.ts since M6-001.
-export type {
- IServiceClient,
- IServiceClientWithProject,
-} from '@openpanel/core';
-export {
- getClientById,
- getClientByIdCached,
- getClientsByOrganizationId,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/conversation.service.ts b/packages/db/src/services/conversation.service.ts
deleted file mode 100644
index 4e8fbd08a..000000000
--- a/packages/db/src/services/conversation.service.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-// Moved to @openpanel/core's conversation module (M5-006). Re-exported here
-// for existing `@openpanel/db` importers (apps/api's live chat route,
-// core's own assistant.routes.ts stub) — same shape as
-// packages/db/src/services/gsc.service.ts since M5-002.
-export type {
- IServiceChatMessage,
- IServiceConversation,
- IServiceConversationWithMessages,
-} from '@openpanel/core';
-export {
- deleteConversation,
- getConversationById,
- listConversations,
- upsertConversationTitle,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/conversion.service.ts b/packages/db/src/services/conversion.service.ts
deleted file mode 100644
index d30fd46d9..000000000
--- a/packages/db/src/services/conversion.service.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-// The conversion service lives in @openpanel/core now (M7-004). Re-exported
-// here for existing `@openpanel/db` importers (the barrel).
-export { getConversion } from '@openpanel/core';
diff --git a/packages/db/src/services/dashboard.service.ts b/packages/db/src/services/dashboard.service.ts
deleted file mode 100644
index 75f7cf788..000000000
--- a/packages/db/src/services/dashboard.service.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-// The dashboard service lives in @openpanel/core now (M7-006). Re-exported
-// here for existing `@openpanel/db` importers (packages/trpc's dashboard/
-// report routers, apps/api's insights controller, the mcp/assistant tools,
-// packages/core's report.service and share.service) — same shape as
-// packages/db/src/services/chart.service.ts since M7-003.
-export type {
- IServiceDashboard,
- IServiceDashboards,
-} from '@openpanel/core';
-export {
- createDashboard,
- deleteDashboard,
- getDashboardById,
- getDashboardByIdOrThrow,
- getDashboardsByProjectId,
- listDashboardsCore,
- updateDashboard,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/date.service.ts b/packages/db/src/services/date.service.ts
deleted file mode 100644
index 041f8c8ea..000000000
--- a/packages/db/src/services/date.service.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-// Chart date-range resolution lives in @openpanel/core now (M8-005):
-// packages/core/src/shared/date.ts. Re-exported here for existing
-// `@openpanel/db` importers (packages/trpc's overview/event routers,
-// apps/api's insights controller, ~40 core modules that still deep-import
-// this exact specifier) — same shape as event.service.ts since M7-002.
-export {
- getChartPrevStartEndDate,
- getChartStartEndDate,
- getDatesFromRange,
- resolveDateRange,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/event.service.ts b/packages/db/src/services/event.service.ts
deleted file mode 100644
index 989a7fd1b..000000000
--- a/packages/db/src/services/event.service.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-// The event service lives in @openpanel/core now (M7-002):
-// packages/core/src/modules/event/event.service.ts, with every ClickHouse
-// query rewritten onto the `sql` tag (packages/core/src/modules/event/src/
-// event.sql.ts). Re-exported here for existing `@openpanel/db` importers
-// (packages/trpc's event router, apps/api's export controller + is-bot hook,
-// apps/worker's incoming-event job, the buffers' row types, the assistant/mcp
-// tools) — same shape as session.service.ts since M7-001.
-export {
- createBotEvent,
- createEvent,
- EVENT_COLUMNS,
- type EventListSelect,
- type GetEventListOptions,
- getConversionEventNames,
- getEventById,
- getEventList,
- getEventMetas,
- getEventMetasCached,
- getEventPropertyValuesCore,
- getEvents,
- getEventsCount,
- getTopEventNames,
- getTopPages,
- type IClickhouseBotEvent,
- type IClickhouseEvent,
- type IEventColumn,
- type IImportedEvent,
- type IServiceBotEvent,
- type IServiceCreateBotEventPayload,
- type IServiceCreateEventPayload,
- type IServiceCreateEventPayloadWithId,
- type IServiceEvent,
- type IServiceEventMinimal,
- type IServiceImportedEventPayload,
- type IServicePage,
- listEventNamesCore,
- listEventPropertiesCore,
- type QueryEventsInput,
- queryEventsCore,
- transformEvent,
- transformMinimalEvent,
- transformSessionToEvent,
-} from '@openpanel/core';
-
-import { getEventById } from '@openpanel/core';
-
-// V1's `eventService.getById(...)` shape, kept for the callers that still
-// reach it through `@openpanel/db`. Resolved at call time: core ↔ db is an
-// import cycle and this module may evaluate first.
-export const eventService = {
- getById: (input: Parameters<typeof getEventById>[0]) => getEventById(input),
-};
diff --git a/packages/db/src/services/filter-where.service.ts b/packages/db/src/services/filter-where.service.ts
deleted file mode 100644
index e44a7d53a..000000000
--- a/packages/db/src/services/filter-where.service.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-// The sessions/profiles/events-table filter compiler lives in @openpanel/core
-// now (M8-005): packages/core/src/modules/chart/src/table-filter-where.ts.
-// Re-exported here for existing `@openpanel/db` importers — same shape as
-// packages/db/src/services/chart.service.ts since M7-003.
-export type { FilterTableContext } from '@openpanel/core';
-export { buildFilterWhere } from '@openpanel/core';
diff --git a/packages/db/src/services/funnel.service.ts b/packages/db/src/services/funnel.service.ts
deleted file mode 100644
index c8091372c..000000000
--- a/packages/db/src/services/funnel.service.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-// The funnel service lives in @openpanel/core now (M7-004). Re-exported here
-// for existing `@openpanel/db` importers (the barrel, reports.service's
-// `getReportDataCore`, apps/api's insights controller, packages/core's mcp and
-// assistant tools).
-export {
- buildFunnelBase,
- buildSessionsCte,
- EMPTY_BREAKDOWN_LABEL,
- getFunnel,
- getFunnelCore,
- getFunnelGroup,
- getFunnelProfileIds,
- toSeries as toFunnelSeries,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/group.service.ts b/packages/db/src/services/group.service.ts
deleted file mode 100644
index 8251dc235..000000000
--- a/packages/db/src/services/group.service.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-// The group service lives in @openpanel/core now (M7-002):
-// packages/core/src/modules/group/group.service.ts, with every ClickHouse
-// query rewritten onto the `sql` tag (packages/core/src/modules/group/src/
-// group.sql.ts). Re-exported here for existing `@openpanel/db` importers
-// (packages/trpc's group router, the assistant/mcp tools) — same shape as
-// session.service.ts since M7-001.
-export {
- createGroup,
- deleteGroup,
- findGroupsCore,
- getGroupById,
- getGroupCore,
- getGroupList,
- getGroupListCount,
- getGroupMemberProfiles,
- getGroupPropertyKeys,
- getGroupStats,
- getGroupsByIds,
- getGroupTypes,
- type IServiceGroup,
- type IServiceGroupStats,
- type IServiceUpsertGroup,
- listGroupTypesCore,
- updateGroup,
- upsertGroup,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/gsc.service.ts b/packages/db/src/services/gsc.service.ts
deleted file mode 100644
index 75b8e28f4..000000000
--- a/packages/db/src/services/gsc.service.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-// The AI-tool wrapper functions live in @openpanel/core now (M5-002).
-// Re-exported here for existing `@openpanel/db` importers (the assistant's
-// SEO tools, the /insights REST controller) — same shape as
-// packages/db/src/encryption.ts since M4-006.
-export type { GscQueryOpportunity } from '@openpanel/core';
-export {
- gscGetCannibalizationCore,
- gscGetOverviewCore,
- gscGetPageDetailsCore,
- gscGetQueryDetailsCore,
- gscGetQueryOpportunitiesCore,
- gscGetTopPagesCore,
- gscGetTopQueriesCore,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/id.service.ts b/packages/db/src/services/id.service.ts
deleted file mode 100644
index 09adf6e65..000000000
--- a/packages/db/src/services/id.service.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-// Slug-based id generation lives in @openpanel/core now (M8-005):
-// packages/core/src/shared/slug-id.ts. Re-exported here for existing
-// `@openpanel/db` importers (core's dashboard/project/onboarding services,
-// which deep-import this exact specifier via dynamic import) — same shape as
-// event.service.ts since M7-002.
-export { getId } from '@openpanel/core';
diff --git a/packages/db/src/services/lookback.ts b/packages/db/src/services/lookback.ts
deleted file mode 100644
index f0ebd096e..000000000
--- a/packages/db/src/services/lookback.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-// The lookback ceiling lives in @openpanel/core now (M8-005):
-// packages/core/src/shared/lookback.ts. Re-exported here for existing
-// `@openpanel/db` importers (core's event/session services, which
-// dynamic-import this exact specifier to keep one dynamic edge per import
-// cycle) — same shape as event.service.ts since M7-002.
-export { resolveMaxLookbackDays } from '@openpanel/core';
diff --git a/packages/db/src/services/organization.service.ts b/packages/db/src/services/organization.service.ts
deleted file mode 100644
index 753a4eb66..000000000
--- a/packages/db/src/services/organization.service.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-// The organization service — plus packages/db/src/services/delete.service.ts,
-// folded in with it — lives in @openpanel/core now (M6-001). Re-exported here
-// for existing `@openpanel/db` importers (packages/db's own engine +
-// analytics services reading `getSettingsForProject`, packages/trpc's
-// organization router, apps/worker's delete cron job) — same shape as
-// packages/db/src/gsc.ts since M5-002.
-export type {
- IServiceInvite,
- IServiceMember,
- IServiceOrganization,
- IServiceProjectAccess,
-} from '@openpanel/core';
-export {
- cancelOrganizationDeletion,
- connectUserToOrganization,
- deleteFromClickhouse,
- deleteOrganization,
- deleteProjects,
- getInviteById,
- getInvites,
- getMember,
- getMembers,
- getOrganizationBillingEventsCount,
- getOrganizationBillingEventsCountSerie,
- getOrganizationBillingEventsCountSerieCached,
- getOrganizationById,
- getOrganizationByProjectId,
- getOrganizationByProjectIdCached,
- getOrganizationEventsCount,
- getOrganizationEventsCountSince,
- getOrganizationSubscriptionChartEndDate,
- getOrganizations,
- getSettingsForOrganization,
- getSettingsForProject,
- inviteUserToOrganization,
- removeOrganizationMember,
- revokeInvite,
- runDeleteCron,
- scheduleOrganizationDeletion,
- updateOrganization,
- updateOrganizationMemberAccess,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/overview.service.ts b/packages/db/src/services/overview.service.ts
deleted file mode 100644
index a4493c952..000000000
--- a/packages/db/src/services/overview.service.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-// Overview — OverviewService, its query builders and the mcp/assistant
-// "*Core" helpers — lives in @openpanel/core now (M7-005). Re-exported here
-// for existing `@openpanel/db` importers (packages/trpc's overview/event
-// routers, apps/api's insights controller, packages/db's pages.service.ts,
-// the mcp analytics tools) — same shape as
-// packages/db/src/services/chart.service.ts since M7-003.
-export type {
- IGetMapDataInput,
- IGetMetricsInput,
- IGetTopEntryExitInput,
- IGetTopEventsInput,
- IGetTopGenericInput,
- IGetTopGenericSeriesInput,
- IGetTopLinkOutInput,
- IGetTopPagesInput,
- IGetUserJourneyInput,
- ILiveData,
- ILiveMinuteCount,
- SegmentDailyPoint,
- TrafficColumn,
-} from '@openpanel/core';
-export {
- getAnalyticsOverviewCore,
- getSegmentDailySeriesCore,
- getTrafficBreakdownCore,
- OverviewService,
- overviewService,
- zGetMapDataInput,
- zGetMetricsInput,
- zGetTopEntryExitInput,
- zGetTopEventsInput,
- zGetTopGenericInput,
- zGetTopGenericSeriesInput,
- zGetTopLinkOutInput,
- zGetTopPagesInput,
- zGetUserJourneyInput,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/pages.service.ts b/packages/db/src/services/pages.service.ts
deleted file mode 100644
index 8aa89ed48..000000000
--- a/packages/db/src/services/pages.service.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-// Pages — PagesService and the mcp/insights "*Core" helpers — lives in
-// @openpanel/core's overview module now (M7-005, the module map's owner of
-// "pages"). Re-exported here for existing `@openpanel/db` importers
-// (packages/trpc's event router, apps/api's insights controller, the mcp
-// analytics tools) — same shape as
-// packages/db/src/services/overview.service.ts since M7-003.
-export type {
- IGetPagesInput,
- IPageConversionRow,
- IPageTimeseriesRow,
- ITopPage,
-} from '@openpanel/core';
-export {
- getEntryExitPagesCore,
- getPageConversionsCore,
- getPagePerformanceCore,
- getTopPagesCore,
- PagesService,
- pagesService,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/profile.service.ts b/packages/db/src/services/profile.service.ts
deleted file mode 100644
index 8c9bcaa67..000000000
--- a/packages/db/src/services/profile.service.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-// The profile service lives in @openpanel/core now (M7-002):
-// packages/core/src/modules/profile/profile.service.ts, with every ClickHouse
-// query rewritten onto the `sql` tag (packages/core/src/modules/profile/src/
-// profile.sql.ts). Re-exported here for existing `@openpanel/db` importers
-// (packages/trpc's profile/chart routers, apps/api's insights controller,
-// the assistant/mcp tools, profile-buffer's IClickhouseProfile type) — same
-// shape as session.service.ts since M7-001.
-export {
- type FindProfilesInput,
- findProfilesCore,
- getProfileById,
- getProfileList,
- getProfileListCount,
- getProfileMetrics,
- getProfileMetricsCore,
- getProfilePropertyKeys,
- getProfilePropertyKeysCached,
- getProfileSessionsCore,
- getProfiles,
- getProfilesCached,
- getProfileWithEvents,
- type IClickhouseProfile,
- type IProfileMetrics,
- type IServiceProfile,
- type IServiceUpsertProfile,
- transformProfile,
- upsertProfile,
-} from '@openpanel/core';
-
-import sqlstring from 'sqlstring';
-
-const MAX_SEARCH_TOKENS = 5;
-
-/**
- * String-SQL twin of core's `profileSearchCondition`, kept for
- * cohort.service.ts's `getCohortProfiles`, which still composes V1 text
- * queries. Goes with that query when it moves onto the `sql` tag.
- */
-export function profileSearchSql(
- search: string | null | undefined
-): string | null {
- const tokens = (search ?? '')
- .trim()
- .split(/\s+/)
- .filter(Boolean)
- .slice(0, MAX_SEARCH_TOKENS);
- if (tokens.length === 0) {
- return null;
- }
- const perToken = tokens.map((token) => {
- const like = sqlstring.escape(`%${token}%`);
- return `(id ILIKE ${like} OR email ILIKE ${like} OR first_name ILIKE ${like} OR last_name ILIKE ${like} OR concat(first_name, ' ', last_name) ILIKE ${like})`;
- });
- return `(${perToken.join(' AND ')})`;
-}
diff --git a/packages/db/src/services/project.service.ts b/packages/db/src/services/project.service.ts
deleted file mode 100644
index e2573a681..000000000
--- a/packages/db/src/services/project.service.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-// The project service lives in @openpanel/core now (M6-002). Re-exported
-// here for existing `@openpanel/db` importers (this package's own
-// access.service.ts + notification.service.ts, several core modules'
-// `src/access.ts`, apps/api/src/utils/auth.ts) — same shape as
-// packages/db/src/services/organization.service.ts since M6-001.
-export type {
- IServiceProject,
- IServiceProjectWithClients,
-} from '@openpanel/core';
-export {
- getLastEventPerProject,
- getProjectById,
- getProjectByIdCached,
- getProjectEventsCount,
- getProjects,
- getProjectWithClients,
- listProjectsCore,
- resolveClientProjectId,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/reference.service.ts b/packages/db/src/services/reference.service.ts
deleted file mode 100644
index d4f098dcd..000000000
--- a/packages/db/src/services/reference.service.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-// The reference service — plus the query/mutation bodies
-// packages/trpc/src/routers/reference.ts held inline — lives in
-// @openpanel/core now (M6-004). Re-exported here for existing
-// `@openpanel/db` importers — same shape as
-// packages/db/src/services/organization.service.ts since M6-001.
-export type { IServiceReference } from '@openpanel/core';
-export {
- createReference,
- deleteReference,
- getChartReferences,
- getReferenceById,
- getReferenceByIdOrThrow,
- listReferences,
- updateReference,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/registration.service.ts b/packages/db/src/services/registration.service.ts
deleted file mode 100644
index 40a31a88a..000000000
--- a/packages/db/src/services/registration.service.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-// Registration-allowed policy lives in @openpanel/core now (M8-005):
-// packages/core/src/modules/auth/src/registration.ts. Re-exported here for
-// existing `@openpanel/db` importers (core's auth.service.ts, which
-// dynamic-imports this exact specifier to keep one dynamic edge per import
-// cycle) — same shape as event.service.ts since M7-002.
-export { getIsRegistrationAllowed } from '@openpanel/core';
diff --git a/packages/db/src/services/reports.service.ts b/packages/db/src/services/reports.service.ts
deleted file mode 100644
index 3fc635892..000000000
--- a/packages/db/src/services/reports.service.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-// The report service — transforms, mutations, listReportsCore and
-// getReportDataCore — lives in @openpanel/core now (M7-006). Re-exported here
-// for existing `@openpanel/db` importers (packages/trpc's report/chart
-// routers, apps/api's insights controller, the chart engine's funnel/
-// conversion services, the mcp/assistant tools) — same shape as
-// packages/db/src/services/chart.service.ts since M7-003.
-export type { IServiceReport } from '@openpanel/core';
-export {
- createReport,
- deleteReport,
- duplicateReport,
- getReportById,
- getReportByIdOrThrow,
- getReportDataCore,
- getReportLayouts,
- getReportsByDashboardId,
- listReportsCore,
- mergeGlobalFilters,
- moveReport,
- onlyReportEvents,
- resetReportLayouts,
- transformFilter,
- transformReport,
- transformReportEventItem,
- updateReport,
- updateReportLayout,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/retention.service.ts b/packages/db/src/services/retention.service.ts
deleted file mode 100644
index 3edcd3ce2..000000000
--- a/packages/db/src/services/retention.service.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-// The retention service — the week-over-week series, the rolling active-user
-// series, the last-seen distribution and the cohort matrix — lives in
-// @openpanel/core now (M7-004). Re-exported here for existing `@openpanel/db`
-// importers (the barrel, apps/api's insights controller, packages/core's mcp
-// and assistant tools) — same shape as chart.service.ts since M7-003.
-export type {
- IGetRetentionCohortInput,
- IRetentionCohortRow,
- IRetentionCriteria,
- IRetentionInterval,
- IServiceRetentionRollingActiveUsers,
-} from '@openpanel/core';
-export {
- getEngagementCore,
- getRetentionCohort,
- getRetentionCohortCore,
- getRetentionLastSeenSeries,
- getRetentionSeries,
- getRollingActiveUsers,
- getRollingActiveUsersCore,
- getWeeklyRetentionSeriesCore,
- processCohortData,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/salt.service.ts b/packages/db/src/services/salt.service.ts
deleted file mode 100644
index 6a0e79a51..000000000
--- a/packages/db/src/services/salt.service.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-// Moved to @openpanel/core (M8-004): packages/core/src/modules/salt/salt.service.ts.
-// Re-exported here so V1's apps/worker (createInitialSalts at boot) and
-// apps/api's event.controller.ts (getSalts) keep working unchanged
-// (DELEGATE PATTERN) — V1 is not deleted before P9. `rotateSalt` is V1's
-// `cron.salt.ts`'s `salt()`, re-exported under its core name for the one
-// caller that still imports this file directly rather than the barrel.
-export { createInitialSalts, getSalts, rotateSalt } from '@openpanel/core';
diff --git a/packages/db/src/services/sankey.service.ts b/packages/db/src/services/sankey.service.ts
deleted file mode 100644
index 3dc69bb41..000000000
--- a/packages/db/src/services/sankey.service.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-// The sankey (user-flow) service lives in @openpanel/core now (M7-004).
-// Re-exported here for existing `@openpanel/db` importers (the barrel,
-// apps/api's insights controller, packages/core's mcp and assistant tools).
-export type { IGetSankeyInput } from '@openpanel/core';
-export {
- getRawWhereClause,
- getSankey,
- getUserFlowCore,
- zGetSankeyInput,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/session.service.ts b/packages/db/src/services/session.service.ts
deleted file mode 100644
index 8340129ef..000000000
--- a/packages/db/src/services/session.service.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-// The session service lives in @openpanel/core now (M7-001):
-// packages/core/src/modules/session/session.service.ts, with every ClickHouse
-// query rewritten onto the `sql` tag (packages/core/src/modules/session/src/
-// session.sql.ts). Re-exported here for existing `@openpanel/db` importers
-// (packages/trpc's event router, the assistant/mcp tools, session-buffer's
-// IClickhouseSession type) — same shape as share.service.ts since M6-004.
-export {
- type GetSessionListOptions,
- getSessionById,
- getSessionDistinctValues,
- getSessionList,
- getSessionReplayChunksFrom,
- getSessionsCount,
- getSessionsCountCached,
- type IClickhouseSession,
- type IServiceSession,
- type ISessionReplayChunkMeta,
- type QuerySessionsInput,
- querySessionsCore,
- SESSION_DISTINCT_FIELDS,
- type SessionDistinctField,
- transformSession,
-} from '@openpanel/core';
-
-import { getSessionById } from '@openpanel/core';
-
-// V1's `sessionService.byId(sessionId, projectId)` shape, kept for the
-// callers that still reach it through `@openpanel/db`. Resolved at call time:
-// core ↔ db is an import cycle and this module may evaluate first.
-export const sessionService = {
- byId: (sessionId: string, projectId: string) =>
- getSessionById(sessionId, projectId),
-};
diff --git a/packages/db/src/services/share.service.ts b/packages/db/src/services/share.service.ts
deleted file mode 100644
index fb3f39e67..000000000
--- a/packages/db/src/services/share.service.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-// The share service — plus the query/mutation bodies
-// packages/trpc/src/routers/share.ts held inline — lives in @openpanel/core
-// now (M6-004). Re-exported here for existing `@openpanel/db` importers
-// (packages/trpc's chart/overview routers, which still reach
-// validateShareAccess/validateOverviewShareAccess through it) — same shape
-// as packages/db/src/services/organization.service.ts since M6-001.
-export {
- createShareDashboard,
- createShareOverview,
- createShareReport,
- getShareByProjectId,
- getShareDashboard,
- getShareDashboardById,
- getShareDashboardByDashboardId,
- getShareDashboardReports,
- getShareDashboardSettings,
- getShareOverview,
- getShareOverviewById,
- getShareOverviewSettings,
- getShareReport,
- getShareReportById,
- getShareReportByReportId,
- getShareReportSettings,
- validateOverviewShareAccess,
- validateReportAccess,
- validateShareAccess,
-} from '@openpanel/core';
diff --git a/packages/db/src/services/user.service.ts b/packages/db/src/services/user.service.ts
deleted file mode 100644
index 6b07f8123..000000000
--- a/packages/db/src/services/user.service.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-// The user service lives in @openpanel/core now (M6-001). Re-exported here
-// for existing `@openpanel/db` importers (packages/trpc's auth/onboarding
-// routers, not yet ported) — same shape as packages/db/src/gsc.ts since
-// M5-002.
-export type { IServiceUser } from '@openpanel/core';
-export { getUserAccount, getUserById } from '@openpanel/core';
diff --git a/packages/db/src/session-context.ts b/packages/db/src/session-context.ts
deleted file mode 100644
index 745983d86..000000000
--- a/packages/db/src/session-context.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-// The ALS session scope lives in @openpanel/core now (M7-001):
-// packages/core/src/modules/session/src/session-context.ts. Re-exported here
-// so V1 (`packages/trpc`, `apps/api`) and core share the ONE
-// AsyncLocalStorage instance — two stores would never see each other's
-// session id. `session-consistency.ts`, its one other V1 reader, is deleted
-// (M8-004, ADR-012: the read-replica extension it backed is never wired into
-// the Prisma client, and Carl ruled both out — docs/ANSWERS.md §1.5).
-export { als, getAlsSessionId, runWithAlsSession } from '@openpanel/core';
diff --git a/packages/db/src/types.ts b/packages/db/src/types.ts
index e8d4e2289..b4b74b4aa 100644
--- a/packages/db/src/types.ts
+++ b/packages/db/src/types.ts
@@ -8,12 +8,23 @@ import type {
IWidgetOptions,
InsightPayload,
} from '@openpanel/validation';
+// `IClickhouseEvent`/`IClickhouseBotEvent`/`IClickhouseProfile`/
+// `INotificationPayload` all moved to @openpanel/core (M9-CLEANUP-001,
+// packages/db's final-surface shrink) — the three local re-export shims that
+// used to bridge them are gone. This is the type-only `db -> core` back-edge
+// ADR-007 named and explicitly declined to resolve ("belongs to P8's db
+// slim-down"; three options, none picked). Taken here: option 3, "accept a
+// declared type-only devDependency edge" — `@openpanel/db` already depends on
+// `@openpanel/core` (these shims were the reason), the edge is `import type`
+// only so it creates no runtime cycle, and it is the same shape as this
+// repo's existing type-only `db -> queue` cycle. Revisit if a future task
+// picks a different one of the three named resolutions.
import type {
IClickhouseBotEvent,
IClickhouseEvent,
-} from './services/event.service';
-import type { INotificationPayload } from './services/notification.service';
-import type { IClickhouseProfile } from './services/profile.service';
+ IClickhouseProfile,
+ INotificationPayload,
+} from '@openpanel/core';
declare global {
namespace PrismaJson {
diff --git a/packages/queue/src/buffers.ts b/packages/queue/src/buffers.ts
new file mode 100644
index 000000000..4e652fb6c
--- /dev/null
+++ b/packages/queue/src/buffers.ts
@@ -0,0 +1,42 @@
+// Moved from packages/db/src/buffers/index.ts (M9-CLEANUP-001, packages/db's
+// final-surface shrink). The seven buffers live in @openpanel/core
+// (M8-001): `createBuffers(deps)` builds them once and V2's main.ts hangs the
+// result on `AppDeps.buffers` (ADR-007). This file is the ONE process-wide
+// singleton instance every call site that predates that ctx wiring still
+// reaches — packages/trpc's overview/widget routers and the several
+// `@openpanel/core` modules that lazy-import this specifier
+// (`loadDbBuffers`) rather than threading `ctx.buffers` through. Repointing
+// those call sites onto `ctx.buffers` is the larger, separately-scoped
+// follow-up docs/TECH_DEBT.md tracks (the 93 lazy db imports bypassing
+// ctx/requestId) — not this task.
+//
+// Lives in @openpanel/queue rather than @openpanel/core because it needs
+// `cronQueue` (ADR-005's BullMQ escape hatch: pausing `cron` from bull-board
+// halts all buffer flushing, preserved deliberately — docs/ANSWERS.md §3:
+// "known!"), and core must not import `@openpanel/queue` back without a real
+// package cycle (see notification-dispatch.ts). `@openpanel/queue` already
+// depends on `@openpanel/core`, so this is the one side of that boundary free
+// of a cycle. Also keeps core's own rule intact: buffers are boot singletons
+// on AppDeps, never a module-level singleton in core itself (M8-005).
+import { createBuffers, createLogger } from '@openpanel/core';
+import { cronQueue } from './queues';
+
+const buffers = createBuffers({
+ createLogger: (name) => createLogger({ name }),
+ isCronPaused: () => cronQueue.isPaused(),
+});
+
+export const eventBuffer = buffers.event;
+export const profileBuffer = buffers.profile;
+export const botBuffer = buffers.bot;
+export const sessionBuffer = buffers.session;
+export const profileBackfillBuffer = buffers.profileBackfill;
+export const replayBuffer = buffers.replay;
+export const groupBuffer = buffers.group;
+
+export type {
+ IClickhouseSessionReplayChunk,
+ ProfileBackfillEntry,
+ SessionIngestResult,
+} from '@openpanel/core';
+export { SESSION_TIMEOUT_MS } from '@openpanel/core';
diff --git a/packages/db/src/services/notification.service.ts b/packages/queue/src/notification-dispatch.ts
similarity index 75%
rename from packages/db/src/services/notification.service.ts
rename to packages/queue/src/notification-dispatch.ts
index 1352cfa89..e744ae5fa 100644
Binary files a/packages/db/src/services/notification.service.ts and b/packages/queue/src/notification-dispatch.ts differ
diff --git a/packages/queue/src/queues.ts b/packages/queue/src/queues.ts
index e20164668..864045ea9 100644
--- a/packages/queue/src/queues.ts
+++ b/packages/queue/src/queues.ts
@@ -1,10 +1,10 @@
-import { createLogger } from '@openpanel/core';
-import type {
- IClickhouseSession,
- IServiceCreateEventPayload,
- IServiceEvent,
- Prisma,
-} from '@openpanel/db';
+import {
+ createLogger,
+ type IClickhouseSession,
+ type IServiceCreateEventPayload,
+ type IServiceEvent,
+} from '@openpanel/core';
+import type { Prisma } from '@openpanel/db';
import { getRedisQueue } from '@openpanel/redis';
import { Queue } from 'bullmq';
import type { ITrackPayload } from '../../validation';
diff --git a/packages/redis/package.json b/packages/redis/package.json
index 79c1e951e..aead1a876 100644
--- a/packages/redis/package.json
+++ b/packages/redis/package.json
@@ -12,6 +12,7 @@
"lru-cache": "^11.2.2"
},
"devDependencies": {
+ "@openpanel/core": "workspace:*",
"@openpanel/db": "workspace:*",
"@openpanel/tsconfig": "workspace:*",
"@types/node": "catalog:",
diff --git a/packages/redis/publisher.ts b/packages/redis/publisher.ts
index 47d04f4c1..08b5d225f 100644
--- a/packages/redis/publisher.ts
+++ b/packages/redis/publisher.ts
@@ -1,6 +1,7 @@
import { type Redis, getRedisPub, getRedisSub } from './redis';
-import type { IServiceEvent, Notification, Prisma } from '@openpanel/db';
+import type { IServiceEvent } from '@openpanel/core';
+import type { Notification, Prisma } from '@openpanel/db';
import { getSuperJson, setSuperJson } from '@openpanel/json';
export type IPublishChannels = {
diff --git a/packages/trpc/src/access.test.ts b/packages/trpc/src/access.test.ts
index 25f82d56d..31586b590 100644
--- a/packages/trpc/src/access.test.ts
+++ b/packages/trpc/src/access.test.ts
@@ -8,7 +8,12 @@ const { getProjectAccess, getOrganizationAccess, getProjectById } = vi.hoisted(
}),
);
-vi.mock('@openpanel/db', () => ({
+vi.mock('@openpanel/core', async () => ({
+ // `createAccessChecks` (the permission ladder itself, GHSA-f9rx-pxgw-c6rg's
+ // fix) stays real — only the lookups it's built from are stubbed.
+ ...(await vi.importActual<typeof import('@openpanel/core')>(
+ '@openpanel/core',
+ )),
getProjectAccess,
getOrganizationAccess,
getProjectById,
diff --git a/packages/trpc/src/access.ts b/packages/trpc/src/access.ts
index c519320f8..ae8e1ebc4 100644
--- a/packages/trpc/src/access.ts
+++ b/packages/trpc/src/access.ts
@@ -1,23 +1,23 @@
// The permission ladder now lives in @openpanel/core (`shared/access`); this
-// file binds it to the real `@openpanel/db` lookups and keeps the specifier
-// V1's routers and `apps/api` already import.
+// file binds it to the real lookups (also core, since M9-CLEANUP-001) and
+// keeps the specifier V1's routers and `apps/api` already import.
//
// The ladder itself — the rules, the messages, GHSA-f9rx-pxgw-c6rg's fix — is
// core's and single-sourced there.
-import { createAccessChecks } from '@openpanel/core';
import {
canWriteProject,
+ createAccessChecks,
getOrganizationAccess,
getProjectAccess,
getProjectById,
-} from '@openpanel/db';
+} from '@openpanel/core';
export {
getClientAccess,
getOrganizationAccess,
getProjectAccess,
-} from '@openpanel/db';
+} from '@openpanel/core';
const checks = createAccessChecks({
getProjectAccess,
diff --git a/packages/trpc/src/routers/chart.ts b/packages/trpc/src/routers/chart.ts
index 435078577..eda4b3131 100644
--- a/packages/trpc/src/routers/chart.ts
+++ b/packages/trpc/src/routers/chart.ts
@@ -14,13 +14,14 @@ import {
getFunnelChart,
getFunnelStepProfiles,
getProjectCard,
+ getReportById,
getRetentionChart,
getSankeyChart,
listChartEvents,
listChartProperties,
resolveReportInput,
+ validateShareAccess,
} from '@openpanel/core';
-import { getReportById, validateShareAccess } from '@openpanel/db';
import {
zChartEventFilter,
zChartSeries,
diff --git a/packages/trpc/src/routers/conversation.ts b/packages/trpc/src/routers/conversation.ts
index 87aca56a9..05fe669cd 100644
--- a/packages/trpc/src/routers/conversation.ts
+++ b/packages/trpc/src/routers/conversation.ts
@@ -10,7 +10,7 @@ import {
listConversations,
upsertConversationTitle,
} from '@openpanel/core';
-import { getOrganizationByProjectIdCached } from '@openpanel/db';
+import { getOrganizationByProjectIdCached } from '@openpanel/core';
import { TRPCError } from '@trpc/server';
import { z } from 'zod';
import { getProjectAccess, requireProjectAccess } from '../access';
diff --git a/packages/trpc/src/routers/event.ts b/packages/trpc/src/routers/event.ts
index 5c6b576e1..c63d48255 100644
--- a/packages/trpc/src/routers/event.ts
+++ b/packages/trpc/src/routers/event.ts
@@ -11,19 +11,17 @@
import {
getBotEventsPage,
+ getChartStartEndDate,
getConversionEventNames,
getConversionListPage,
getEventById,
getEventDetails,
getEventListPage,
+ getSettingsForProject,
getTopOrigins,
+ pagesService,
updateEventMeta,
} from '@openpanel/core';
-import {
- getChartStartEndDate,
- getSettingsForProject,
- pagesService,
-} from '@openpanel/db';
import {
zChartEventFilter,
zRange,
diff --git a/packages/trpc/src/routers/insight.ts b/packages/trpc/src/routers/insight.ts
index b0d398235..fd949c85f 100644
--- a/packages/trpc/src/routers/insight.ts
+++ b/packages/trpc/src/routers/insight.ts
@@ -144,7 +144,7 @@ export const insightRouter = createTRPCRouter({
const iso = (d: Date) => d.toISOString();
const { getSegmentDailySeriesCore, getTrafficBreakdownCore } =
- await import('@openpanel/db');
+ await import('@openpanel/core');
const breakdowns = await Promise.all(
EXPLAIN_COLUMNS.map(async (column) => {
diff --git a/packages/trpc/src/routers/overview.ts b/packages/trpc/src/routers/overview.ts
index 1f391c69a..d09c5a79a 100644
--- a/packages/trpc/src/routers/overview.ts
+++ b/packages/trpc/src/routers/overview.ts
@@ -9,6 +9,8 @@
// `overviewService.getLiveData` with everything else this module runs.
import {
+ getChartPrevStartEndDate,
+ getChartStartEndDate,
getConversionEventNames,
getOrganizationSubscriptionChartEndDate,
getReferrerSpikes,
@@ -25,11 +27,7 @@ import {
zGetTopPagesInput,
zGetUserJourneyInput,
} from '@openpanel/core';
-import {
- eventBuffer,
- getChartPrevStartEndDate,
- getChartStartEndDate,
-} from '@openpanel/db';
+import { eventBuffer } from '@openpanel/queue/src/buffers';
import {
type IChartRange,
pageContextSchema,
diff --git a/packages/trpc/src/routers/share.test.ts b/packages/trpc/src/routers/share.test.ts
index 83f647f6a..c68400bd4 100644
--- a/packages/trpc/src/routers/share.test.ts
+++ b/packages/trpc/src/routers/share.test.ts
@@ -12,18 +12,30 @@ const {
}));
// The share business logic itself moved to @openpanel/core (M6-004); share.ts
-// now only delegates to it. `@openpanel/db` is still mocked for `../access`'s
+// now only delegates to it. `@openpanel/core` is also mocked for `../access`'s
// and `trpc.ts`'s own imports (unrelated to this file's assertions) — the
// deep `@openpanel/db/src/*` paths below are what core's share functions
// actually read through (lazy `await import(...)`, so vi.mock still applies
-// to the dynamic form).
-vi.mock('@openpanel/db', () => ({
+// to the dynamic form). `createAccessChecks` (the permission ladder itself,
+// GHSA-f9rx-pxgw-c6rg's fix) stays real via importActual — everything it's
+// built from, plus share's own core reads, are the only stubs, one
+// vi.mock call, since every one of these now resolves through the same
+// @openpanel/core specifier (M9-CLEANUP-001) and a second/third call would
+// silently drop the earlier overrides.
+vi.mock('@openpanel/core', async () => ({
+ ...(await vi.importActual<typeof import('@openpanel/core')>(
+ '@openpanel/core',
+ )),
getProjectById: vi.fn(),
getProjectAccess: vi.fn(),
getOrganizationAccess: vi.fn(),
getClientAccess: vi.fn(),
canWriteProject: vi.fn(),
runWithAlsSession: (_id: unknown, fn: () => unknown) => fn(),
+ transformReport: (report: unknown) => report,
+ getReportById: vi.fn(),
+ getReportsByDashboardId: vi.fn(),
+ getDashboardById: vi.fn(),
}));
vi.mock('@openpanel/db/src/prisma-client', () => ({
@@ -34,20 +46,6 @@ vi.mock('@openpanel/db/src/prisma-client', () => ({
},
}));
-vi.mock('@openpanel/db/src/services/reports.service', () => ({
- transformReport: (report: unknown) => report,
- getReportById: vi.fn(),
- getReportsByDashboardId: vi.fn(),
-}));
-
-vi.mock('@openpanel/db/src/services/dashboard.service', () => ({
- getDashboardById: vi.fn(),
-}));
-
-vi.mock('@openpanel/db/src/services/access.service', () => ({
- getProjectAccess: vi.fn(),
-}));
-
import { shareRouter } from './share';
const PASSWORD_HASH =
diff --git a/packages/trpc/src/routers/widget.ts b/packages/trpc/src/routers/widget.ts
index 529db12a2..70c16baf5 100644
--- a/packages/trpc/src/routers/widget.ts
+++ b/packages/trpc/src/routers/widget.ts
@@ -6,15 +6,13 @@
// delegate to, so V1 keeps its own ClickHouse/Postgres calls here, reading
// the schemas core now owns instead of @openpanel/validation's copy.
-import { zWidgetOptions, zWidgetType } from '@openpanel/core';
import {
- ch,
- clix,
- db,
- eventBuffer,
getSettingsForProject,
- TABLE_NAMES,
-} from '@openpanel/db';
+ zWidgetOptions,
+ zWidgetType,
+} from '@openpanel/core';
+import { ch, clix, db, TABLE_NAMES } from '@openpanel/db';
+import { eventBuffer } from '@openpanel/queue/src/buffers';
import { getCache } from '@openpanel/redis';
import ShortUniqueId from 'short-unique-id';
import { z } from 'zod';
diff --git a/packages/trpc/src/trpc.ts b/packages/trpc/src/trpc.ts
index 69a3c690c..413fc1d11 100644
--- a/packages/trpc/src/trpc.ts
+++ b/packages/trpc/src/trpc.ts
@@ -19,7 +19,7 @@ import {
type RpcCache,
type TrpcContext,
} from '@openpanel/core';
-import { runWithAlsSession } from '@openpanel/db';
+import { runWithAlsSession } from '@openpanel/core';
import { getRedisCache } from '@openpanel/redis';
import { TRPCError } from '@trpc/server';
import { has } from 'ramda';
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 9e2d606f7..5ee7b1da9 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -938,6 +938,9 @@ importers:
'@openpanel/payments':
specifier: workspace:*
version: link:../payments
+ '@openpanel/queue':
+ specifier: workspace:*
+ version: link:../queue
'@openpanel/redis':
specifier: workspace:*
version: link:../redis
@@ -1098,12 +1101,6 @@ importers:
'@hyperdx/node-opentelemetry':
specifier: 'catalog:'
version: 0.10.3([email protected])
- '@openpanel/common':
- specifier: workspace:*
- version: link:../common
- '@openpanel/constants':
- specifier: workspace:*
- version: link:../constants
'@openpanel/core':
specifier: workspace:*
version: link:../core
@@ -1125,15 +1122,9 @@ importers:
'@prisma/client':
specifier: ^6.14.0
- fast-deep-equal:
- specifier: ^3.1.3
- version: 3.1.3
jiti:
specifier: ^2.4.1
version: 2.4.1
- mathjs:
- specifier: ^12.3.2
- version: 12.3.2
pino:
specifier: 'catalog:'
version: 10.3.1
@@ -1143,18 +1134,9 @@ importers:
prisma-json-types-generator:
specifier: ^3.1.1
- ramda:
- specifier: ^0.29.1
- version: 0.29.1
sqlstring:
specifier: ^2.3.3
version: 2.3.3
- superjson:
- specifier: ^1.13.3
- version: 1.13.3
- uuid:
- specifier: ^9.0.1
- version: 9.0.1
zod:
specifier: 'catalog:'
version: 4.3.6
@@ -1165,15 +1147,9 @@ importers:
'@types/node':
specifier: 'catalog:'
version: 24.10.1
- '@types/ramda':
- specifier: ^0.29.6
- version: 0.29.10
'@types/sqlstring':
specifier: ^2.3.2
version: 2.3.2
- '@types/uuid':
- specifier: ^9.0.8
- version: 9.0.8
prisma:
specifier: ^6.14.0
@@ -1326,6 +1302,9 @@ importers:
specifier: ^11.2.2
version: 11.2.2
devDependencies:
+ '@openpanel/core':
+ specifier: workspace:*
+ version: link:../core
'@openpanel/db':
specifier: workspace:*
version: link:../db
@@ -9639,9 +9618,6 @@ packages:
resolution: {integrity: sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==}
- '@types/[email protected]':
- resolution: {integrity: sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==}
-
resolution: {integrity: sha512-QlyDyX7rsOIJHASzXWlih8DT9fR+XCG9cwIV/4pKrtScdHv4XFshdEf/7iiqLqG0lzWcoBdzG8ylMHQ5XLNixw==}
@@ -29241,8 +29217,6 @@ snapshots:
'@types/[email protected]': {}
- '@types/[email protected]': {}
-
dependencies:
'@types/webpack': 4.41.40