This project is a scalable Full-Stack web application that automates the process of creating a weekly timetable in an educational institution. The application automatically generates weekly timetables while satisfying teacher availability, classroom occupancy, and lesson assignment constraints.
- Project Overview
- Key Features
- Architecture and Tech Stack
- Project Directory Structure
- Problem Approach and Algorithm Design
- API Overview
- Installation and Running Guide
- Database Schema
- Future Developments
- Highlights
Creating a timetable in educational institutions requires balancing hundreds of teachers, dozens of classes, and limited time slots. It is a Constraint Satisfaction Problem. SmartScheduler programmatically generates a collision-free weekly schedule, ensuring that all relational data is maintained in a centralized database.
- Teacher Management: Tracking teachers' branches and personal availability hours.
- Class Management: Definition of all physical or virtual classes in the school.
- Subject Management: Managing the subjects in the curriculum from a centralized list.
- Lesson Assignment: Determining which teacher will give which lesson to which classes and how many hours a week.
- Automatic Generation: Collision-free weekly plan fully compliant with teacher and class constraints with a single click.
- JWT Authentication
- Role-Based Authorization
- Protected Routes
- Automatic Token Expiration Handling
Next.js
│
REST API
│
FastAPI
│
SQLAlchemy
│
PostgreSQL
- Next.js 14 (App Router)
- Zustand
- TypeScript
- Tailwind CSS
- FastAPI
- SQLAlchemy
- Pydantic
- PostgreSQL / SQLite
timetable-scheduler/
├── backend/ # FastAPI Backend Application
│ ├── app/ # Main application code
│ │ ├── api/ # API endpoints (routers)
│ │ ├── core/ # Core configurations (security, config)
│ │ ├── models/ # SQLAlchemy database models
│ │ ├── schemas/ # Pydantic validation schemas
│ │ ├── services/ # Business logic and algorithm implementation
│ │ └── database.py # Database connection setup
│ ├── requirements.txt # Python dependencies
│ └── run.py # Application entry point
│
└── frontend/ # Next.js Frontend Application
├── src/ # Source code
│ ├── app/ # Next.js App Router pages and layouts
│ ├── components/ # Reusable React components (UI, Dashboard)
│ ├── lib/ # Utility functions and axios configuration
│ ├── store/ # Zustand global state stores
│ └── types/ # TypeScript type definitions
├── public/ # Static assets
├── tailwind.config.ts # Tailwind CSS configuration
└── package.json # Node.js dependencies
The timetable preparation problem falls into the Constraint Satisfaction Problem (CSP) category in computer science. In this project, the goal is to optimize teachers' busyness, classes' availability, and the weekly total hour load of lessons simultaneously.
Worst Case: O(A × S)
- A = Total Assignments (Lessons to be taught)
- S = Available Slots per week
The algorithm used in the application follows these steps:
- Preparation: All current assignments are fetched and randomized.
- Constraint Check: While searching for a suitable slot for each assignment, the following checks are made:
- Is the teacher in another class at that time? (Teacher Conflict)
- Is the teacher marked as "Busy" at that time? (Availability)
- Is the class full with another lesson at that time? (Class Conflict)
- Placement: If the slot is suitable, placement is made; otherwise, the next slot is tried.
- Error Handling: If placement cannot be made despite all slots being tried, a "Constraints are too tight" warning is given to the user.
- Why Not Genetic Algorithm?: Genetic algorithms are good for very large datasets (e.g., 5000+ students), but for small and medium-sized schools (e.g., 50 teachers, 20 classes), the Greedy approach gives results in milliseconds and reduces complexity.
- Relational Data Structure: Instead of JSON-based storage, data integrity was ensured by establishing Foreign Key relationships between
Teacher,Subject,Class, andCoursetables. - State Management (Zustand): Zustand was preferred to avoid Context API complexity and make authentication data accessible from anywhere in the app.
- Session Management: 401 Unauthorized errors returning from the API are caught centrally. When the user's session expires, the system automatically logs the user out.
Some of the core REST endpoints interacting with the client:
POST /token- Obtain JWT access tokenGET /teachers- Retrieve list of teachers and their availabilityPOST /teachers- Add a new teacherGET /classes- Retrieve list of all classesGET /courses- Retrieve lesson assignmentsPOST /schedule/generate- Trigger the automatic scheduling algorithmGET /schedule- Fetch the generated timetableDELETE /schedule- Clear the current schedule
- Python 3.9+
- Node.js 18+
- npm or yarn
cd backend
python -m venv venv
# For Windows:
venv\Scripts\activate
# For macOS/Linux:
source venv/bin/activate
pip install -r requirements.txtInitializing Database and Loading Seed:
# This command creates tables and loads sample data (4 classes, 8 teachers, etc.).
python -m app.seedStarting the Server:
uvicorn app.main:app --reloadcd frontend
npm install
npm run devThe application will start running at http://localhost:3000.
The application uses the CASCADE structure to maintain dependencies between data:
- Subjects: Lesson names (e.g., Math, Physics).
- Teachers: Teacher names and availability matrix.
- Classes: Class definitions (e.g., 9-A, 10-A).
- Courses: The bridge table representing a teacher giving a lesson to a class.
- Schedule Entries: Final schedule data generated by the algorithm.
Note: When you delete a teacher or a lesson, all related assignments and schedule entries are automatically cleared.
While this project more than meets the basic requirements, it can be enriched with the following in the future:
- Export Timetable: Downloading the generated schedule in PDF or Excel format.
- Student Management: Assigning students to classes and viewing their personal schedules.
- Constraint Optimization with Metaheuristic Algorithms: Implementing advanced search techniques to provide a more balanced distribution.
- Multi-School Support: Multiple institutions using the same infrastructure with the SaaS model.
- ✔ Constraint Satisfaction Scheduling
- ✔ FastAPI REST API
- ✔ Next.js App Router
- ✔ Zustand State Management
- ✔ PostgreSQL / SQLite
- ✔ Responsive Dashboard
- ✔ Automatic Timetable Generation
- ✔ JWT Authentication