-Analyze my workspace of project. Project use NestJS, Mysql, Swagger, Jwt (Main Stack) -I want you to generate code follow my code quality standar
- •Name for class, method, variable,... must clear and easy to understand Variable name must be in camelCase Class name must be in PascalCase Method name must be in camelCase + Verb Constant name must be in UPPER_SNAKE_CASE
- •Comply with SOLID: o SRP: one responsibility per class o OCP: extend via polymorphism, no if-else logic o LSP: child classes must be substitutable o ISP: small, focused interfaces o DIP: depend on abstractions, use dependency injection o Use a strict Controller → Service → Repository architecture where an HTTP request flows from routes/controllers, through validation and DTO mapping, into services for business logic, then to repositories for data access, and returns back in reverse order without any layer bypassing another or mixing responsibilities.
- •Do not use magic number / magic string
- •Do NOT throw raw strings.
- •Use structured error objects with: Error code HTTP status Human-readable message
- •Error handling must be centralized and consistent. Use Prisma ORM for data access layer. Every Repository must inject PrismaService. Use Prisma Transactions ($transaction) for any business logic in Services that involves multiple write operations (e.g., Creating an Order + Updating Stock + Creating Debt Record). Use Prisma's generated types for entities to ensure strict typing across layers."
- •Use dto.request layer (NestJS) / validation layer (NestJS) to coding validate input (Mandatory)
- •Always choose the most optimal Big-O complexity for business logic: Priority 1: O(1), You can refer to Hash-based lookup (HashMap / Dictionary), ID-based access (Primary key), Caching (In-memory / Redis), Precomputed values (tính sẵn, không tính lại), Flag / State checking, Early return / Short-circuit logic. Priority 2: O(log n), You can refer to Binary Search, Index-based query (DB index), Tree-based structures (BST, B-Tree), Heap / Priority Queue, Range query with index Priority 3: O(n) You can refer to Single-pass iteration, Filtering / Mapping / Validation, Batch processing, Linear scan with break condition, Streaming processing General optimization techniques beyond Big-O notation: Reduce loop nesting, Avoid redundant computation, Lazy loading, Pagination, Asynchronous processing, Debounce / Throttle, Load balancing
- •Clearly explain why the chosen algorithm meets the required complexity.
- •Avoid unnecessary loops, nested iterations, or in-memory filtering when database-level optimization is possible.
- •Unit test for layers: Controller, Service, Repository, Validator, Utils. Always ensure test 100% total testcase at local as well as CI in Git Actions with Jest
- •Security: o Hash password: Bcrypt and cost = 14 o Never log passwords, secrets, or tokens. o Always enforce authorization and permission checks on backend. o Apply rate limiting to public endpoints. o Ensure SQL Injection safety using ORM (NestJS) or prepared statements only.
- •No business logic in controllers.
- •No static access to repositories or services.
- •No shared mutable state.
- •No hard-coded configuration values.
- •No direct framework coupling inside domain logic.
- •Use folder Constant to save files variable="value" restrict hard code
- •Use class validator to validate input advoid use if-else
- •Create script resovle data or config something in utils folder
- •Files are placed in the correct layer according to the workspace structure.