Skip to content

adam0white/AI-Study-Companion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

52 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Study Companion

An intelligent AI-powered study companion built on Cloudflare's Developer Platform.

Tech Stack

  • 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

Project Status

βœ… Story 1.1 Complete - Foundation setup ready
πŸš€ Deployed: https://study.adamwhite.work
⏳ Next: Story 1.2 - Durable Object Implementation

Security

Authentication is handled by Clerk with proper JWT signature verification using JWKS. All API endpoints require valid authentication tokens.

Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • npm or pnpm
  • Cloudflare account (free tier available)
  • Clerk account (free tier available)

Initial Setup (Completed)

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

Manual Steps Required

1. Cloudflare Authentication

# Login to Cloudflare
npx wrangler login

# Verify authentication
npx wrangler whoami

2. Cloudflare Resources (Auto-Provisioned)

Good 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-storage

Learn more: Automatic Resource Provisioning (Cloudflare, Oct 2024)

3. Set Up Clerk Authentication

  1. Create account at clerk.com
  2. Create new application
  3. Configure environment variables:

Frontend (.env file):

# Create .env file in project root
VITE_CLERK_PUBLISHABLE_KEY=pk_test_YOUR_KEY

Backend (wrangler.jsonc):

{
  "vars": {
    "CLERK_PUBLISHABLE_KEY": "pk_test_YOUR_KEY"
  }
}

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 prompted

Important: Never commit .env or secret keys to version control.

4. Local Development

# Install dependencies (if not already done)
npm install

# Start local development server
npm run dev

The dev server will start on http://localhost:8787

5. Deploy to Cloudflare

# Build the project
npm run build

# Deploy to Cloudflare
npm run deploy

Project Structure

src/
β”œβ”€β”€ 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

Available Scripts

  • npm run dev - Start local development server with Wrangler
  • npm run build - Build for production
  • npm run deploy - Deploy to Cloudflare
  • npm run lint - Run ESLint
  • npm run preview - Preview production build locally

Health Check

Once deployed, verify the worker is running:

curl https://your-worker-url.workers.dev/health

Expected response:

{
  "status": "ok",
  "timestamp": "2025-11-07T...",
  "service": "ai-study-companion"
}

Next Steps

After completing the setup:

  1. Implement full Durable Objects functionality (Story 1.2)
  2. Set up database schema (Story 1.3)
  3. Build UI components (Stories 1.4-1.6)
  4. Integrate memory system (Story 1.7)

Memory Intelligence System

The AI Study Companion features a sophisticated dual-memory architecture that enables true personalization through automatic knowledge consolidation.

How It Works

Short-Term Memory β†’ Automatic Consolidation β†’ Long-Term Memory β†’ Personalized Responses

  1. Session Ingestion: Tutoring sessions are stored as short-term memories
  2. Automatic Consolidation: After 4 hours, an alarm triggers LLM-powered analysis
  3. Knowledge Extraction: AI extracts background, strengths, struggles, and goals
  4. Long-Term Storage: Consolidated insights persist in the student's profile
  5. Personalized Responses: Chat responses reference the student's learning journey

The Magic Moment

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

Key Features

πŸ“Š 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

Learn More

See the complete Memory Intelligence Documentation for:

  • Detailed architecture and flow diagrams
  • Consolidation process deep-dive
  • Performance optimizations
  • Demo data and testing guides

Documentation

License

Private project

About

AI-powered study companion built on Cloudflare's platform with dual-memory architecture that consolidates learning sessions into personalized profiles, providing intelligent tutoring through React + TypeScript frontend.

Topics

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages