Files

118 lines
2.1 KiB
Markdown

# 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
```bash
yarn install
```
Copy `.env.example` to `.env` and fill in your database credentials:
```bash
cp .env.example .env
```
## Run
```bash
# 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:
```bash
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.):
```bash
yarn migration:create --name=SeedData
```
### Run pending migrations
```bash
yarn migration:run
```
### Revert the last migration
```bash
yarn migration:revert
```
### Typical workflow
```bash
# 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
```bash
# unit tests
yarn test
# test coverage
yarn test:cov
# e2e tests
yarn test:e2e
```
## License
[MIT](https://github.com/nestjs/nest/blob/master/LICENSE)