# โครงสร้างโฟลเดอร์และไฟล์ทั้งหมดสำหรับ **Backend (NestJS)** ตามแผนงาน **LCBP3-DMS v1.4.3** ตั้งแต่ Phase 0 ถึง Phase 6 (T0-T6.2) ที่ได้ดำเนินการไปแล้ว โครงสร้างนี้ออกแบบตามหลัก **Domain-Driven Design** และ **Modular Architecture** ที่ระบุไว้ในแผนพัฒนา --- ## 📂 **backend/** (Backend Application) * [x] `.env` (สำหรับ Local Dev เท่านั้น ห้าม commit) * [x] `.gitignore` * [x] `docker-compose.yml` (Configuration หลักสำหรับ Deploy) * [x] `docker-compose.override.yml` (สำหรับ Inject Secrets ตอน Dev) * [x] `package.json` * [x] `pnpm-lock.yaml` * [x] `tsconfig.json` * [x] `nest-cli.json` * [x] `README.md` --- ## 📂 **backend/src/** (Source Code) ### **📄 Entry Points** * [x] `main.ts` (Application Bootstrap, Swagger, Global Pipes) * [x] `app.module.ts` (Root Module ที่รวมทุก Modules เข้าด้วยกัน) ### **📁 src/common/** (Shared Resources) * [x] **common.module.ts** * **auth/** * **dto/** * [x] **login.dto.ts** * [x] **register.dto.ts** * [x] **auth.controller.spec.ts** * [x] **auth.controller.ts** * [x] **auth.module.ts** * [x] **auth.service.spec.ts** * [x] **auth.service.ts** * **config/** (Configuration Service) * [x] **env.validation.ts** * **decorators/** * [x] **audit.decorator.ts** * [x] `current-user.decorator.ts` * [x] `require-permission.decorator.ts` * **entities/** * [x] **audit-log.entity.ts** * [x] **base.entity.ts** * **exceptions/** * [x] `http-exception.filter.ts` (Global Filter) * **file-storage/** (Two-Phase Storage System) * **entities/** * [x] **attachment.entity.ts** * [x] **file-storage.controller.spec.ts** * [x] **file-storage.controller.ts** * [x] **file-storage.module.ts** * [x] **file-storage.service.spec.ts** * [x] `file-storage.service.ts` (Upload, Scan Virus, Commit) * [x] `guards/` * [x] `jwt-auth.guard.ts` * [x] **jwt.strategy.ts** * [x] `rbac.guard.ts` (ตรวจสอบสิทธิ์ 4 ระดับ) * **interceptors/** * [x] `audit-log.interceptor.ts` (เก็บ Log ลง DB) * [x] `transform.interceptor.ts` (Standard Response Format) * **resilience/** (Circuit Breaker & Retry) ### **📁 src/modules/** (Feature Modules) 1. **user/** (User Management & RBAC) * [x] `dto/` * [x] **assign-user-role.dto.ts** * [x] `create-user.dto.ts` * [x] `update-user.dto.ts` * [x] `entities/` * [x] `user.entity.ts` * [x] `role.entity.ts` * [x] `permission.entity.ts` * [x] `user-preference.entity.ts` * [x] **user-assignment.service.ts** * [x] `user.controller.ts` * [x] `user.module.ts` * [x] `user.service.ts` * [x] **user.service.spec.ts** 2. **project/** (Project Structure) * [x] `dto/` * [x] **create-project.dto.ts** * [x] `search-project.dto.ts` * [x] `update-project.dto.ts` * [x] `entities/` * [x] `contract-organization.entity.ts` * [x] `contract.entity.ts` * [x] `organization.entity.ts` * [x] `project-organization.entity.ts` (Junction) * [x] **project.entity.ts** * [x] **project.controller.spec.ts** * [x] `project.controller.ts` * [x] `project.module.ts` * [x] **project.service.spec.ts** * [x] `project.service.ts` 3. **correspondence/** (Core Document System) * [x] `dto/` * [x] `add-reference.dto.ts` * [x] `create-correspondence.dto.ts` * [x] `search-correspondence.dto.ts` * [x] **submit-correspondence.dto.ts** * [x] `workflow-action.dto.ts` * [x] `entities/` * [x] `correspondence-reference.entity.ts` * [x] `correspondence-revision.entity.ts` * [x] `correspondence-routing.entity.ts` (Unified Workflow) * [x] `correspondence-status.entity.ts` * [x] `correspondence-type.entity.ts` * [x] `correspondence.entity.ts` * [x] **routing-template-step.entity.ts** * [x] `routing-template.entity.ts` * [x] **correspondence.controller.spec.ts** * [x] `correspondence.controller.ts` * [x] `correspondence.module.ts` * [x] **correspondence.service.spec.ts** * [x] `correspondence.service.ts` (Impersonation & Workflow Logic) 4. **drawing/** (Contract & Shop Drawings) * [x] `dto/` * [x] `create-contract-drawing.dto.ts` * [x] `create-shop-drawing-revision.dto.ts` * [x] `create-shop-drawing.dto.ts` * [x] `search-contract-drawing.dto.ts` * [x] `search-shop-drawing.dto.ts` * [x] `update-contract-drawing.dto.ts` * [x] `entities/` * [x] `contract-drawing-sub-category.entity.ts` * [x] `contract-drawing-volume.entity.ts` * [x] `contract-drawing.entity.ts` * [x] `shop-drawing-main-category.entity.ts` * [x] `shop-drawing-revision.entity.ts` * [x] `shop-drawing-sub-category.entity.ts` * [x] `shop-drawing.entity.ts` * [x] `contract-drawing.controller.ts` * [x] `contract-drawing.service.ts` * [x] `drawing-master-data.controller.ts` * [x] `drawing-master-data.service.ts` * [x] `drawing.module.ts` * [x] `shop-drawing.controller.ts` * [x] `shop-drawing.service.ts` 4. **rfa/** (Request for Approval & Advanced Workflow) * [x] `dto/` * [x] `create-rfa.dto.ts` * [x] `search-rfa.dto.ts` * [x] `update-rfa.dto.ts` * [x] `entities/` * [x] `rfa-approve-code.entity.ts` * [x] `rfa-item.entity.ts` * [x] `rfa-revision.entity.ts` * [x] `rfa-status-code.entity.ts` * [x] `rfa-type.entity.ts` * [x] `rfa-workflow-template-step.entity.ts` * [x] `rfa-workflow-template.entity.ts` * [x] `rfa-workflow.entity.ts` * [x] `rfa.entity.ts` * [x] `rfa.controller.ts` * [x] `rfa.module.ts` * [x] `rfa.service.ts` (Unified Workflow Integration) 5. **circulation/** (Internal Routing) * [x] `dto/` * [x] `create-circulation.dto.ts` * [x] `update-circulation-routing.dto.ts` * [x] `search-circulation.dto.ts` * [x] `entities/` * [x] `circulation-routing.entity.ts` * [x] `circulation-status-code.entity.ts` * [x] `circulation.entity.ts` * [x] `circulation.controller.ts` * [x] `circulation.module.ts` * [x] `circulation.service.ts` 6. **transmittal/** (Document Forwarding) * [x] `dto/` * [x] `create-transmittal.dto.ts` * [x] `search-transmittal.dto.ts` * [x] **update-transmittal.dto.ts** * [x] `entities/` * [x] `transmittal-item.entity.ts` * [x] `transmittal.entity.ts` * [x] `transmittal.controller.ts` * [x] `transmittal.module.ts` * [x] `transmittal.service.ts` 7. **notification/** (System Alerts) * [x] `dto/` * [x] `create-notification.dto.ts` * [x] `search-notification.dto.ts` * [x] `entities/` * [x] `notification.entity.ts` * [x] `notification-cleanup.service.ts` (Cron Job) * [x] `notification.controller.ts` * [x] `notification.gateway.ts` * [x] `notification.module.ts` (Real-time WebSocket) * [x] `notification.processor.ts` (Consumer/Worker for Email & Line) * [x] `notification.service.ts` (Producer) 8. **search/** (Elasticsearch) * [x] `dto/search-query.dto.ts` * [x] `search.controller.ts` * [x] `search.module.ts` * [x] `search.service.ts` (Indexing & Searching) 9. **document-numbering/** (Internal Service) * [x] `entities/` * [x] `document-number-format.entity.ts` * [x] `document-number-counter.entity.ts` * [x] `document-numbering.module.ts` * [x] **document-numbering.service.spec.ts** * [x] `document-numbering.service.ts` (Double-Lock Mechanism) 10. **workflow-engine/** (Unified Logic) * [x] `interfaces/workflow.interface.ts` * [x] `workflow-engine.module.ts` * [x] **workflow-engine.service.spec.ts** * [x] `workflow-engine.service.ts` (State Machine Logic) 11. **json-schema/** (Validation) * [x] `dto/` * [x] `create-json-schema.dto.ts`+ * [x] `search-json-schema.dto.ts` * [x] `update-json-schema.dto.ts` * [x] `entities/` * [x] `json-schema.entity.ts` * [x] **json-schema.controller.spec.ts** * [x] **json-schema.controller.ts** * [x] `json-schema.module.ts` * [x] **json-schema.service.spec.ts** * [x] `json-schema.service.ts` --- นี่คือโครงสร้าง **Folder Structure** ของโปรเจกต์ Backend (NestJS) ฉบับสมบูรณ์ ที่รวบรวมจาก **Requirements**, **FullStackJS Guidelines**, **Data Dictionary** และสิ่งที่เราได้ **Implement ไปแล้วตั้งแต่ Phase 0 ถึง Phase 6.2** ครับ โครงสร้างนี้เป็นแบบ **Domain-Driven Modular Architecture** ครับ ```text lcbp3-backend/ ├── .env # Environment variables (Local Dev) ├── .gitignore ├── docker-compose.yml # Main config for services (DB, Redis, ES, App) ├── docker-compose.override.yml # Secrets injection for Dev ├── nest-cli.json ├── package.json ├── pnpm-lock.yaml ├── README.md ├── tsconfig.json │ └── src/ ├── main.ts # Entry point (Swagger, Helmet, Global Pipes) ├── app.module.ts # Root Module │ ├── common/ # 🛠️ Shared Resources │ ├── auth/ │ │ ├── guards/ │ │ │ ├── jwt-auth.guard.ts │ │ │ └── rbac.guard.ts │ │ └── strategies/ │ │ └── jwt.strategy.ts │ ├── config/ # Config Service │ ├── decorators/ │ │ ├── current-user.decorator.ts │ │ └── require-permission.decorator.ts │ ├── exceptions/ │ │ └── http-exception.filter.ts │ ├── file-storage/ # 📂 Two-Phase Storage System │ │ ├── dto/ │ │ ├── entities/ │ │ │ └── attachment.entity.ts │ │ ├── file-storage.module.ts │ │ └── file-storage.service.ts │ ├── interceptors/ │ │ ├── audit-log.interceptor.ts │ │ └── transform.interceptor.ts │ └── resilience/ # Circuit Breaker & Retry logic │ └── modules/ # 📦 Feature Modules │ ├── user/ # 👤 User & RBAC │ ├── dto/ │ │ ├── create-user.dto.ts │ │ └── update-user.dto.ts │ ├── entities/ │ │ ├── permission.entity.ts │ │ ├── role.entity.ts │ │ ├── user-preference.entity.ts │ │ └── user.entity.ts │ ├── user.controller.ts │ ├── user.module.ts │ └── user.service.ts │ ├── project/ # 🏢 Projects & Organizations │ ├── dto/ │ │ ├── create-project.dto.ts │ │ ├── search-project.dto.ts │ │ └── update-project.dto.ts │ ├── entities/ │ │ ├── contract-organization.entity.ts │ │ ├── contract.entity.ts │ │ ├── organization.entity.ts │ │ ├── project-organization.entity.ts │ │ └── project.entity.ts │ ├── project.controller.ts │ ├── project.module.ts │ └── project.service.ts │ ├── correspondence/ # ✉️ Core Document │ ├── dto/ │ │ ├── add-reference.dto.ts │ │ ├── create-correspondence.dto.ts │ │ ├── search-correspondence.dto.ts │ │ └── workflow-action.dto.ts │ ├── entities/ │ │ ├── correspondence-reference.entity.ts │ │ ├── correspondence-revision.entity.ts │ │ ├── correspondence-routing.entity.ts │ │ ├── correspondence-status.entity.ts │ │ ├── correspondence-type.entity.ts │ │ ├── correspondence.entity.ts │ │ └── routing-template.entity.ts │ ├── correspondence.controller.ts │ ├── correspondence.module.ts │ └── correspondence.service.ts │ ├── drawing/ # 📐 Shop & Contract Drawings │ ├── dto/ │ │ ├── create-contract-drawing.dto.ts │ │ ├── create-shop-drawing-revision.dto.ts │ │ ├── create-shop-drawing.dto.ts │ │ ├── search-contract-drawing.dto.ts │ │ ├── search-shop-drawing.dto.ts │ │ └── update-contract-drawing.dto.ts │ ├── entities/ │ │ ├── contract-drawing-sub-category.entity.ts │ │ ├── contract-drawing-volume.entity.ts │ │ ├── contract-drawing.entity.ts │ │ ├── shop-drawing-main-category.entity.ts │ │ ├── shop-drawing-revision.entity.ts │ │ ├── shop-drawing-sub-category.entity.ts │ │ └── shop-drawing.entity.ts │ ├── contract-drawing.controller.ts │ ├── contract-drawing.service.ts │ ├── drawing-master-data.controller.ts │ ├── drawing-master-data.service.ts │ ├── drawing.module.ts │ ├── shop-drawing.controller.ts │ └── shop-drawing.service.ts │ ├── rfa/ # ✅ Request for Approval │ ├── dto/ │ │ ├── create-rfa.dto.ts │ │ ├── search-rfa.dto.ts │ │ └── update-rfa.dto.ts │ ├── entities/ │ │ ├── rfa-approve-code.entity.ts │ │ ├── rfa-item.entity.ts │ │ ├── rfa-revision.entity.ts │ │ ├── rfa-status-code.entity.ts │ │ ├── rfa-type.entity.ts │ │ ├── rfa-workflow-template-step.entity.ts │ │ ├── rfa-workflow-template.entity.ts │ │ ├── rfa-workflow.entity.ts │ │ └── rfa.entity.ts │ ├── rfa.controller.ts │ ├── rfa.module.ts │ └── rfa.service.ts │ ├── circulation/ # 🔄 Internal Routing │ ├── dto/ │ │ ├── create-circulation.dto.ts │ │ ├── search-circulation.dto.ts │ │ └── update-circulation-routing.dto.ts │ ├── entities/ │ │ ├── circulation-routing.entity.ts │ │ ├── circulation-status-code.entity.ts │ │ └── circulation.entity.ts │ ├── circulation.controller.ts │ ├── circulation.module.ts │ └── circulation.service.ts │ ├── transmittal/ # 📤 Outgoing Documents │ ├── dto/ │ │ ├── create-transmittal.dto.ts │ │ └── search-transmittal.dto.ts │ ├── entities/ │ │ ├── transmittal-item.entity.ts │ │ └── transmittal.entity.ts │ ├── transmittal.controller.ts │ ├── transmittal.module.ts │ └── transmittal.service.ts │ ├── notification/ # 🔔 Real-time & Queue │ ├── dto/ │ │ ├── create-notification.dto.ts │ │ └── search-notification.dto.ts │ ├── entities/ │ │ └── notification.entity.ts │ ├── notification-cleanup.service.ts │ ├── notification.controller.ts │ ├── notification.gateway.ts │ ├── notification.module.ts │ ├── notification.processor.ts │ └── notification.service.ts │ ├── search/ # 🔍 Elasticsearch │ ├── dto/ │ │ └── search-query.dto.ts │ ├── search.controller.ts │ ├── search.module.ts │ └── search.service.ts │ ├── document-numbering/ # 🔢 Internal Numbering Service │ ├── entities/ │ │ ├── document-number-counter.entity.ts │ │ └── document-number-format.entity.ts │ ├── document-numbering.module.ts │ └── document-numbering.service.ts │ ├── workflow-engine/ # ⚙️ Unified Logic │ ├── interfaces/ │ │ └── workflow.interface.ts │ ├── workflow-engine.module.ts │ └── workflow-engine.service.ts │ └── json-schema/ # 📋 Validation Logic ├── json-schema.module.ts └── json-schema.service.ts ```