Skip to content

Identifying Bounded Contexts

A bounded context is a conceptual boundary within which a particular domain model is defined and applicable. In a large system like the PRS, identifying clear bounded contexts is crucial for maintaining a clean and maintainable codebase.

Current State

The current codebase doesn't have explicit bounded contexts. Instead, it organizes code by technical layers (domain, app, infra, interfaces) rather than by business domains. This leads to:

  • Unclear boundaries between different business domains
  • Difficulty in understanding which entities belong together
  • Potential for inconsistent models across the system
  • Challenges in maintaining and evolving the system

Proposed Bounded Contexts

Based on analysis of the codebase, we can identify several potential bounded contexts:

1. User Management

Core Domain: Managing users, roles, and permissions

Key Entities: - User - Role - Department - Permission

Key Operations: - User registration and authentication - Role assignment - Permission management

Repository Files: - src/infra/repositories/userRepository.js - src/infra/repositories/roleRepository.js - src/infra/repositories/departmentRepository.js

Service Files: - src/app/services/authService.js - src/app/services/userService.js

2. Requisition Management

Core Domain: Managing purchase requisitions and their lifecycle

Key Entities: - Requisition - RequisitionItem - RequisitionApprover - TomItem (Transfer of Materials)

Key Operations: - Creating and submitting requisitions - Adding items to requisitions - Approving/rejecting requisitions - Tracking requisition status

Repository Files: - src/infra/repositories/requisitionRepository.js - src/infra/repositories/requisitionItemListRepository.js - src/infra/repositories/requisitionApproverRepository.js - src/infra/repositories/tomItemRepository.js

Service Files: - src/app/services/requisitionService.js

3. Supplier Management

Core Domain: Managing suppliers and the canvassing process

Key Entities: - Supplier - Canvass - CanvassItem - CanvassItemSupplier

Key Operations: - Supplier registration and management - Canvassing (requesting quotes from suppliers) - Supplier selection - Quote comparison

Repository Files: - src/infra/repositories/supplierRepository.js - src/infra/repositories/canvassRepository.js - src/infra/repositories/canvassItemRepository.js - src/infra/repositories/canvassItemSupplierRepository.js

Service Files: - src/app/services/supplierService.js - src/app/services/canvassService.js

4. Purchase Order Management

Core Domain: Managing purchase orders and delivery receipts

Key Entities: - PurchaseOrder - DeliveryReceipt - DeliveryReceiptItem

Key Operations: - Creating purchase orders - Tracking delivery receipts - Managing delivery items - Handling warranties

Repository Files: - src/infra/repositories/purchaseOrderRepository.js - src/infra/repositories/deliveryReceiptRepository.js - src/infra/repositories/deliveryReceiptItemRepository.js - src/infra/repositories/warrantyRepository.js

Service Files: - src/app/services/purchaseOrderService.js - src/app/services/deliveryReceiptService.js

5. Invoice Management

Core Domain: Managing invoices and payments

Key Entities: - Invoice - InvoiceItem - RSPaymentRequest - NonRequisitionInvoice

Key Operations: - Creating and processing invoices - Managing payment requests - Tracking payment status

Repository Files: - src/infra/repositories/invoiceRepository.js - src/infra/repositories/rsPaymentRequestRepository.js - src/infra/repositories/invoiceReportRepository.js

Service Files: - src/app/services/invoiceService.js - src/app/services/rsPaymentRequestService.js

6. Project Management

Core Domain: Managing projects, companies, and their relationships

Key Entities: - Project - Company - ProjectTrade

Key Operations: - Project creation and management - Company management - Project-company associations

Repository Files: - src/infra/repositories/projectRepository.js - src/infra/repositories/companyRepository.js - src/infra/repositories/projectTradeRepository.js

Service Files: - src/app/services/projectService.js - src/app/services/companyService.js

Shared Kernel

Some concepts are shared across multiple bounded contexts and form a "Shared Kernel":

Key Shared Concepts: - Attachment - Note/Comment - Notification - AuditLog - History

Repository Files: - src/infra/repositories/attachmentRepository.js - src/infra/repositories/commentRepository.js - src/infra/repositories/noteRepository.js - src/infra/repositories/notificationRepository.js - src/infra/repositories/auditLogRepository.js - src/infra/repositories/historyRepository.js

Proposed Directory Structure

To better reflect these bounded contexts, we propose reorganizing the codebase:

Text Only
src/
  domain/
    userManagement/
      entities/
      repositories/
      services/
      events/
    requisitionManagement/
      entities/
      repositories/
      services/
      events/
    supplierManagement/
      entities/
      repositories/
      services/
      events/
    purchaseOrderManagement/
      entities/
      repositories/
      services/
      events/
    invoiceManagement/
      entities/
      repositories/
      services/
      events/
    projectManagement/
      entities/
      repositories/
      services/
      events/
    sharedKernel/
      valueObjects/
      entities/
      services/
  infrastructure/
    database/
    repositories/
    messaging/
    logging/
  application/
    userManagement/
    requisitionManagement/
    supplierManagement/
    purchaseOrderManagement/
    invoiceManagement/
    projectManagement/
  interfaces/
    api/
    events/

This structure organizes code primarily by business domain rather than by technical layer, making it easier to understand and maintain the system.