A modern, intelligent timetable generation system built with Django, MongoDB, and Genetic Algorithms. Class Routine Optimizer helps educational institutions automatically generate optimal class schedules that satisfy both hard and soft constraints.
Class Routine Optimizer Django MongoDB Genetic Algorithm SQLite
π Data Management - Comprehensive CRUD operations for all timetable components:
- π¨βπ« Instructor Management - Add, edit, and manage faculty members
- π« Room Management - Manage classrooms with seating capacity tracking
- β° Meeting Time Management - Configure available time slots and days
- π Course Management - Create courses with instructor assignments and student capacity
- ποΈ Department Management - Organize courses by departments
- π Section Management - Manage class sections with course assignments
𧬠Genetic Algorithm Optimization - Advanced algorithm that:
- Satisfies hard constraints (no conflicts, room capacity, instructor availability)
- Optimizes soft constraints (preferred times, balanced schedules)
- Configurable population size and mutation rates
- Generates optimal timetables automatically
π Timetable Generation - Intelligent scheduling system:
- Automatic conflict detection and resolution
- Multi-constraint optimization
- Real-time generation progress
- Export to PDF format
π PDF Export - Download generated timetables as professional PDF documents
π Django Authentication - Secure user authentication system π JWT Token Support - RESTful API with JWT authentication π€ User Profiles - Manage user profiles with additional information π‘οΈ Role-Based Access - Secure admin dashboard access
π RESTful API - Complete REST API for all operations π API Documentation - Interactive API docs with drf-spectacular (Swagger/ReDoc) π CORS Support - Configured for frontend integration π Serializers - Comprehensive data validation and serialization
- Django 5.1 - Modern Python web framework
- Django REST Framework - Powerful REST API toolkit
- MongoDB - NoSQL database for flexible data storage (via mongoengine)
- SQLite - Relational database for Django's built-in features
- mongoengine - MongoDB ODM for Python
- JWT Authentication - Secure token-based authentication
- drf-spectacular - OpenAPI 3.0 schema generation
- python-decouple - Environment variable management
- xhtml2pdf - PDF generation from HTML templates
- Pillow - Image processing
- django-cors-headers - CORS handling for API
- Repository Pattern - Data access abstraction layer
- Service Layer - Business logic separation
- Strategy Pattern - Pluggable generation algorithms
- Factory Pattern - Dynamic strategy creation
- Python 3.8+ (Python 3.13 recommended)
- MongoDB (local installation or MongoDB Atlas)
- pip (Python package manager)
- Virtual environment (recommended)
- Clone the repository
git clone https://github.com/yourusername/Class-Routine_Optimizer.git
cd Class-Routine_Optimizer- Create and activate virtual environment
python -m venv venv
# On macOS/Linux
source venv/bin/activate
# On Windows
venv\Scripts\activate- Install dependencies
cd projttgs
pip install -r requirements.txt- Set up environment variables
Create a .env file in the projttgs directory:
# Django Settings
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
# MongoDB Configuration
MONGODB_NAME=class_routine_db
MONGODB_HOST=localhost
MONGODB_PORT=27017
MONGODB_USER=
MONGODB_PASSWORD=
MONGODB_AUTH_SOURCE=admin
# CORS Settings (for frontend integration)
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000- Set up the database
# Run Django migrations (for SQLite)
python manage.py migrate
# MongoDB will be automatically connected when the server starts- Create a superuser (optional)
python manage.py createsuperuser- Run the development server
python manage.py runserver- Open your browser
Navigate to http://127.0.0.1:8000/
Class-Routine_Optimizer/
βββ projttgs/ # Main project directory
β βββ accounts/ # User authentication and profiles
β β βββ services/ # Authentication and user services
β β βββ repositories/ # Data access layer
β β βββ serializers.py # API serializers
β β
β βββ core/ # Core utilities and base classes
β β βββ repositories/ # Base repository pattern
β β βββ services/ # Base service classes
β β βββ exceptions.py # Custom exceptions
β β
β βββ routine/ # Timetable generation app
β β βββ models.py # MongoDB models (mongoengine)
β β βββ repositories/ # Data repositories
β β β βββ course_repository.py
β β β βββ department_repository.py
β β β βββ instructor_repository.py
β β β βββ meeting_time_repository.py
β β β βββ room_repository.py
β β β βββ section_repository.py
β β βββ services/ # Business logic services
β β β βββ routine_generation_service.py
β β β βββ timetable_service.py
β β β βββ pdf_generation_service.py
β β βββ strategies/ # Generation algorithms
β β β βββ base_strategy.py
β β β βββ genetic_algorithm_strategy.py
β β βββ factories/ # Factory pattern implementations
β β β βββ generation_factory.py
β β βββ serializers.py # API serializers
β β
β βββ projttgs/ # Django project settings
β β βββ settings.py # Main configuration
β β βββ urls.py # URL routing
β β βββ wsgi.py # WSGI configuration
β β
β βββ templates/ # HTML templates
β βββ static/ # Static files (CSS, JS, images)
β βββ requirements.txt # Python dependencies
β βββ manage.py # Django management script
β
βββ README.md # Project documentation
The timetable generation uses a sophisticated genetic algorithm that:
- Population Initialization - Creates diverse initial schedules
- Fitness Evaluation - Scores schedules based on constraint satisfaction
- Selection - Chooses best-performing schedules for reproduction
- Crossover - Combines features from parent schedules
- Mutation - Introduces random variations to explore solution space
- Convergence - Iteratively improves until optimal solution is found
Data access is abstracted through repositories:
- Separation of Concerns - Business logic separated from data access
- Testability - Easy to mock and test
- Flexibility - Can switch data sources without changing business logic
Business logic is encapsulated in service classes:
- RoutineGenerationService - Orchestrates timetable generation
- TimetableService - Manages timetable operations
- PDFGenerationService - Handles PDF export functionality
# Run development server
python manage.py runserver
# Run migrations
python manage.py migrate
# Create migrations
python manage.py makemigrations
# Create superuser
python manage.py createsuperuser
# Collect static files
python manage.py collectstatic
# Run tests
python manage.py test
# Access Django shell
python manage.py shell
# Access Django shell with MongoDB models
python manage.py shell_plusOnce the server is running, access the interactive API documentation:
- Swagger UI: http://127.0.0.1:8000/api/schema/swagger-ui/
- ReDoc: http://127.0.0.1:8000/api/schema/redoc/
The application uses a hybrid database approach:
- Room - Classroom information
- Instructor - Faculty members
- MeetingTime - Available time slots
- Course - Course details with instructor assignments
- Department - Academic departments
- Section - Class sections with course assignments
- User - Django authentication users
- Profile - User profile information
- Sessions - Django session management
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is open source and available under the MIT License.
Maruf Hossain
- GitHub: @MarufPulok
- LinkedIn: Maruf Hossain
- Built with Django and Django REST Framework
- Genetic algorithm implementation for constraint optimization
- MongoDB for flexible data storage
- UI components styled with Bootstrap
- PDF generation powered by xhtml2pdf
If you find this project helpful, please consider giving it a star!
Note: This project uses both MongoDB (for timetable data) and SQLite (for Django's built-in features). Make sure MongoDB is running before starting the development server.