free doc 0
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Documentation
Comprehensive technical documentation is available in the /docs directory:
- Profile System Architecture - Multi-account profile management
- Profile API Reference - Complete API documentation
- Profile Implementation Guide - Implementation details
- Documentation Index - All available documentation
Development Commands
# Development
npm run dev # Start development server with Turbopack
npm run build # Build for production (includes prisma generate)
npm run start # Start production server
npm run lint # Run ESLint
npm run db:push # Push database schema changes
npm run db:seed # Seed database with sample data
# Database operations (requires DATABASE_URL environment variable)
npx prisma generate # Generate Prisma client
npx prisma db push # Push schema changes to database
npx prisma migrate dev # Create and apply new migration
npx prisma studio # Open Prisma Studio for database browsing
Important Development Workflow
When making changes to this codebase:
- Always run linting: Use
npm run lintafter making changes - Check build success: Run
npm run buildto ensure no compilation errors - Database Adapter Pattern: Use adapters for all data access - never access data directly
- Type Safety: Maintain strict TypeScript compliance with runtime Zod validation
- Caching: All adapter methods include built-in caching for performance
- Database Changes: Use
npx prisma generateafter schema changes,npx prisma db pushfor development
ESLint Configuration
The project uses a customized ESLint configuration in eslint.config.mjs:
- Extends
next/core-web-vitalsandnext/typescript - Disabled Rules:
@typescript-eslint/no-unused-varsandno-unused-vars@typescript-eslint/no-unused-paramsandno-unused-params@typescript-eslint/no-explicit-any
Project Architecture
This is a Next.js 15 application with React 19 using the App Router pattern. The project demonstrates a sophisticated developer education platform with hybrid data architecture combining traditional databases with Nostr protocol for content management.
Key Architectural Patterns
Hybrid Data Architecture
The project uses a unique Database + Nostr Events approach:
- Minimal Database Fields: Only essential data (ID, price, timestamps, relations) stored in PostgreSQL
- Rich Content from Nostr: Full content comes from NIP-23 (free) and NIP-99 (paid) events
- Unified Display Layer: Combines both sources for complete UI data via Display interfaces
- Development Mode: JSON mock files + real Nostr events for rapid development without database setup
Database Adapter Pattern
Clean data access abstraction in src/lib/db-adapter.ts:
- CourseAdapter: CRUD operations with JSON database simulation + Nostr event integration
- ResourceAdapter: Handles both documents and videos from JSON files + Nostr events
- LessonAdapter: Course-to-resource relationships with JSON persistence
- Performance: Built-in hierarchical caching for sub-50ms response times
- IMPORTANT: Always use adapters, never access mock data or database directly
Nostr Integration
Real-time content management through Nostr protocol:
- SnstrProvider: Context provider for relay pool management in
src/contexts/snstr-context.tsx - Event Parsing: Parser functions in
src/data/types.tsconvert Nostr events to UI data - Publishing System: Complete draft-to-Nostr publishing flow with NIP-07 browser extension support
- Atomic Operations: All draft lessons published before course creation
Key Architectural Files
Data Management
src/data/types.ts- Complete type system: Database models, Nostr event types, Display interfaces, and parser functionssrc/lib/db-adapter.ts- Database adapter pattern: Clean data abstraction with JSON mock + Nostr integrationsrc/data/mockDb/- JSON mock database: Course.json, Resource.json, Lesson.json files for developmentsrc/lib/cache.ts- Production caching: Hierarchical L1/L2 cache with TTL and statistics
Authentication System
src/lib/auth.ts- Dual Identity Architecture:- Nostr-first (NIP07, Anonymous): Nostr profile is source of truth, syncs on every login
- OAuth-first (Email, GitHub): OAuth profile is authoritative, gets ephemeral Nostr keys
- 5 Authentication Methods: Email magic links, GitHub OAuth, NIP07 browser extension, Anonymous, Recovery mode
- Universal Nostr Access: All users get Nostr capabilities with appropriate key custody models
Publishing System
src/lib/nostr-events.ts- Event builders: Create NIP-23/NIP-99/NIP-51 compliant eventssrc/lib/publish-service.ts- Publishing service: Atomic operations for drafts to Nostrsrc/lib/draft-service.ts- Draft management: CourseDraftService, DraftService, DraftLessonService classes
API Routes
/api/health- Health check endpoint/api/courses- Course CRUD with validation/api/resources- Resource management endpoints/api/drafts/*/publish- Publishing endpoints for drafts- Error Handling: Structured error classes (NotFoundError, ValidationError, etc.)
- Validation: Comprehensive Zod schemas matching TypeScript types
Core Technologies
- Next.js 15.3.5 with Turbopack
- React 19 with Server Components
- TypeScript with strict mode
- Tailwind CSS v4 with shadcn/ui
- snstr for Nostr protocol
- Zod for runtime validation
- @tanstack/react-query for data fetching
- NextAuth.js with Prisma adapter
- Prisma with PostgreSQL
Environment Variables
Required:
DATABASE_URL- PostgreSQL connection stringNEXTAUTH_SECRET- Secret for JWT encryptionNEXTAUTH_URL- Application URL (e.g., http://localhost:3000)
Optional (for GitHub OAuth):
GITHUB_CLIENT_ID- GitHub OAuth client IDGITHUB_CLIENT_SECRET- GitHub OAuth client secret
Code Style Guidelines
-
Component Structure:
- Use function declarations for pages:
export default function PageName() {} - Use arrow functions for components:
export const ComponentName = () => {}
- Use function declarations for pages:
-
Import Organization:
- React/Next imports first
- Third-party libraries
- Internal components
- Types/interfaces
- Utils/lib functions
-
Data Access:
- ALWAYS use adapters (CourseAdapter, ResourceAdapter, etc.)
- NEVER access mock data or database directly
- Always check cache before fetching data
-
Error Handling:
- Use try-catch blocks for async operations
- Return structured error responses from API routes
- Use custom error classes
Smart Image Optimization
- OptimizedImage Component: Automatically handles images from any domain without manual configuration
- Seamless Fallback: Uses
unoptimizedprop for unknown domains - Pre-configured Domains: Unsplash, GitHub avatars, YouTube thumbnails, DiceBear, DigitalOcean Spaces
Git Workflow
When creating commits:
- Always run:
npm run lintandnpm run buildbefore committing - Database changes: Run
npx prisma generateafter schema changes - Atomic commits: Keep commits focused on single features or fixes
Common Pitfalls to Avoid
- Don’t add domains to next.config.ts - Use OptimizedImage component instead
- Don’t create new mock data files - Use existing JSON structure
- Don’t bypass the adapter pattern - Always use adapters for data access
- Don’t ignore TypeScript errors - Fix them properly
- Don’t skip cache invalidation - Update caches when data changes
- Don’t create files unless necessary - Prefer editing existing files