An intelligent backend system for educational content management, leveraging AI to generate comprehensive syllabi, questions, and learning materials.
HomeWork Server is a production-ready REST API built with Express.js and TypeScript that helps educators create, manage, and enhance educational content using AI. It combines local LLM inference (Ollama), semantic search (Qdrant), and web research (Tavily) to generate curriculum-aligned syllabi and questions.
- Automatic Curriculum Creation: Generate complete syllabi with units, topics, objectives, and resources
- Multi-Board Support: CBSE, ICSE, State boards, and IB curriculum alignment
- Web-Enhanced Context: Real-time curriculum research via Tavily API
- Smart Caching: Three-layer caching (Vector DB → WebSearch → Fresh API) saves costs
- Version Control: Track multiple AI-generated versions with comparison tools
- AI Question Generation: Create MCQs, short-answer, essay, and true/false questions
- Duplicate Detection: Semantic similarity checks prevent repetitive questions
- Adaptive Generation: Smart retry logic with increasing diversity parameters
- Difficulty Levels: Easy, medium, hard questions for any topic
- Batch Processing: Generate 5-100 questions asynchronously via job queue
- Vector Embeddings: 384-dimension embeddings using nomic-embed-text model
- Similar Content Discovery: Find related topics across different syllabi
- Context-Aware Generation: AI uses past content to avoid duplication
- Curriculum Search: Semantic matching of similar syllabi (85%+ similarity)
- Background Job Processing: BullMQ + Redis for long-running AI tasks
- Real-time Notifications: WebSocket support for job status updates
- Completeness Scoring: Automatic quality assessment of generated content
- Resource Management: Link external learning materials to topics
- Stage Management: Draft → Published → Archived workflow
- Runtime: Node.js + TypeScript
- Framework: Express.js 5.x
- Database: PostgreSQL with pgvector extension
- ORM: Prisma
- LLM: Ollama (local inference with qwen2.5, mistral, llama models)
- Embeddings: nomic-embed-text:v1.5 (384D vectors)
- Vector DB: Qdrant for semantic search
- Web Search: Tavily API for curriculum research
- Job Queue: BullMQ
- Cache/Queue: Redis
- Concurrency: 2 workers with rate limiting (10 jobs/minute)
POST /- Create manual syllabusGET /- List all syllabi with filtersGET /:id- Get single syllabus with units and topicsPATCH /:id- Update syllabusDELETE /:id- Delete syllabusGET /teacher/:teacherId- Get teacher's syllabiGET /similar- Find similar syllabi (semantic search)
POST /- Queue AI syllabus generation (background job)GET /job/:jobId- Check generation statusGET /:id/completeness- Get quality score
GET /- List all versions of a syllabusGET /:versionId- Get specific version detailsGET /compare- Compare two versions side-by-sidePATCH /:versionId/set-latest- Mark version as active
POST /syllabi/:id/units- Add unit to syllabusGET /units/:id- Get unit detailsPATCH /units/:id- Update unitDELETE /units/:id- Delete unitPOST /units/:id/topics- Add topic to unitPOST /units/:id/topics/bulk- Add multiple topicsGET /topics/:id- Get topic detailsPATCH /topics/:id- Update topicDELETE /topics/:id- Delete topicGET /topics/:id/resources- Get external resourcesGET /topics/:id/similar- Find similar topics
POST /- Create manual questionGET /- List questions with filtersPOST /generate-ai- Generate AI questions (sync/async)GET /job/:jobId- Check generation job status
GET /health- Check AI service statusPOST /chat- Context-aware AI chatPOST /generate-text- Custom text generationPOST /embeddings- Generate embeddings
Features:
- Syllabus library with search and filters
- AI generation wizard with progress tracking
- Version comparison tool with diff viewer
- Question bank management
- Real-time generation status updates
- Analytics: completeness scores, usage stats
Features:
- Browse published syllabi by class/subject
- Topic-wise study materials
- Practice questions by difficulty
- Progress tracking per unit/topic
- Resource library (videos, articles)
- Semantic search for topics
Features:
- User management (teachers, students)
- Content moderation (review AI-generated content)
- System monitoring (job queue, AI health)
- Cache statistics and optimization
- Bulk operations (import/export syllabi)
Features:
- Quick syllabus access
- Offline question practice
- Push notifications for job completion
- Simple CRUD for teachers on-the-go
- QR code sharing for syllabi
- Create Syllabus: Enter basic details (class, subject, board)
- AI Generation: Click "Generate with AI" → Background job starts
- Monitor Progress: Real-time updates via WebSocket
- Review & Edit: Check completeness score, modify units/topics
- Publish: Mark as published for student access
- Regenerate: Create new versions with different parameters
- Browse Syllabi: Filter by class/subject/board
- View Content: Units, topics, objectives, resources
- Practice Questions: Filter by topic, difficulty, type
- Track Progress: Mark completed topics
# Server
PORT=3001
NODE_ENV=development
# Database (PostgreSQL with pgvector)
DATABASE_URL=postgresql://user:pass@localhost:5432/homeworkdb
# AI - Ollama (Local LLM)
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=qwen2.5:7b-instruct-q4_K_M
OLLAMA_TIMEOUT=300000
# Redis (Job Queue & Cache)
REDIS_URL=redis://:pass@localhost:6379
# Vector Database
QDRANT_URL=http://localhost:6333
# Web Search
TAVILY_API_KEY=your_tavily_key# Install dependencies
npm install
# Setup database
npx prisma migrate dev
# Start Ollama
ollama serve
ollama pull qwen2.5:7b-instruct-q4_K_M
ollama pull nomic-embed-text:v1.5
# Start Redis & Qdrant (Docker)
docker run -d -p 6379:6379 redis:7-alpine
docker run -d -p 6333:6333 qdrant/qdrant
# Run development server
npm run devAll endpoints return consistent JSON:
{
"success": true,
"message": "Description of result",
"data": { /* payload */ },
"count": 10 // For list responses
}Custom error classes with proper HTTP status codes:
ValidationError(400) - Invalid inputNotFoundError(404) - Resource not foundConflictError(409) - Duplicate or version conflictAIServiceError(500) - AI generation failureVectorSearchError(500) - Embedding/search failure
- Token Optimization: Dynamic token allocation based on subject complexity
- Embedding Exclusion: API responses exclude 384D vectors (saves bandwidth)
- Adaptive Thresholds: Smart duplicate detection with progressive relaxation
- Batch Operations: Efficient multi-topic/question creation
- Database Indexing: Optimized queries on common filters
- Polling for Job Status: Poll
/api/syllabi/generate/:jobIdevery 3-5 seconds - WebSocket for Real-time: Connect to get instant job completion notifications
- Pagination: Use
?page=1&limit=20for large lists - Caching: Cache published syllabi on frontend (they rarely change)
- Optimistic Updates: Update UI immediately, sync with backend
- Error Boundaries: Handle AI failures gracefully with retry options
- Add authentication middleware (JWT, OAuth)
- Implement rate limiting per user (currently global)
- Add input sanitization for user-generated content
- Restrict AI generation to authenticated teachers
- Add CORS configuration for frontend domains
- Authentication & Authorization (JWT)
- File upload support (PDFs, images)
- OCR for syllabus extraction
- Collaborative editing (real-time)
- Analytics dashboard
- Export to PDF/DOCX
- Multi-language support
- Parent/Student access controls
ISC
- 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
Built with ❤️ for educators and students