Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🚚 Normalize feature folder file names to the closed vocabulary (#2603)

Luke Vella795a4316b8f4
diff --git a/apps/web/src/app/[locale]/(auth)/layout.tsx b/apps/web/src/app/[locale]/(auth)/layout.tsx
index ba6c4ffcc..e98b1dc68 100644
--- a/apps/web/src/app/[locale]/(auth)/layout.tsx
+++ b/apps/web/src/app/[locale]/(auth)/layout.tsx
@@ -1,8 +1,6 @@
-import {
- isQuickCreateEnabled,
- QuickCreateButton,
- QuickCreateWidget,
-} from "@/features/quick-create";
+import { QuickCreateButton } from "@/features/quick-create/components/quick-create-button";
+import { QuickCreateWidget } from "@/features/quick-create/components/quick-create-widget";
+import { isQuickCreateEnabled } from "@/features/quick-create/constants";
import { getLocale } from "@/i18n/server/get-locale";
import { DeviceDateTimeProvider } from "@/lib/datetime/device";
import { getDeviceDateTimeConfig } from "@/lib/datetime/server";
diff --git a/apps/web/src/app/[locale]/(optional-space)/layout.tsx b/apps/web/src/app/[locale]/(optional-space)/layout.tsx
index d987e531e..09943a019 100644
--- a/apps/web/src/app/[locale]/(optional-space)/layout.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/layout.tsx
@@ -1,7 +1,7 @@
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
import { SessionRefresher } from "@/components/session-refresher";
import { PayWall } from "@/features/billing/components/pay-wall";
-import { isQuickCreateEnabled } from "@/features/quick-create";
+import { isQuickCreateEnabled } from "@/features/quick-create/constants";
import { getLocale } from "@/i18n/server/get-locale";
import { DeviceDateTimeProvider } from "@/lib/datetime/device";
import { getDeviceDateTimeConfig } from "@/lib/datetime/server";
diff --git a/apps/web/src/app/[locale]/(optional-space)/new/page.tsx b/apps/web/src/app/[locale]/(optional-space)/new/page.tsx
index dafc5f53c..389dcd120 100644
--- a/apps/web/src/app/[locale]/(optional-space)/new/page.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/new/page.tsx
@@ -12,7 +12,7 @@ import type { Metadata } from "next";
import Link from "next/link";
import { CreatePoll } from "@/components/create-poll";
import { UserDropdown } from "@/components/user-dropdown";
-import { BrandStyle } from "@/features/branding/brand-style";
+import { BrandStyle } from "@/features/branding/components/brand-style";
import { createSpaceDTO } from "@/features/space/data";
import { Trans } from "@/i18n/client";
import { getTranslation } from "@/i18n/server";
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/components/upgrade-menu-item.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/components/upgrade-menu-item.tsx
index c6cf3d37b..3475340f2 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/components/upgrade-menu-item.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/components/upgrade-menu-item.tsx
@@ -3,8 +3,7 @@
import { posthog } from "@rallly/posthog/client";
import { SidebarMenuButton, SidebarMenuItem } from "@rallly/ui/sidebar";
import { SparklesIcon } from "lucide-react";
-import { useIsFree } from "@/features/billing/client";
-import { showPayWall } from "@/features/billing/paywall-store";
+import { showPayWall, useIsFree } from "@/features/billing/client";
import { Trans } from "@/i18n/client";
export function UpgradeMenuItem() {
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/layout.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/layout.tsx
index 2e1736612..e23999bf5 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/layout.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/layout.tsx
@@ -17,7 +17,7 @@ import Link from "next/link";
import { NavUser } from "@/components/nav-user";
import { CustomBrandingPrompt } from "@/features/branding/components/custom-branding-prompt";
import { LicenseLimitWarning } from "@/features/licensing/components/license-limit-warning";
-import { CommandMenu } from "@/features/navigation/command-menu";
+import { CommandMenu } from "@/features/navigation/components/command-menu";
import { SpaceDropdown } from "@/features/space/components/space-dropdown";
import { Trans } from "@/i18n/client";
import { IfFeatureEnabled } from "@/lib/feature-flags/client";
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/page-client.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/page-client.tsx
index 5ac13c92b..29a6ec4f7 100644
--- a/apps/web/src/app/[locale]/(space)/settings/billing/page-client.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/page-client.tsx
@@ -37,8 +37,8 @@ import {
SettingsPageTitle,
} from "@/components/settings-layout";
import { openCustomerPortalAction } from "@/features/billing/actions";
+import { showPayWall } from "@/features/billing/client";
import { SubscriptionStatusLabel } from "@/features/billing/components/subscription-status-label";
-import { showPayWall } from "@/features/billing/paywall-store";
import { useSpace } from "@/features/space/client";
import type { SpaceTier } from "@/features/space/schema";
import { Trans } from "@/i18n/client";
diff --git a/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx b/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
index 18ce01ed4..63842196c 100644
--- a/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
@@ -14,8 +14,7 @@ import {
PageSectionTitle,
} from "@/components/page-layout";
import { ProBadge } from "@/components/pro-badge";
-import { useIsFree } from "@/features/billing/client";
-import { showPayWall } from "@/features/billing/paywall-store";
+import { showPayWall, useIsFree } from "@/features/billing/client";
import { DEFAULT_PRIMARY_COLOR } from "@/features/branding/constants";
import { useSpace } from "@/features/space/client";
import { Trans } from "@/i18n/client";
diff --git a/apps/web/src/app/[locale]/(space)/settings/members/components/invite-member-button.tsx b/apps/web/src/app/[locale]/(space)/settings/members/components/invite-member-button.tsx
index 07dc6c3c6..dd70f4d6c 100644
--- a/apps/web/src/app/[locale]/(space)/settings/members/components/invite-member-button.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/members/components/invite-member-button.tsx
@@ -5,7 +5,7 @@ import { useDialog } from "@rallly/ui/dialog";
import { Icon } from "@rallly/ui/icon";
import { toast } from "@rallly/ui/sonner";
import { UserPlusIcon } from "lucide-react";
-import { showPayWall } from "@/features/billing/paywall-store";
+import { showPayWall } from "@/features/billing/client";
import { useSpace } from "@/features/space/client";
import { Trans, useTranslation } from "@/i18n/client";
import { InviteMemberDialog } from "./invite-member-dialog";
diff --git a/apps/web/src/app/[locale]/(space)/settings/security/page.tsx b/apps/web/src/app/[locale]/(space)/settings/security/page.tsx
index e2a26a22e..8a16bc2e2 100644
--- a/apps/web/src/app/[locale]/(space)/settings/security/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/security/page.tsx
@@ -17,7 +17,7 @@ import {
SettingsPageHeader,
SettingsPageTitle,
} from "@/components/settings-layout";
-import { getUserHasPassword } from "@/features/user/queries";
+import { getUserHasPassword } from "@/features/user/data";
import { Trans } from "@/i18n/client";
import { getTranslation } from "@/i18n/server";
import { isFeatureEnabled } from "@/lib/feature-flags/server";
diff --git a/apps/web/src/app/[locale]/control-panel/branding/page.tsx b/apps/web/src/app/[locale]/control-panel/branding/page.tsx
index a6ab28a46..e138d5e29 100644
--- a/apps/web/src/app/[locale]/control-panel/branding/page.tsx
+++ b/apps/web/src/app/[locale]/control-panel/branding/page.tsx
@@ -18,7 +18,7 @@ import {
SettingsPageHeader,
SettingsPageTitle,
} from "@/components/settings-layout";
-import { getCustomBrandingConfig } from "@/features/branding/queries";
+import { getCustomBrandingConfig } from "@/features/branding/data";
import { loadInstanceLicense } from "@/features/licensing/data";
import { Trans } from "@/i18n/client";
import { getTranslation } from "@/i18n/server";
diff --git a/apps/web/src/app/[locale]/control-panel/layout.tsx b/apps/web/src/app/[locale]/control-panel/layout.tsx
index 02e98a0ff..51ae411e1 100644
--- a/apps/web/src/app/[locale]/control-panel/layout.tsx
+++ b/apps/web/src/app/[locale]/control-panel/layout.tsx
@@ -4,7 +4,7 @@ import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
import { GaugeIcon } from "lucide-react";
import type { Metadata } from "next";
import { LicenseLimitWarning } from "@/features/licensing/components/license-limit-warning";
-import { CommandMenu } from "@/features/navigation/command-menu";
+import { CommandMenu } from "@/features/navigation/components/command-menu";
import { Trans } from "@/i18n/client";
import { getTranslation } from "@/i18n/server";
import { getLocale } from "@/i18n/server/get-locale";
diff --git a/apps/web/src/app/[locale]/control-panel/page.tsx b/apps/web/src/app/[locale]/control-panel/page.tsx
index 601934b0c..32020ff6c 100644
--- a/apps/web/src/app/[locale]/control-panel/page.tsx
+++ b/apps/web/src/app/[locale]/control-panel/page.tsx
@@ -19,7 +19,7 @@ import {
} from "@/components/settings-layout";
import { DEFAULT_SEAT_LIMIT } from "@/features/licensing/constants";
import { loadInstanceLicense } from "@/features/licensing/data";
-import { getUserCount } from "@/features/user/queries";
+import { getUserCount } from "@/features/user/data";
import { Trans } from "@/i18n/client";
import { VersionTile } from "./version-tile";
diff --git a/apps/web/src/app/[locale]/control-panel/settings/page.tsx b/apps/web/src/app/[locale]/control-panel/settings/page.tsx
index 7a2c468cc..f4ffe8db0 100644
--- a/apps/web/src/app/[locale]/control-panel/settings/page.tsx
+++ b/apps/web/src/app/[locale]/control-panel/settings/page.tsx
@@ -13,7 +13,7 @@ import {
SettingsPageHeader,
SettingsPageTitle,
} from "@/components/settings-layout";
-import { getInstanceSettings } from "@/features/instance-settings/queries";
+import { getInstanceSettings } from "@/features/instance-settings/data";
import { Trans } from "@/i18n/client";
import { InstanceSettingsForm } from "./instance-settings-form";
diff --git a/apps/web/src/app/[locale]/e/[id]/components/rsvp-area.tsx b/apps/web/src/app/[locale]/e/[id]/components/rsvp-area.tsx
index 85f888ddb..ff76daefb 100644
--- a/apps/web/src/app/[locale]/e/[id]/components/rsvp-area.tsx
+++ b/apps/web/src/app/[locale]/e/[id]/components/rsvp-area.tsx
@@ -1,9 +1,6 @@
import type { ScheduledEventStatus } from "@rallly/database";
import { getEventRegistration } from "@/features/scheduled-event/data";
-import {
- getEventPhase,
- isEventFull,
-} from "@/features/scheduled-event/registration";
+import { getEventPhase, isEventFull } from "@/features/scheduled-event/utils";
import { getSession } from "@/lib/auth";
import { RsvpCancel } from "./rsvp-cancel";
import { RsvpNotice } from "./rsvp-notice";
diff --git a/apps/web/src/app/[locale]/e/[id]/page.tsx b/apps/web/src/app/[locale]/e/[id]/page.tsx
index 27963f2e1..56ed9513e 100644
--- a/apps/web/src/app/[locale]/e/[id]/page.tsx
+++ b/apps/web/src/app/[locale]/e/[id]/page.tsx
@@ -12,7 +12,7 @@ import LogoMarkGray from "@/assets/logo-mark-gray.svg";
import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";
import TruncatedLinkify from "@/components/poll/truncated-linkify";
import { SessionRefresher } from "@/components/session-refresher";
-import { BrandStyle } from "@/features/branding/brand-style";
+import { BrandStyle } from "@/features/branding/components/brand-style";
import { formatLocationText } from "@/features/location/utils";
import {
EventCalendarCard,
diff --git a/apps/web/src/app/[locale]/layout.tsx b/apps/web/src/app/[locale]/layout.tsx
index 05c83c5f7..56ee688d5 100644
--- a/apps/web/src/app/[locale]/layout.tsx
+++ b/apps/web/src/app/[locale]/layout.tsx
@@ -11,7 +11,7 @@ import type React from "react";
import type { Params } from "@/app/[locale]/types";
import { SkipNavLink } from "@/components/skip-nav-link";
import { BrandingProvider } from "@/features/branding/client";
-import { getInstanceBrandingConfig } from "@/features/branding/queries";
+import { getInstanceBrandingConfig } from "@/features/branding/data";
import { ThemeProvider } from "@/features/theme/client";
import { I18nProvider } from "@/i18n/client";
import { initI18next } from "@/i18n/i18n";
diff --git a/apps/web/src/app/[locale]/quick-create/page.tsx b/apps/web/src/app/[locale]/quick-create/page.tsx
index 1e26bad25..af6bfd7df 100644
--- a/apps/web/src/app/[locale]/quick-create/page.tsx
+++ b/apps/web/src/app/[locale]/quick-create/page.tsx
@@ -5,10 +5,8 @@ import { LogInIcon } from "lucide-react";
import type { Metadata } from "next";
import Link from "next/link";
import { notFound } from "next/navigation";
-import {
- isQuickCreateEnabled,
- QuickCreateWidget,
-} from "@/features/quick-create";
+import { QuickCreateWidget } from "@/features/quick-create/components/quick-create-widget";
+import { isQuickCreateEnabled } from "@/features/quick-create/constants";
import { getTranslation } from "@/i18n/server";
import { getLocale } from "@/i18n/server/get-locale";
import { DeviceDateTimeProvider } from "@/lib/datetime/device";
diff --git a/apps/web/src/app/api/private/[...route]/route.test.ts b/apps/web/src/app/api/private/[...route]/route.test.ts
index 47b2a1b5f..b97dd3368 100644
--- a/apps/web/src/app/api/private/[...route]/route.test.ts
+++ b/apps/web/src/app/api/private/[...route]/route.test.ts
@@ -57,7 +57,7 @@ vi.mock("@/lib/kv", () => ({
import { prisma } from "@rallly/database";
import { after } from "next/server";
-import { hashApiKey, verifyApiKey } from "@/features/api-keys/api-key";
+import { hashApiKey, verifyApiKey } from "@/features/api-keys/utils";
import { app } from "./route";
// Pre-generated test API key fixture. The stored hash deliberately uses the
diff --git a/apps/web/src/app/api/private/utils/api-key.ts b/apps/web/src/app/api/private/utils/api-key.ts
index ce809da7f..8635e0cd2 100644
--- a/apps/web/src/app/api/private/utils/api-key.ts
+++ b/apps/web/src/app/api/private/utils/api-key.ts
@@ -10,7 +10,7 @@ import {
hashApiKey,
isLegacyApiKeyHash,
verifyApiKey,
-} from "@/features/api-keys/api-key";
+} from "@/features/api-keys/utils";
import { isSelfHosted } from "@/lib/constants";
import { apiError } from "./poll";
diff --git a/apps/web/src/app/api/stripe/portal/route.ts b/apps/web/src/app/api/stripe/portal/route.ts
index a4d52dc54..175c9145b 100644
--- a/apps/web/src/app/api/stripe/portal/route.ts
+++ b/apps/web/src/app/api/stripe/portal/route.ts
@@ -3,7 +3,7 @@ import * as Sentry from "@sentry/nextjs";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
-import { createStripePortalSession } from "@/features/billing/portal";
+import { createStripePortalSession } from "@/features/billing/mutations";
/**
* Checkout return endpoint. Stripe redirects the browser here after payment
diff --git a/apps/web/src/components/forms/poll-settings.tsx b/apps/web/src/components/forms/poll-settings.tsx
index 3e1bf961d..a2e5d3e30 100644
--- a/apps/web/src/components/forms/poll-settings.tsx
+++ b/apps/web/src/components/forms/poll-settings.tsx
@@ -13,8 +13,7 @@ import type React from "react";
import { useFormContext } from "react-hook-form";
import type { PollSettingsFormData } from "@/components/forms/types";
import { ProBadge } from "@/components/pro-badge";
-import { useIsFree } from "@/features/billing/client";
-import { showPayWall } from "@/features/billing/paywall-store";
+import { showPayWall, useIsFree } from "@/features/billing/client";
import { Trans } from "@/i18n/client";
const PollSetting = ({
diff --git a/apps/web/src/components/logo.tsx b/apps/web/src/components/logo.tsx
index c45fd7e7c..c119e756c 100644
--- a/apps/web/src/components/logo.tsx
+++ b/apps/web/src/components/logo.tsx
@@ -1,6 +1,6 @@
import { cn } from "@rallly/ui";
import { env } from "@/env";
-import { getInstanceBrandingConfig } from "@/features/branding/queries";
+import { getInstanceBrandingConfig } from "@/features/branding/data";
const sizes = {
sm: {
diff --git a/apps/web/src/components/poll/manage-poll.tsx b/apps/web/src/components/poll/manage-poll.tsx
index 8de6c1b2c..7595c11f4 100644
--- a/apps/web/src/components/poll/manage-poll.tsx
+++ b/apps/web/src/components/poll/manage-poll.tsx
@@ -27,8 +27,7 @@ import * as React from "react";
import { DuplicateDialog } from "@/app/[locale]/(optional-space)/poll/[urlId]/duplicate-dialog";
import { SchedulePollDialog } from "@/components/poll/manage-poll/schedule-poll-dialog";
import { ProBadge } from "@/components/pro-badge";
-import { useIsFree } from "@/features/billing/client";
-import { showPayWall } from "@/features/billing/paywall-store";
+import { showPayWall, useIsFree } from "@/features/billing/client";
import { usePoll } from "@/features/poll/client";
import { Trans } from "@/i18n/client";
import { trpc } from "@/trpc/client";
diff --git a/apps/web/src/components/poll/poll-branding.tsx b/apps/web/src/components/poll/poll-branding.tsx
index 489d6fcc0..d43d1071e 100644
--- a/apps/web/src/components/poll/poll-branding.tsx
+++ b/apps/web/src/components/poll/poll-branding.tsx
@@ -1,6 +1,6 @@
"use client";
-import { BrandStyle } from "@/features/branding/brand-style";
+import { BrandStyle } from "@/features/branding/components/brand-style";
import { usePoll } from "@/features/poll/client";
export function PollBrandingFromContext() {
diff --git a/apps/web/src/emails/branding.ts b/apps/web/src/emails/branding.ts
index 07bd2224d..cda34d82d 100644
--- a/apps/web/src/emails/branding.ts
+++ b/apps/web/src/emails/branding.ts
@@ -1,6 +1,6 @@
import type { EmailBranding } from "@rallly/emails";
-import { getInstanceBrandingConfig } from "@/features/branding/queries";
+import { getInstanceBrandingConfig } from "@/features/branding/data";
import { resolveStorageUrl } from "@/lib/storage/resolve-storage-url";
/**
diff --git a/apps/web/src/features/api-keys/api-key.test.ts b/apps/web/src/features/api-keys/utils.test.ts
similarity index 99%
rename from apps/web/src/features/api-keys/api-key.test.ts
rename to apps/web/src/features/api-keys/utils.test.ts
index 36455df50..b2e5823e2 100644
--- a/apps/web/src/features/api-keys/api-key.test.ts
+++ b/apps/web/src/features/api-keys/utils.test.ts
@@ -7,7 +7,7 @@ import {
isLegacyApiKeyHash,
randomToken,
verifyApiKey,
-} from "./api-key";
+} from "./utils";
// Helper to create a hash in the deprecated scrypt format, as stored by the
// previous implementation (scrypt$N$r$p$salt$hash)
diff --git a/apps/web/src/features/api-keys/api-key.ts b/apps/web/src/features/api-keys/utils.ts
similarity index 100%
rename from apps/web/src/features/api-keys/api-key.ts
rename to apps/web/src/features/api-keys/utils.ts
diff --git a/apps/web/src/features/billing/actions.ts b/apps/web/src/features/billing/actions.ts
index 1b386192b..c7b468560 100644
--- a/apps/web/src/features/billing/actions.ts
+++ b/apps/web/src/features/billing/actions.ts
@@ -4,7 +4,7 @@ import { getProPricing, stripe } from "@rallly/billing";
import { absoluteUrl } from "@rallly/utils/absolute-url";
import { redirect } from "next/navigation";
import * as z from "zod";
-import { createStripePortalSession } from "@/features/billing/portal";
+import { createStripePortalSession } from "@/features/billing/mutations";
import type { CustomerMetadata } from "@/features/billing/schema";
import { getActiveSpaceForUser } from "@/features/space/data";
import type {
diff --git a/apps/web/src/features/billing/client.tsx b/apps/web/src/features/billing/client.tsx
index 33c8fd14f..aac0dddbe 100644
--- a/apps/web/src/features/billing/client.tsx
+++ b/apps/web/src/features/billing/client.tsx
@@ -1,5 +1,6 @@
"use client";
+import { create } from "zustand";
import type { SpaceTier } from "@/features/space/schema";
import { trpc } from "@/trpc/client";
@@ -12,3 +13,17 @@ export function useTier(): SpaceTier {
export function useIsFree() {
return useTier() === "hobby";
}
+
+type PayWallStore = {
+ isOpen: boolean;
+ show: () => void;
+ hide: () => void;
+};
+
+export const usePayWallStore = create<PayWallStore>((set) => ({
+ isOpen: false,
+ show: () => set({ isOpen: true }),
+ hide: () => set({ isOpen: false }),
+}));
+
+export const showPayWall = () => usePayWallStore.getState().show();
diff --git a/apps/web/src/features/billing/components/pay-wall.tsx b/apps/web/src/features/billing/components/pay-wall.tsx
index 6abb3620a..bd4067b21 100644
--- a/apps/web/src/features/billing/components/pay-wall.tsx
+++ b/apps/web/src/features/billing/components/pay-wall.tsx
@@ -1,6 +1,6 @@
"use client";
-import { usePayWallStore } from "../paywall-store";
+import { usePayWallStore } from "../client";
import { PayWallDialog } from "./pay-wall-dialog";
/**
diff --git a/apps/web/src/features/billing/data.ts b/apps/web/src/features/billing/data.ts
index b2b21ba6a..79a0d9f18 100644
--- a/apps/web/src/features/billing/data.ts
+++ b/apps/web/src/features/billing/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import { prisma } from "@rallly/database";
import type { SpaceTier } from "@/features/space/schema";
diff --git a/apps/web/src/features/billing/portal.ts b/apps/web/src/features/billing/mutations.ts
similarity index 99%
rename from apps/web/src/features/billing/portal.ts
rename to apps/web/src/features/billing/mutations.ts
index 65dcb8364..2ce8d955b 100644
--- a/apps/web/src/features/billing/portal.ts
+++ b/apps/web/src/features/billing/mutations.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import { getProPricing, stripe } from "@rallly/billing";
import {
SEAT_UPDATE_PORTAL_HEADLINE,
diff --git a/apps/web/src/features/billing/paywall-store.ts b/apps/web/src/features/billing/paywall-store.ts
deleted file mode 100644
index 4aaa7e84c..000000000
--- a/apps/web/src/features/billing/paywall-store.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { create } from "zustand";
-
-type PayWallStore = {
- isOpen: boolean;
- show: () => void;
- hide: () => void;
-};
-
-export const usePayWallStore = create<PayWallStore>((set) => ({
- isOpen: false,
- show: () => set({ isOpen: true }),
- hide: () => set({ isOpen: false }),
-}));
-
-export const showPayWall = () => usePayWallStore.getState().show();
diff --git a/apps/web/src/features/billing/webhook/mutations.ts b/apps/web/src/features/billing/webhook/mutations.ts
index 0ed4c5858..ab64fdb47 100644
--- a/apps/web/src/features/billing/webhook/mutations.ts
+++ b/apps/web/src/features/billing/webhook/mutations.ts
@@ -17,8 +17,8 @@ import {
isSubscriptionActive,
toDate,
} from "@/features/billing/webhook/utils";
+import { licenseManager } from "@/features/licensing/mutations";
import { licenseCheckoutMetadataSchema } from "@/features/licensing/schema";
-import { licenseManager } from "@/features/licensing/server";
import { subscriptionMetadataSchema } from "@/features/subscription/schema";
async function getExpandedSubscription(subscriptionId: string) {
diff --git a/apps/web/src/features/branding/brand-style.tsx b/apps/web/src/features/branding/components/brand-style.tsx
similarity index 86%
rename from apps/web/src/features/branding/brand-style.tsx
rename to apps/web/src/features/branding/components/brand-style.tsx
index 18c86557c..44641e95d 100644
--- a/apps/web/src/features/branding/brand-style.tsx
+++ b/apps/web/src/features/branding/components/brand-style.tsx
@@ -1,4 +1,4 @@
-import { getPrimaryColorVars } from "@/features/branding/color";
+import { getPrimaryColorVars } from "@/features/branding/utils";
export function BrandStyle({ primaryColor }: { primaryColor: string }) {
const v = getPrimaryColorVars(primaryColor);
diff --git a/apps/web/src/features/branding/queries.ts b/apps/web/src/features/branding/data.ts
similarity index 97%
rename from apps/web/src/features/branding/queries.ts
rename to apps/web/src/features/branding/data.ts
index a81ce0b73..6ef92d4f0 100644
--- a/apps/web/src/features/branding/queries.ts
+++ b/apps/web/src/features/branding/data.ts
@@ -7,7 +7,6 @@ import { isSelfHosted } from "@/lib/constants";
import { isMaintenanceModeEnabled } from "@/lib/maintenance";
import { getForegroundColor } from "@/lib/utils/color";
import type { BrandingConfig } from "./client";
-import { getPrimaryColorVars } from "./color";
import {
DEFAULT_APP_NAME,
DEFAULT_LOGO_ICON_URL,
@@ -15,6 +14,7 @@ import {
DEFAULT_LOGO_URL_DARK,
DEFAULT_PRIMARY_COLOR,
} from "./constants";
+import { getPrimaryColorVars } from "./utils";
function getDefaultBrandingConfig(): BrandingConfig {
return {
diff --git a/apps/web/src/features/branding/color.ts b/apps/web/src/features/branding/utils.ts
similarity index 100%
rename from apps/web/src/features/branding/color.ts
rename to apps/web/src/features/branding/utils.ts
diff --git a/apps/web/src/features/calendars/queries.ts b/apps/web/src/features/calendars/data.ts
similarity index 97%
rename from apps/web/src/features/calendars/queries.ts
rename to apps/web/src/features/calendars/data.ts
index b696e4c98..e4f934955 100644
--- a/apps/web/src/features/calendars/queries.ts
+++ b/apps/web/src/features/calendars/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import { prisma } from "@rallly/database";
export const getCalendars = async (userId: string) => {
diff --git a/apps/web/src/features/calendars/mutations.ts b/apps/web/src/features/calendars/mutations.ts
index 81db5f40d..09ace4910 100644
--- a/apps/web/src/features/calendars/mutations.ts
+++ b/apps/web/src/features/calendars/mutations.ts
@@ -1,5 +1,7 @@
+import "server-only";
+
import { prisma } from "@rallly/database";
-import { loadCredential } from "@/features/credentials/queries";
+import { loadCredential } from "@/features/credentials/data";
import type { UserInfo } from "@/lib/oauth/types";
import { createCalendarService } from "./service";
diff --git a/apps/web/src/features/conferencing/data.ts b/apps/web/src/features/conferencing/data.ts
index 9a3ecec0d..dcbfd4f07 100644
--- a/apps/web/src/features/conferencing/data.ts
+++ b/apps/web/src/features/conferencing/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import type { Prisma } from "@rallly/database";
import { createLogger } from "@rallly/logger";
import type { Conferencing } from "./schema";
diff --git a/apps/web/src/features/credentials/queries.ts b/apps/web/src/features/credentials/data.ts
similarity index 98%
rename from apps/web/src/features/credentials/queries.ts
rename to apps/web/src/features/credentials/data.ts
index 03e937963..caf95b3f8 100644
--- a/apps/web/src/features/credentials/queries.ts
+++ b/apps/web/src/features/credentials/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import { prisma } from "@rallly/database";
import { decrypt } from "@rallly/utils/encryption";
import { env } from "@/env";
diff --git a/apps/web/src/features/credentials/mutations.ts b/apps/web/src/features/credentials/mutations.ts
index 171ad55a1..af37b8228 100644
--- a/apps/web/src/features/credentials/mutations.ts
+++ b/apps/web/src/features/credentials/mutations.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import { prisma } from "@rallly/database";
import { encrypt } from "@rallly/utils/encryption";
import { env } from "@/env";
diff --git a/apps/web/src/features/developer/data.ts b/apps/web/src/features/developer/data.ts
index 6b5995eba..0f82cf69f 100644
--- a/apps/web/src/features/developer/data.ts
+++ b/apps/web/src/features/developer/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import { posthog } from "@/features/analytics/posthog";
import type { SpaceTier } from "@/features/space/schema";
import { isSelfHosted } from "@/lib/constants";
diff --git a/apps/web/src/features/event-types/hooks.ts b/apps/web/src/features/event-types/client.tsx
similarity index 100%
rename from apps/web/src/features/event-types/hooks.ts
rename to apps/web/src/features/event-types/client.tsx
diff --git a/apps/web/src/features/event-types/data.ts b/apps/web/src/features/event-types/data.ts
index aa51bea70..cb25e42ef 100644
--- a/apps/web/src/features/event-types/data.ts
+++ b/apps/web/src/features/event-types/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import type { EventType, User } from "@rallly/database";
import { prisma } from "@rallly/database";
import { createLogger } from "@rallly/logger";
diff --git a/apps/web/src/features/instance-settings/data.ts b/apps/web/src/features/instance-settings/data.ts
index 7898229e1..08dc383d5 100644
--- a/apps/web/src/features/instance-settings/data.ts
+++ b/apps/web/src/features/instance-settings/data.ts
@@ -1,7 +1,31 @@
import "server-only";
-import { getInstanceSettings } from "@/features/instance-settings/queries";
+import { prisma } from "@rallly/database";
+import { unstable_cache } from "next/cache";
import { isFeatureEnabled } from "@/lib/feature-flags/server";
+import { instanceSettingsTag } from "./constants";
+
+export const getInstanceSettings = unstable_cache(
+ async () => {
+ const instanceSettings = await prisma.instanceSettings.findUnique({
+ where: {
+ id: 1,
+ },
+ select: {
+ disableUserRegistration: true,
+ },
+ });
+
+ return {
+ disableUserRegistration:
+ instanceSettings?.disableUserRegistration ?? false,
+ };
+ },
+ [],
+ {
+ tags: [instanceSettingsTag],
+ },
+);
export async function getRegistrationEnabled() {
if (!isFeatureEnabled("registration")) {
diff --git a/apps/web/src/features/instance-settings/queries.ts b/apps/web/src/features/instance-settings/queries.ts
deleted file mode 100644
index 1bc716bf2..000000000
--- a/apps/web/src/features/instance-settings/queries.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import "server-only";
-
-import { prisma } from "@rallly/database";
-import { unstable_cache } from "next/cache";
-import { instanceSettingsTag } from "./constants";
-
-export const getInstanceSettings = unstable_cache(
- async () => {
- const instanceSettings = await prisma.instanceSettings.findUnique({
- where: {
- id: 1,
- },
- select: {
- disableUserRegistration: true,
- },
- });
-
- return {
- disableUserRegistration:
- instanceSettings?.disableUserRegistration ?? false,
- };
- },
- [],
- {
- tags: [instanceSettingsTag],
- },
-);
diff --git a/apps/web/src/features/licensing/actions.ts b/apps/web/src/features/licensing/actions.ts
index b79853833..24d909b2e 100644
--- a/apps/web/src/features/licensing/actions.ts
+++ b/apps/web/src/features/licensing/actions.ts
@@ -7,7 +7,7 @@ import { INSTANCE_LICENSE_TAG } from "@/features/licensing/constants";
import { validateLicenseKeyInputSchema } from "@/features/licensing/schema";
import { AppError } from "@/lib/errors/app-error";
import { adminActionClient } from "@/lib/safe-action/server";
-import { licenseManager } from "./server";
+import { licenseManager } from "./mutations";
const logger = createLogger("licensing/actions");
diff --git a/apps/web/src/features/licensing/components/license-key-form.tsx b/apps/web/src/features/licensing/components/license-key-form.tsx
index c27101bc6..205ef94a0 100644
--- a/apps/web/src/features/licensing/components/license-key-form.tsx
+++ b/apps/web/src/features/licensing/components/license-key-form.tsx
@@ -17,7 +17,7 @@ import * as z from "zod";
import { validateLicenseKeyAction } from "@/features/licensing/actions";
import { Trans, useTranslation } from "@/i18n/client";
import { useSafeAction } from "@/lib/safe-action/client";
-import { checkLicenseKey } from "../helpers/check-license-key";
+import { checkLicenseKey } from "../utils";
const formSchema = z.object({
licenseKey: z.string().trim().min(1).refine(checkLicenseKey, {
diff --git a/apps/web/src/features/licensing/components/license-limit-warning.tsx b/apps/web/src/features/licensing/components/license-limit-warning.tsx
index ac9a2d3cf..b70e9d235 100644
--- a/apps/web/src/features/licensing/components/license-limit-warning.tsx
+++ b/apps/web/src/features/licensing/components/license-limit-warning.tsx
@@ -1,7 +1,7 @@
import Link from "next/link";
import { DEFAULT_SEAT_LIMIT } from "@/features/licensing/constants";
import { loadInstanceLicense } from "@/features/licensing/data";
-import { getUserCount } from "@/features/user/queries";
+import { getUserCount } from "@/features/user/data";
import { Trans } from "@/i18n/client";
import { isSelfHosted } from "@/lib/constants";
diff --git a/apps/web/src/features/licensing/data.ts b/apps/web/src/features/licensing/data.ts
index f420657bf..d156a362a 100644
--- a/apps/web/src/features/licensing/data.ts
+++ b/apps/web/src/features/licensing/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import { prisma } from "@rallly/database";
import { unstable_cache } from "next/cache";
import { cache } from "react";
diff --git a/apps/web/src/features/licensing/helpers/calculate-checksum.ts b/apps/web/src/features/licensing/helpers/calculate-checksum.ts
deleted file mode 100644
index db6c57935..000000000
--- a/apps/web/src/features/licensing/helpers/calculate-checksum.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-/**
- * Calculate a checksum for a string
- * @param str The string to calculate the checksum for
- * @returns The checksum
- */
-export function calculateChecksum(str: string): string {
- // Simple checksum: sum char codes, mod 100000, base36
- let sum = 0;
- for (let i = 0; i < str.length; i++) {
- sum += str.charCodeAt(i);
- }
- return (sum % 100000).toString(36).toUpperCase().padStart(5, "0");
-}
diff --git a/apps/web/src/features/licensing/helpers/check-license-key.ts b/apps/web/src/features/licensing/helpers/check-license-key.ts
deleted file mode 100644
index f2f1e41e3..000000000
--- a/apps/web/src/features/licensing/helpers/check-license-key.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { calculateChecksum } from "./calculate-checksum";
-
-export function checkLicenseKey(key: string): boolean {
- const parts = key.split("-");
- if (parts.length !== 6) return false;
- const checksum = parts[5];
- const licenseBody = parts.slice(0, 5).join("-");
- return calculateChecksum(licenseBody) === checksum;
-}
diff --git a/apps/web/src/features/licensing/helpers/generate-license-key.ts b/apps/web/src/features/licensing/helpers/generate-license-key.ts
deleted file mode 100644
index e4ae149ba..000000000
--- a/apps/web/src/features/licensing/helpers/generate-license-key.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { customAlphabet } from "nanoid";
-import { calculateChecksum } from "./calculate-checksum";
-
-const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
-const generate = customAlphabet(alphabet, 4);
-
-/**
- * Generate user friendly licenses
- * eg. RLYV4-ABCD-1234-ABCD-1234-XXXX
- */
-export const generateLicenseKey = ({ version }: { version?: number }) => {
- let license = `RLYV${version ?? "X"}-`;
- for (let i = 0; i < 4; i++) {
- license += generate();
- if (i < 3) {
- license += "-";
- }
- }
- const checksum = calculateChecksum(license);
- return `${license}-${checksum}`;
-};
diff --git a/apps/web/src/features/licensing/lib/licensing-manager.ts b/apps/web/src/features/licensing/lib/licensing-manager.ts
deleted file mode 100644
index 23b509d24..000000000
--- a/apps/web/src/features/licensing/lib/licensing-manager.ts
+++ /dev/null
@@ -1,69 +0,0 @@
-import { createLogger } from "@rallly/logger";
-import { AppError } from "@/lib/errors/app-error";
-import type {
- CreateLicenseInput,
- ValidateLicenseInputKeySchema,
-} from "../schema";
-import {
- createLicenseResponseSchema,
- validateLicenseKeyResponseSchema,
-} from "../schema";
-
-const logger = createLogger("licensing/manager");
-
-export class LicenseManager {
- apiUrl: string;
- authToken?: string;
-
- constructor({
- apiUrl = "https://licensing.rallly.co/api/licensing/v1",
- authToken,
- }: {
- apiUrl?: string;
- authToken?: string;
- }) {
- this.apiUrl = apiUrl;
- this.authToken = authToken;
- }
- async createLicense(input: CreateLicenseInput) {
- if (!this.authToken) {
- throw new Error("Licensing API auth token is not configured.");
- }
-
- const res = await fetch(`${this.apiUrl}/licenses`, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${this.authToken}`,
- },
- body: JSON.stringify(input),
- });
-
- if (!res.ok) {
- throw new Error("Failed to create license.");
- }
- return createLicenseResponseSchema.parse(await res.json());
- }
- async validateLicenseKey(input: ValidateLicenseInputKeySchema) {
- const res = await fetch(`${this.apiUrl}/licenses/actions/validate-key`, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify(input),
- });
-
- const data = await res.json();
-
- if (!res.ok) {
- logger.error({ data }, "License validation failed");
- throw new AppError({
- code: "INTERNAL_SERVER_ERROR",
- cause: data,
- message: "Failed to validate license",
- });
- }
-
- return validateLicenseKeyResponseSchema.parse(data);
- }
-}
diff --git a/apps/web/src/features/licensing/mutations.ts b/apps/web/src/features/licensing/mutations.ts
index 741428641..7f8f26e76 100644
--- a/apps/web/src/features/licensing/mutations.ts
+++ b/apps/web/src/features/licensing/mutations.ts
@@ -1,8 +1,82 @@
import "server-only";
import { prisma } from "@rallly/database";
-import { generateLicenseKey } from "@/features/licensing/helpers/generate-license-key";
-import type { CreateLicenseInput } from "@/features/licensing/schema";
+import { createLogger } from "@rallly/logger";
+import { env } from "@/env";
+import type {
+ CreateLicenseInput,
+ ValidateLicenseInputKeySchema,
+} from "@/features/licensing/schema";
+import {
+ createLicenseResponseSchema,
+ validateLicenseKeyResponseSchema,
+} from "@/features/licensing/schema";
+import { generateLicenseKey } from "@/features/licensing/utils";
+import { AppError } from "@/lib/errors/app-error";
+
+const logger = createLogger("licensing/manager");
+
+export class LicenseManager {
+ apiUrl: string;
+ authToken?: string;
+
+ constructor({
+ apiUrl = "https://licensing.rallly.co/api/licensing/v1",
+ authToken,
+ }: {
+ apiUrl?: string;
+ authToken?: string;
+ }) {
+ this.apiUrl = apiUrl;
+ this.authToken = authToken;
+ }
+ async createLicense(input: CreateLicenseInput) {
+ if (!this.authToken) {
+ throw new Error("Licensing API auth token is not configured.");
+ }
+
+ const res = await fetch(`${this.apiUrl}/licenses`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${this.authToken}`,
+ },
+ body: JSON.stringify(input),
+ });
+
+ if (!res.ok) {
+ throw new Error("Failed to create license.");
+ }
+ return createLicenseResponseSchema.parse(await res.json());
+ }
+ async validateLicenseKey(input: ValidateLicenseInputKeySchema) {
+ const res = await fetch(`${this.apiUrl}/licenses/actions/validate-key`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(input),
+ });
+
+ const data = await res.json();
+
+ if (!res.ok) {
+ logger.error({ data }, "License validation failed");
+ throw new AppError({
+ code: "INTERNAL_SERVER_ERROR",
+ cause: data,
+ message: "Failed to validate license",
+ });
+ }
+
+ return validateLicenseKeyResponseSchema.parse(data);
+ }
+}
+
+export const licenseManager = new LicenseManager({
+ apiUrl: env.LICENSE_API_URL,
+ authToken: env.LICENSE_API_AUTH_TOKEN,
+});
export async function createLicense({
type,
diff --git a/apps/web/src/features/licensing/server.ts b/apps/web/src/features/licensing/server.ts
deleted file mode 100644
index bc56d19ca..000000000
--- a/apps/web/src/features/licensing/server.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { env } from "@/env";
-import { LicenseManager } from "./lib/licensing-manager";
-
-export const licenseManager = new LicenseManager({
- apiUrl: env.LICENSE_API_URL,
- authToken: env.LICENSE_API_AUTH_TOKEN,
-});
diff --git a/apps/web/src/features/licensing/utils.ts b/apps/web/src/features/licensing/utils.ts
new file mode 100644
index 000000000..6584170a6
--- /dev/null
+++ b/apps/web/src/features/licensing/utils.ts
@@ -0,0 +1,42 @@
+import { customAlphabet } from "nanoid";
+
+/**
+ * Calculate a checksum for a string
+ * @param str The string to calculate the checksum for
+ * @returns The checksum
+ */
+export function calculateChecksum(str: string): string {
+ // Simple checksum: sum char codes, mod 100000, base36
+ let sum = 0;
+ for (let i = 0; i < str.length; i++) {
+ sum += str.charCodeAt(i);
+ }
+ return (sum % 100000).toString(36).toUpperCase().padStart(5, "0");
+}
+
+export function checkLicenseKey(key: string): boolean {
+ const parts = key.split("-");
+ if (parts.length !== 6) return false;
+ const checksum = parts[5];
+ const licenseBody = parts.slice(0, 5).join("-");
+ return calculateChecksum(licenseBody) === checksum;
+}
+
+const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+const generate = customAlphabet(alphabet, 4);
+
+/**
+ * Generate user friendly licenses
+ * eg. RLYV4-ABCD-1234-ABCD-1234-XXXX
+ */
+export const generateLicenseKey = ({ version }: { version?: number }) => {
+ let license = `RLYV${version ?? "X"}-`;
+ for (let i = 0; i < 4; i++) {
+ license += generate();
+ if (i < 3) {
+ license += "-";
+ }
+ }
+ const checksum = calculateChecksum(license);
+ return `${license}-${checksum}`;
+};
diff --git a/apps/web/src/features/location/data.ts b/apps/web/src/features/location/data.ts
index 009857347..ac606acad 100644
--- a/apps/web/src/features/location/data.ts
+++ b/apps/web/src/features/location/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import type { Prisma } from "@rallly/database";
import { createLogger } from "@rallly/logger";
import type { Location } from "./schema";
diff --git a/apps/web/src/features/moderation/libs/ai-moderation.ts b/apps/web/src/features/moderation/libs/ai-moderation.ts
deleted file mode 100644
index 67a681cbf..000000000
--- a/apps/web/src/features/moderation/libs/ai-moderation.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-import { openai } from "@ai-sdk/openai";
-import { createLogger } from "@rallly/logger";
-import { generateText } from "ai";
-
-const logger = createLogger("moderation/ai");
-
-export type ModerationVerdict = "flagged" | "safe";
-
-export type ModerationResult = {
- verdict: ModerationVerdict;
- reason: string;
-};
-
-/**
- * Moderates content using AI to detect inappropriate content
- * @param text The text to moderate
- * @returns The moderation result with verdict and explanation
- */
-export async function moderateContentWithAI(
- text: string,
-): Promise<ModerationResult> {
- try {
- const result = await generateText({
- model: openai("gpt-4.1"),
- messages: [
- {
- role: "system",
- content: `You are a content moderator for a scheduling and polling application. Users create polls about any topic — finding meeting times, making group decisions, voting on proposals, etc. Content may be in any language.
-
-Respond with one of two verdicts:
-- FLAGGED: Content is clearly abusive and harmful to the platform. Use this for:
- - Phishing or scams: fake account notifications, brand impersonation
- - Financial fraud: fake crypto mining, investment scams, unclaimed funds, lottery winnings
- - Illegal activities: drugs, prostitution, illegal gambling
-
-- SAFE: Content is not harmful.
-
-Do NOT flag content because:
-- It is in a non-English language
-- It is short, brief, or lacks detail
-- It is ambiguous or unclear
-
-When in doubt, choose SAFE.
-
-Respond in exactly this format:
-VERDICT
-Brief explanation of why this verdict was chosen.`,
- },
- { role: "user", content: text },
- ],
- });
-
- const lines = result.text.trim().split("\n");
- const verdictLine = (lines[0] ?? "").trim().toUpperCase();
- const reason = lines.slice(1).join("\n").trim() || "No reason provided";
-
- let verdict: ModerationVerdict = "safe";
- if (verdictLine.includes("FLAGGED")) {
- verdict = "flagged";
- }
-
- return { verdict, reason };
- } catch (err) {
- logger.error({ error: err }, "AI moderation failed");
- return {
- verdict: "safe",
- reason: "AI moderation failed, defaulting to safe",
- };
- }
-}
diff --git a/apps/web/src/features/moderation/index.ts b/apps/web/src/features/moderation/mutations.ts
similarity index 64%
rename from apps/web/src/features/moderation/index.ts
rename to apps/web/src/features/moderation/mutations.ts
index b2452fb58..955968a8a 100644
--- a/apps/web/src/features/moderation/index.ts
+++ b/apps/web/src/features/moderation/mutations.ts
@@ -1,13 +1,73 @@
+import "server-only";
+
+import { openai } from "@ai-sdk/openai";
import { prisma } from "@rallly/database";
import { sendRawEmail } from "@rallly/emails";
import { createLogger } from "@rallly/logger";
+import { generateText } from "ai";
import { after } from "next/server";
import { env } from "@/env";
-import type { ModerationResult, ModerationVerdict } from "./libs/ai-moderation";
-import { moderateContentWithAI } from "./libs/ai-moderation";
-import { containsSuspiciousPatterns } from "./libs/pattern-moderation";
+import type { ModerationResult, ModerationVerdict } from "./types";
+import { containsSuspiciousPatterns } from "./utils";
const logger = createLogger("moderation");
+const aiLogger = createLogger("moderation/ai");
+
+/**
+ * Moderates content using AI to detect inappropriate content
+ * @param text The text to moderate
+ * @returns The moderation result with verdict and explanation
+ */
+async function moderateContentWithAI(text: string): Promise<ModerationResult> {
+ try {
+ const result = await generateText({
+ model: openai("gpt-4.1"),
+ messages: [
+ {
+ role: "system",
+ content: `You are a content moderator for a scheduling and polling application. Users create polls about any topic — finding meeting times, making group decisions, voting on proposals, etc. Content may be in any language.
+
+Respond with one of two verdicts:
+- FLAGGED: Content is clearly abusive and harmful to the platform. Use this for:
+ - Phishing or scams: fake account notifications, brand impersonation
+ - Financial fraud: fake crypto mining, investment scams, unclaimed funds, lottery winnings
+ - Illegal activities: drugs, prostitution, illegal gambling
+
+- SAFE: Content is not harmful.
+
+Do NOT flag content because:
+- It is in a non-English language
+- It is short, brief, or lacks detail
+- It is ambiguous or unclear
+
+When in doubt, choose SAFE.
+
+Respond in exactly this format:
+VERDICT
+Brief explanation of why this verdict was chosen.`,
+ },
+ { role: "user", content: text },
+ ],
+ });
+
+ const lines = result.text.trim().split("\n");
+ const verdictLine = (lines[0] ?? "").trim().toUpperCase();
+ const reason = lines.slice(1).join("\n").trim() || "No reason provided";
+
+ let verdict: ModerationVerdict = "safe";
+ if (verdictLine.includes("FLAGGED")) {
+ verdict = "flagged";
+ }
+
+ return { verdict, reason };
+ } catch (err) {
+ aiLogger.error({ error: err }, "AI moderation failed");
+ return {
+ verdict: "safe",
+ reason: "AI moderation failed, defaulting to safe",
+ };
+ }
+}
function getBannedDomains(): string[] {
const csv = env.BANNED_DOMAINS;
@@ -25,8 +85,6 @@ function containsBannedDomain(text: string): boolean {
return domains.some((domain) => lower.includes(domain));
}
-export type { ModerationResult, ModerationVerdict };
-
const safeResult: ModerationResult = {
verdict: "safe",
reason: "",
diff --git a/apps/web/src/features/moderation/types.ts b/apps/web/src/features/moderation/types.ts
new file mode 100644
index 000000000..772158e75
--- /dev/null
+++ b/apps/web/src/features/moderation/types.ts
@@ -0,0 +1,6 @@
+export type ModerationVerdict = "flagged" | "safe";
+
+export type ModerationResult = {
+ verdict: ModerationVerdict;
+ reason: string;
+};
diff --git a/apps/web/src/features/moderation/libs/pattern-moderation.ts b/apps/web/src/features/moderation/utils.ts
similarity index 100%
rename from apps/web/src/features/moderation/libs/pattern-moderation.ts
rename to apps/web/src/features/moderation/utils.ts
diff --git a/apps/web/src/features/navigation/command-menu/command-global-shortcut.tsx b/apps/web/src/features/navigation/components/command-menu/command-global-shortcut.tsx
similarity index 100%
rename from apps/web/src/features/navigation/command-menu/command-global-shortcut.tsx
rename to apps/web/src/features/navigation/components/command-menu/command-global-shortcut.tsx
diff --git a/apps/web/src/features/navigation/command-menu/command-menu.tsx b/apps/web/src/features/navigation/components/command-menu/command-menu.tsx
similarity index 100%
rename from apps/web/src/features/navigation/command-menu/command-menu.tsx
rename to apps/web/src/features/navigation/components/command-menu/command-menu.tsx
diff --git a/apps/web/src/features/navigation/command-menu/index.ts b/apps/web/src/features/navigation/components/command-menu/index.ts
similarity index 100%
rename from apps/web/src/features/navigation/command-menu/index.ts
rename to apps/web/src/features/navigation/components/command-menu/index.ts
diff --git a/apps/web/src/features/notifications/queries.ts b/apps/web/src/features/notifications/data.ts
similarity index 98%
rename from apps/web/src/features/notifications/queries.ts
rename to apps/web/src/features/notifications/data.ts
index 4ce61e085..c7156fd0c 100644
--- a/apps/web/src/features/notifications/queries.ts
+++ b/apps/web/src/features/notifications/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import { prisma } from "@rallly/database";
import { defaultNotificationPreferences } from "./constants";
diff --git a/apps/web/src/features/poll/data.ts b/apps/web/src/features/poll/data.ts
index dada0b478..a93201f67 100644
--- a/apps/web/src/features/poll/data.ts
+++ b/apps/web/src/features/poll/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import type { PollStatus, Prisma } from "@rallly/database";
import { prisma } from "@rallly/database";
@@ -243,3 +245,51 @@ export const getPolls = async ({
currentPage: page,
};
};
+
+export async function canUserManagePoll(
+ user: {
+ id: string;
+ isGuest: boolean;
+ },
+ poll: {
+ userId?: string | null;
+ spaceId?: string | null;
+ },
+) {
+ if (poll.userId && poll.userId === user.id) {
+ // user is owner
+ return true;
+ }
+
+ if (poll.spaceId) {
+ const space = await prisma.spaceMember.findUnique({
+ where: {
+ spaceId_userId: {
+ spaceId: poll.spaceId,
+ userId: user.id,
+ },
+ },
+ });
+
+ if (space) {
+ // user a member of this space
+ return true;
+ }
+ }
+
+ return false;
+}
+
+export const hasPollAdminAccess = async (pollId: string, userId: string) => {
+ const poll = await prisma.poll.findFirst({
+ where: {
+ id: pollId,
+ OR: [{ userId: userId }, { space: { members: { some: { userId } } } }],
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ return poll !== null;
+};
diff --git a/apps/web/src/features/poll/helpers.ts b/apps/web/src/features/poll/helpers.ts
deleted file mode 100644
index 8c69a96ba..000000000
--- a/apps/web/src/features/poll/helpers.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import { prisma } from "@rallly/database";
-import "server-only";
-
-export async function canUserManagePoll(
- user: {
- id: string;
- isGuest: boolean;
- },
- poll: {
- userId?: string | null;
- spaceId?: string | null;
- },
-) {
- if (poll.userId && poll.userId === user.id) {
- // user is owner
- return true;
- }
-
- if (poll.spaceId) {
- const space = await prisma.spaceMember.findUnique({
- where: {
- spaceId_userId: {
- spaceId: poll.spaceId,
- userId: user.id,
- },
- },
- });
-
- if (space) {
- // user a member of this space
- return true;
- }
- }
-
- return false;
-}
diff --git a/apps/web/src/features/poll/query.ts b/apps/web/src/features/poll/query.ts
deleted file mode 100644
index 957590799..000000000
--- a/apps/web/src/features/poll/query.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { prisma } from "@rallly/database";
-
-export const hasPollAdminAccess = async (pollId: string, userId: string) => {
- const poll = await prisma.poll.findFirst({
- where: {
- id: pollId,
- OR: [{ userId: userId }, { space: { members: { some: { userId } } } }],
- },
- select: {
- id: true,
- },
- });
-
- return poll !== null;
-};
diff --git a/apps/web/src/features/quick-create/quick-create-button.tsx b/apps/web/src/features/quick-create/components/quick-create-button.tsx
similarity index 100%
rename from apps/web/src/features/quick-create/quick-create-button.tsx
rename to apps/web/src/features/quick-create/components/quick-create-button.tsx
diff --git a/apps/web/src/features/quick-create/quick-create-widget.tsx b/apps/web/src/features/quick-create/components/quick-create-widget.tsx
similarity index 96%
rename from apps/web/src/features/quick-create/quick-create-widget.tsx
rename to apps/web/src/features/quick-create/components/quick-create-widget.tsx
index 78722041d..8c7c3a6f9 100644
--- a/apps/web/src/features/quick-create/quick-create-widget.tsx
+++ b/apps/web/src/features/quick-create/components/quick-create-widget.tsx
@@ -4,10 +4,10 @@ import Link from "next/link";
import { Trans } from "react-i18next/TransWithoutContext";
import { PollPageIcon } from "@/components/page-icons";
-import { getGuestPolls } from "@/features/quick-create/lib/get-guest-polls";
+import { getGuestPolls } from "@/features/quick-create/data";
import { getTranslation } from "@/i18n/server";
-import { RelativeDate } from "./components/relative-date";
+import { RelativeDate } from "./relative-date";
export async function QuickCreateWidget() {
const polls = await getGuestPolls();
diff --git a/apps/web/src/features/quick-create/lib/get-guest-polls.ts b/apps/web/src/features/quick-create/data.ts
similarity index 95%
rename from apps/web/src/features/quick-create/lib/get-guest-polls.ts
rename to apps/web/src/features/quick-create/data.ts
index b71069bb2..63d599cf5 100644
--- a/apps/web/src/features/quick-create/lib/get-guest-polls.ts
+++ b/apps/web/src/features/quick-create/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import { prisma } from "@rallly/database";
import { getSession } from "@/lib/auth";
diff --git a/apps/web/src/features/quick-create/index.ts b/apps/web/src/features/quick-create/index.ts
deleted file mode 100644
index 757efce3e..000000000
--- a/apps/web/src/features/quick-create/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export { isQuickCreateEnabled } from "./constants";
-export { QuickCreateButton } from "./quick-create-button";
-export { QuickCreateWidget } from "./quick-create-widget";
diff --git a/apps/web/src/features/scheduled-event/actions.ts b/apps/web/src/features/scheduled-event/actions.ts
index 64b067cfb..b1e0936d4 100644
--- a/apps/web/src/features/scheduled-event/actions.ts
+++ b/apps/web/src/features/scheduled-event/actions.ts
@@ -7,10 +7,7 @@ import {
getPublicScheduledEvent,
} from "@/features/scheduled-event/data";
import { cancelRsvp, createRsvp } from "@/features/scheduled-event/mutations";
-import {
- getEventPhase,
- isEventFull,
-} from "@/features/scheduled-event/registration";
+import { getEventPhase, isEventFull } from "@/features/scheduled-event/utils";
import { authLib, getSession } from "@/lib/auth";
import { AppError } from "@/lib/errors/app-error";
import { actionClient, authActionClient } from "@/lib/safe-action/server";
diff --git a/apps/web/src/features/scheduled-event/data.ts b/apps/web/src/features/scheduled-event/data.ts
index e95ec0cb2..c32a6485b 100644
--- a/apps/web/src/features/scheduled-event/data.ts
+++ b/apps/web/src/features/scheduled-event/data.ts
@@ -1,14 +1,13 @@
+import "server-only";
+
import type { Prisma, ScheduledEventStatus } from "@rallly/database";
import { prisma } from "@rallly/database";
import { parseConferencing } from "@/features/conferencing/data";
import type { Conferencing } from "@/features/conferencing/schema";
import { parseLocation } from "@/features/location/data";
import type { Location } from "@/features/location/schema";
-import {
- pastScheduledEventWhere,
- upcomingScheduledEventWhere,
-} from "./predicates";
import type { Status } from "./schema";
+import { pastScheduledEventWhere, upcomingScheduledEventWhere } from "./utils";
export function getPublicScheduledEvent(id: string) {
return prisma.scheduledEvent.findUnique({
diff --git a/apps/web/src/features/scheduled-event/mutations.ts b/apps/web/src/features/scheduled-event/mutations.ts
index c0c894284..0e9eb0132 100644
--- a/apps/web/src/features/scheduled-event/mutations.ts
+++ b/apps/web/src/features/scheduled-event/mutations.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import type { ScheduledEventInviteStatus } from "@rallly/database";
import { Prisma, prisma } from "@rallly/database";
import { nanoid } from "@rallly/utils/nanoid";
diff --git a/apps/web/src/features/scheduled-event/predicates.test.ts b/apps/web/src/features/scheduled-event/predicates.test.ts
deleted file mode 100644
index 857f76911..000000000
--- a/apps/web/src/features/scheduled-event/predicates.test.ts
+++ /dev/null
@@ -1,146 +0,0 @@
-import { describe, expect, it } from "vitest";
-import {
- pastScheduledEventWhere,
- upcomingScheduledEventWhere,
-} from "./predicates";
-
-type TestEvent = {
- status: string;
- deletedAt: Date | null;
- allDay: boolean;
- start: Date;
- end: Date;
-};
-
-type Where =
- | ReturnType<typeof upcomingScheduledEventWhere>
- | ReturnType<typeof pastScheduledEventWhere>;
-
-// Interprets the Prisma where clause against an in-memory event so the tests
-// exercise the exact predicate the queries send to the database.
-function matchesWhere(where: Where, event: TestEvent) {
- if (event.status !== where.status || event.deletedAt !== where.deletedAt) {
- return false;
- }
- return where.OR.some((arm) => {
- if (arm.allDay !== event.allDay) {
- return false;
- }
- if ("gt" in arm.end && arm.end.gt !== undefined) {
- return event.end.getTime() > arm.end.gt.getTime();
- }
- if ("lte" in arm.end && arm.end.lte !== undefined) {
- return event.end.getTime() <= arm.end.lte.getTime();
- }
- throw new Error("Unexpected end filter shape");
- });
-}
-
-function allDayEvent({ start, end }: { start: string; end: string }) {
- return {
- status: "confirmed",
- deletedAt: null,
- allDay: true,
- start: new Date(`${start}T00:00:00Z`),
- end: new Date(`${end}T00:00:00Z`),
- } satisfies TestEvent;
-}
-
-function timedEvent({ start, end }: { start: string; end: string }) {
- return {
- status: "confirmed",
- deletedAt: null,
- allDay: false,
- start: new Date(start),
- end: new Date(end),
- } satisfies TestEvent;
-}
-
-// 3pm July 1 in Honolulu (UTC-10)
-const honolulu = {
- now: new Date("2025-07-02T01:00:00Z"),
- timeZone: "Pacific/Honolulu",
-};
-
-describe("upcomingScheduledEventWhere", () => {
- it("keeps today's all-day event upcoming for a viewer west of UTC", () => {
- // Stored as UTC midnight; end is exclusive (start + 1 day)
- const event = allDayEvent({ start: "2025-07-01", end: "2025-07-02" });
-
- expect(matchesWhere(upcomingScheduledEventWhere(honolulu), event)).toBe(
- true,
- );
- expect(matchesWhere(pastScheduledEventWhere(honolulu), event)).toBe(false);
- });
-
- it("moves the same all-day event to past for a viewer already on the next day", () => {
- const event = allDayEvent({ start: "2025-07-01", end: "2025-07-02" });
- const utcViewer = { now: honolulu.now, timeZone: "UTC" };
-
- expect(matchesWhere(upcomingScheduledEventWhere(utcViewer), event)).toBe(
- false,
- );
- expect(matchesWhere(pastScheduledEventWhere(utcViewer), event)).toBe(true);
- });
-
- it("keeps a multi-day all-day span upcoming through its final day", () => {
- const event = allDayEvent({ start: "2025-06-29", end: "2025-07-02" });
-
- expect(matchesWhere(upcomingScheduledEventWhere(honolulu), event)).toBe(
- true,
- );
- });
-
- it("counts an in-progress timed event as upcoming", () => {
- const event = timedEvent({
- start: "2025-07-02T00:30:00Z",
- end: "2025-07-02T01:30:00Z",
- });
-
- expect(matchesWhere(upcomingScheduledEventWhere(honolulu), event)).toBe(
- true,
- );
- });
-});
-
-describe("pastScheduledEventWhere", () => {
- it("is the exact negation of upcoming for the same inputs", () => {
- const events = [
- allDayEvent({ start: "2025-06-30", end: "2025-07-01" }),
- allDayEvent({ start: "2025-07-01", end: "2025-07-02" }),
- allDayEvent({ start: "2025-07-02", end: "2025-07-03" }),
- allDayEvent({ start: "2025-06-29", end: "2025-07-02" }),
- // Boundary: all-day event ending exactly at today's UTC midnight
- allDayEvent({ start: "2025-06-28", end: "2025-07-01" }),
- timedEvent({
- start: "2025-07-01T22:00:00Z",
- end: "2025-07-02T00:00:00Z",
- }),
- timedEvent({
- start: "2025-07-02T00:30:00Z",
- end: "2025-07-02T01:30:00Z",
- }),
- timedEvent({
- start: "2025-07-02T02:00:00Z",
- end: "2025-07-02T03:00:00Z",
- }),
- // Boundary: timed event ending exactly at now
- timedEvent({
- start: "2025-07-02T00:00:00Z",
- end: "2025-07-02T01:00:00Z",
- }),
- ];
-
- for (const viewer of [
- honolulu,
- { now: honolulu.now, timeZone: "UTC" },
- { now: honolulu.now, timeZone: "Asia/Tokyo" },
- ]) {
- const upcoming = upcomingScheduledEventWhere(viewer);
- const past = pastScheduledEventWhere(viewer);
- for (const event of events) {
- expect(matchesWhere(upcoming, event)).toBe(!matchesWhere(past, event));
- }
- }
- });
-});
diff --git a/apps/web/src/features/scheduled-event/predicates.ts b/apps/web/src/features/scheduled-event/predicates.ts
deleted file mode 100644
index d49236a06..000000000
--- a/apps/web/src/features/scheduled-event/predicates.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import type { Prisma } from "@rallly/database";
-import {
- calendarDateToUTCMidnight,
- getCalendarDate,
-} from "@/lib/datetime/utils";
-
-// For allDay rows, `start`/`end` are calendar dates encoded as UTC midnight,
-// not instants, so they must be compared against "today in the viewer's zone"
-// encoded the same way. `end` is stored exclusive (start + 1 day), so
-// `end > todayUtcMidnight` keeps an event through its final day and handles
-// multi-day spans. The timed arm uses `end > now` so in-progress meetings
-// still count as upcoming. A single core with the gt/lte complements side by
-// side makes past the exact negation of upcoming structurally, so the two
-// cannot drift apart.
-function scheduledEventWhere({
- now,
- timeZone,
- past,
-}: {
- now: Date;
- timeZone: string;
- past: boolean;
-}) {
- const todayUtcMidnight = calendarDateToUTCMidnight(
- getCalendarDate(now, timeZone),
- );
- return {
- status: "confirmed",
- deletedAt: null,
- OR: [
- { allDay: false, end: past ? { lte: now } : { gt: now } },
- {
- allDay: true,
- end: past ? { lte: todayUtcMidnight } : { gt: todayUtcMidnight },
- },
- ],
- } satisfies Prisma.ScheduledEventWhereInput;
-}
-
-export function upcomingScheduledEventWhere(args: {
- now: Date;
- timeZone: string;
-}) {
- return scheduledEventWhere({ ...args, past: false });
-}
-
-export function pastScheduledEventWhere(args: { now: Date; timeZone: string }) {
- return scheduledEventWhere({ ...args, past: true });
-}
diff --git a/apps/web/src/features/scheduled-event/registration.ts b/apps/web/src/features/scheduled-event/registration.ts
deleted file mode 100644
index f17116790..000000000
--- a/apps/web/src/features/scheduled-event/registration.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import type { ScheduledEventStatus } from "@rallly/database";
-
-export type EventPhase = "canceled" | "ended" | "inProgress" | "upcoming";
-
-/**
- * Resolves the registration-relevant phase of an event. Registration is only
- * open while the event is "upcoming"; every other phase blocks it.
- */
-export function getEventPhase({
- status,
- start,
- end,
- now,
-}: {
- status: ScheduledEventStatus;
- start: Date;
- end: Date;
- now: Date;
-}): EventPhase {
- if (status === "canceled") {
- return "canceled";
- }
- if (now > end) {
- return "ended";
- }
- if (now >= start) {
- return "inProgress";
- }
- return "upcoming";
-}
-
-export function isEventFull({
- capacity,
- acceptedCount,
-}: {
- capacity: number | null;
- acceptedCount: number;
-}) {
- return capacity !== null && acceptedCount >= capacity;
-}
diff --git a/apps/web/src/features/scheduled-event/utils.test.ts b/apps/web/src/features/scheduled-event/utils.test.ts
index e74d84974..a2a1d682a 100644
--- a/apps/web/src/features/scheduled-event/utils.test.ts
+++ b/apps/web/src/features/scheduled-event/utils.test.ts
@@ -1,5 +1,9 @@
import { describe, expect, it } from "vitest";
-import { formatEventDateTime } from "./utils";
+import {
+ formatEventDateTime,
+ pastScheduledEventWhere,
+ upcomingScheduledEventWhere,
+} from "./utils";
// 26 Jun 2026, 13:00–14:00 UTC.
const start = new Date(Date.UTC(2026, 5, 26, 13));
@@ -84,3 +88,144 @@ describe("formatEventDateTime", () => {
expect(result.time).toContain("15:00");
});
});
+
+type TestEvent = {
+ status: string;
+ deletedAt: Date | null;
+ allDay: boolean;
+ start: Date;
+ end: Date;
+};
+
+type Where =
+ | ReturnType<typeof upcomingScheduledEventWhere>
+ | ReturnType<typeof pastScheduledEventWhere>;
+
+// Interprets the Prisma where clause against an in-memory event so the tests
+// exercise the exact predicate the queries send to the database.
+function matchesWhere(where: Where, event: TestEvent) {
+ if (event.status !== where.status || event.deletedAt !== where.deletedAt) {
+ return false;
+ }
+ return where.OR.some((arm) => {
+ if (arm.allDay !== event.allDay) {
+ return false;
+ }
+ if ("gt" in arm.end && arm.end.gt !== undefined) {
+ return event.end.getTime() > arm.end.gt.getTime();
+ }
+ if ("lte" in arm.end && arm.end.lte !== undefined) {
+ return event.end.getTime() <= arm.end.lte.getTime();
+ }
+ throw new Error("Unexpected end filter shape");
+ });
+}
+
+function allDayEvent({ start, end }: { start: string; end: string }) {
+ return {
+ status: "confirmed",
+ deletedAt: null,
+ allDay: true,
+ start: new Date(`${start}T00:00:00Z`),
+ end: new Date(`${end}T00:00:00Z`),
+ } satisfies TestEvent;
+}
+
+function timedEvent({ start, end }: { start: string; end: string }) {
+ return {
+ status: "confirmed",
+ deletedAt: null,
+ allDay: false,
+ start: new Date(start),
+ end: new Date(end),
+ } satisfies TestEvent;
+}
+
+// 3pm July 1 in Honolulu (UTC-10)
+const honolulu = {
+ now: new Date("2025-07-02T01:00:00Z"),
+ timeZone: "Pacific/Honolulu",
+};
+
+describe("upcomingScheduledEventWhere", () => {
+ it("keeps today's all-day event upcoming for a viewer west of UTC", () => {
+ // Stored as UTC midnight; end is exclusive (start + 1 day)
+ const event = allDayEvent({ start: "2025-07-01", end: "2025-07-02" });
+
+ expect(matchesWhere(upcomingScheduledEventWhere(honolulu), event)).toBe(
+ true,
+ );
+ expect(matchesWhere(pastScheduledEventWhere(honolulu), event)).toBe(false);
+ });
+
+ it("moves the same all-day event to past for a viewer already on the next day", () => {
+ const event = allDayEvent({ start: "2025-07-01", end: "2025-07-02" });
+ const utcViewer = { now: honolulu.now, timeZone: "UTC" };
+
+ expect(matchesWhere(upcomingScheduledEventWhere(utcViewer), event)).toBe(
+ false,
+ );
+ expect(matchesWhere(pastScheduledEventWhere(utcViewer), event)).toBe(true);
+ });
+
+ it("keeps a multi-day all-day span upcoming through its final day", () => {
+ const event = allDayEvent({ start: "2025-06-29", end: "2025-07-02" });
+
+ expect(matchesWhere(upcomingScheduledEventWhere(honolulu), event)).toBe(
+ true,
+ );
+ });
+
+ it("counts an in-progress timed event as upcoming", () => {
+ const event = timedEvent({
+ start: "2025-07-02T00:30:00Z",
+ end: "2025-07-02T01:30:00Z",
+ });
+
+ expect(matchesWhere(upcomingScheduledEventWhere(honolulu), event)).toBe(
+ true,
+ );
+ });
+});
+
+describe("pastScheduledEventWhere", () => {
+ it("is the exact negation of upcoming for the same inputs", () => {
+ const events = [
+ allDayEvent({ start: "2025-06-30", end: "2025-07-01" }),
+ allDayEvent({ start: "2025-07-01", end: "2025-07-02" }),
+ allDayEvent({ start: "2025-07-02", end: "2025-07-03" }),
+ allDayEvent({ start: "2025-06-29", end: "2025-07-02" }),
+ // Boundary: all-day event ending exactly at today's UTC midnight
+ allDayEvent({ start: "2025-06-28", end: "2025-07-01" }),
+ timedEvent({
+ start: "2025-07-01T22:00:00Z",
+ end: "2025-07-02T00:00:00Z",
+ }),
+ timedEvent({
+ start: "2025-07-02T00:30:00Z",
+ end: "2025-07-02T01:30:00Z",
+ }),
+ timedEvent({
+ start: "2025-07-02T02:00:00Z",
+ end: "2025-07-02T03:00:00Z",
+ }),
+ // Boundary: timed event ending exactly at now
+ timedEvent({
+ start: "2025-07-02T00:00:00Z",
+ end: "2025-07-02T01:00:00Z",
+ }),
+ ];
+
+ for (const viewer of [
+ honolulu,
+ { now: honolulu.now, timeZone: "UTC" },
+ { now: honolulu.now, timeZone: "Asia/Tokyo" },
+ ]) {
+ const upcoming = upcomingScheduledEventWhere(viewer);
+ const past = pastScheduledEventWhere(viewer);
+ for (const event of events) {
+ expect(matchesWhere(upcoming, event)).toBe(!matchesWhere(past, event));
+ }
+ }
+ });
+});
diff --git a/apps/web/src/features/scheduled-event/utils.ts b/apps/web/src/features/scheduled-event/utils.ts
index 042411f66..3f2eda133 100644
--- a/apps/web/src/features/scheduled-event/utils.ts
+++ b/apps/web/src/features/scheduled-event/utils.ts
@@ -1,9 +1,14 @@
+import type { Prisma, ScheduledEventStatus } from "@rallly/database";
import {
formatDateParts,
formatDateTime,
formatDateTimeRange,
} from "@/lib/datetime/format";
import type { TimeFormat } from "@/lib/datetime/types";
+import {
+ calendarDateToUTCMidnight,
+ getCalendarDate,
+} from "@/lib/datetime/utils";
export interface FormattedEventDateTime {
date: string;
@@ -72,3 +77,86 @@ export const formatEventDateTime = ({
}),
};
};
+
+// For allDay rows, `start`/`end` are calendar dates encoded as UTC midnight,
+// not instants, so they must be compared against "today in the viewer's zone"
+// encoded the same way. `end` is stored exclusive (start + 1 day), so
+// `end > todayUtcMidnight` keeps an event through its final day and handles
+// multi-day spans. The timed arm uses `end > now` so in-progress meetings
+// still count as upcoming. A single core with the gt/lte complements side by
+// side makes past the exact negation of upcoming structurally, so the two
+// cannot drift apart.
+function scheduledEventWhere({
+ now,
+ timeZone,
+ past,
+}: {
+ now: Date;
+ timeZone: string;
+ past: boolean;
+}) {
+ const todayUtcMidnight = calendarDateToUTCMidnight(
+ getCalendarDate(now, timeZone),
+ );
+ return {
+ status: "confirmed",
+ deletedAt: null,
+ OR: [
+ { allDay: false, end: past ? { lte: now } : { gt: now } },
+ {
+ allDay: true,
+ end: past ? { lte: todayUtcMidnight } : { gt: todayUtcMidnight },
+ },
+ ],
+ } satisfies Prisma.ScheduledEventWhereInput;
+}
+
+export function upcomingScheduledEventWhere(args: {
+ now: Date;
+ timeZone: string;
+}) {
+ return scheduledEventWhere({ ...args, past: false });
+}
+
+export function pastScheduledEventWhere(args: { now: Date; timeZone: string }) {
+ return scheduledEventWhere({ ...args, past: true });
+}
+
+export type EventPhase = "canceled" | "ended" | "inProgress" | "upcoming";
+
+/**
+ * Resolves the registration-relevant phase of an event. Registration is only
+ * open while the event is "upcoming"; every other phase blocks it.
+ */
+export function getEventPhase({
+ status,
+ start,
+ end,
+ now,
+}: {
+ status: ScheduledEventStatus;
+ start: Date;
+ end: Date;
+ now: Date;
+}): EventPhase {
+ if (status === "canceled") {
+ return "canceled";
+ }
+ if (now > end) {
+ return "ended";
+ }
+ if (now >= start) {
+ return "inProgress";
+ }
+ return "upcoming";
+}
+
+export function isEventFull({
+ capacity,
+ acceptedCount,
+}: {
+ capacity: number | null;
+ acceptedCount: number;
+}) {
+ return capacity !== null && acceptedCount >= capacity;
+}
diff --git a/apps/web/src/features/space/client.tsx b/apps/web/src/features/space/client.tsx
index 29177fc21..10b00dcc2 100644
--- a/apps/web/src/features/space/client.tsx
+++ b/apps/web/src/features/space/client.tsx
@@ -4,7 +4,7 @@ import { posthog } from "@rallly/posthog/client";
import { useRouter } from "next/navigation";
import React from "react";
import { RouterLoadingIndicator } from "@/components/router-loading-indicator";
-import { getPrimaryColorVars } from "@/features/branding/color";
+import { getPrimaryColorVars } from "@/features/branding/utils";
import { defineAbilityForMember } from "@/features/space/member/ability";
import { trpc } from "@/trpc/client";
import { defineAbilityForSpace } from "./ability";
diff --git a/apps/web/src/features/space/data.ts b/apps/web/src/features/space/data.ts
index e6f6733e2..fd9a01c60 100644
--- a/apps/web/src/features/space/data.ts
+++ b/apps/web/src/features/space/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import type {
SpaceMemberRole as DBSpaceMemberRole,
SpaceTier as DBSpaceTier,
diff --git a/apps/web/src/features/space/mutations.ts b/apps/web/src/features/space/mutations.ts
index 6dccdb736..2b0a05b5a 100644
--- a/apps/web/src/features/space/mutations.ts
+++ b/apps/web/src/features/space/mutations.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import type { SpaceTier } from "@rallly/database";
import { prisma } from "@rallly/database";
import { createSpaceDTO } from "@/features/space/data";
diff --git a/apps/web/src/features/user/data.ts b/apps/web/src/features/user/data.ts
index 42ab54071..3b53eddf5 100644
--- a/apps/web/src/features/user/data.ts
+++ b/apps/web/src/features/user/data.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import type { User } from "@rallly/database";
import { prisma } from "@rallly/database";
import { cache } from "react";
@@ -53,3 +55,30 @@ export function getUserProfile(userId: string) {
},
});
}
+
+export const getUserCount = async () => {
+ return await prisma.user.count({
+ where: {
+ isAnonymous: false,
+ },
+ });
+};
+
+export const getUserHasPassword = async (userId: string) => {
+ const account = await prisma.account.findFirst({
+ where: {
+ userId,
+ provider: "credential",
+ },
+ });
+ return !!account;
+};
+
+export const getUserHasNoAccounts = async (userId: string) => {
+ const accountCount = await prisma.account.count({
+ where: {
+ userId,
+ },
+ });
+ return accountCount === 0;
+};
diff --git a/apps/web/src/features/user/mutations.ts b/apps/web/src/features/user/mutations.ts
index 7595c132b..29cfc52e2 100644
--- a/apps/web/src/features/user/mutations.ts
+++ b/apps/web/src/features/user/mutations.ts
@@ -1,3 +1,5 @@
+import "server-only";
+
import type { TimeFormat } from "@rallly/database";
import { prisma } from "@rallly/database";
import { revalidateTag } from "next/cache";
diff --git a/apps/web/src/features/user/queries.ts b/apps/web/src/features/user/queries.ts
deleted file mode 100644
index 5fcd69152..000000000
--- a/apps/web/src/features/user/queries.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { prisma } from "@rallly/database";
-
-export const getUserCount = async () => {
- return await prisma.user.count({
- where: {
- isAnonymous: false,
- },
- });
-};
-
-export const getUserHasPassword = async (userId: string) => {
- const account = await prisma.account.findFirst({
- where: {
- userId,
- provider: "credential",
- },
- });
- return !!account;
-};
-
-export const getUserHasNoAccounts = async (userId: string) => {
- const accountCount = await prisma.account.count({
- where: {
- userId,
- },
- });
- return accountCount === 0;
-};
diff --git a/apps/web/src/trpc/routers/api-keys.ts b/apps/web/src/trpc/routers/api-keys.ts
index 61cd3552e..117a96289 100644
--- a/apps/web/src/trpc/routers/api-keys.ts
+++ b/apps/web/src/trpc/routers/api-keys.ts
@@ -1,7 +1,7 @@
import { prisma } from "@rallly/database";
import { TRPCError } from "@trpc/server";
import * as z from "zod";
-import { createApiKey } from "@/features/api-keys/api-key";
+import { createApiKey } from "@/features/api-keys/utils";
import { isApiAccessEnabled } from "@/features/developer/data";
import { router, spaceOwnerProcedure } from "../trpc";
diff --git a/apps/web/src/trpc/routers/billing.ts b/apps/web/src/trpc/routers/billing.ts
index ac5024760..6ef7816e0 100644
--- a/apps/web/src/trpc/routers/billing.ts
+++ b/apps/web/src/trpc/routers/billing.ts
@@ -2,7 +2,7 @@ import { TRPCError } from "@trpc/server";
import * as z from "zod";
import { getSpaceSubscription } from "@/features/billing/data";
-import { createStripeSubscriptionUpdateConfirmation } from "@/features/billing/portal";
+import { createStripeSubscriptionUpdateConfirmation } from "@/features/billing/mutations";
import {
getActiveSpaceForUser,
getSpaceSeatCount,
diff --git a/apps/web/src/trpc/routers/calendars.ts b/apps/web/src/trpc/routers/calendars.ts
index 5b032108b..851e0ad38 100644
--- a/apps/web/src/trpc/routers/calendars.ts
+++ b/apps/web/src/trpc/routers/calendars.ts
@@ -1,11 +1,11 @@
import * as z from "zod";
+import { getCalendars, getDefaultCalendar } from "@/features/calendars/data";
import {
disconnectCalendarConnection,
setCalendarSelection,
setDefaultCalendar,
syncCalendars,
} from "@/features/calendars/mutations";
-import { getCalendars, getDefaultCalendar } from "@/features/calendars/queries";
import { privateProcedure, router } from "../trpc";
export const calendars = router({
diff --git a/apps/web/src/trpc/routers/dashboard.ts b/apps/web/src/trpc/routers/dashboard.ts
index 90c3e6666..0be6c443f 100644
--- a/apps/web/src/trpc/routers/dashboard.ts
+++ b/apps/web/src/trpc/routers/dashboard.ts
@@ -1,7 +1,7 @@
import type { Prisma } from "@rallly/database";
import { prisma } from "@rallly/database";
import * as z from "zod";
-import { upcomingScheduledEventWhere } from "@/features/scheduled-event/predicates";
+import { upcomingScheduledEventWhere } from "@/features/scheduled-event/utils";
import type { MemberAbilityContext } from "@/features/space/member/ability";
import { defineAbilityForMember } from "@/features/space/member/ability";
import { getTotalSeatsForSpace } from "@/features/space/utils";
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index 132c9ea3f..ace76dd11 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -10,10 +10,12 @@ import { after } from "next/server";
import * as z from "zod";
import { getInstanceBranding, getSpaceBranding } from "@/emails/branding";
import { posthog } from "@/features/analytics/posthog";
-import { moderateContent } from "@/features/moderation";
-import { getPolls } from "@/features/poll/data";
-import { canUserManagePoll } from "@/features/poll/helpers";
-import { hasPollAdminAccess } from "@/features/poll/query";
+import { moderateContent } from "@/features/moderation/mutations";
+import {
+ canUserManagePoll,
+ getPolls,
+ hasPollAdminAccess,
+} from "@/features/poll/data";
import { formatEventDateTime } from "@/features/scheduled-event/utils";
import { getActiveSpaceForUser } from "@/features/space/data";
import { dayjs } from "@/lib/dayjs";
diff --git a/apps/web/src/trpc/routers/polls/comments.ts b/apps/web/src/trpc/routers/polls/comments.ts
index 6820f99b1..bb953b8a9 100644
--- a/apps/web/src/trpc/routers/polls/comments.ts
+++ b/apps/web/src/trpc/routers/polls/comments.ts
@@ -7,8 +7,8 @@ import { after } from "next/server";
import * as z from "zod";
import { getInstanceBranding } from "@/emails/branding";
import { posthog } from "@/features/analytics/posthog";
-import { getNotificationRecipient } from "@/features/notifications/queries";
-import { hasPollAdminAccess } from "@/features/poll/query";
+import { getNotificationRecipient } from "@/features/notifications/data";
+import { hasPollAdminAccess } from "@/features/poll/data";
import {
createRateLimitMiddleware,
publicProcedure,
diff --git a/apps/web/src/trpc/routers/polls/participants.ts b/apps/web/src/trpc/routers/polls/participants.ts
index a7ad125b8..430fa9bf2 100644
--- a/apps/web/src/trpc/routers/polls/participants.ts
+++ b/apps/web/src/trpc/routers/polls/participants.ts
@@ -9,8 +9,8 @@ import { after } from "next/server";
import * as z from "zod";
import { getInstanceBranding, getSpaceBranding } from "@/emails/branding";
import { posthog } from "@/features/analytics/posthog";
-import { getNotificationRecipient } from "@/features/notifications/queries";
-import { hasPollAdminAccess } from "@/features/poll/query";
+import { getNotificationRecipient } from "@/features/notifications/data";
+import { hasPollAdminAccess } from "@/features/poll/data";
import { getGravatarUrl } from "@/lib/utils/gravatar";
import {
createRateLimitMiddleware,
diff --git a/apps/web/src/trpc/routers/user.ts b/apps/web/src/trpc/routers/user.ts
index 58f849131..e4b9ea3bd 100644
--- a/apps/web/src/trpc/routers/user.ts
+++ b/apps/web/src/trpc/routers/user.ts
@@ -6,7 +6,7 @@ import * as z from "zod";
import { posthog } from "@/features/analytics/posthog";
import { feedbackSchema } from "@/features/feedback/schema";
import { defaultNotificationPreferences } from "@/features/notifications/constants";
-import { getNotificationPreferences } from "@/features/notifications/queries";
+import { getNotificationPreferences } from "@/features/notifications/data";
import { activityEventTypes } from "@/features/notifications/schema";
import { defineAbilityFor } from "@/features/user/ability";
import {
diff --git a/apps/web/src/trpc/trpc.ts b/apps/web/src/trpc/trpc.ts
index ec32743aa..4323e65ad 100644
--- a/apps/web/src/trpc/trpc.ts
+++ b/apps/web/src/trpc/trpc.ts
@@ -1,7 +1,7 @@
import { prisma } from "@rallly/database";
import { initTRPC, TRPCError } from "@trpc/server";
import superjson from "superjson";
-import { isQuickCreateEnabled } from "@/features/quick-create";
+import { isQuickCreateEnabled } from "@/features/quick-create/constants";
import { getActiveSpaceForUser } from "@/features/space/data";
import { createUserDTO } from "@/features/user/data";
import { signOut } from "@/lib/auth";
diff --git a/scripts/check-feature-structure.mjs b/scripts/check-feature-structure.mjs
index 71e50e11a..ed6965db1 100644
--- a/scripts/check-feature-structure.mjs
+++ b/scripts/check-feature-structure.mjs
@@ -36,36 +36,10 @@ const UNRESTRICTED_DIRS = new Set(["components", "assets"]);
// apps/web/src/features/; entries ending in "/" exempt a whole directory.
const GRANDFATHERED = [
"analytics/posthog.ts",
- "api-keys/api-key.ts",
- "billing/paywall-store.ts",
- "billing/portal.ts",
- "branding/brand-style.tsx",
- "branding/color.ts",
- "branding/queries.ts",
- "calendars/queries.ts",
"calendars/service.ts",
"calendars/services/",
- "credentials/queries.ts",
- "event-types/hooks.ts",
"google/service.ts",
- "instance-settings/queries.ts",
- "licensing/helpers/",
- "licensing/lib/",
- "licensing/server.ts",
- "moderation/index.ts",
- "moderation/libs/",
- "navigation/command-menu/",
"navigation/config.tsx",
- "notifications/queries.ts",
- "poll/helpers.ts",
- "poll/query.ts",
- "quick-create/index.ts",
- "quick-create/lib/",
- "quick-create/quick-create-button.tsx",
- "quick-create/quick-create-widget.tsx",
- "scheduled-event/predicates.ts",
- "scheduled-event/registration.ts",
- "user/queries.ts",
];
const usedGrandfatherEntries = new Set();