CLAUDE.md Template: Log Analysis SaaS with Next.js, TypeScript, Supabase, Clerk, Stripe
CLAUDE.md Template for a complete Log Analysis SaaS stack using Next.js, TypeScript, Supabase, Clerk, Stripe, with AI error clustering, root-cause suggestions, and dashboards.
Target User
Developers building a multi-tenant Log Analysis SaaS with Next.js, TypeScript, Supabase, Clerk, Stripe
Use Cases
- Build a multi-tenant log analytics dashboard
- Cluster errors with AI and provide root-cause analysis
- Add user authentication and billing with Clerk and Stripe
- Deliver dashboards and AI-driven insights from logs
Markdown Template
CLAUDE.md Template: Log Analysis SaaS with Next.js, TypeScript, Supabase, Clerk, Stripe
# CLAUDE.md
Project Role
- You are Claude Code, an AI assistant specialized in delivering production-ready CLAUDE.md templates for building a complete Log Analysis SaaS on the Next.js + TypeScript + Supabase + Clerk + Stripe stack. Your goal is to produce a precise blueprint that a developer can paste into CLAUDE.md and start implementing immediately.
Architecture Rules
- Multi-tenant Postgres in Supabase with row-level security (RLS) using a tenant_id on all data tables.
- Authentication via Clerk with roles: admin, user; per-tenant authorization enforced in the backend.
- Authorization tokens are short-lived and rotated; use Clerk sessions for API requests.
- Billing via Stripe with hosted invoices; use webhooks to synchronize subscription state.
- Frontend: Next.js + TypeScript; server components allowed; client components for dashboards.
- AI error clustering: use Claude Code to process logs, cluster anomalies, and generate root-cause suggestions.
- All data exports must be behind authentication; no raw keys in client bundles.
File Structure Rules
- apps/web/ # Next.js frontend
- apps/web/pages/ # Pages and routes for dashboards and logs
- apps/web/composables/ # React hooks and utilities
- libs/ # Shared code
- libs/db/ # Supabase client, table schemas, and permissions
- libs/auth/ # Clerk configuration and auth guards
- libs/ai/ # AI clustering pipelines and prompts
- libs/stripe/ # Stripe integration and webhooks
- components/ # UI components reused across dashboards
- scripts/ # Migration and deployment scripts
Authentication Rules
- Use Clerk for authentication; enforce role-based access to dashboards and logs.
- Admins can configure tenants, plans, and user roles; users can view dashboards and run analyses.
- Sessions must be validated on every API call; JWTs are short-lived and rotated.
Database Rules
- Supabase Postgres with tables: tenants, users, projects, logs, clusters, root_causes, dashboards, subscriptions, payments.
- Enforce RLS with tenant_id and user role to prevent cross-tenant data access.
- Validate data types and ensure appropriate indexes for queries on logs and dashboards.
Validation Rules
- Validate API payloads using strict schemas; reject unexpected fields.
- Validate incoming log records for required fields: timestamp, level, message, service, tenant_id.
- Use migrations for schema changes and never alter production data without migrations.
Security Rules
- Do not expose service keys in the frontend; use server-only environment variables.
- Enforce TLS, CSRF protection, and origin checks on API routes.
- Do not bypass Clerk for auth; require authentication on all sensitive endpoints.
- Do not process PII without explicit consent and masking in UI.
Testing Rules
- Unit tests for data access layers and AI clustering logic.
- Integration tests for auth, billing webhooks, and log ingestion endpoints.
- E2E tests for login, dashboard rendering, and AI-driven recommendations.
- CI should run linting, type checks, unit tests, and integration tests on PRs.
Deployment Rules
- Deploy frontend to Vercel with environment variables for Clerk, Supabase, and Stripe.
- Use Supabase Arc or migrations for database changes; run migrations in CI before prod deployment.
- Webhooks must be validated; Stripe webhook endpoint should be behind authentication checks if applicable.
Things Claude Must Not Do
- Do not generate or expose private keys, connection strings, or API secrets in code or docs.
- Do not assume Prisma, Mongoose, or Drizzle are part of this stack unless explicitly used.
- Do not implement non-production logging or insecure data retention without consent.Overview
A CLAUDE.md template for building a complete Log Analysis SaaS with Next.js, TypeScript, Supabase, Clerk, Stripe, AI error clustering, root cause suggestions, and dashboards. This page delivers a copyable CLAUDE.md template plus stack-specific guidance to accelerate production-grade development on Claude Code.
Direct answer for developers: This CLAUDE.md Template provides a concrete blueprint to implement a multi-tenant log analytics SaaS using Next.js, TypeScript, Supabase, Clerk, Stripe, with AI-driven clustering and actionable dashboards.
When to Use This CLAUDE.md Template
- When building a multi-tenant Log Analysis SaaS on the Next.js + TS + Supabase + Clerk + Stripe stack.
- When you need a complete, copyable Claude Code blueprint with architecture, data, and security rules.
- When you require explicit file structure, validation, and deployment guidance for production readiness.
- When you want built-in AI error clustering, root-cause suggestions, and dashboard integrations.
Copyable CLAUDE.md Template
# CLAUDE.md
Project Role
- You are Claude Code, an AI assistant specialized in delivering production-ready CLAUDE.md templates for building a complete Log Analysis SaaS on the Next.js + TypeScript + Supabase + Clerk + Stripe stack. Your goal is to produce a precise blueprint that a developer can paste into CLAUDE.md and start implementing immediately.
Architecture Rules
- Multi-tenant Postgres in Supabase with row-level security (RLS) using a tenant_id on all data tables.
- Authentication via Clerk with roles: admin, user; per-tenant authorization enforced in the backend.
- Authorization tokens are short-lived and rotated; use Clerk sessions for API requests.
- Billing via Stripe with hosted invoices; use webhooks to synchronize subscription state.
- Frontend: Next.js + TypeScript; server components allowed; client components for dashboards.
- AI error clustering: use Claude Code to process logs, cluster anomalies, and generate root-cause suggestions.
- All data exports must be behind authentication; no raw keys in client bundles.
File Structure Rules
- apps/web/ # Next.js frontend
- apps/web/pages/ # Pages and routes for dashboards and logs
- apps/web/composables/ # React hooks and utilities
- libs/ # Shared code
- libs/db/ # Supabase client, table schemas, and permissions
- libs/auth/ # Clerk configuration and auth guards
- libs/ai/ # AI clustering pipelines and prompts
- libs/stripe/ # Stripe integration and webhooks
- components/ # UI components reused across dashboards
- scripts/ # Migration and deployment scripts
Authentication Rules
- Use Clerk for authentication; enforce role-based access to dashboards and logs.
- Admins can configure tenants, plans, and user roles; users can view dashboards and run analyses.
- Sessions must be validated on every API call; JWTs are short-lived and rotated.
Database Rules
- Supabase Postgres with tables: tenants, users, projects, logs, clusters, root_causes, dashboards, subscriptions, payments.
- Enforce RLS with tenant_id and user role to prevent cross-tenant data access.
- Validate data types and ensure appropriate indexes for queries on logs and dashboards.
Validation Rules
- Validate API payloads using strict schemas; reject unexpected fields.
- Validate incoming log records for required fields: timestamp, level, message, service, tenant_id.
- Use migrations for schema changes and never alter production data without migrations.
Security Rules
- Do not expose service keys in the frontend; use server-only environment variables.
- Enforce TLS, CSRF protection, and origin checks on API routes.
- Do not bypass Clerk for auth; require authentication on all sensitive endpoints.
- Do not process PII without explicit consent and masking in UI.
Testing Rules
- Unit tests for data access layers and AI clustering logic.
- Integration tests for auth, billing webhooks, and log ingestion endpoints.
- E2E tests for login, dashboard rendering, and AI-driven recommendations.
- CI should run linting, type checks, unit tests, and integration tests on PRs.
Deployment Rules
- Deploy frontend to Vercel with environment variables for Clerk, Supabase, and Stripe.
- Use Supabase Arc or migrations for database changes; run migrations in CI before prod deployment.
- Webhooks must be validated; Stripe webhook endpoint should be behind authentication checks if applicable.
Things Claude Must Not Do
- Do not generate or expose private keys, connection strings, or API secrets in code or docs.
- Do not assume Prisma, Mongoose, or Drizzle are part of this stack unless explicitly used.
- Do not implement non-production logging or insecure data retention without consent.
Recommended Project Structure
my-saas-log-analysis/
├── apps/
│ └── web/ # Next.js + TS frontend for dashboards and log views
├── libs/
│ ├── auth/ # Clerk integration and guards
│ ├── db/ # Supabase client, schemas, helpers
│ ├── ai/ # AI error clustering and root-cause prompts
│ └── stripe/ # Stripe integration and webhooks
├── components/ # Shared UI components (charts, tables, forms)
├── data/ # Migrations for Supabase
│ └── migrations/
└── scripts/ # Deployment and maintenance scripts
Core Engineering Principles
- Security by design: enforce tenant boundaries with RLS and role-based access.
- Declarative, testable architecture: clear boundaries between frontend, API, and AI services.
- Observability: structured logging, metrics, and dashboards for all critical paths.
- Privacy and compliance: minimize PII exposure and secure sensitive data with masking.
- Automation-first deployment: CI/CD with migrations, tests, and feature flags.
Code Construction Rules
- Follow TypeScript strict mode; type all API payloads precisely.
- Use Supabase client with row-level security for data access; avoid client-side queries that bypass security rules.
- Abstract Stripe operations behind a service layer; validate webhook signatures.
- AI prompts for error clustering must be deterministic and idempotent where possible.
- Keep Claude Code blocks self-contained and copy-pasteable; avoid external dependencies in template blocks.
- Do not hardcode secrets; use environment variables and secret management.
Security and Production Rules
- Enforce TLS everywhere; disable insecure endpoints in production.
- Enable Row-Level Security on all tables connected to tenants; test with sample tenants.
- Validate Stripe webhooks with signature verification; reject invalid requests.
- Mask PII in logs and analytics exports; offer redaction options for dashboards.
- Limit data retention per tenant; provide export controls and data deletion workflows.
Testing Checklist
- Unit tests for DB access, AI clustering, and billing logic.
- Integration tests for Clerk auth, Supabase permissions, and Stripe webhooks.
- End-to-end tests for login, dashboard rendering, and AI-driven insights generation.
- Migration tests to ensure smooth schema changes in production environments.
- Security tests: vulnerable endpoint checks, API key exposure, and RBAC enforcement.
Common Mistakes to Avoid
- Assuming client-side code can enforce security without server-side checks.
- Neglecting RLS and tenant isolation in logs and analytics endpoints.
- Overfitting AI prompts; produce inconsistent root-cause suggestions without context.
- Failing to validate Stripe webhooks; missing secure webhook handling.
Related implementation resources: AI Use Case for Wellness Coaches Using Stripe Data To Analyze Which Subscription Models Have The Highest Retention.
FAQ
Q: What is the scope of this CLAUDE.md Template?
A: A full blueprint for a Next.js + TypeScript + Supabase + Clerk + Stripe Log Analysis SaaS with AI clustering and dashboards.
Q: Can I customize the AI clustering prompts?
A: Yes. The template includes configurable prompts and prompts-safe defaults; adjust in libs/ai.
Q: How is multi-tenancy enforced?
A: Tenant isolation is implemented with tenant_id on data tables and Supabase Row-Level Security (RLS); Clerk handles per-user access.
Q: How do I deploy this in production?
A: Deploy frontend to Vercel, run migrations via CI, configure Stripe webhooks, and securely manage environment variables.
Q: Where can I find the canonical CLAUDE.md Template?
A: This page in the AI Skills Library: CLAUDE.md Templates collection.