Skip to content

unsigned6/university-backend

Repository files navigation

University Management System API

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.

🚀 Features

  • 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

🗄️ Database Structure

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"
Loading

🛠️ Technologies Used

  • Framework: NestJS with TypeScript
  • Database: SQLite with TypeORM
  • Validation: class-validator, class-transformer
  • Documentation: Swagger/OpenAPI
  • Testing: Jest
  • Linting: ESLint
  • Package Manager: npm

📋 Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn

⚡ Quick Start

1. Installation

# Clone the repository
git clone <repository-url>
cd university-backend

# Install dependencies
npm install

2. Environment Setup

The 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.

3. Run the Application

# Development mode with hot reload
npm run start:dev

# Production mode
npm run start:prod

# Debug mode
npm run start:debug

The API will be available at http://localhost:3000

4. Access API Documentation

Visit http://localhost:3000/api to view the interactive Swagger documentation.

📖 API Endpoints

Specialities

  • GET /specialities - Get all specialities
  • GET /specialities/:id - Get speciality by ID
  • POST /specialities - Create new speciality
  • PATCH /specialities/:id - Update speciality
  • DELETE /specialities/:id - Delete speciality

Students

  • GET /students - Get all students (with optional speciality filter)
  • GET /students/:id - Get student by ID
  • POST /students - Create new student
  • PATCH /students/:id - Update student
  • DELETE /students/:id - Delete student
  • POST /students/:id/subjects/:subjectId - Enroll student in subject
  • DELETE /students/:id/subjects/:subjectId - Remove student from subject

Teachers

  • GET /teachers - Get all teachers
  • GET /teachers/:id - Get teacher by ID
  • POST /teachers - Create new teacher
  • PATCH /teachers/:id - Update teacher
  • DELETE /teachers/:id - Delete teacher
  • POST /teachers/:id/subjects/:subjectId - Assign teacher to subject
  • DELETE /teachers/:id/subjects/:subjectId - Remove teacher from subject

Subjects

  • GET /subjects - Get all subjects (with optional teacher/semester filters)
  • GET /subjects/:id - Get subject by ID
  • POST /subjects - Create new subject
  • PATCH /subjects/:id - Update subject
  • DELETE /subjects/:id - Delete subject

📁 Project Structure

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

🧪 Testing

# 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

🔧 Development Commands

# Start development server
npm run start:dev

# Build for production
npm run build

# Lint code
npm run lint

# Format code
npm run format

📊 Sample Data

Create a Speciality

curl -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
  }'

Create a Student

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
  }'

🚀 Deployment

Production Build

npm run build
npm run start:prod

Environment Variables

Create a .env file for production configuration:

NODE_ENV=production
PORT=3000
DATABASE_URL=your_database_url

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙋‍♂️ Support

For support and questions:

  • Create an issue in the repository
  • Check the API documentation at /api endpoint
  • Review the project structure and examples above

🔄 Version History

  • v1.0.0 - Initial release with basic CRUD operations
  • v1.1.0 - Added relationship management
  • v1.2.0 - Enhanced validation and error handling

About

NestJS application for university generated with AI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published