Welcome to the Express TypeScript Clean Architecture API β A robust TypeScript-based backend boilerplate for building scalable web applications.
This project is a modern, feature-rich backend starter kit built with TypeScript and Express.js. It implements best practices, clean architecture principles, and provides essential features needed for building production-ready APIs. The architecture follows SOLID principles and emphasizes maintainability, scalability, and testability.
- Node.js (>= 20.x)
- PostgreSQL (>= 13)
- npm or yarn
- Docker (optional, for containerization)
- β‘ TypeScript & Express.js - Type-safe backend development
- ποΈ Clean Architecture - Well-organized folder structure for scalability
- π Authentication - JWT-based authentication system
- π TypeORM - Elegant database operations with TypeORM
- π― Dependency Injection - Using InversifyJS for better modularity
- π Migrations - Database version control
- π§ͺ Environment Configuration - Separate configs for different environments
- π¨ Code Quality - ESLint and Prettier integration
src/
βββ config/ # Application configuration files
βββ constants/ # Constants, enums, and type definitions
βββ controllers/ # HTTP request handlers
βββ decorators/ # Custom TypeScript decorators
βββ entities/ # TypeORM entity definitions
βββ exceptions/ # Custom exception classes
βββ interfaces/ # TypeScript interfaces and types
βββ mappers/ # Data transformation and mapping
βββ middlewares/ # Express middleware functions
βββ migrations/ # Database migration scripts
βββ repositories/ # Data access layer implementations
β βββ contracts/ # Repository interfaces
β βββ implements/ # Repository implementations
βββ requests/ # Request validation schemas
βββ services/ # Business logic layer
β βββ contracts/ # Service interfaces
β βββ implements/ # Service implementations
βββ seeders/ # Database seed data
βββ subscribers/ # Event subscribers
βββ types/ # Additional TypeScript type definitions
βββ utils/ # Utility functions and helpers
βββ validators/ # Custom validation rules
data-source.ts- TypeORM configuration and database connectioninversify-config.ts- Dependency injection container setupindex.ts- Application entry point
- Clone the repository
git clone https://github.com/vdhuyme/vdhuyme-api.git
cd vdhuyme-api- Install dependencies
npm install- Environment Setup
cp .env.example .envConfigure your .env file with the following variables:
NODE_ENV=development
PORT=3000
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=your_username
DB_PASSWORD=your_password
DB_DATABASE=your_database
JWT_SECRET=your_jwt_secret- Start Development Server
npm run devdocker-compose up -d- Build for production
npm run build- First-time setup
npm run production:first- Regular production deployment
npm run productionnpm run dev- Start development server with hot reloadnpm run lint- Run ESLint code analysisnpm run format- Format code with Prettier
npm run db:create- Create databasenpm run migration:generate- Generate new migrationnpm run migration:run- Run pending migrationsnpm run migration:revert- Revert last migrationnpm run seed- Seed database with initial data
npm run build- Build the projectnpm run start- Start the production servernpm run production- Build and start production servernpm run production:first- First-time production setup with migrations
POST /api/auth/register- Register new userPOST /api/auth/login- User loginPOST /api/auth/refresh-token- Refresh JWT tokenPOST /api/auth/change-password- Change user password
GET /api/posts- Get all postsGET /api/posts/:id- Get post by IDPOST /api/posts- Create new postPUT /api/posts/:id- Update postDELETE /api/posts/:id- Delete post
GET /api/categories- Get all categoriesPOST /api/categories- Create categoryPUT /api/categories/:id- Update categoryDELETE /api/categories/:id- Delete category
GET /api/users/profile- Get user profilePUT /api/users/profile- Update user profilePUT /api/users/:id/status- Update user status
...
- TypeScript 5.x
- Express.js 4.x
- Node.js 20+
- PostgreSQL 13+
- TypeORM 0.3.x
- JSON Web Tokens (JWT)
- bcrypt for password hashing
- Express-validator for request validation
- InversifyJS for Dependency Injection
- Clean Architecture principles
- SOLID principles
- Repository Pattern
- ESLint for code linting
- Prettier for code formatting
- Jest for unit testing
- Supertest for API testing
- Docker & Docker Compose
- GitHub Actions for CI/CD
- PM2 for process management
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ by Vo Duc Huy