This project serves as the backend for a University Management System, designed to streamline the management of student data, course registrations, and more. Built with Express.js and TypeScript, it emphasizes strong typing and modern asynchronous patterns for handling HTTP requests.
- 🔧 Express.js with TypeScript: Leverage the robustness of Express.js combined with the strong typing provided by TypeScript for scalable and maintainable backend development.
- ✅ Custom Validation and DTOs: Implements custom validation and Data Transfer Objects (DTOs) to ensure the integrity and correctness of request data.
- 📂 Absolute Imports: Simplifies import paths, enhancing readability and maintainability.
- 🔨 Custom Migration Utility: Manages database schema changes and data migrations to ensure consistency across environments.
- ⚙️ Reflective Middleware & Utilities: Includes asyncHandler for better error handling and structured constants for consistent validation messages.
- Node.js: Version >=18.0.0 (recommended).
- npm: Version >=8.0.0 (recommended).
Before running the application, make sure you create a .env file in the root of the project. This file is crucial for defining your environment variables, such as database credentials and API keys.
-
Clone the repository:
git clone https://github.com/Swiatlon/University-BN
-
Navigate to the project directory:
cd University-BN
-
Install NPM packages:
npm install
-
Generate a migration:
npm run migration:generate name"(optional)"
-
Apply migrations:
npm run migration:apply
-
Development mode with live reloads via
nodemon
:npm run dev
-
Build the application for production:
npm run build
-
Start the application post-build:
npm start:prod
This project includes a Docker Compose configuration designed for development and production environments. The docker-compose.yml
file simplifies running the application, database, and related services.
- Development & Production Profiles: Easily switch between development and production using Docker Compose profiles (
dev
orprod
). - Integrated Database: PostgreSQL is included as a service, pre-configured to work with the application.
- Modular Repository Structure: Works alongside the frontend repository for seamless orchestration in a unified environment.
-
Clone both frontend and backend repositories into the same parent directory:
git clone https://github.com/Swiatlon/University-FN University-FN git clone https://github.com/Swiatlon/University-BN University-BN
-
Ensure the parent directory looks like this:
Parent Directory/ ├── University-FN/ # Frontend repository └── University-BN/ # Backend repository
-
Place the provided
docker-compose.yml
file in the parent directory.
git clone https://github.com/Swiatlon/University-FN University-FN
git clone https://github.com/Swiatlon/University-BN University-BN
Ensure your directory looks like this:
Parent Directory/
├── docker-compose.yml # Unified orchestration file
├── University-FN/ # Frontend repository
└── University-BN/ # Backend repository
If docker-compose.yml
files exist in University-FN or University-BN repositories, remove them to avoid conflicts.
Before running the containers, generate migrations for your backend:
cd University-BN
npm run migration:generate <migration-name>
Run the following commands from the parent directory:
-
Development Mode:
docker-compose --profile dev up --build
-
Production Mode:
docker-compose --profile prod up --build
To stop and clean up all services:
docker-compose down
-
Frontend:
- Access at
http://localhost:5173
(development mode). - Built using Dockerfile in the
University-FN
repository.
- Access at
-
Backend:
- Access at
http://localhost:8800
. - Includes automatic database migrations and seeders for development.
- Access at
-
Database:
- PostgreSQL runs in a container, pre-configured for the backend.
A custom migration utility helps you streamline database migrations, ensuring schema changes are consistently applied across all environments.
- Automatic Migration Generation: Generates migration files based on TypeORM entity changes.
- Simplified Migration Execution: Apply or revert migrations with ease.
-
Generate Migrations: After updating entities, generate a migration file:
npm run migration:generate <migration-name>
-
Run Migrations: Apply migrations to the database:
npm run migration:run
-
Revert Migrations: Rollback the most recent migration:
npm run migration:revert
src/
: Contains all source files.controllers/
: Handles incoming requests and returns responses to clients.entities/
: Represents database tables and relations.services/
: Contains core business logic.dtos/
: Ensures type safety and validation for incoming data.constants/
: Stores validation rules and constants.utils/
: Provides utility functions and middleware.app.ts
: The entry point of the application.
dist/
: Contains compiled JavaScript files for production.
Guidelines for contributing to the project will be established, including code style, pull request procedures, and best practices.
The project is open-source under the MIT license.
Let me know if you'd like any further adjustments! 😊