An intelligent AI-powered study companion built on Cloudflare's Developer Platform.
- Runtime: Cloudflare Workers
- Frontend: React + Vite + TypeScript
- Styling: Tailwind CSS + shadcn/ui
- State Management: Durable Objects
- Database: Cloudflare D1 (SQLite)
- Storage: Cloudflare R2
- Authentication: Clerk
β
Story 1.1 Complete - Foundation setup ready
π Deployed: https://study.adamwhite.work
β³ Next: Story 1.2 - Durable Object Implementation
Authentication is handled by Clerk with proper JWT signature verification using JWKS. All API endpoints require valid authentication tokens.
- Node.js (v18 or higher)
- npm or pnpm
- Cloudflare account (free tier available)
- Clerk account (free tier available)
The following has been set up:
- β Project structure with TypeScript
- β Build system (Vite + Wrangler)
- β All dependencies installed
- β Tailwind CSS + shadcn/ui configured
- β Git repository initialized
- β Worker entry point with health check
- β Durable Objects structure
# Login to Cloudflare
npx wrangler login
# Verify authentication
npx wrangler whoamiGood news! If you're using Wrangler v4.45+ (which this project uses), D1 and R2 resources are automatically provisioned on your first deploy. No manual creation needed!
The first time you run npm run deploy, Wrangler will:
- β¨ Automatically create the D1 database:
ai-study-companion-db - β¨ Automatically create the R2 bucket:
ai-study-companion-storage - β¨ Write the resource IDs back to your
wrangler.jsonc
Manual Creation (Optional):
If you prefer to create resources manually first, you can:
# Optional: Create D1 database manually
npx wrangler d1 create ai-study-companion-db
# Copy the database_id from output and update wrangler.jsonc
# Optional: Create R2 bucket manually
npx wrangler r2 bucket create ai-study-companion-storageLearn more: Automatic Resource Provisioning (Cloudflare, Oct 2024)
- Create account at clerk.com
- Create new application
- Configure environment variables:
Frontend (.env file):
# Create .env file in project root
VITE_CLERK_PUBLISHABLE_KEY=pk_test_YOUR_KEYBackend (wrangler.jsonc):
Secret Keys (Cloudflare Secrets):
# Store secret key in Cloudflare (optional - only needed for certain Clerk features)
npx wrangler secret put CLERK_SECRET_KEY
# Paste your secret key when promptedImportant: Never commit .env or secret keys to version control.
# Install dependencies (if not already done)
npm install
# Start local development server
npm run devThe dev server will start on http://localhost:8787
# Build the project
npm run build
# Deploy to Cloudflare
npm run deploysrc/
βββ worker.ts # Cloudflare Worker entry point
βββ durable-objects/ # Durable Object classes
β βββ StudentCompanion.ts
βββ components/ # React components
β βββ ui/ # shadcn/ui components
β βββ chat/ # Chat interface
β βββ practice/ # Practice questions
β βββ progress/ # Progress tracking
β βββ layout/ # Layout components
βββ lib/ # Utility libraries
β βββ rpc/ # RPC client
β βββ db/ # Database utilities
β βββ ai/ # AI integration
β βββ auth.ts # Authentication utilities
β βββ utils.ts # General utilities
βββ types/ # TypeScript type definitions
βββ hooks/ # React hooks
npm run dev- Start local development server with Wranglernpm run build- Build for productionnpm run deploy- Deploy to Cloudflarenpm run lint- Run ESLintnpm run preview- Preview production build locally
Once deployed, verify the worker is running:
curl https://your-worker-url.workers.dev/healthExpected response:
{
"status": "ok",
"timestamp": "2025-11-07T...",
"service": "ai-study-companion"
}After completing the setup:
- Implement full Durable Objects functionality (Story 1.2)
- Set up database schema (Story 1.3)
- Build UI components (Stories 1.4-1.6)
- Integrate memory system (Story 1.7)
The AI Study Companion features a sophisticated dual-memory architecture that enables true personalization through automatic knowledge consolidation.
Short-Term Memory β Automatic Consolidation β Long-Term Memory β Personalized Responses
- Session Ingestion: Tutoring sessions are stored as short-term memories
- Automatic Consolidation: After 4 hours, an alarm triggers LLM-powered analysis
- Knowledge Extraction: AI extracts background, strengths, struggles, and goals
- Long-Term Storage: Consolidated insights persist in the student's profile
- Personalized Responses: Chat responses reference the student's learning journey
When a student returns after multiple sessions, the companion remembers:
"I remember discriminants were confusing for you at first, but you made incredible progress! You went from struggling with the basic concept to mastering all three types of roots in just a few days."
This personalization is powered by:
- Dual-Memory System: Ephemeral short-term + permanent long-term storage
- LLM Consolidation: AI analyzes sessions to extract structured insights
- Durable Object Alarms: Cloudflare's "sleep" functionality for scheduled processing
- In-Memory Caching: Fast retrieval with 10-minute cache for long-term memory
π Profile Card - Displays consolidated learning profile (background, goals, strengths, areas for growth)
π Recent Sessions - Shows session history with consolidation status
β‘ Memory Status - Displays last consolidation and pending memories
β¨ Personalization Badges - Highlights when responses reference student's memory
See the complete Memory Intelligence Documentation for:
- Detailed architecture and flow diagrams
- Consolidation process deep-dive
- Performance optimizations
- Demo data and testing guides
Private project
{ "vars": { "CLERK_PUBLISHABLE_KEY": "pk_test_YOUR_KEY" } }