A comprehensive NestJS-based REST API for managing university data including students, teachers, subjects, and specialities. Built with TypeScript, TypeORM, and SQLite for efficient university administration.
- Student Management: Complete CRUD operations for student records with speciality relationships
- Teacher Management: Full teacher profile management with subject assignments
- Subject Management: Subject catalog with teacher and student associations
- Speciality Management: Academic program management with student enrollments
- Relationship Management: Many-to-many relationships between students/subjects and teachers/subjects
- Data Validation: Comprehensive input validation using class-validator
- API Documentation: Auto-generated Swagger/OpenAPI documentation
- Database Integration: TypeORM with SQLite for development
erDiagram
SPECIALITY {
uuid id PK
string name
string description
string code
int durationYears
datetime createdAt
datetime updatedAt
}
STUDENT {
uuid id PK
string firstName
string lastName
string email
string studentNumber
string phone
date dateOfBirth
date enrollmentDate
int currentYear
datetime createdAt
datetime updatedAt
}
TEACHER {
uuid id PK
string firstName
string lastName
string email
string phone
string department
string position
date hireDate
datetime createdAt
datetime updatedAt
}
SUBJECT {
uuid id PK
string name
string description
string code
int credits
int semester
datetime createdAt
datetime updatedAt
}
STUDENT_SUBJECTS {
uuid student_id FK
uuid subject_id FK
}
TEACHER_SUBJECTS {
uuid teacher_id FK
uuid subject_id FK
}
SPECIALITY ||--o{ STUDENT : "has many"
STUDENT }o--o{ SUBJECT : "enrolled in"
TEACHER }o--o{ SUBJECT : "teaches"
- Framework: NestJS with TypeScript
- Database: SQLite with TypeORM
- Validation: class-validator, class-transformer
- Documentation: Swagger/OpenAPI
- Testing: Jest
- Linting: ESLint
- Package Manager: npm
- Node.js (v16 or higher)
- npm or yarn
# Clone the repository
git clone <repository-url>
cd university-backend
# Install dependencies
npm installThe application uses SQLite by default, so no additional database setup is required. The database file (university.db) will be created automatically in the project root.
# Development mode with hot reload
npm run start:dev
# Production mode
npm run start:prod
# Debug mode
npm run start:debugThe API will be available at http://localhost:3000
Visit http://localhost:3000/api to view the interactive Swagger documentation.
GET /specialities- Get all specialitiesGET /specialities/:id- Get speciality by IDPOST /specialities- Create new specialityPATCH /specialities/:id- Update specialityDELETE /specialities/:id- Delete speciality
GET /students- Get all students (with optional speciality filter)GET /students/:id- Get student by IDPOST /students- Create new studentPATCH /students/:id- Update studentDELETE /students/:id- Delete studentPOST /students/:id/subjects/:subjectId- Enroll student in subjectDELETE /students/:id/subjects/:subjectId- Remove student from subject
GET /teachers- Get all teachersGET /teachers/:id- Get teacher by IDPOST /teachers- Create new teacherPATCH /teachers/:id- Update teacherDELETE /teachers/:id- Delete teacherPOST /teachers/:id/subjects/:subjectId- Assign teacher to subjectDELETE /teachers/:id/subjects/:subjectId- Remove teacher from subject
GET /subjects- Get all subjects (with optional teacher/semester filters)GET /subjects/:id- Get subject by IDPOST /subjects- Create new subjectPATCH /subjects/:id- Update subjectDELETE /subjects/:id- Delete subject
src/
├── common/ # Shared utilities and decorators
│ ├── decorators/
│ ├── dto/
│ ├── guards/
│ └── pipes/
├── entities/ # Database entities
│ ├── speciality.entity.ts
│ ├── student.entity.ts
│ ├── teacher.entity.ts
│ ├── subject.entity.ts
│ └── index.ts
├── modules/ # Feature modules
│ ├── specialities/
│ │ ├── dto/
│ │ ├── specialities.controller.ts
│ │ ├── specialities.service.ts
│ │ └── specialities.module.ts
│ ├── students/
│ ├── teachers/
│ └── subjects/
├── app.module.ts # Root application module
└── main.ts # Application entry point
# Unit tests
npm run test
# End-to-end tests
npm run test:e2e
# Test coverage
npm run test:cov
# Watch mode
npm run test:watch# Start development server
npm run start:dev
# Build for production
npm run build
# Lint code
npm run lint
# Format code
npm run formatcurl -X POST http://localhost:3000/specialities \
-H "Content-Type: application/json" \
-d '{
"name": "Computer Science",
"description": "Bachelor of Computer Science program",
"code": "CS",
"durationYears": 4
}'curl -X POST http://localhost:3000/students \
-H "Content-Type: application/json" \
-d '{
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"studentNumber": "CS2024001",
"phone": "+1234567890",
"dateOfBirth": "2000-05-15",
"enrollmentDate": "2024-09-01",
"currentYear": 1,
"specialityId": 1
}'npm run build
npm run start:prodCreate a .env file for production configuration:
NODE_ENV=production
PORT=3000
DATABASE_URL=your_database_url- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Check the API documentation at
/apiendpoint - Review the project structure and examples above
- v1.0.0 - Initial release with basic CRUD operations
- v1.1.0 - Added relationship management
- v1.2.0 - Enhanced validation and error handling