ARTICLE AD BOX
I am working on a university project using Node.js, TypeScript, and Sequelize. I've implemented a Repository layer to decouple my database logic from the Service layer.
Initially, my repository was very clean:
static async create (payload: EstateInput): Promise<EstateOutput> { const estate = await Estate.create(payload); return estate; }Now, the requirements have grown. When creating an Estate, I need to handle several associations simultaneously:
Address: 1:1 association (nested creation).
Amenities: N:M association (linking existing IDs or creating new ones).
Photos: 1:M association (multiple uploads).
If I move this logic to the Service Layer, the service starts "knowing" too much about Sequelize internals (like transaction, include, or setAmenities), which violates the principle that the Service should be database-agnostic.
What is the standard for handling complex, multi-table creations in a Repository pattern?
Should the Repository accept a deeply nested object and use Sequelize's { include } feature?
Should the Service coordinate multiple Repository calls (e.g., estateRepo.create, then photoRepo.bulkCreate)?
Is there a "Unit of Work" pattern or a better way to manage the transaction across these related entities?
