A web application that optimally assigns students to classes based on their preferences using constraint satisfaction algorithms (PuLP library).
- Student Management: Add students manually or import from Excel
- Preference System: "Wants with" and "Doesn't want with" preferences
- Constraint Satisfaction: Uses PuLP optimization algorithm
- Results Visualization: Clear display of class assignments and statistics
- Multiple Export Formats: Excel, CSV, JSON, and PDF
- Configuration Backup: Save and restore complete configurations
- Framework: Next.js 14+ with App Router
- Language: TypeScript (strict mode)
- Styling: Tailwind CSS v3
- State Management: React Context API
- File Handling: SheetJS (xlsx)
- Framework: Flask (Python)
- Algorithm: PuLP (Linear Programming)
- API: RESTful endpoints with CORS
- Port: 5001 (to avoid macOS AirPlay conflict on port 5000)
- Python 3.8+
- Node.js 18+
- npm or yarn
# Navigate to backend directory
cd python-backend
# Activate virtual environment
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies (if not already done)
pip install -r requirements.txt
# Start the server (Option A - recommended)
./start.sh
# OR Option B - manual start
export PORT=5001 # Windows: set PORT=5001
python app.pyBackend will run on: http://localhost:5001
# Open new terminal, navigate to frontend directory
cd student-class-matcher
# Install dependencies (if not already done)
npm install
# Start development server
PORT=3002 npm run devFrontend will run on: http://localhost:3002
Backend Port (5001):
- Set in
python-backend/app.pyviaPORTenvironment variable - Default: 5001 (avoids macOS AirPlay on port 5000)
Frontend Port (3002):
- Set via
PORTenvironment variable when starting - Default: 3000 (we use 3002 to avoid conflicts)
API URL:
- Configured in
student-class-matcher/.env.local - Default:
NEXT_PUBLIC_API_URL=http://localhost:5001
If you need to use different ports:
-
Backend:
export PORT=5002 # Your desired port python app.py
-
Frontend:
- Update
student-class-matcher/.env.local:NEXT_PUBLIC_API_URL=http://localhost:5002 - Restart frontend:
PORT=3003 npm run dev
- Update
Bob_Matching/
βββ python-backend/
β βββ venv/ # Python virtual environment
β βββ app.py # Flask API server
β βββ solver.py # PuLP algorithm implementation
β βββ models.py # Data models
β βββ test_solver.py # Backend tests
β βββ requirements.txt # Python dependencies
β βββ start.sh # Startup script
β
βββ student-class-matcher/
β βββ app/ # Next.js app directory
β β βββ page.tsx # Home page
β β βββ configure/ # Configuration page
β β βββ results/ # Results page
β β βββ layout.tsx # Root layout
β β βββ globals.css # Global styles
β βββ components/ # React components
β β βββ FileUpload.tsx
β β βββ StudentForm.tsx
β β βββ StudentList.tsx
β βββ contexts/ # React contexts
β β βββ ConfigurationContext.tsx
β β βββ ResultsContext.tsx
β βββ lib/ # Utility libraries
β β βββ apiClient.ts
β β βββ xlsxParser.ts
β β βββ exportUtils.ts
β βββ types/ # TypeScript types
β βββ .env.local # Environment variables
β βββ package.json # Node dependencies
β
βββ TESTING_GUIDE.md # Complete testing guide
βββ ALGORITHM_ANALYSIS.md # Algorithm documentation
βββ XLSX_STRUCTURE.md # Excel format specification
βββ README.md # This file
See TESTING_GUIDE.md for comprehensive testing instructions including:
- 24 detailed test cases
- Setup verification
- Troubleshooting guide
- Success criteria
Quick test:
# Backend tests
cd python-backend
source venv/bin/activate
python test_solver.py
# Frontend (open browser)
# Navigate to http://localhost:3002
# Follow test cases in TESTING_GUIDE.mdStudents can be imported from Excel files with the following structure:
| Student_ID | Student_Name | Wants_With | Doesnt_Want_With |
|---|---|---|---|
| S001 | John Doe | S002, S003 | S004 |
| S002 | Jane Smith | S001 |
See XLSX_STRUCTURE.md for complete specification.
The application uses PuLP (Python Linear Programming) to solve the class assignment problem as a constraint satisfaction problem.
Constraints:
- Each student assigned to exactly one class
- Class sizes within min/max bounds
- "Wants with" preferences satisfied (students in same class)
- "Doesn't want with" preferences satisfied (students in different classes)
See ALGORITHM_ANALYSIS.md for detailed algorithm documentation.
Problem: macOS AirPlay Receiver uses port 5000
Solution: Backend now uses port 5001 by default. If you still see this error:
- Disable AirPlay Receiver in System Settings
- Or use a different port (see Configuration section)
Symptoms: Frontend shows "Failed to run algorithm" error
Solutions:
- Verify backend is running:
curl http://localhost:5001/api/health - Check
.env.localhas correct API URL - Restart both frontend and backend
- Check terminal for error messages
Problem: ModuleNotFoundError: No module named 'flask'
Solution:
cd python-backend
source venv/bin/activate
pip install -r requirements.txtProblem: Type errors in VS Code
Solution:
cd student-class-matcher
npm install
# Restart VS Code TypeScript server: Cmd+Shift+P β "TypeScript: Restart TS Server"GET http://localhost:5001/api/health
POST http://localhost:5001/api/solve
Content-Type: application/json
{
"numClasses": 3,
"minClassSize": 5,
"maxClassSize": 10,
"students": [...]
}
-
Configure Students
- Add manually or import from Excel
- Set preferences (wants with / doesn't want with)
-
Set Class Parameters
- Number of classes
- Minimum class size
- Maximum class size
-
Run Algorithm
- Click "Run Algorithm"
- Wait for optimization (usually <5 seconds)
-
View Results
- See class assignments
- Check statistics
- Review any violations
-
Export
- Download results (Excel, CSV, PDF)
- Save configuration for later use
This project follows a phased development approach:
- Phase 1-8: Complete β
- Phase 9: Data Persistence (Optional)
- Phase 10: Testing & QA
- Phase 11: Documentation & Deployment
- Phase 12: Final Review
This project was built with Bob (AI Assistant).
For issues or questions:
- Check TESTING_GUIDE.md
- Review error messages in terminal
- Verify all prerequisites are installed
- Ensure both frontend and backend are running
Made with β€οΈ using Next.js, Flask, and PuLP