A full-stack AI-powered lesson plan generation application built with Next.js and Node.js, featuring an integrated RAG (Retrieval-Augmented Generation) system for more accurate educational content generation.
- Node.js >= 18.17.0
- pnpm >= 8.0.0
- Python >= 3.8 (for ChromaDB)
This project uses pnpm as the package manager. If you haven't installed pnpm yet, please install it first:
# Install pnpm globally
npm install -g pnpm
# Or use Corepack (Node.js 16.10+)
corepack enable
corepack prepare pnpm@latest --activate-
Clone the repository
git clone https://github.com/your-username/teachai.git cd teachai -
Install all dependencies
# Install dependencies for root, web, and server pnpm run install:all # Or install separately pnpm install # Root dependencies cd web && pnpm install # Frontend dependencies cd ../server && pnpm install # Backend dependencies
-
Install ChromaDB (RAG System)
# Install ChromaDB pip install chromadb # Or use conda conda install -c conda-forge chromadb
-
Configure environment variables
# Copy environment template cp server/.env.example server/.env # Edit environment variables, set AI API key # DASHSCOPE_API_KEY=your_api_key_here
This project integrates an advanced RAG (Retrieval-Augmented Generation) system using ChromaDB as the vector database, providing intelligent content generation based on educational materials.
-
Start ChromaDB service
# Start ChromaDB vector database pnpm run chroma:start -
Load educational materials data
# Load educational materials from enhanced chunks to vector database pnpm run rag:load -
Check RAG system status
# Check database status and data statistics pnpm run rag:status
# Automatically start ChromaDB and load data
pnpm run setup:rag# Start ChromaDB service
pnpm run chroma:start
# Stop ChromaDB service
pnpm run chroma:stop
# Check system status
pnpm run rag:status
# Reload data
pnpm run rag:load
# Monitor loading progress (live updates)
pnpm run rag:progress:watch
# Verify data integrity and performance
pnpm run rag:verify
# Run comprehensive RAG system tests
pnpm run rag:test-
Standard development mode (without RAG)
# Start both frontend and backend development servers pnpm dev -
Full development mode (with RAG)
# Start ChromaDB, frontend, and backend servers simultaneously pnpm run dev:full
# Start ChromaDB service
pnpm run chroma:start
# Start backend server
pnpm run dev:server
# Start frontend server
pnpm run dev:webAccess URLs:
- Frontend application: http://localhost:3000
- Backend API: http://localhost:3001
- ChromaDB: http://localhost:8000
The project's server/rag_data/chunks/ folder contains enhanced educational materials data in JSON format:
server/rag_data/chunks/
├── enhanced_chunk_0001.json
├── enhanced_chunk_0002.json
├── enhanced_chunk_0003.json
└── ... (95,360+ educational chunks)
Each JSON file contains the following structure:
{
"content": "Educational content text",
"metadata": {
"source": "filename",
"page_number": 1,
"chunk_index": 0,
"qualityScore": 0.85,
"ocrConfidence": 0.92,
"semanticFeatures": ["definitions", "examples"]
}
}- Mathematics: People's Education Press, Beijing Normal University, Hunan Education, East China Normal University
- Chinese: People's Education Press, Jiangsu Education, Beijing Normal University
- English: People's Education Press, Foreign Language Teaching and Research Press, Yilin Press
- Physics: People's Education Press, Beijing Normal University, Shanghai Science
- Chemistry: People's Education Press, Shandong Science and Technology
- Biology: People's Education Press, Jiangsu Education
- Others: Music, Art, Science, etc.
- OCR Error Correction: Improved text accuracy for Chinese educational content
- Duplicate Detection: Advanced algorithms to identify and merge similar content
- Quality Scoring: Each chunk includes reliability metrics (0.3-1.0 scale)
- Content Classification: Semantic features like formulas, experiments, definitions
- Smart Chunking: Optimized text segmentation for better retrieval
- 95,360+ Enhanced Chunks: Comprehensive K-12 curriculum coverage
# Build entire project
pnpm build
# Build separately
pnpm run build:web # Build frontend
pnpm run build:server # Build backendThis project integrates an advanced RAG system that retrieves relevant educational materials through a vector database, significantly improving the quality and accuracy of AI-generated content.
- Intelligent Retrieval: Semantic similarity-based retrieval of relevant educational content
- Multi-version Textbook Support: Covers mainstream textbooks like People's Education Press, Beijing Normal University, Jiangsu Education, etc.
- Grade Adaptation: Automatically matches grade-relevant educational materials
- Subject Specialization: Provides specialized educational content for different subjects
- Real-time Enhancement: Real-time retrieval and integration of relevant educational resources during generation
- Educational Materials: 95,360+ enhanced educational content chunks
- Grade Coverage: Elementary Grade 1 to High School Grade 12
- Supported Subjects: Mathematics, Chinese, English, Physics, Chemistry, Biology, History, Geography, Politics, Music, Art, Science
- Textbook Versions: 20+ mainstream textbook versions
User Request → AI Service → Vector Retrieval → Content Fusion → Enhanced Generation → Return Result
↓
ChromaDB Vector Database
(95,360+ educational materials)
- Lesson Plan Generation: Supports complete instructional design including teaching objectives, key points, and teaching process
- Exercise Generation: Intelligent question generation supporting multiple question types and difficulty levels
- Content Analysis: Intelligent analysis of educational content, extracting core concepts
- Multi-format Output: Supports text, mind maps, flowcharts, timelines, and other display formats
- Streaming Output: Real-time display of generation process, enhancing user experience
- Personalized Settings: Customize generated content based on user preferences
- Content Management: Complete content bookmarking, export, and deletion functionality
- Multi-format Export: Supports PDF, Word, image, and other export formats
-
Start Services
# Start complete services (recommended) pnpm run dev:full -
Generate Lesson Plans
- Visit http://localhost:3000
- Select subject, grade, and topic
- Click generate, AI will provide professional lesson plans combined with RAG system
-
Manage Content
- View generation history
- Bookmark quality content
- Export as PDF/Word
- RAG System Management: Use
pnpm run rag:statusto check database status - Data Updates: Use
pnpm run rag:loadto reload educational materials - System Monitoring: View generation logs and performance metrics
# Start production environment
pnpm start
# Start separately
pnpm run start:web # Start frontend production server
pnpm run start:server # Start backend production serverteachai/
├── web/ # Next.js frontend application
│ ├── src/
│ │ ├── app/ # App Router pages
│ │ └── components/ # React components
│ ├── package.json
│ └── pnpm-lock.yaml
├── server/ # Node.js backend service
│ ├── models/ # Data models
│ ├── services/ # Business services
│ ├── middleware/ # Middleware
│ ├── config/ # Configuration files
│ ├── utils/ # Utility functions
│ ├── rag/ # RAG system implementation
│ ├── rag_data/ # Enhanced educational materials (95,360+ chunks)
│ ├── package.json
│ └── pnpm-lock.yaml
├── package.json # Root configuration (workspace)
├── pnpm-lock.yaml # Lock file
└── .gitignore # Git ignore file
pnpm dev # Start frontend and backend in development mode
pnpm build # Build production version
pnpm start # Start production servers
pnpm lint # Code style check
pnpm test # Run tests
pnpm clean # Clean node_modules and build files
pnpm format # Code formattingThe project has a complete .gitignore file configured to automatically ignore:
**/node_modules/- Dependency directories at all levels**/.next/- Next.js build output**/*.log- Log files.env*- Environment variable files.DS_Store- macOS system files- IDE configuration files, etc.
Please create a .env file in the server/ directory:
# MongoDB connection
MONGODB_URI=your_mongodb_connection_string
# JWT secret
JWT_SECRET=your_jwt_secret
# Qwen API Key (Alibaba Cloud DashScope)
DASHSCOPE_API_KEY=your_dashscope_api_key
# Server port
PORT=3001
# AI Configuration
QWEN_MODEL=qwen-plus
AI_MAX_TOKENS=2000
AI_TEMPERATURE=0.7
# ChromaDB Configuration (Local)
CHROMADB_HOST=localhost
CHROMADB_PORT=8000
# ChromaDB Cloud Configuration (Production)
CHROMA_CLOUD_ENABLED=false
CHROMADB_API_KEY=your_chromadb_cloud_api_key
CHROMADB_TENANT=your_tenant_id
CHROMADB_DATABASE=teachai
CHROMADB_COLLECTION=teachai_main- Next.js 15 - React full-stack framework
- React 19 - UI library
- TypeScript - Type safety
- Tailwind CSS - Styling framework
- Framer Motion - Animation library
- Lucide React - Icon library
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database
- Mongoose - ODM
- JWT - Authentication
- Winston - Logging
- ChromaDB - Vector database for RAG
- ChromaDB - Vector database
- OpenAI Embeddings - Text embeddings
- Enhanced Educational Data - 95,360+ quality-scored chunks
- Semantic Search - Intelligent content retrieval
pnpm build
pnpm startFor production deployment with ChromaDB Cloud, see the comprehensive Production Deployment Guide.
- Set Environment Variables:
export CHROMA_CLOUD_ENABLED=true
export CHROMADB_API_KEY=your_chromadb_api_key
export CHROMADB_TENANT=your_tenant_id
export CHROMADB_DATABASE=teachai
export CHROMADB_COLLECTION=teachai_main- Test Configuration:
node test-env-config.js- Upload RAG Data to Cloud:
node server/rag/scripts/cloud-uploader.js- Deploy Application:
NODE_ENV=production pnpm build && pnpm start# Run all tests
pnpm test
# Run tests with coverage
pnpm test:coverage
# Run server tests only
pnpm run test:server
# Run web tests only
pnpm run test:web
# Run single test file
cd web && pnpm test -- --testPathPattern=page.test.tsx
cd server && pnpm test -- --testPathPattern=ai-service.test.js# Test RAG accuracy with quality scoring
pnpm run rag:test-accuracy
# Run comprehensive RAG system tests
pnpm run rag:test
# Verify loaded data integrity and performance
pnpm run rag:verifyWelcome to submit Pull Requests and Issues!
- Fork the project
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License
- Project Link: GitHub Repository
- Issue Reports: Issues
TeachAI - Let AI become your teaching assistant 🚀
基于 Next.js 和 Node.js 的全栈 AI 教案生成应用,集成 RAG (检索增强生成) 系统,提供更准确的教学内容生成。
- Node.js >= 18.17.0
- pnpm >= 8.0.0
- Python >= 3.8 (用于 ChromaDB)
项目使用 pnpm 作为包管理器。如果您还没有安装 pnpm,请先安装:
# 全局安装 pnpm
npm install -g pnpm
# 或者使用 Corepack (Node.js 16.10+)
corepack enable
corepack prepare pnpm@latest --activate-
克隆项目
git clone https://github.com/your-username/teachai.git cd teachai -
安装所有依赖
# 安装根目录、web 和 server 的所有依赖 pnpm run install:all # 或者分别安装 pnpm install # 根目录依赖 cd web && pnpm install # 前端依赖 cd ../server && pnpm install # 后端依赖
-
安装 ChromaDB (RAG 系统)
# 安装 ChromaDB pip install chromadb # 或者使用 conda conda install -c conda-forge chromadb
-
配置环境变量
# 复制环境变量模板 cp server/.env.example server/.env # 编辑环境变量,设置 AI API 密钥 # DASHSCOPE_API_KEY=your_api_key_here
本项目集成了 RAG (检索增强生成) 系统,使用 ChromaDB 作为向量数据库,提供基于教学材料的智能内容生成。
-
启动 ChromaDB 服务
# 启动 ChromaDB 向量数据库 pnpm run chroma:start -
加载教学材料数据
# 加载增强版教学材料到向量数据库 pnpm run rag:load -
检查 RAG 系统状态
# 检查数据库状态和数据统计 pnpm run rag:status
# 自动启动 ChromaDB 并加载数据
pnpm run setup:rag# 启动 ChromaDB 服务
pnpm run chroma:start
# 停止 ChromaDB 服务
pnpm run chroma:stop
# 检查系统状态
pnpm run rag:status
# 重新加载数据
pnpm run rag:load
# 实时监控加载进度
pnpm run rag:progress:watch
# 验证数据完整性和性能
pnpm run rag:verify
# 运行综合 RAG 系统测试
pnpm run rag:test-
标准开发模式 (不含 RAG)
# 同时启动前端和后端开发服务器 pnpm dev -
完整开发模式 (含 RAG)
# 同时启动 ChromaDB、前端和后端服务器 pnpm run dev:full
# 启动 ChromaDB 服务
pnpm run chroma:start
# 启动后端服务器
pnpm run dev:server
# 启动前端服务器
pnpm run dev:web访问地址:
- 前端应用:http://localhost:3000
- 后端 API:http://localhost:3001
- ChromaDB:http://localhost:8000
项目的 server/rag_data/chunks/ 文件夹包含了增强版教学材料数据,格式为 JSON 文件:
server/rag_data/chunks/
├── enhanced_chunk_0001.json
├── enhanced_chunk_0002.json
├── enhanced_chunk_0003.json
└── ... (95,360+ 教学内容片段)
每个 JSON 文件包含以下结构:
{
"content": "教学内容文本",
"metadata": {
"source": "文件名",
"page_number": 1,
"chunk_index": 0,
"qualityScore": 0.85,
"ocrConfidence": 0.92,
"semanticFeatures": ["definitions", "examples"]
}
}- 数学: 人教版、北师大版、湘教版、华师大版
- 语文: 人教版、苏教版、北师大版
- 英语: 人教版、外研版、译林版
- 物理: 人教版、北师大版、沪科版
- 化学: 人教版、鲁科版
- 生物: 人教版、苏教版
- 其他: 音乐、美术、科学等
- OCR 错误纠正: 提高中文教育内容的文本准确性
- 重复检测: 高级算法识别和合并相似内容
- 质量评分: 每个片段包含可靠性指标 (0.3-1.0 评分)
- 内容分类: 语义特征如公式、实验、定义等
- 智能分块: 优化文本分割以提高检索效果
- 95,360+ 增强片段: 全面覆盖 K-12 课程内容
# 构建整个项目
pnpm build
# 分别构建
pnpm run build:web # 构建前端
pnpm run build:server # 构建后端本项目集成了先进的 RAG 系统,通过向量数据库检索相关教学材料,显著提升AI生成内容的质量和准确性。
- 智能检索: 基于语义相似度检索相关教学内容
- 多版本教材支持: 覆盖人教版、北师大版、苏教版等主流教材
- 年级适配: 自动匹配年级相关的教学材料
- 学科专业化: 针对不同学科提供专业化的教学内容
- 实时增强: 生成过程中实时检索和融合相关教学资源
- 教学材料数量: 95,360+ 个增强教学内容片段
- 覆盖年级: 小学一年级至高中三年级
- 支持学科: 数学、语文、英语、物理、化学、生物、历史、地理、政治、音乐、美术、科学
- 教材版本: 20+ 种主流教材版本
用户请求 → AI服务 → 向量检索 → 内容融合 → 增强生成 → 返回结果
↓
ChromaDB向量数据库
(95,360+ 教学材料)
- 教案生成: 支持完整的教学设计,包含教学目标、重难点、教学过程
- 练习题生成: 智能出题,支持多种题型和难度级别
- 内容分析: 智能分析教学内容,提取核心概念
- 多格式输出: 支持文本、思维导图、流程图、时间线等多种展示格式
- 流式输出: 实时显示生成过程,提升用户体验
- 个性化设置: 根据用户偏好定制生成内容
- 内容管理: 完整的内容收藏、导出、删除功能
- 多格式导出: 支持PDF、Word、图片等多种导出格式
-
启动服务
# 启动完整服务(推荐) pnpm run dev:full -
生成教案
- 访问 http://localhost:3000
- 选择学科、年级、主题
- 点击生成,AI将结合RAG系统提供专业教案
-
管理内容
- 查看生成历史
- 收藏优质内容
- 导出为PDF/Word
- RAG系统管理: 使用
pnpm run rag:status查看数据库状态 - 数据更新: 使用
pnpm run rag:load重新加载教学材料 - 系统监控: 查看生成日志和性能指标
# 启动生产环境
pnpm start
# 分别启动
pnpm run start:web # 启动前端生产服务器
pnpm run start:server # 启动后端生产服务器teachai/
├── web/ # Next.js 前端应用
│ ├── src/
│ │ ├── app/ # App Router 页面
│ │ └── components/ # React 组件
│ ├── package.json
│ └── pnpm-lock.yaml
├── server/ # Node.js 后端服务
│ ├── models/ # 数据模型
│ ├── services/ # 业务服务
│ ├── middleware/ # 中间件
│ ├── config/ # 配置文件
│ ├── utils/ # 工具函数
│ ├── rag/ # RAG 系统实现
│ ├── rag_data/ # 增强版教学材料 (95,360+ 片段)
│ ├── package.json
│ └── pnpm-lock.yaml
├── package.json # 根目录配置(工作空间)
├── pnpm-lock.yaml # 锁定文件
└── .gitignore # Git 忽略文件
pnpm dev # 开发模式启动前后端
pnpm build # 构建生产版本
pnpm start # 启动生产服务器
pnpm lint # 代码风格检查
pnpm test # 运行测试
pnpm clean # 清理 node_modules 和构建文件
pnpm format # 代码格式化项目已配置完整的 .gitignore 文件,自动忽略:
**/node_modules/- 所有层级的依赖目录**/.next/- Next.js 构建输出**/*.log- 日志文件.env*- 环境变量文件.DS_Store- macOS 系统文件- IDE 配置文件等
请在 server/ 目录下创建 .env 文件:
# MongoDB 连接
MONGODB_URI=your_mongodb_connection_string
# JWT 密钥
JWT_SECRET=your_jwt_secret
# 通义千问 API Key (阿里云 DashScope)
DASHSCOPE_API_KEY=your_dashscope_api_key
# 服务器端口
PORT=3001
# AI 配置
QWEN_MODEL=qwen-plus
AI_MAX_TOKENS=2000
AI_TEMPERATURE=0.7
# ChromaDB 配置 (本地)
CHROMADB_HOST=localhost
CHROMADB_PORT=8000
# ChromaDB 云端配置 (生产环境)
CHROMA_CLOUD_ENABLED=false
CHROMADB_API_KEY=your_chromadb_cloud_api_key
CHROMADB_TENANT=your_tenant_id
CHROMADB_DATABASE=teachai
CHROMADB_COLLECTION=teachai_main- Next.js 15 - React 全栈框架
- React 19 - UI 库
- TypeScript - 类型安全
- Tailwind CSS - 样式框架
- Framer Motion - 动画库
- Lucide React - 图标库
- Node.js - 运行时环境
- Express.js - Web 框架
- MongoDB - 数据库
- Mongoose - ODM
- JWT - 身份验证
- Winston - 日志记录
- ChromaDB - RAG 向量数据库
- ChromaDB - 向量数据库
- OpenAI Embeddings - 文本嵌入
- 增强版教育数据 - 95,360+ 质量评分片段
- 语义搜索 - 智能内容检索
pnpm build
pnpm start有关 ChromaDB 云端生产部署的详细信息,请参阅综合 生产部署指南。
- 设置环境变量:
export CHROMA_CLOUD_ENABLED=true
export CHROMADB_API_KEY=your_chromadb_api_key
export CHROMADB_TENANT=your_tenant_id
export CHROMADB_DATABASE=teachai
export CHROMADB_COLLECTION=teachai_main- 测试配置:
node test-env-config.js- 上传 RAG 数据到云端:
node server/rag/scripts/cloud-uploader.js- 部署应用:
NODE_ENV=production pnpm build && pnpm start# 运行所有测试
pnpm test
# 运行测试并生成覆盖率报告
pnpm test:coverage
# 仅运行服务器测试
pnpm run test:server
# 仅运行前端测试
pnpm run test:web
# 运行单个测试文件
cd web && pnpm test -- --testPathPattern=page.test.tsx
cd server && pnpm test -- --testPathPattern=ai-service.test.js# 测试 RAG 准确性和质量评分
pnpm run rag:test-accuracy
# 运行综合 RAG 系统测试
pnpm run rag:test
# 验证加载数据的完整性和性能
pnpm run rag:verify欢迎提交 Pull Request 和 Issue!
- Fork 项目
- 创建功能分支
- 提交更改
- 推送到分支
- 创建 Pull Request
MIT License
- 项目链接: GitHub Repository
- 问题反馈: Issues
TeachAI - 让 AI 成为您的教学助手 🚀