A comprehensive backend system for managing university operations including class routines, research papers, and hostel allocations.
- Add class routines with course details, teacher, day, and time
- View all routines
- Filter routines by day
- Add research papers with title, author, department, and year
- Update research paper status (Draft, Under Review, Published, Rejected)
- View all research papers
- Filter papers by department or status
- Add student hostel allocations
- View all hostel records
- Filter by hostel name or student ID
- Runtime: Node.js
- Framework: Express.js
- Database: MySQL
- Packages:
- mysql2 (MySQL client)
- body-parser (Parse request bodies)
- cors (Enable cross-origin requests)
University System/
βββ config/
β βββ db.js # Database connection configuration
βββ controllers/
β βββ routineController.js # Business logic for routines
β βββ researchPaperController.js # Business logic for research papers
β βββ hostelController.js # Business logic for hostel
βββ routes/
β βββ routineRoutes.js # API routes for routines
β βββ researchPaperRoutes.js # API routes for research papers
β βββ hostelRoutes.js # API routes for hostel
βββ database.sql # Database schema and sample data
βββ server.js # Main application entry point
βββ package.json # Project dependencies
βββ README.md # Documentation
-
Clone or download the project
cd "e:\Downloads\University System"
-
Install dependencies
npm install
-
Set up the database
a. Start your MySQL server
b. Open MySQL command line or MySQL Workbench
c. Run the database.sql file:
mysql -u root -p < database.sqlOr manually execute the SQL commands in
database.sql -
Configure database connection
Edit
config/db.jsand update the following with your MySQL credentials:host: 'localhost', user: 'root', // Your MySQL username password: '', // Your MySQL password database: 'university_management'
-
Start the server
npm start
For development with auto-restart:
npm run dev
-
Verify the server is running
You should see:
====================================================== University Management System API Server ====================================================== Server is running on port 3000 API URL: http://localhost:3000 ======================================================
http://localhost:3000
GET /Returns API information and available endpoints.
POST /api/routinesRequest Body:
{
"course": "Database Systems",
"teacher": "Dr. John Smith",
"day": "Monday",
"start_time": "09:00:00",
"end_time": "10:30:00"
}Success Response (201):
{
"success": true,
"message": "Routine added successfully",
"data": {
"id": 1,
"course": "Database Systems",
"teacher": "Dr. John Smith",
"day": "Monday",
"start_time": "09:00:00",
"end_time": "10:30:00"
}
}GET /api/routinesSuccess Response (200):
{
"success": true,
"count": 3,
"data": [
{
"id": 1,
"course": "Database Systems",
"teacher": "Dr. John Smith",
"day": "Monday",
"start_time": "09:00:00",
"end_time": "10:30:00",
"created_at": "2024-01-15T10:30:00.000Z"
}
]
}GET /api/routines/day/:dayExample:
GET /api/routines/day/MondaySuccess Response (200):
{
"success": true,
"day": "Monday",
"count": 2,
"data": [...]
}POST /api/research-papersRequest Body:
{
"title": "Machine Learning in Healthcare",
"author": "Dr. Alice Brown",
"department": "Computer Science",
"year": 2024,
"status": "Draft"
}Note: status is optional. Default value is "Draft". Valid values: Draft, Under Review, Published, Rejected
Success Response (201):
{
"success": true,
"message": "Research paper added successfully",
"data": {
"id": 1,
"title": "Machine Learning in Healthcare",
"author": "Dr. Alice Brown",
"department": "Computer Science",
"year": 2024,
"status": "Draft"
}
}PATCH /api/research-papers/:id/statusRequest Body:
{
"status": "Published"
}Example:
PATCH /api/research-papers/1/statusSuccess Response (200):
{
"success": true,
"message": "Research paper status updated successfully",
"data": {
"id": 1,
"status": "Published"
}
}GET /api/research-papersSuccess Response (200):
{
"success": true,
"count": 5,
"data": [...]
}GET /api/research-papers/department/:departmentExample:
GET /api/research-papers/department/Computer ScienceGET /api/research-papers/status/:statusExample:
GET /api/research-papers/status/PublishedPOST /api/hostelRequest Body:
{
"student_name": "John Doe",
"student_id": "CS2024001",
"hostel_name": "North Hall",
"room_number": "101",
"department": "Computer Science",
"allocated_date": "2024-01-15"
}Success Response (201):
{
"success": true,
"message": "Hostel student allocation added successfully",
"data": {
"id": 1,
"student_name": "John Doe",
"student_id": "CS2024001",
"hostel_name": "North Hall",
"room_number": "101",
"department": "Computer Science",
"allocated_date": "2024-01-15"
}
}GET /api/hostelSuccess Response (200):
{
"success": true,
"count": 10,
"data": [...]
}GET /api/hostel/hostel/:hostelNameExample:
GET /api/hostel/hostel/North HallGET /api/hostel/student/:studentIdExample:
GET /api/hostel/student/CS2024001Success Response (200):
{
"success": true,
"data": {
"id": 1,
"student_name": "John Doe",
"student_id": "CS2024001",
"hostel_name": "North Hall",
"room_number": "101",
"department": "Computer Science",
"allocated_date": "2024-01-15",
"created_at": "2024-01-15T10:30:00.000Z"
}
}Add a routine:
curl -X POST http://localhost:3000/api/routines \
-H "Content-Type: application/json" \
-d '{"course":"Web Development","teacher":"Prof. Sarah","day":"Tuesday","start_time":"10:00:00","end_time":"11:30:00"}'Get all routines:
curl http://localhost:3000/api/routines- Download and install Postman
- Create a new request
- Set the method (GET, POST, PATCH)
- Enter the URL (e.g.,
http://localhost:3000/api/routines) - For POST/PATCH requests:
- Go to "Body" tab
- Select "raw" and "JSON"
- Enter the JSON data
- Click "Send"
- Install the "REST Client" extension in VS Code
- Create a file named
test.http - Add your requests:
### Get API Info
GET http://localhost:3000
### Add Routine
POST http://localhost:3000/api/routines
Content-Type: application/json
{
"course": "Data Structures",
"teacher": "Dr. Mike Wilson",
"day": "Wednesday",
"start_time": "14:00:00",
"end_time": "15:30:00"
}
### Get All Routines
GET http://localhost:3000/api/routines- Click "Send Request" above each request
All endpoints return consistent error responses:
400 Bad Request - Missing or invalid parameters
{
"success": false,
"message": "All fields are required (course, teacher, day, start_time, end_time)"
}404 Not Found - Resource not found
{
"success": false,
"message": "Research paper not found"
}409 Conflict - Duplicate entry
{
"success": false,
"message": "Student ID already exists in hostel records"
}500 Internal Server Error - Server error
{
"success": false,
"message": "Failed to add routine",
"error": "Error details..."
}- id (INT, PRIMARY KEY, AUTO_INCREMENT)
- course (VARCHAR(100))
- teacher (VARCHAR(100))
- day (VARCHAR(20))
- start_time (TIME)
- end_time (TIME)
- created_at (TIMESTAMP)- id (INT, PRIMARY KEY, AUTO_INCREMENT)
- title (VARCHAR(255))
- author (VARCHAR(100))
- department (VARCHAR(100))
- year (INT)
- status (VARCHAR(50))
- created_at (TIMESTAMP)
- updated_at (TIMESTAMP)- id (INT, PRIMARY KEY, AUTO_INCREMENT)
- student_name (VARCHAR(100))
- student_id (VARCHAR(50), UNIQUE)
- hostel_name (VARCHAR(100))
- room_number (VARCHAR(20))
- department (VARCHAR(100))
- allocated_date (DATE)
- created_at (TIMESTAMP)1. "Cannot connect to MySQL database"
- Verify MySQL server is running
- Check database credentials in
config/db.js - Ensure the database
university_managementexists
2. "Port 3000 already in use"
- Change the port in
server.jsor set PORT environment variable:PORT=3001 npm start
3. "Module not found"
- Run
npm installto install all dependencies
4. "ER_NO_SUCH_TABLE"
- Run the
database.sqlfile to create tables
- Code Organization: The project follows MVC pattern with controllers and routes separated
- Database Connection: Uses connection pooling for better performance
- Async/Await: All database operations use modern async/await syntax
- Error Handling: Comprehensive try-catch blocks in all controllers
- Validation: Input validation on all POST/PATCH requests
- Comments: Well-documented code for easy understanding
- Add authentication and authorization (JWT)
- Implement pagination for large datasets
- Add search and filtering capabilities
- Create frontend dashboard
- Add email notifications
- Implement file upload for research papers
- Add unit and integration tests
ISC
University Management System API - Backend
For issues or questions:
- Check the troubleshooting section
- Review error messages in console
- Verify database connection and table structure
Happy Coding! π