This project is a robust Student Credit Application System built with TypeScript, Express, and TypeORM. It provides a secure and efficient platform for students to register, login, and apply for credit, with an admin interface for managing applications.
- Student registration and authentication
- Credit application submission and management
- Admin dashboard for overseeing credit applications
- Secure JWT-based authentication
- RESTful API design
- Comprehensive test coverage
- Swagger API documentation
- Backend: Node.js with Express
- Language: TypeScript
- Database: PostgreSQL with TypeORM
- Testing: Jest
- Authentication: JWT
- API Documentation: Swagger
- Code Quality: ESLint, Prettier
- Version Control: Git
The project follows a clean, modular architecture:
src/
├── config/ # Configuration files
├── controllers/ # Request handlers
├── middleware/ # Custom middleware
├── models/ # Database models
├── routes/ # API routes
├── services/ # Business logic
├── utils/ # Utility functions
└── types/ # TypeScript type definitions
- Separation of Concerns: The project is structured into distinct layers (controllers, services, models) for better maintainability.
- DRY (Don't Repeat Yourself): Common functionalities are abstracted into reusable services and utilities.
- SOLID Principles: The codebase adheres to SOLID principles, particularly the Single Responsibility Principle in the service layer.
- Error Handling: Consistent error handling across the application with custom error classes.
- Code Style: Enforced consistent code style using ESLint and Prettier.
- Repository Pattern: Used in the service layer to abstract database operations.
- Dependency Injection: Controllers depend on service interfaces, allowing for easier testing and flexibility.
- Middleware Pattern: Custom middleware for authentication and request processing.
- Comprehensive unit tests for controllers, services, and middleware.
- Integration tests for API endpoints.
- Use of mocks and stubs for isolated unit testing.
- ESLint: For identifying and fixing code quality issues.
- Prettier: For consistent code formatting.
- Husky: Pre-commit hooks to ensure code quality before commits.
To set up and run this project locally, follow these steps:
-
Clone the repository
git clone https://github.com/helioLJ/student-credit-application-system.git cd student-credit-application-system
-
Install dependencies
npm install
-
Set up the database using Docker
- Run the following command to start the database container:
docker-compose up -d
- Run the following command to start the database container:
-
Configure environment variables
- Copy the
.env.example
file to.env
:cp .env.example .env
- Open the
.env
file and update the following variables:DB_HOST=localhost DB_PORT=5432 DB_USERNAME=your_postgres_username DB_PASSWORD=your_postgres_password DB_NAME=your_database_name JWT_SECRET=your_jwt_secret
- Copy the
ormconfig.example.json
file toormconfig.json
:cp ormconfig.example.json ormconfig.json
- Open the
ormconfig.json
file and update the database credentials.{
"type": "postgres", "host": "localhost", "port": 5432, "username": "myapp_user", "password": "myapp_password", "database": "myapp_db", "synchronize": true, "logging": true, "entities": ["src/entities//*.ts"], "migrations": ["src/migrations//.ts"], "subscribers": ["src/subscribers/**/.ts"], "cli": { "entitiesDir": "src/entities", "migrationsDir": "src/migrations", "subscribersDir": "src/subscribers" } }
- Copy the
-
Run database migrations
npm run migration:run
-
Seed the database (optional)
npm run seed
-
Start the development server
npm run dev
The server should now be running on http://localhost:3000
(or the port specified in your .env
file).
This project uses Jest for testing. To run the tests, follow these steps:
-
Run all tests
npm test
-
Run tests with coverage report
npm run test:coverage
-
Run tests in watch mode (for development)
npm run test:watch
After starting the server, you can access the Swagger API documentation at:
http://localhost:3000/api-docs
This provides an interactive interface to explore and test the API endpoints.
- Repository Layer: Implement a dedicated repository layer to abstract database operations from services.
- Data Transfer Objects (DTOs): Introduce DTOs for improved type safety and data validation.
- Validation Layer: Implement request validation using libraries like Joi or class-validator.
- Enhanced Error Handling: Centralize error handling with custom error classes and consistent error responses.
- Logging System: Implement a robust logging system using Winston or similar libraries.
- Configuration Management: Centralize configuration using environment variables and dotenv.
- Expanded Middleware: Add more middleware for request logging, CORS handling, etc.
- Utils/Helpers Layer: Create a dedicated layer for utility functions and helper methods.
- Constants Layer: Implement a constants file for storing application-wide constant values.