An intelligent flashcard application that uses OpenAI to generate study materials, explanations, and hints while minimizing token usage through Redis caching and smart batching.
- 🤖 AI-Generated Flashcards: Create study decks from topics, text, or URLs using GPT-3.5-turbo
- 💡 Progressive Hints: Smart hint system with 3 levels of assistance
- 🧠 AI Explanations: Detailed explanations for incorrect answers
- 📊 Study Analytics: Track progress with AI-powered insights
- 🔄 Smart Caching: Redis-based caching to minimize API costs
- 🎯 Spaced Repetition: Algorithm-based study scheduling
- 📱 Responsive Design: Beautiful UI that works on all devices
- Node.js + Express
- PostgreSQL (persistent storage)
- Redis (caching + job queues)
- OpenAI API (GPT-3.5-turbo)
- Bull (background job processing)
- JWT authentication
- React + Vite
- TailwindCSS
- Zustand (state management)
- React Query (server state)
- Framer Motion (animations)
- Node.js 18+
- PostgreSQL 15+
- Redis 7+
- OpenAI API key
- Backend Environment (
backend/.env):
# Server
PORT=5000
NODE_ENV=development
# Database
DATABASE_URL=postgresql://studybuddy:securepass@localhost:5432/ai_study_buddy
# Redis
REDIS_URL=redis://localhost:6379
# OpenAI
OPENAI_API_KEY=sk-your-openai-key-here
OPENAI_MODEL=gpt-3.5-turbo
# Auth
JWT_SECRET=your-super-secure-jwt-secret-key- Frontend Environment (
frontend/.env):
VITE_API_URL=http://localhost:5000/api
VITE_APP_NAME=AI Study Buddy- Install Dependencies:
# Backend
cd backend
npm install
# Frontend
cd ../frontend
npm install- Database Setup:
# Create database
createdb ai_study_buddy
# Run migrations
cd backend
npm run migrate- Start Services:
# Terminal 1: Start Redis
redis-server
# Terminal 2: Start PostgreSQL (if not running as service)
postgres -D /usr/local/var/postgres
# Terminal 3: Start Backend
cd backend
npm run dev
# Terminal 4: Start Frontend
cd frontend
npm run dev- Access Application:
- Frontend: http://localhost:5173
- Backend API: http://localhost:5000
- Visit http://localhost:5173
- Click "Sign up" and create an account
- You'll start with 10,000 daily AI tokens
- Click "Generate with AI" on the dashboard
- Choose from three options:
- From Topic: Enter any subject (e.g., "React Hooks", "World War II")
- From Text: Paste text content to extract flashcards from
- From URL: Provide a webpage URL to scrape content
- Configure difficulty level (1-5) and number of cards (5-50)
- Review estimated token usage
- Click "Generate Deck"
- Select a deck from your dashboard
- Click "Start Studying"
- Read the question and think of the answer
- Use hints if needed (up to 3 progressive hints per card)
- Flip the card to see the answer
- Rate your performance: Incorrect, Partial, or Correct
- Get AI explanations for incorrect answers
- Caching: All AI responses cached for 7-30 days
- Batching: Multiple requests processed together
- Limits: 10,000 tokens per day per user
- Optimization: Aggressive prompt optimization
- Level 1: Subtle hint
- Level 2: Moderate guidance
- Level 3: Strong hint
- All hints cached to prevent re-generation
- Progress tracking
- Study streaks
- Performance insights
- Time spent analysis
POST /api/auth/register- Create accountPOST /api/auth/login- Sign inGET /api/auth/me- Get current userPOST /api/auth/logout- Sign out
GET /api/decks- List user's decksPOST /api/decks- Create new deckPOST /api/decks/generate- Generate deck with AIGET /api/decks/:id- Get deck details
POST /api/study/start- Start study sessionPOST /api/study/answer- Submit answerGET /api/study/hint/:cardId/:level- Get progressive hintPOST /api/study/complete/:sessionId- Complete session
POST /api/ai/explain- Get explanation for wrong answerPOST /api/ai/hint- Generate hintGET /api/ai/usage- Check token usage
ai-study-buddy/
├── backend/
│ ├── src/
│ │ ├── routes/ # API routes
│ │ ├── services/ # Business logic
│ │ ├── middleware/ # Auth, validation
│ │ ├── config/ # DB, Redis, queue
│ │ └── migrations/ # Database schema
│ └── package.json
├── frontend/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── pages/ # Route components
│ │ ├── hooks/ # Custom hooks
│ │ ├── stores/ # Zustand stores
│ │ └── services/ # API client
│ └── package.json
└── README.md
- Backend: Add routes in
src/routes/, business logic insrc/services/ - Frontend: Add components in
src/components/, hooks insrc/hooks/ - Database: Create migrations in
src/migrations/
# Backend tests
cd backend
npm test
# Frontend tests
cd frontend
npm test# Start all services
docker-compose up -d
# View logs
docker-compose logs -f- Set
NODE_ENV=production - Use secure JWT secret
- Configure production database
- Set up Redis cluster for scaling
- Add rate limiting and monitoring
- Card Generation: ~100 tokens per card
- Hints: ~30 tokens per hint
- Explanations: ~150 tokens per explanation
- Daily Cost: ~$0.01 per user with GPT-3.5
- Aggressive caching (7-30 day TTL)
- Request batching
- Prompt optimization
- Popular content pre-generation
-
Database Connection Error:
- Ensure PostgreSQL is running
- Check DATABASE_URL in .env
- Verify database exists
-
Redis Connection Error:
- Start Redis server:
redis-server - Check REDIS_URL in .env
- Start Redis server:
-
OpenAI API Errors:
- Verify OPENAI_API_KEY is set
- Check account has credits
- Review rate limits
-
Frontend Build Issues:
- Clear node_modules:
rm -rf node_modules && npm install - Check Node.js version (18+)
- Clear node_modules:
- Backend logs: Console output in development
- Frontend logs: Browser console
- Database logs: PostgreSQL logs
- Redis logs: Redis server output
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request
MIT License - see LICENSE file for details
Built with ❤️ for effective learning through AI-powered flashcards.