A full-stack, AI-powered School Management System built with Next.js, MongoDB, and OpenRouter AI.
- Admin Panel (Principal + Teachers)
- Teacher Portal with AI-powered tools
- Student Portal with performance tracking
- Parent Portal with child monitoring
- Campus/Class/Section Management
- Role-based Authentication (NextAuth + JWT)
- AI Paper Generation - Generate MCQs, short questions, long questions, and full exam papers
- AI Auto-Grading - Automated grading with explanations
- Student Performance Forecast - Predict future performance based on past data
- AI Insights for Principal - Weak subjects, weak teachers, class improvement suggestions
- Early Warning System - Detect at-risk students
- AI Homework Generator - Generate practice questions
- Syllabus Delay Detection - Track and alert on syllabus progress
- Frontend: Next.js 14 (App Router), React, TypeScript
- Styling: Tailwind CSS, ShadCN UI
- Database: MongoDB Atlas
- Authentication: NextAuth.js (JWT)
- AI: OpenRouter (Free Models)
- meta-llama/llama-3.1-8b-instruct
- mistralai/mistral-7b-instruct
- google/gemma-7b
- qwen/qwen-2.5-7b-instruct
- Node.js 18+
- MongoDB Atlas account (or local MongoDB)
- OpenRouter API key (get one at https://openrouter.ai)
-
Clone the repository
git clone <repository-url> cd school-management-system
-
Install dependencies
npm install
-
Set up MongoDB
📖 See MONGODB_SETUP.md for detailed instructions
Quick Setup Options:
Option A: MongoDB Atlas (Cloud - Recommended)
- Sign up at mongodb.com/cloud/atlas
- Create a free cluster (M0 Sandbox)
- Create a database user (Security → Database Access)
- Whitelist your IP (Security → Network Access → Add IP Address → Allow from anywhere for dev)
- Get connection string (Connect → Connect your application)
- Format:
mongodb+srv://username:password@cluster.mongodb.net/school_management
Option B: Local MongoDB
- Install MongoDB locally (macOS:
brew install mongodb-community) - Start MongoDB:
brew services start mongodb-community - Connection string:
mongodb://localhost:27017/school_management
Using TablePlus? ✅ Yes! TablePlus fully supports MongoDB. See MONGODB_SETUP.md for TablePlus connection instructions.
-
Set up environment variables
# Create .env file touch .envEdit
.envand add your credentials:MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/school_management NEXTAUTH_URL=http://localhost:3000 NEXTAUTH_SECRET=your-secret-key-here OPENROUTER_API_KEY=your-openrouter-api-key OPENROUTER_BASE_URL=https://openrouter.ai/api/v1 JWT_SECRET=your-jwt-secret-key
For Local Development: You can use simple values (they're required but don't need to be secure for local dev):
NEXTAUTH_SECRET=local-dev-secret-key-12345 JWT_SECRET=local-jwt-secret-12345
For Production: Generate secure random strings:
openssl rand -base64 32
Note:
NEXTAUTH_SECRETis required even for local development as it's used in authentication middleware. -
Seed the database (optional)
npm run seed
This will create:
- 1 Principal
- 2 Teachers
- 2 Students
- 1 Parent
- 1 Admin
- Sample schools, classes, sections, and subjects
Default password for all users:
password123 -
Run the development server
npm run dev
-
Open your browser Navigate to http://localhost:3000
- Push your code to GitHub/GitLab/Bitbucket
- Ensure all environment variables are documented in
.env.example
- Go to vercel.com
- Sign in with your GitHub account
- Click "New Project"
- Import your repository
- Configure the project:
- Framework Preset: Next.js
- Root Directory:
./(default) - Build Command:
npm run build(default) - Output Directory:
.next(default)
In Vercel project settings, add all environment variables from your .env file:
MONGODB_URINEXTAUTH_URL(set to your Vercel domain, e.g.,https://your-app.vercel.app)NEXTAUTH_SECRET(generate a secure random string)OPENROUTER_API_KEYOPENROUTER_BASE_URL(https://openrouter.ai/api/v1)JWT_SECRET(generate a secure random string)
- Click "Deploy"
- Wait for the build to complete
- Your app will be live at
https://your-app.vercel.app
- Go to MongoDB Atlas dashboard
- Add your Vercel domain to the IP whitelist (or allow all IPs:
0.0.0.0/0) - Update connection string if needed
school-management-system/
├── app/
│ ├── admin/ # Admin portal pages
│ ├── teacher/ # Teacher portal pages
│ ├── student/ # Student portal pages
│ ├── parent/ # Parent portal pages
│ ├── api/ # API routes
│ │ ├── auth/ # NextAuth routes
│ │ └── ai/ # AI endpoints
│ ├── layout.tsx
│ └── page.tsx
├── components/
│ ├── ui/ # ShadCN UI components
│ └── providers.tsx
├── lib/
│ ├── models/ # Mongoose models
│ ├── ai.ts # OpenRouter AI utilities
│ ├── auth.ts # NextAuth configuration
│ ├── db.ts # MongoDB connection
│ └── middleware.ts # Route protection
├── scripts/
│ └── seed.ts # Database seeding script
└── types/
└── next-auth.d.ts # TypeScript definitions
POST /api/auth/signin- Sign inPOST /api/auth/signout- Sign out
POST /api/ai/generate-paper- Generate exam paperPOST /api/ai/grade- AI gradingPOST /api/ai/forecast- Performance forecastPOST /api/ai/insights- Generate insightsPOST /api/ai/homework- Generate homework questions
GET/POST /api/grades- Manage gradesGET/POST /api/attendance- Manage attendanceGET/POST /api/homework- Manage homework
- Login at
/admin/login - Manage schools, campuses, classes, and sections
- Assign teachers to classes
- View AI-generated insights and early warnings
- Login at
/teacher/login - Manage student grades
- Generate exam papers using AI
- Use AI grading assistant
- Track syllabus progress
- Assign homework (with AI generation)
- Mark attendance
- Login at
/student/login - View grades and performance
- Check AI performance forecast
- View attendance record
- Access homework and study materials
- Track syllabus progress
- Login at
/parent/login - Monitor child's performance
- View homework assignments
- Receive weak subject alerts
- Check attendance warnings
- Communicate with teachers
The system uses OpenRouter's free models with automatic fallback:
- Primary: meta-llama/llama-3.1-8b-instruct
- Fallback 1: mistralai/mistral-7b-instruct
- Fallback 2: google/gemma-7b
- Fallback 3: qwen/qwen-2.5-7b-instruct
If one model fails, the system automatically tries the next one.
| Variable | Description | Required |
|---|---|---|
MONGODB_URI |
MongoDB connection string | Yes |
NEXTAUTH_URL |
Application URL | Yes |
NEXTAUTH_SECRET |
Secret for NextAuth | Yes |
OPENROUTER_API_KEY |
OpenRouter API key | Yes |
OPENROUTER_BASE_URL |
OpenRouter API base URL | Yes |
JWT_SECRET |
JWT signing secret | Yes |
Yes, you can use TablePlus! TablePlus has excellent MongoDB support.
-
For MongoDB Atlas:
- Open TablePlus → Create new connection → MongoDB
- Host: Your cluster hostname (e.g.,
cluster0.xxxxx.mongodb.net) - Port:
27017 - User: Your database username
- Password: Your database password
- Database:
school_management - ✅ Enable SSL (required for Atlas)
-
For Local MongoDB:
- Host:
localhost - Port:
27017 - Database:
school_management - ❌ Disable SSL (not needed for local)
- Host:
-
Features in TablePlus:
- Browse collections (users, students, teachers, etc.)
- Edit documents directly
- Run MongoDB queries
- Export/Import data
- Visual database structure
📖 See MONGODB_SETUP.md for detailed TablePlus setup instructions
- Ensure your MongoDB Atlas cluster is running
- Check IP whitelist settings (Network Access in Atlas)
- Verify connection string format
- For TablePlus: Make sure SSL is enabled for Atlas, disabled for local
- Verify your API key is correct
- Check API rate limits
- Ensure you have credits/quota available
- Clear browser cookies
- Check
NEXTAUTH_SECRETis set - Verify
NEXTAUTH_URLmatches your domain
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is licensed under the MIT License.
For issues and questions:
- Open an issue on GitHub
- Check the documentation
- Review the code comments
- Next.js team for the amazing framework
- ShadCN for the UI components
- OpenRouter for AI capabilities
- MongoDB for the database solution
Built with ❤️ for educational institutions