ARTICLE AD BOX
Question:
I'm building a NestJS application using CQRS pattern and I'm having trouble deciding where to place a query that spans two domains.
The scenario:
I have two modules: ProjectModule and InvoiceModule. I need to create a GetProjectInvoiceDueDates query that displays invoice due dates on the Project Dashboard page. The data lives in the invoice table but it's consumed by the project feature.
My current structure looks like this:
src/ project/ project.controller.ts project.module.ts invoice/ invoice.controller.ts invoice.module.tsMy questions are:
Should GetProjectInvoiceDueDates live inside the project/ folder or the invoice/ folder?
Which controller should expose the endpoint — ProjectController or InvoiceController?
Where should the handler be registered — ProjectModule or InvoiceModule?
What I tried:
I placed the query inside InvoiceModule since the data comes from the invoice table, but it felt wrong because the feature belongs to the Project Dashboard, not the Invoice section.
typescript
// invoice/queries/get-project-invoice-due-dates.handler.ts @QueryHandler(GetProjectInvoiceDueDatesQuery) export class GetProjectInvoiceDueDatesHandler implements IQueryHandler<GetProjectInvoiceDueDatesQuery> { constructor( @InjectRepository(Invoice) private readonly invoiceRepository: Repository<Invoice>, ) {} async execute(query: GetProjectInvoiceDueDatesQuery) { return this.invoiceRepository.find({ where: { projectId: query.projectId }, select: ['dueDate', 'status'], }); } }Is there a best practice or industry standard for this in NestJS CQRS?
