db6271e36b8b26e36d9f0d797dd5f6a44ae2037f
Nest App
NestJS starter template with TypeORM, Swagger, validation, and security best practices.
Tech Stack
- NestJS v11
- TypeORM v0.3 + MySQL
- Swagger (OpenAPI)
- class-validator + class-transformer
- Helmet + ThrottlerModule
Project Setup
yarn install
Copy .env.example to .env and fill in your database credentials:
cp .env.example .env
Run
# development (watch mode)
yarn start:dev
# production
yarn build
yarn start:prod
API is available at http://localhost:3000/api/v1
Swagger docs at http://localhost:3000/api/docs
Database Migrations
This project uses TypeORM migrations to manage database schema. Do not use synchronize: true.
Generate a migration from Entity changes
After creating or modifying an Entity, generate a migration automatically:
yarn migration:generate --name=CreateUser
This compares your Entity definitions against the current database schema and generates the corresponding SQL.
Create an empty migration
For manual SQL (seed data, indexes, etc.):
yarn migration:create --name=SeedData
Run pending migrations
yarn migration:run
Revert the last migration
yarn migration:revert
Typical workflow
# 1. Create or modify an Entity file
# 2. Generate migration
yarn migration:generate --name=AddEmailToUser
# 3. Review the generated file in src/database/migrations/
# 4. Run the migration
yarn migration:run
Project Structure
src/
├── common/
│ ├── filters/ # Global exception filter
│ ├── interceptors/ # Response transform interceptor
│ └── interfaces/ # Shared interfaces (ApiResponse)
├── config/
│ └── database.config.ts
├── database/
│ ├── data-source.ts # TypeORM CLI data source
│ └── migrations/ # Migration files
├── app.module.ts
└── main.ts
Testing
# unit tests
yarn test
# test coverage
yarn test:cov
# e2e tests
yarn test:e2e
License
Description
Languages
TypeScript
87.5%
JavaScript
12.5%