# ๐Ÿ“š Inquiries Module - Complete Exploration Documentation **Generated:** April 11, 2026 **Module:** `apps/api/src/modules/inquiries/` **Status:** โœ… Complete & Thorough Analysis --- ## ๐Ÿ“– DOCUMENTATION FILES This exploration includes **3 comprehensive documentation files** designed for different use cases: ### 1. **INQUIRIES_MODULE_EXPLORATION.md** (23 KB) **Purpose:** In-depth reference guide **Best for:** Understanding architecture, patterns, and complete file descriptions Contains: - ๐Ÿ“ Complete directory structure - ๐Ÿ“„ Full file listing with descriptions - ๐Ÿ—๏ธ Module architecture diagrams - ๐Ÿ”‘ Key classes & handlers breakdown - ๐ŸŽฏ DDD layer analysis - ๐Ÿ“Š Test file summary - ๐Ÿ› ๏ธ Dependencies & security - ๐Ÿ“ API contracts **Read this when:** You need complete understanding of the module --- ### 2. **INQUIRIES_MODULE_QUICK_REFERENCE.md** (9.3 KB) **Purpose:** Quick lookup guide **Best for:** Getting up to speed quickly, finding specific information Contains: - ๐Ÿ“Š Module at a glance - ๐Ÿ“ Files by layer overview - ๐Ÿ”„ Request flow diagrams - ๐Ÿ”‘ Key classes table - ๐Ÿ“ Key interfaces - ๐Ÿงช Test statistics - ๐Ÿ” Authorization matrix - ๐ŸŽฏ DDD principles - ๐Ÿ“Œ Common patterns - ๐Ÿ” Where to look for X guide **Read this when:** You need quick answers or are new to the module --- ### 3. **INQUIRIES_COMPLETE_FILE_INDEX.md** (23 KB) **Purpose:** Exhaustive file reference **Best for:** Finding specific files, understanding dependencies, planning modifications Contains: - ๐Ÿ“‹ Complete file listing by path - ๐Ÿ“Š File statistics tables - ๐Ÿ” File discovery guide - ๐Ÿ”— Dependency graph - ๐Ÿ“ File cross-references - ๐ŸŽฏ Entry points for modifications - Line count for each file - Detailed method descriptions **Read this when:** You need file-by-file details or planning changes --- ## ๐ŸŽฏ QUICK START BY USE CASE ### I want to understand the overall architecture โ†’ Start with **Quick Reference** โ†’ Dive into **Exploration** ### I'm new to this module โ†’ Start with **Quick Reference** โ†’ Browse **File Index** as needed ### I need to add a new endpoint โ†’ Check **File Index** โ†’ Entry Points section โ†’ Follow the guide ### I need to understand a specific layer โ†’ Search **Quick Reference** for layer โ†’ Read full details in **Exploration** ### I'm looking for a specific class or method โ†’ Use **File Index** โ†’ File Discovery Guide section ### I need to understand data flow โ†’ **Quick Reference** โ†’ Request Flows section ### I'm fixing a bug or refactoring โ†’ **File Index** โ†’ Dependency Graph & Cross-References --- ## ๐Ÿ“Š MODULE SNAPSHOT ``` Location: apps/api/src/modules/inquiries/ Files: 25 total (19 source + 6 test files) LOC: 1,212 lines of code Pattern: CQRS + DDD (Clean Architecture) Tests: 24 test cases across 6 suites Endpoints: 4 HTTP endpoints ``` ### Layer Breakdown | Layer | Files | Purpose | |-------|-------|---------| | **Presentation** | 5 | HTTP endpoints + validation | | **Application** | 8 | Commands/Queries + orchestration | | **Domain** | 6 | Business logic + contracts | | **Infrastructure** | 1 | Prisma persistence | | **Module** | 2 | Configuration + exports | --- ## ๐Ÿ—‚๏ธ FILE TREE ``` inquiries/ โ”œโ”€โ”€ ๐Ÿ“„ index.ts [Barrel export] โ”œโ”€โ”€ ๐Ÿ“„ inquiries.module.ts [NestJS Module] โ”‚ โ”œโ”€โ”€ ๐Ÿ“ presentation/ โ”‚ โ”œโ”€โ”€ controllers/ โ”‚ โ”‚ โ””โ”€โ”€ inquiries.controller.ts [4 endpoints] โ”‚ โ”œโ”€โ”€ dto/ โ”‚ โ”‚ โ”œโ”€โ”€ create-inquiry.dto.ts [Input validation] โ”‚ โ”‚ โ””โ”€โ”€ list-inquiries.dto.ts [Pagination] โ”‚ โ””โ”€โ”€ __tests__/ โ”‚ โ””โ”€โ”€ inquiries.controller.spec.ts [6 tests] โ”‚ โ”œโ”€โ”€ ๐Ÿ“ application/ โ”‚ โ”œโ”€โ”€ commands/ โ”‚ โ”‚ โ”œโ”€โ”€ create-inquiry/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ create-inquiry.command.ts โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ create-inquiry.handler.ts โ”‚ โ”‚ โ””โ”€โ”€ mark-inquiry-read/ โ”‚ โ”‚ โ”œโ”€โ”€ mark-inquiry-read.command.ts โ”‚ โ”‚ โ””โ”€โ”€ mark-inquiry-read.handler.ts โ”‚ โ”œโ”€โ”€ queries/ โ”‚ โ”‚ โ”œโ”€โ”€ get-inquiries-by-agent/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ get-inquiries-by-agent.query.ts โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ get-inquiries-by-agent.handler.ts โ”‚ โ”‚ โ””โ”€โ”€ get-inquiries-by-listing/ โ”‚ โ”‚ โ”œโ”€โ”€ get-inquiries-by-listing.query.ts โ”‚ โ”‚ โ””โ”€โ”€ get-inquiries-by-listing.handler.ts โ”‚ โ””โ”€โ”€ __tests__/ โ”‚ โ”œโ”€โ”€ create-inquiry.handler.spec.ts โ”‚ โ”œโ”€โ”€ mark-inquiry-read.handler.spec.ts โ”‚ โ”œโ”€โ”€ get-inquiries-by-listing.handler.spec.ts โ”‚ โ””โ”€โ”€ get-inquiries-by-agent.handler.spec.ts โ”‚ โ”œโ”€โ”€ ๐Ÿ“ domain/ โ”‚ โ”œโ”€โ”€ entities/ โ”‚ โ”‚ โ””โ”€โ”€ inquiry.entity.ts [Aggregate Root] โ”‚ โ”œโ”€โ”€ events/ โ”‚ โ”‚ โ”œโ”€โ”€ inquiry-created.event.ts โ”‚ โ”‚ โ””โ”€โ”€ inquiry-read.event.ts โ”‚ โ”œโ”€โ”€ repositories/ โ”‚ โ”‚ โ”œโ”€โ”€ inquiry.repository.ts [Interface] โ”‚ โ”‚ โ””โ”€โ”€ inquiry-read.dto.ts [Read DTO] โ”‚ โ””โ”€โ”€ __tests__/ โ”‚ โ””โ”€โ”€ inquiry-domain.spec.ts [5 tests] โ”‚ โ””โ”€โ”€ ๐Ÿ“ infrastructure/ โ””โ”€โ”€ repositories/ โ””โ”€โ”€ prisma-inquiry.repository.ts [Implementation] ``` --- ## ๐Ÿ”„ REQUEST FLOWS ### Create Inquiry ``` POST /inquiries โ†’ Controller validates JWT โ†’ CreateInquiryCommand dispatched โ†’ CreateInquiryHandler executes: โ€ข Validate listing exists โ€ข Create InquiryEntity โ€ข Save to repository โ€ข Publish InquiryCreatedEvent โ†’ Response: { id, listingId, createdAt } ``` ### Mark as Read ``` PATCH /inquiries/:id/read (AGENT only) โ†’ Controller validates JWT + AGENT role โ†’ MarkInquiryReadCommand dispatched โ†’ MarkInquiryReadHandler executes: โ€ข Load inquiry entity โ€ข Verify agent owns listing โ€ข Update entity state โ€ข Persist change โ€ข Publish InquiryReadEvent โ†’ Response: { success: true } ``` ### List Inquiries ``` GET /inquiries/listing/:id or /agent/me โ†’ Controller validates JWT (+ AGENT for /agent/me) โ†’ Query dispatched โ†’ Handler resolves pagination โ†’ Repository executes paginated query โ†’ Response: PaginatedResult ``` --- ## ๐Ÿ”‘ KEY CONCEPTS ### DDD (Domain-Driven Design) - **Domain Entity:** `InquiryEntity` encapsulates inquiry logic - **Domain Events:** `InquiryCreatedEvent`, `InquiryReadEvent` - **Repository Pattern:** Interface in domain, implementation in infrastructure - **Aggregate Root:** InquiryEntity manages state transitions ### CQRS (Command Query Responsibility Segregation) - **Commands:** CreateInquiryCommand, MarkInquiryReadCommand (write operations) - **Queries:** GetInquiriesByListingQuery, GetInquiriesByAgentQuery (read operations) - **Handlers:** Separate classes for each command/query ### Clean Architecture Layers 1. **Presentation:** HTTP endpoints, DTOs, decorators 2. **Application:** Commands/Queries, handlers, coordination 3. **Domain:** Business logic, entities, events, interfaces 4. **Infrastructure:** Database, persistence implementation --- ## ๐Ÿงช TEST COVERAGE **Total:** 24 tests across 6 test suites | Test Suite | Tests | Focus | |-----------|-------|-------| | Domain Entity | 5 | Aggregate behavior, events | | CreateInquiryHandler | 4 | Happy path, validation, events | | MarkInquiryReadHandler | 5 | Happy path, auth, errors | | GetInquiriesByListingHandler | 2 | Pagination, empty results | | GetInquiriesByAgentHandler | 2 | Results, agent lookup | | InquiriesController | 6 | All endpoints, defaults | --- ## ๐Ÿ” Security **Authentication:** All endpoints require JWT token **Authorization:** RBAC with AGENT role for certain endpoints ### Endpoint Security Matrix | Endpoint | Auth | Role | Extra Checks | |----------|------|------|--------------| | POST /inquiries | JWT | Any | Listing exists | | GET /listing/:id | JWT | Any | - | | GET /agent/me | JWT | AGENT | - | | PATCH /:id/read | JWT | AGENT | Agent owns listing | --- ## ๐Ÿ“ก API CONTRACTS ### POST /inquiries ``` Request: { listingId: string, message: string, phone?: string } Response: { id: string, listingId: string, createdAt: string } Status: 201 | 400 | 401 | 404 ``` ### GET /inquiries/listing/:listingId ``` Query: { page?: number, limit?: number } Response: PaginatedResult Status: 200 | 401 ``` ### GET /inquiries/agent/me ``` Query: { page?: number, limit?: number } Response: PaginatedResult Status: 200 | 401 | 403 ``` ### PATCH /inquiries/:id/read ``` Response: { success: boolean } Status: 200 | 401 | 403 | 404 ``` --- ## ๐Ÿš€ GETTING STARTED ### For Understanding the Code 1. Read **Quick Reference** (5 min) 2. Review **Request Flows** (5 min) 3. Explore specific layers in **Exploration** as needed ### For Adding Features 1. Check **File Index** โ†’ Entry Points (2 min) 2. Follow the modification guide (varies) 3. Check existing tests for patterns ### For Debugging 1. Identify the layer (presentation/application/domain/infrastructure) 2. Find the file in **File Index** 3. Check tests for expected behavior --- ## ๐Ÿ“‹ COMMON PATTERNS ### Adding a Command 1. Create `application/commands/[name]/[name].command.ts` 2. Create `application/commands/[name]/[name].handler.ts` 3. Implement `ICommandHandler` 4. Register in `inquiries.module.ts` CommandHandlers array 5. Add tests in `application/__tests__/` ### Adding a Query 1. Create `application/queries/[name]/[name].query.ts` 2. Create `application/queries/[name]/[name].handler.ts` 3. Implement `IQueryHandler` 4. Register in `inquiries.module.ts` QueryHandlers array 5. Add tests in `application/__tests__/` ### Adding an Endpoint 1. Add method to `InquiriesController` 2. Add DTOs if needed to `presentation/dto/` 3. Dispatch command/query via bus 4. Add tests to `presentation/__tests__/` --- ## ๐Ÿ”— EXTERNAL DEPENDENCIES **Core:** - `@nestjs/common` - Framework - `@nestjs/cqrs` - CQRS bus - `@prisma/client` - ORM **Validation:** - `class-validator` - DTO validation - `class-transformer` - Type transformation **Documentation:** - `@nestjs/swagger` - OpenAPI docs **Internal:** - `@modules/shared` - AggregateRoot, exceptions - `@modules/auth` - JWT guards, decorators --- ## ๐Ÿ“ˆ QUALITY METRICS | Aspect | Rating | Notes | |--------|--------|-------| | Architecture | โญโญโญโญโญ | Clean DDD + CQRS | | Organization | โญโญโญโญโญ | Clear layer separation | | Type Safety | โญโญโญโญโญ | Full TypeScript | | Tests | โญโญโญโญโ˜† | 24 tests, good depth | | Auth | โญโญโญโญโญ | Proper RBAC | | Maintainability | โญโญโญโญโญ | Easy to extend | --- ## ๐Ÿ’ก ARCHITECTURAL HIGHLIGHTS โœ… **Separation of Concerns** - Each layer has single responsibility โœ… **Dependency Inversion** - Depend on abstractions, not concrete implementations โœ… **Event-Driven** - Domain events for business significance โœ… **CQRS** - Read/write paths separate and optimizable โœ… **Type Safety** - Full TypeScript with no any types โœ… **Testability** - All layers independently testable โœ… **Extensibility** - Easy to add new commands/queries --- ## ๐ŸŽ“ LEARNING PATH **Beginner:** Read Quick Reference โ†’ Understand layers โ†’ Look at controller **Intermediate:** Study handlers โ†’ Review entities โ†’ Examine tests **Advanced:** Deep dive into event sourcing โ†’ Pagination โ†’ Optimization patterns --- ## ๐Ÿ“ž REFERENCE QUICK LINKS Within documentation files: **Quick Reference:** - Files by layer - Request flows - Authorization matrix - Entry points for changes **File Index:** - Complete file descriptions - Dependency graph - Cross-references - Modification guide **Exploration:** - Architecture diagrams - Design patterns - Security details - Test coverage analysis --- ## โœจ Next Steps 1. **Read the Quick Reference** to get oriented 2. **Pick a documentation file** based on your need 3. **Use the discovery guides** to find specific information 4. **Follow the modification guides** when making changes 5. **Check tests** for expected behavior --- **Happy exploring! ๐Ÿš€** Generated: April 11, 2026 Documentation Status: โœ… Complete