
Role-Based School Management System with CBT
This is a comprehensive school management system with role-based access control and a Computer-Based Testing (CBT) module built with FastAPI and SQLite.
Features
- User Management - Register and manage users with different roles (admin, teacher, student)
- Role-Based Access Control - Different permissions based on user roles
- Student Management - Register, update, and track student information
- Teacher Management - Manage teacher profiles and course assignments
- Course Management - Create and manage courses, assign teachers
- Class Enrollment - Enroll students in courses, track academic progress
- Computer-Based Testing (CBT):
- Exam Creation - Create exams with different question types
- Question Management - Add, update, and delete questions and answer options
- Exam Taking - Students can take exams and submit answers
- Result Analysis - Automatic grading and score calculation
API Documentation
The API documentation is available at the /docs
or /redoc
endpoints when the application is running.
API Endpoints
Authentication
POST /api/v1/login/access-token
- Get JWT tokenPOST /api/v1/login/test-token
- Test token validation
Users
GET /api/v1/users/
- List usersPOST /api/v1/users/
- Create a new userGET /api/v1/users/{user_id}
- Get user detailsPUT /api/v1/users/{user_id}
- Update a userDELETE /api/v1/users/{user_id}
- Delete a user
Roles
GET /api/v1/roles/
- List rolesPOST /api/v1/roles/
- Create a new roleGET /api/v1/roles/{role_id}
- Get role detailsPUT /api/v1/roles/{role_id}
- Update a roleDELETE /api/v1/roles/{role_id}
- Delete a role
Students
GET /api/v1/students/
- List studentsPOST /api/v1/students/
- Create a new student profileGET /api/v1/students/{student_id}
- Get student detailsPUT /api/v1/students/{student_id}
- Update a studentDELETE /api/v1/students/{student_id}
- Delete a studentGET /api/v1/students/{student_id}/exams
- Get student's exam results
Teachers
GET /api/v1/teachers/
- List teachersPOST /api/v1/teachers/
- Create a new teacher profileGET /api/v1/teachers/{teacher_id}
- Get teacher detailsPUT /api/v1/teachers/{teacher_id}
- Update a teacherDELETE /api/v1/teachers/{teacher_id}
- Delete a teacherGET /api/v1/teachers/{teacher_id}/courses
- Get courses taught by teacher
Courses
GET /api/v1/courses/
- List coursesPOST /api/v1/courses/
- Create a new courseGET /api/v1/courses/{course_id}
- Get course detailsPUT /api/v1/courses/{course_id}
- Update a courseDELETE /api/v1/courses/{course_id}
- Delete a courseGET /api/v1/courses/{course_id}/exams
- Get exams for a course
Enrollments
GET /api/v1/enrollments/
- List enrollmentsPOST /api/v1/enrollments/
- Create a new enrollmentGET /api/v1/enrollments/{enrollment_id}
- Get enrollment detailsPUT /api/v1/enrollments/{enrollment_id}
- Update an enrollmentDELETE /api/v1/enrollments/{enrollment_id}
- Delete an enrollment
Exams (CBT)
GET /api/v1/exams/
- List examsGET /api/v1/exams/active
- Get active examsGET /api/v1/exams/available
- Get available examsPOST /api/v1/exams/
- Create a new examGET /api/v1/exams/{exam_id}
- Get exam details with questionsGET /api/v1/exams/{exam_id}/creator
- Get exam with creator infoPUT /api/v1/exams/{exam_id}
- Update an examDELETE /api/v1/exams/{exam_id}
- Delete an exam
Questions (CBT)
GET /api/v1/questions/
- List questionsPOST /api/v1/questions/
- Create a new questionGET /api/v1/questions/{question_id}
- Get question with optionsPUT /api/v1/questions/{question_id}
- Update a questionDELETE /api/v1/questions/{question_id}
- Delete a question
Question Options (CBT)
GET /api/v1/options/
- List question optionsPOST /api/v1/options/
- Create a new optionGET /api/v1/options/{option_id}
- Get option detailsPUT /api/v1/options/{option_id}
- Update an optionDELETE /api/v1/options/{option_id}
- Delete an option
Exam Results (CBT)
GET /api/v1/exam-results/
- List exam resultsPOST /api/v1/exam-results/
- Start a new exam attemptGET /api/v1/exam-results/{result_id}
- Get exam result with answersPUT /api/v1/exam-results/{result_id}
- Update an exam resultPOST /api/v1/exam-results/{result_id}/complete
- Complete an exam and calculate scoreDELETE /api/v1/exam-results/{result_id}
- Delete an exam result
Health Check
GET /health
- Check application health status
Environment Variables
The application uses the following environment variables:
SECRET_KEY
- Secret key for the application (default: auto-generated)JWT_SECRET_KEY
- Secret key for JWT token generation (default: same as SECRET_KEY)DATABASE_URL
- SQLite database URL (default:sqlite:////app/storage/db/db.sqlite
)ENVIRONMENT
- Application environment (default:development
)
Getting Started
Prerequisites
- Python 3.8+
- pip
Installation
- Clone the repository
- Install the dependencies:
pip install -r requirements.txt
- Run the migrations:
alembic upgrade head
- Start the application:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
- Open the API documentation at http://localhost:8000/docs
Database Schema
The application uses SQLite as the database. The main entities are:
- User - Base user model with authentication details
- Role - User roles (admin, teacher, student)
- Student - Student profile linked to a user
- Teacher - Teacher profile linked to a user
- Course - Course details and teacher assignment
- ClassEnrollment - Student enrollment in courses
- Exam - CBT exam definitions
- Question - Exam questions with different types
- QuestionOption - Answer options for questions
- ExamResult - Student exam attempts and scores
- StudentAnswer - Student answers to questions
CBT System
The Computer-Based Testing (CBT) system allows teachers to create exams with different question types, and students to take these exams online. The system supports:
- Multiple choice questions
- True/False questions
- Short answer questions
- Essay questions
Exams can be time-limited, have specific availability periods, and include different scoring mechanisms. After an exam is completed, the system automatically calculates the score based on the correct answers.
Security
The application uses JWT tokens for authentication and role-based authorization for controlling access to resources. Password hashing is implemented using bcrypt.
License
This project is licensed under the MIT License.