diff --git a/.env.example b/.env.example index 6c249675..2a0b5b04 100644 --- a/.env.example +++ b/.env.example @@ -10,11 +10,13 @@ DIFFBOT_API_KEY= UPSTASH_REDIS_REST_URL= UPSTASH_REDIS_REST_TOKEN= -# Analytics (required) -CLICKHOUSE_URL=http://localhost:8123 -CLICKHOUSE_USER=default -CLICKHOUSE_PASSWORD=clickhouse -CLICKHOUSE_DATABASE=smry_analytics +# Analytics - PostHog (required) +POSTHOG_API_KEY=phc_xxx +POSTHOG_HOST=https://us.i.posthog.com +POSTHOG_PROJECT_ID=12345 +POSTHOG_PERSONAL_API_KEY=phx_xxx +NEXT_PUBLIC_POSTHOG_KEY=phc_xxx +NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com # Alerting ALERT_EMAIL= diff --git a/CLAUDE.md b/CLAUDE.md index deeadf41..1033c28b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -9,7 +9,8 @@ Article reader and summarizer with AI chat. - **Backend**: Elysia (Bun-native web framework) - **AI/LLM**: OpenRouter (Vercel AI SDK for streaming) - **Auth**: Clerk (billing + JWT) -- **Database**: ClickHouse (analytics), Upstash Redis (rate limiting, chat thread storage) +- **Analytics**: PostHog (product analytics, session recording, heatmaps, LLM analytics) +- **Database**: Upstash Redis (rate limiting, chat thread storage) - **Client Storage**: IndexedDB (offline-first chat threads), localStorage (article history, preferences) ## Project Structure @@ -27,7 +28,7 @@ types/ Zod schemas and shared types ## Key Commands ```bash -bun dev # Start dev server (Next.js + Elysia + ClickHouse) +bun dev # Start dev server (Next.js + Elysia) bun run build # Production build bun run lint # ESLint bun run typecheck # TypeScript check diff --git a/ONBOARDING.md b/ONBOARDING.md index d63e228c..7fd7cb8a 100644 --- a/ONBOARDING.md +++ b/ONBOARDING.md @@ -11,7 +11,7 @@ Welcome to SMRY (internally "13ft") - an AI-powered article summarizer that bypa bun install # Start development environment -bun run dev # Starts ClickHouse + Elysia server + Next.js +bun run dev # Starts Elysia server + Next.js # Or with full Docker stack bun run dev:docker @@ -58,7 +58,7 @@ SMRY fetches articles from behind paywalls using multiple extraction sources and │ │ │ ▼ ▼ ▼ ┌─────────┐ ┌──────────┐ ┌──────────┐ - │ Diffbot │ │OpenRouter│ │ClickHouse│ + │ Diffbot │ │OpenRouter│ │ PostHog │ │ (API) │ │ (AI) │ │(Analytics)│ └─────────┘ └──────────┘ └──────────┘ │ @@ -98,7 +98,7 @@ SMRY/ │ └── validation/ # Zod schemas ├── types/ # TypeScript type definitions ├── tests/ # Unit and integration tests -├── docker/ # Docker and ClickHouse setup +├── docker/ # Docker setup ├── messages/ # i18n translation files └── docs/ # Additional documentation ``` @@ -124,7 +124,7 @@ SMRY/ | Elysia | Lightweight TypeScript HTTP framework | | Clerk | Authentication and billing | | Upstash Redis | Serverless caching (with zlib compression) | -| ClickHouse | Analytics database | +| PostHog | Product analytics, session recording, heatmaps | | OpenRouter | AI model access (300+ models) | | Diffbot | AI-powered article extraction | @@ -185,11 +185,13 @@ NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY= CLERK_SECRET_KEY= CLERK_WEBHOOK_SECRET= -# Analytics -CLICKHOUSE_HOST= # ClickHouse for analytics -CLICKHOUSE_DATABASE= -CLICKHOUSE_USERNAME= -CLICKHOUSE_PASSWORD= +# Analytics (PostHog) +POSTHOG_API_KEY= # Server-side PostHog key +POSTHOG_HOST= # PostHog instance URL +POSTHOG_PROJECT_ID= # Project ID for HogQL queries +POSTHOG_PERSONAL_API_KEY= # Personal key for analytics dashboard +NEXT_PUBLIC_POSTHOG_KEY= # Client-side PostHog key +NEXT_PUBLIC_POSTHOG_HOST= # Client-side PostHog host # Optional NEXT_PUBLIC_API_URL= # API URL for client (default: /api) @@ -427,7 +429,6 @@ bun run pages:deploy # Deploy to Cloudflare Pages - [README.md](./README.md) - Project overview and motivation - [DESIGN_PHILOSOPHY.md](./DESIGN_PHILOSOPHY.md) - UI/UX guidelines - [MIGRATION_PLAN.md](./MIGRATION_PLAN.md) - Deployment guide -- [docs/clickhouse-schema.sql](./docs/clickhouse-schema.sql) - Analytics schema - [docs/MEMORY_LEAK_FIX.md](./docs/MEMORY_LEAK_FIX.md) - Performance optimizations --- diff --git a/README.md b/README.md index 6bf07fa0..1e90c5ae 100644 --- a/README.md +++ b/README.md @@ -225,11 +225,13 @@ DIFFBOT_API_KEY= # https://diffbot.com UPSTASH_REDIS_REST_URL= UPSTASH_REDIS_REST_TOKEN= -# Analytics - ClickHouse (use docker-compose for local dev) -CLICKHOUSE_URL=http://localhost:8123 -CLICKHOUSE_USER=default -CLICKHOUSE_PASSWORD= -CLICKHOUSE_DATABASE=smry_analytics +# Analytics - PostHog +POSTHOG_API_KEY= +POSTHOG_HOST= +POSTHOG_PROJECT_ID= +POSTHOG_PERSONAL_API_KEY= +NEXT_PUBLIC_POSTHOG_KEY= +NEXT_PUBLIC_POSTHOG_HOST= # Alerting - https://resend.com RESEND_API_KEY= @@ -250,7 +252,7 @@ pnpm install 2. **Set up environment variables**: - Copy `.env.example` to `.env.local` - Get API keys from: Clerk, OpenRouter, Diffbot, Upstash, Resend - - Run `docker-compose up -d clickhouse` for local analytics + - PostHog analytics is cloud-hosted (no local setup needed) 3. **Run development server**: ```bash diff --git a/app/layout.tsx b/app/layout.tsx index 90dfe876..3c41d96a 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -44,6 +44,7 @@ import { ClerkProvider } from "@clerk/nextjs"; import { Toaster } from "@/components/ui/sonner"; import { getLocale } from 'next-intl/server'; import { JsonLd, organizationSchema, websiteSchema } from "@/components/seo/json-ld"; +import { PostHogProvider } from "@/components/providers/posthog-provider"; // Root metadata - OG images are handled by file-based convention (opengraph-image.tsx) // in each route segment for proper caching and to avoid robots.txt blocking issues @@ -105,6 +106,7 @@ export default async function RootLayout({
+