|
1 | | -<p align="center"> |
2 | | - <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a> |
3 | | -</p> |
4 | | - |
5 | | -[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 |
6 | | -[circleci-url]: https://circleci.com/gh/nestjs/nest |
7 | | - |
8 | | - <p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p> |
9 | | - <p align="center"> |
10 | | -<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a> |
11 | | -<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a> |
12 | | -<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a> |
13 | | -<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a> |
14 | | -<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a> |
15 | | -<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a> |
16 | | -<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a> |
17 | | - <a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a> |
18 | | - <a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a> |
19 | | - <a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a> |
20 | | -</p> |
21 | | - <!--[](https://opencollective.com/nest#backer) |
22 | | - [](https://opencollective.com/nest#sponsor)--> |
23 | | - |
24 | | -## Description |
25 | | - |
26 | | -[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. |
27 | | - |
28 | | -## Project setup |
29 | | - |
| 1 | +# Nothing Backend - NestJS Scaffold Template |
| 2 | + |
| 3 | +A progressive and production-ready NestJS scaffold template designed for scalability, type-safety, and clean architecture. This project serves as a foundation for building robust e-commerce or catalog-based backends. |
| 4 | + |
| 5 | +## 🚀 Tech Stack |
| 6 | + |
| 7 | +- **Framework:** [NestJS v11](https://nestjs.com/) (Express-based) |
| 8 | +- **Language:** TypeScript (ES2023) |
| 9 | +- **Database:** PostgreSQL with [TypeORM](https://typeorm.io/) |
| 10 | +- **Validation:** [Zod](https://zod.dev/) via `nestjs-zod` for absolute type safety. |
| 11 | +- **Authentication:** JWT (Passport.js strategy) with Access & Refresh token rotation. |
| 12 | +- **File Storage:** AWS S3 / MinIO integration via AWS SDK v3. |
| 13 | +- **API Documentation:** Integrated Swagger UI (OpenAPI 3.0). |
| 14 | +- **Tooling:** ESLint, Prettier, Jest. |
| 15 | + |
| 16 | +## 🏗️ Architectural Decisions |
| 17 | + |
| 18 | +### 1. Modular Structure |
| 19 | +The application is organized into domain-driven modules located in `src/modules`. Each module is self-contained, encapsulating its own controllers, services, entities, and DTOs. |
| 20 | +- `AuthModule`: Identity and access management. |
| 21 | +- `UsersModule`: Profile and user management. |
| 22 | +- `ProductsModule`: Catalog and inventory management. |
| 23 | +- `CategoriesModule`: Hierarchical classification. |
| 24 | + |
| 25 | +### 2. Path Aliases |
| 26 | +To avoid deep relative imports (`../../../../`), the project uses TypeScript path aliases defined in `tsconfig.json`: |
| 27 | +- `@modules/*` -> `src/modules/*` |
| 28 | +- `@common/*` -> `src/common/*` |
| 29 | +- `@config/*` -> `src/config/*` |
| 30 | +- `@database/*` -> `src/database/*` |
| 31 | +- `@helpers/*` -> `src/helpers/*` |
| 32 | + |
| 33 | +### 3. Response & Error Standardization |
| 34 | +The backend enforces a strict design system for API communication: |
| 35 | +- **Success Interceptor**: All successful responses are automatically wrapped in a standard `ApiResponse` structure: |
| 36 | + ```json |
| 37 | + { |
| 38 | + "success": true, |
| 39 | + "message": "Success", |
| 40 | + "data": { ... }, |
| 41 | + "meta": { ... } // Optional (e.g., pagination) |
| 42 | + } |
| 43 | + ``` |
| 44 | +- **Global Exception Filter**: Errors are caught and formatted consistently by the `HttpExceptionFilter`, ensuring even internal errors return a safe and readable JSON response. |
| 45 | + |
| 46 | +### 4. Schema-First Validation |
| 47 | +We use `zod` for all DTOs. This ensures that validation and TypeScript types are always in sync. Use the `ZodValidationPipe` (global) to handle input validation automatically. |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +## 🛠️ Getting Started |
| 52 | + |
| 53 | +### Prerequisites |
| 54 | +- Node.js (v18+) |
| 55 | +- PostgreSQL |
| 56 | +- S3 Compatible Storage (MinIO or AWS S3) |
| 57 | + |
| 58 | +### Installation |
30 | 59 | ```bash |
31 | | -$ npm install |
| 60 | +npm install |
32 | 61 | ``` |
33 | 62 |
|
34 | | -## Compile and run the project |
35 | | - |
| 63 | +### Environment Setup |
| 64 | +Copy `.env.example` to `.env` and fill in your credentials: |
36 | 65 | ```bash |
37 | | -# development |
38 | | -$ npm run start |
39 | | - |
40 | | -# watch mode |
41 | | -$ npm run start:dev |
42 | | - |
43 | | -# production mode |
44 | | -$ npm run start:prod |
| 66 | +cp .env.example .env |
45 | 67 | ``` |
46 | 68 |
|
47 | | -## Run tests |
48 | | - |
| 69 | +### Running the App |
49 | 70 | ```bash |
50 | | -# unit tests |
51 | | -$ npm run test |
52 | | - |
53 | | -# e2e tests |
54 | | -$ npm run test:e2e |
| 71 | +# Development |
| 72 | +npm run start:dev |
55 | 73 |
|
56 | | -# test coverage |
57 | | -$ npm run test:cov |
| 74 | +# Production Build |
| 75 | +npm run build |
| 76 | +npm run start:prod |
58 | 77 | ``` |
59 | 78 |
|
60 | | -## Deployment |
| 79 | +### API Documentation |
| 80 | +Once the app is running, visit: |
| 81 | +- **Swagger UI**: `http://localhost:3000/docs` |
| 82 | +- **Static Spec**: `src/swagger.json` |
61 | 83 |
|
62 | | -When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information. |
| 84 | +--- |
63 | 85 |
|
64 | | -If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps: |
| 86 | +## 📘 Integration Guide (For AI Agents & Developers) |
65 | 87 |
|
66 | | -```bash |
67 | | -$ npm install -g @nestjs/mau |
68 | | -$ mau deploy |
69 | | -``` |
70 | | - |
71 | | -With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure. |
| 88 | +When building new features on top of this scaffold, follow these guidelines to maintain consistency: |
72 | 89 |
|
73 | | -## Resources |
| 90 | +### 1. Adding a New Module |
| 91 | +Use the NestJS CLI or create a directory in `src/modules/[feature]`: |
| 92 | +1. **Define Entity**: Create `entities/[feature].entity.ts` using TypeORM decorators. |
| 93 | +2. **Define Schema/DTO**: Create `dto/[feature].dto.ts` using `zod` schemas. |
| 94 | +3. **Service**: Implement business logic in `[feature].service.ts`. |
| 95 | +4. **Controller**: Define endpoints in `[feature].controller.ts`. |
| 96 | +5. **Module**: Wire everything in `[feature].module.ts` and import it into `AppModule`. |
74 | 97 |
|
75 | | -Check out a few resources that may come in handy when working with NestJS: |
| 98 | +### 2. Working with Standard Responses |
| 99 | +You do not need to wrap your data in `success` or `message` keys manually in the controller. Return the raw data (or a promise), and the `ResponseInterceptor` will handle the wrapping. |
| 100 | +- **Custom Message**: If you need a specific message, return an object like `{ data, message: 'Your message' }`. |
76 | 101 |
|
77 | | -- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework. |
78 | | -- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy). |
79 | | -- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/). |
80 | | -- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks. |
81 | | -- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com). |
82 | | -- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com). |
83 | | -- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs). |
84 | | -- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com). |
| 102 | +### 3. Storage Integration |
| 103 | +Use the `S3Helper` from `@helpers/s3.helper`: |
| 104 | +```typescript |
| 105 | +constructor(private readonly s3Helper: S3Helper) {} |
85 | 106 |
|
86 | | -## Support |
87 | | - |
88 | | -Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). |
| 107 | +async upload(file: Express.Multer.File) { |
| 108 | + return await this.s3Helper.uploadFile(file, 'folder-name'); |
| 109 | +} |
| 110 | +``` |
89 | 111 |
|
90 | | -## Stay in touch |
| 112 | +### 4. Authentication & RBAC |
| 113 | +Protect routes using the built-in guards: |
| 114 | +- **JWT Protection**: `@UseGuards(JwtAuthGuard)` |
| 115 | +- **Role Based Access**: `@Roles(Role.Admin)` + `@UseGuards(JwtAuthGuard, RolesGuard)` |
91 | 116 |
|
92 | | -- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec) |
93 | | -- Website - [https://nestjs.com](https://nestjs.com/) |
94 | | -- Twitter - [@nestframework](https://twitter.com/nestframework) |
| 117 | +### 5. Database Conventions |
| 118 | +- Always use `uuid` for primary keys. |
| 119 | +- Use `CreateDateColumn` and `UpdateDateColumn` for auditing. |
| 120 | +- Prefer relations over manual ID handling where possible. |
95 | 121 |
|
96 | | -## License |
| 122 | +--- |
97 | 123 |
|
98 | | -Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE). |
| 124 | +## 🛡️ Design System & Standards |
| 125 | +- **Naming**: camelCase for variables/functions, PascalCase for classes, kebab-case for files. |
| 126 | +- **Comments**: We follow the **NO non-essential comments** rule. Code should be self-documenting. Use comments only for complex algorithmic logic. |
| 127 | +- **Git**: Commits should be descriptive. Feature branches are preferred. |
0 commit comments