AI-powered personalized storybook generator for kids. Parents upload photos of their child, choose a story template, and generate custom storybooks featuring their child as the hero.
- Frontend: Next.js 16 (App Router), React 19, Radix UI, Tailwind CSS v4
- Backend: Next.js API Routes, Supabase (PostgreSQL, Auth, Storage)
- AI: Replicate API (Google Nano Banana for image generation)
- Deployment: Vercel (with Cron Jobs for background processing)
``` ├── app/ # Next.js App Router │ ├── api/ # API routes │ │ ├── v1/ # REST API endpoints │ │ └── cron/ # Background job handlers │ └── page.tsx # Main app page ├── components/ # React components │ ├── ui/ # UI primitives (Radix UI) │ └── *.tsx # Feature components ├── lib/ # Utilities and services │ ├── supabase/ # Supabase client helpers │ └── services/ # Business logic (image generation, etc.) ├── db_scripts/ # Database migrations ├── public/ # Static assets └── tech-spec.md # Technical specification
```
- Node.js 18+
- pnpm (or npm/yarn)
- Supabase account
- Replicate API account
-
Clone and install: ```bash pnpm install ```
-
Environment variables (
.env.local): ```envNEXT_PUBLIC_SUPABASE_URL=your_supabase_url NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
REPLICATE_API_TOKEN=your_replicate_token NANOBANANA_MODEL_VERSION=google/nano-banana
CRON_SECRET=your_random_secret ```
-
Database setup: ```bash
```
-
Storage setup:
- Create Supabase Storage buckets:
character-photos(private)storybook-scenes(private)story-template-assets(public)
- Upload template cover images and thumbnails
- Update URLs in database (see
db_scripts/004_update_template_storage_urls.sql)
- Create Supabase Storage buckets:
-
Run development server: ```bash pnpm dev ```
The native iOS/Android app is a thin Capacitor shell that loads the live web app at https://www.twinklebot.app/app. No local web build is required for the native app.
-
Sync the Capacitor config to the native project:
npx cap sync
-
Open the project in Xcode:
npx cap open ios
-
In Xcode, select your target device/simulator and press the play button to build and run.
-
Sync the Capacitor config:
npx cap sync
-
Open in Android Studio:
npx cap open android
-
Build and run from Android Studio.
- Uses Supabase Auth (JWT tokens)
- Get token: Use
public/get-token.htmlhelper page
GET /api/v1/characters- List user's charactersPOST /api/v1/characters- Create character (with photo uploads)GET /api/v1/characters/:id- Get character detailsPUT /api/v1/characters/:id- Update characterDELETE /api/v1/characters/:id- Delete character
GET /api/v1/story-templates- List all templatesGET /api/v1/story-templates/:id- Get template details
GET /api/v1/storybooks- List user's storybooksPOST /api/v1/storybooks- Create storybook (auto-starts generation in dev)GET /api/v1/storybooks/:id- Get storybook with scenesGET /api/v1/storybooks/:id/status- Get generation statusPOST /api/v1/storybooks/:id/generate- Manually trigger generationDELETE /api/v1/storybooks/:id- Delete storybook
GET /api/v1/profile- Get user profilePUT /api/v1/profile- Update profile
- Open
http://localhost:3000/get-token.html - Sign in to get your JWT token
- Open
http://localhost:3000/test-api.html - Paste token and test endpoints
```bash
curl -X POST https://your-project.supabase.co/auth/v1/token?grant_type=password
-H "apikey: YOUR_ANON_KEY"
-d '{"email":"[email protected]","password":"password"}'
curl http://localhost:3000/api/v1/story-templates
-H "Authorization: Bearer YOUR_TOKEN"
```
- Create Storybook: User selects template and character
- Queue Job: Storybook created with
status: 'pending' - Background Processing:
- Development: Auto-starts immediately
- Production: Vercel Cron picks up every minute
- Scene Generation:
- For each scene:
- Build prompt (fixed parts + scene-specific action/detail)
- Call Replicate API with character photos
- Download generated image
- Upload to Supabase Storage
- Update progress (0-100%)
- Retries: 3 attempts per scene with exponential backoff
- For each scene:
- Completion: Status set to
completed, all scenes stored
See db-schema.md for complete schema documentation.
Key tables:
profiles- User profilescharacters- Child characters (with photo URLs)story_templates- Pre-defined story templatesstorybooks- Generated storybooks (with scenes array)generation_models- AI model configurationsgeneration_jobs- Background job tracking
- Connect GitHub repository
- Set environment variables
- Deploy (Cron jobs configured in
vercel.json)
- All variables from
.env.local - Ensure
CRON_SECRETis set for cron job security
-
Check Replicate API:
- Verify
REPLICATE_API_TOKENis set - Check model version is valid
- Review Replicate API logs
- Verify
-
Check Character Photos:
- Photos must be accessible URLs
- Private bucket photos use signed URLs (auto-generated)
-
Check Database: ```sql SELECT status, error_message FROM storybooks WHERE id = '...'; SELECT * FROM generation_jobs WHERE storybook_id = '...'; ```
- Verify Supabase credentials
- Check JWT token expiration
- Ensure RLS policies are set correctly
- Verify bucket permissions
- Check file paths match database URLs
- Ensure service role key has storage access
scripts/upload-cover-images.ts— Bulk upload.pngcover images to a Supabase Storage bucket. Each image is placed in a folder named after the file (e.g.my-story.png→<bucket>/my-story/my-story.png). Skips files that already exist.npx tsx scripts/upload-cover-images.ts <local-folder> <bucket-name>
scripts/cleanup-storybook-storage.ts— Removes orphaned files from thestorybook-scenesbucket for storybooks that no longer have scenes in the database.npx tsx scripts/cleanup-storybook-storage.ts
tech-spec.md- Complete technical specificationdb-schema.md- Database schema documentationdb_scripts/README.md- Migration guide
[Your License Here]