# 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 token - `POST /api/v1/login/test-token` - Test token validation #### Users - `GET /api/v1/users/` - List users - `POST /api/v1/users/` - Create a new user - `GET /api/v1/users/{user_id}` - Get user details - `PUT /api/v1/users/{user_id}` - Update a user - `DELETE /api/v1/users/{user_id}` - Delete a user #### Roles - `GET /api/v1/roles/` - List roles - `POST /api/v1/roles/` - Create a new role - `GET /api/v1/roles/{role_id}` - Get role details - `PUT /api/v1/roles/{role_id}` - Update a role - `DELETE /api/v1/roles/{role_id}` - Delete a role #### Students - `GET /api/v1/students/` - List students - `POST /api/v1/students/` - Create a new student profile - `GET /api/v1/students/{student_id}` - Get student details - `PUT /api/v1/students/{student_id}` - Update a student - `DELETE /api/v1/students/{student_id}` - Delete a student - `GET /api/v1/students/{student_id}/exams` - Get student's exam results #### Teachers - `GET /api/v1/teachers/` - List teachers - `POST /api/v1/teachers/` - Create a new teacher profile - `GET /api/v1/teachers/{teacher_id}` - Get teacher details - `PUT /api/v1/teachers/{teacher_id}` - Update a teacher - `DELETE /api/v1/teachers/{teacher_id}` - Delete a teacher - `GET /api/v1/teachers/{teacher_id}/courses` - Get courses taught by teacher #### Courses - `GET /api/v1/courses/` - List courses - `POST /api/v1/courses/` - Create a new course - `GET /api/v1/courses/{course_id}` - Get course details - `PUT /api/v1/courses/{course_id}` - Update a course - `DELETE /api/v1/courses/{course_id}` - Delete a course - `GET /api/v1/courses/{course_id}/exams` - Get exams for a course #### Enrollments - `GET /api/v1/enrollments/` - List enrollments - `POST /api/v1/enrollments/` - Create a new enrollment - `GET /api/v1/enrollments/{enrollment_id}` - Get enrollment details - `PUT /api/v1/enrollments/{enrollment_id}` - Update an enrollment - `DELETE /api/v1/enrollments/{enrollment_id}` - Delete an enrollment #### Exams (CBT) - `GET /api/v1/exams/` - List exams - `GET /api/v1/exams/active` - Get active exams - `GET /api/v1/exams/available` - Get available exams - `POST /api/v1/exams/` - Create a new exam - `GET /api/v1/exams/{exam_id}` - Get exam details with questions - `GET /api/v1/exams/{exam_id}/creator` - Get exam with creator info - `PUT /api/v1/exams/{exam_id}` - Update an exam - `DELETE /api/v1/exams/{exam_id}` - Delete an exam #### Questions (CBT) - `GET /api/v1/questions/` - List questions - `POST /api/v1/questions/` - Create a new question - `GET /api/v1/questions/{question_id}` - Get question with options - `PUT /api/v1/questions/{question_id}` - Update a question - `DELETE /api/v1/questions/{question_id}` - Delete a question #### Question Options (CBT) - `GET /api/v1/options/` - List question options - `POST /api/v1/options/` - Create a new option - `GET /api/v1/options/{option_id}` - Get option details - `PUT /api/v1/options/{option_id}` - Update an option - `DELETE /api/v1/options/{option_id}` - Delete an option #### Exam Results (CBT) - `GET /api/v1/exam-results/` - List exam results - `POST /api/v1/exam-results/` - Start a new exam attempt - `GET /api/v1/exam-results/{result_id}` - Get exam result with answers - `PUT /api/v1/exam-results/{result_id}` - Update an exam result - `POST /api/v1/exam-results/{result_id}/complete` - Complete an exam and calculate score - `DELETE /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 1. Clone the repository 2. Install the dependencies: ```bash pip install -r requirements.txt ``` 3. Run the migrations: ```bash alembic upgrade head ``` 4. Start the application: ```bash uvicorn main:app --host 0.0.0.0 --port 8000 --reload ``` 5. 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.