HotSpring is a modern TypeScript framework built on top of Express.js that provides dependency injection, decorators for routing, and structured application organization. It simplifies building scalable web applications by offering Spring-style annotations and automated component scanning.
The framework features automatic dependency injection through Inversify, decorator-based routing similar to Spring Boot, component scanning for automatic registration of services and controllers, and a robust logging system. It provides a clean architecture pattern separating concerns into controllers, services, and repositories while maintaining type safety through TypeScript.
.
├── docs/ # Documentation files
├── src/ # Source code
│ ├── @type/ # TypeScript type definitions
│ ├── common/ # Common utilities and annotations
│ │ ├── annotations/
│ │ ├── enums/
│ ├── core/ # Core framework implementation
│ │ ├── exception/
│ │ ├── framework/
│ ├── exemples/ # Example implementations
│ └── repository/ # Repository implementations
- Node.js (v16 or higher)
- TypeScript (v4.5 or higher)
- npm or yarn package manager
# Clone the repository
git clone <repository-url>
cd hotspring
# Install dependencies
npm install
# For yarn users
yarn install
- Create a new controller:
import { Controller, Get } from '@common/annotations';
@Controller('/api')
export class UserController {
@Get('/users')
public async getUsers() {
return { users: [] };
}
}
- Create a main application file:
import { HotApplication, HotSpringApplication } from '../common';
// Application will automatically scan and register components
@HotSpringApplication()
export class Main {
public static async start (...args: string[]): Promise<void> {
void HotApplication.run(Main, args);
}
}
- Run the application:
npm run dev
- Creating a Service with Dependency Injection:
import { Service } from '@common/annotations';
@Service()
export class UserService {
public async findAll() {
return [];
}
}
@Controller('/api')
export class UserController {
constructor(private userService: UserService) {}
@Get('/users')
public async getUsers() {
return await this.userService.findAll();
}
}
- Component Scanning Issues
- Problem: Components not being detected
- Solution: Ensure components are decorated with @Controller, @Service, or @Repository
- Debug: Enable debug logging in Logger configuration
- Dependency Injection Errors
- Problem: "No matching bindings found"
- Solution: Verify that all dependencies are properly decorated and included in scanBasePackages
- Debug: Check container bindings using:
console.log(container.getAll());
HotSpring follows a traditional three-tier architecture where requests flow through controllers, services, and repositories. The framework handles dependency injection and request routing automatically.
Client Request → Controller → Service → Repository → Database
↑ ↓ ↓ ↓ ↓
└────────────────────Response────────────────────┘
Component interactions:
- Controllers receive HTTP requests and handle routing
- Services contain business logic and orchestrate operations
- Repositories handle data access and persistence
- Dependency injection manages component lifecycle and dependencies
- Express middleware processes requests before reaching controllers
- Error handling is centralized through the exception system
- Logging occurs at each layer for debugging and monitoring
The framework provides the following core infrastructure:
- Bootstrap: Configures Express application with middleware and error handling
- Middleware: Configures CORS, body parsing, security headers, and logging
- Error Handling: Global error handling and status code mapping
- Container: Inversify-based IoC container for dependency management
- Component Scanning: Automatic discovery and registration of annotated classes
- Lifecycle Management: Handles component instantiation and dependency resolution
- Winston-based logging system with customizable formats
- Support for console and file-based logging
- Different log levels (DEBUG, INFO, WARN, ERROR)