feat(deploy): production deployment setup and fixes
- Debian-based api image (bookworm-slim), docker/debian mirrors, prisma binaryTargets for openssl 3.0 - nginx: admin SPA under /admin, TLS via acme.sh (ZeroSSL) + auto-renewal cron, http->https redirect - prisma: add origin_goods.delisted migration, sync missing schema (good_image/tag_font_color/good_tags), fix users.createdAt Timestamptz - api: CORS wildcard reflection, helmet CORP cross-origin, price backfill in persistProductDetail, categoryIcon ancestor fallback, mediaByColor per-color gallery in public goods detail - admin: /admin base path (vite + router) - import-data.mjs: udt_name casting, serial sequence advance fix
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
---
|
||||
title: Organize by Feature Modules
|
||||
impact: CRITICAL
|
||||
impactDescription: "3-5x faster onboarding and development"
|
||||
tags: architecture, modules, organization
|
||||
---
|
||||
|
||||
## Organize by Feature Modules
|
||||
|
||||
Organize your application into feature modules that encapsulate related functionality. Each feature module should be self-contained with its own controllers, services, entities, and DTOs. Avoid organizing by technical layer (all controllers together, all services together). This enables 3-5x faster onboarding and feature development.
|
||||
|
||||
**Incorrect (technical layer organization):**
|
||||
|
||||
```typescript
|
||||
// Technical layer organization (anti-pattern)
|
||||
src/
|
||||
├── controllers/
|
||||
│ ├── users.controller.ts
|
||||
│ ├── orders.controller.ts
|
||||
│ └── products.controller.ts
|
||||
├── services/
|
||||
│ ├── users.service.ts
|
||||
│ ├── orders.service.ts
|
||||
│ └── products.service.ts
|
||||
├── entities/
|
||||
│ ├── user.entity.ts
|
||||
│ ├── order.entity.ts
|
||||
│ └── product.entity.ts
|
||||
└── app.module.ts // Imports everything directly
|
||||
```
|
||||
|
||||
**Correct (feature module organization):**
|
||||
|
||||
```typescript
|
||||
// Feature module organization
|
||||
src/
|
||||
├── users/
|
||||
│ ├── dto/
|
||||
│ │ ├── create-user.dto.ts
|
||||
│ │ └── update-user.dto.ts
|
||||
│ ├── entities/
|
||||
│ │ └── user.entity.ts
|
||||
│ ├── users.controller.ts
|
||||
│ ├── users.service.ts
|
||||
│ ├── users.repository.ts
|
||||
│ └── users.module.ts
|
||||
├── orders/
|
||||
│ ├── dto/
|
||||
│ ├── entities/
|
||||
│ ├── orders.controller.ts
|
||||
│ ├── orders.service.ts
|
||||
│ └── orders.module.ts
|
||||
├── shared/
|
||||
│ ├── guards/
|
||||
│ ├── interceptors/
|
||||
│ ├── filters/
|
||||
│ └── shared.module.ts
|
||||
└── app.module.ts
|
||||
|
||||
// users.module.ts
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([User])],
|
||||
controllers: [UsersController],
|
||||
providers: [UsersService, UsersRepository],
|
||||
exports: [UsersService], // Only export what others need
|
||||
})
|
||||
export class UsersModule {}
|
||||
|
||||
// app.module.ts
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forRoot(),
|
||||
UsersModule,
|
||||
OrdersModule,
|
||||
SharedModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
```
|
||||
|
||||
Reference: [NestJS Modules](https://docs.nestjs.com/modules)
|
||||
Reference in New Issue
Block a user