Provider Stack Overview
All providers are configured insrc/app/layout.tsx:106-149:
Provider Hierarchy
ThemeProvider
Package:next-themesLocation:
src/components/theme-provider.tsxPurpose: Light/dark/system theme management
Configuration
Usage in Components
PostHogProvider
Package:posthog-js, posthog-js/reactLocation:
src/components/posthog-provider.tsxPurpose: Product analytics and feature flags
Configuration
PostHogIdentify Component
Location:src/components/posthog-identify.tsxPurpose: Link Clerk user identity to PostHog
PostHogPageview Component
Location:src/components/posthog-pageview.tsxPurpose: Track route changes in App Router
<Suspense> to prevent blocking during static generation.
Why PostHog is second: It needs to initialize before Clerk so analytics are ready when user authentication happens.
ClerkProviderWrapper
Package:@clerk/nextjsLocation:
src/components/clerk-provider-wrapper.tsxPurpose: User authentication and session management
Configuration
- Theme adaptation: Clerk UI matches app theme (light/dark)
- Auto-sync: Uses
useTheme()from ThemeProvider - Session management: Provides
useAuth(),useUser(),useSession()hooks
Environment Variables
Usage in Components
ConvexClientProvider
Package:convex/react, convex/react-clerkLocation:
src/lib/convex-client-provider.tsxPurpose: Realtime database with Clerk authentication
Configuration
Clerk + Convex Integration
Convex uses Clerk’s JWT tokens for authentication. The integration requires: 1. Convex auth config (convex/auth.config.ts:1-15):
useAuth hook to:
- Get JWT token from Clerk session
- Send token with every Convex query/mutation
- Enable
ctx.auth.getUserIdentity()in Convex functions
Usage in Components
useAuth() hook for authentication.
TooltipProvider
Package:@radix-ui/react-tooltip (via shadcn/ui)Location:
src/components/ui/tooltip.tsxPurpose: Shared tooltip context for UI components
Configuration
delayDuration prop)
Usage in Components
Additional Components
Toaster
Package:sonnerLocation:
src/components/ui/sonner.tsxPurpose: Toast notifications
Analytics & SpeedInsights
Packages:@vercel/analytics, @vercel/speed-insightsLocation:
src/app/layout.tsx:145-146Purpose: Vercel web analytics and performance monitoring
- Page views
- Web vitals (LCP, FID, CLS, TTFB, FCP)
- No configuration required on Vercel
Provider Dependency Graph
Key dependencies:- ClerkProviderWrapper depends on ThemeProvider for theme state
- PostHogIdentify depends on ClerkProviderWrapper for user data
- ConvexClientProvider depends on ClerkProviderWrapper for
useAuth()hook
Environment Variables
All required environment variables for providers:Common Patterns
Accessing User Data
Theme-aware Styling
Analytics Tracking
Troubleshooting
Hydration Errors
Problem: Theme flicker or hydration mismatchSolution: Add
suppressHydrationWarning to <html> tag
Clerk Theme Not Updating
Problem: Clerk UI doesn’t match app themeSolution: Ensure ClerkProviderWrapper uses
resolvedTheme not theme
PostHog Not Tracking
Problem: Events not appearing in PostHogSolution: Check environment variables and init config
Convex Auth Errors
Problem:Unauthenticated errors in Convex queriesSolution: Verify
CLERK_JWT_ISSUER_DOMAIN matches Clerk dashboard
Next Steps
Architecture
Learn about the overall tech stack and data flow
Authentication
Deep dive into Clerk authentication setup
Convex Guide
Learn how to write queries and mutations
Theming
Customize colors and styles