Overview
Zen Nurture is built with Next.js 16, Convex for the backend, and Better Auth for authentication. This guide covers everything you need to run the app locally or deploy it to production.Prerequisites
Before you begin, ensure you have:- Node.js: Version 18 or higher
- Package Manager: pnpm (recommended), npm, or yarn
- Convex Account: Free account at convex.dev
- OpenAI API Key: For Mora AI assistant features (optional)
Installation
Clone and Install Dependencies
Zen Nurture uses pnpm v9.10.0 as specified in
package.json. Using pnpm ensures consistent dependency resolution.Set Up Convex
Convex is the real-time backend database for Zen Nurture.This will:
Create a Convex Project
- Create a new Convex project (or link to an existing one)
- Generate
.env.localwithNEXT_PUBLIC_CONVEX_URL - Deploy your Convex functions from the
convex/directory
Convex Schema
The database schema is defined inconvex/schema.ts:convex/schema.ts
Convex automatically manages database migrations. When you update the schema and run
npx convex dev, changes are applied automatically.Configure Environment Variables
Create a
.env.local file in the project root:.env.local
Environment Variable Details
NEXT_PUBLIC_CONVEX_URL & NEXT_PUBLIC_CONVEX_SITE_URL
NEXT_PUBLIC_CONVEX_URL & NEXT_PUBLIC_CONVEX_SITE_URL
These are automatically set when you run
npx convex dev. They point to your Convex backend.NEXT_PUBLIC_CONVEX_URL: The Convex deployment URLNEXT_PUBLIC_CONVEX_SITE_URL: The Convex site URL for authentication
SITE_URL
SITE_URL
The base URL where your Next.js app is running. Better Auth uses this for authentication flows.
- Local:
http://localhost:3000 - Production:
https://yourdomain.com
OPENAI_API_KEY
OPENAI_API_KEY
Required for the Mora AI assistant feature. Get your API key from platform.openai.com.Mora uses
@ai-sdk/openai with GPT-4 models to answer parenting questions and analyze your baby’s data.VAPID Keys (Web Push)
VAPID Keys (Web Push)
Required for browser push notifications. Generate VAPID keys:This outputs a public/private key pair. Add them to
.env.local.CRON_SECRET
CRON_SECRET
A secret string used to authenticate cron job requests for push notification reminders.Also add this to your Convex dashboard: Settings > Environment VariablesThe cron endpoint (
/api/push/check-reminders) requires an Authorization: Bearer <CRON_SECRET> header.Configure Better Auth
Better Auth is already set up in the codebase. Here’s how it’s configured:
Convex Auth Setup
convex/auth.ts
Client Auth Setup
src/lib/auth-client.ts
Auth Config
convex/auth.config.ts
Better Auth is integrated with Convex via the
@convex-dev/better-auth package. User data is stored in Convex’s managed auth tables.Run the Development Server
Now you’re ready to start the app!The app will be available at:
- Next.js: http://localhost:3000
- Convex Dashboard: https://dashboard.convex.dev
Available Scripts
package.json
Production Deployment
Deploy to Vercel
Zen Nurture is optimized for Vercel deployment:vercel build --prod- Builds the Next.js appvercel deploy --prebuilt --prod- Deploys to Vercel
Convex Production Deployment
- Set
NEXT_PUBLIC_CONVEX_URLto your production Convex URL - Set
SITE_URLto your production domain - Add all other env vars in Vercel’s dashboard
Remember to add
CRON_SECRET in both Vercel environment variables and Convex dashboard (Settings > Environment Variables).Set Up Cron for Push Notifications
If you’re using reminders with push notifications, configure a cron job to check for due reminders:vercel.json
Database Management
Viewing Data
Use the Convex dashboard to view and query your data:- Go to dashboard.convex.dev
- Select your project
- Navigate to “Data” to browse tables
- Use the “Functions” tab to test queries and mutations
Backup and Export
Zen Nurture includes a built-in export feature:Troubleshooting
Convex connection errors
Convex connection errors
Problem: “Failed to connect to Convex”Solution:
- Ensure
npx convex devis running - Check that
NEXT_PUBLIC_CONVEX_URLis set in.env.local - Verify you’re logged in:
npx convex login
Authentication not working
Authentication not working
Problem: “Unable to sign in” or CORS errorsSolution:
- Verify
SITE_URLmatches your app URL - Add your URL to
BETTER_AUTH_TRUSTED_ORIGINS - Check that
NEXT_PUBLIC_CONVEX_SITE_URLis set correctly - Clear browser cookies and try again
Mora AI not responding
Mora AI not responding
Problem: AI assistant times out or gives errorsSolution:
- Verify
OPENAI_API_KEYis set and valid - Check you have API credits in your OpenAI account
- Ensure you’re using GPT-4 (check
src/app/api/mora/route.ts)
Push notifications not working
Push notifications not working
Problem: Reminders don’t trigger push notificationsSolution:
- Verify VAPID keys are set correctly
- Check
CRON_SECRETis set in both.env.localand Convex dashboard - Ensure user has granted browser notification permissions
- Test the subscription endpoint:
/api/push/subscribe
Build errors
Build errors
Problem: TypeScript or build errorsSolution:
- Delete
node_modulesand reinstall:rm -rf node_modules && pnpm install - Clear Next.js cache:
rm -rf .next - Regenerate Convex types:
npx convex dev --once - Ensure you’re using Node.js 18+
Architecture Deep Dive
Frontend Stack
- Next.js 16: React framework with App Router
- React 19: Latest React with concurrent features
- TailwindCSS 4: Utility-first CSS
- Radix UI: Accessible component primitives (dialogs, dropdowns, etc.)
- shadcn/ui: Pre-built components using Radix
- Recharts: Data visualization library
- Motion: Animation library (Framer Motion successor)
Backend Stack
- Convex: Real-time database with TypeScript functions
- Better Auth: Authentication with email/password
- OpenAI: AI assistant (Mora) powered by GPT-4
- Web Push: Browser push notifications via
web-pushpackage
Key Directories
Next Steps
Explore the Codebase
Browse
convex/schema.ts for the data model and convex/events.ts for backend logicAPI Reference
Learn about all available Convex queries and mutations
Customize UI
Modify components in
src/components/ using Tailwind and shadcn/uiAdd Features
Extend the schema and add new event types or analytics views
