0

I need to rewrite my project due to many underlying issues causing errors and I started following clean architecture by Uncle Bob (I read the book).

I created my domain, infrastructure, application and interface-adapters. In my domain directory I have an entity called TreatmentPlan containing all the business logic. I also define ITreatmentPlanRepository which defines my base methods of accessing data.

This is my TreatmentPlan entity

// TreatmentPlan.ts
interface TreatmentPlan {
    id?: number
    physicianId: number
    patientId: number
    startDate: Date | string
    endDate: Date | string
    endReason: string
    status: TreatmentPlanStatus
    diagnosisId: number
    diagnosisDate: Date | string
    initiationFormId: number
    activeSubstanceId: number
    activeSubstanceDosageId: number
    countryId: number
}

// TreatmentPlanRepository.ts import { TreatmentPlan } from './entities/treatment-plan'

export interface AbstractTreatmentPlanRepository { listTreatmentPlans(): Promise<TreatmentPlan[] | []>

getTreatmentPlan(id: string): Promise<TreatmentPlan[] | null>

createTreatmentPlan(data: any): Promise<TreatmentPlan>

updateTreatmentPlan(id: string, item: any): Promise<number>

deleteTreatmentPlan(id: string, force?: boolean): Promise<number> }

In my application directory I define my usecases eg. CreateNewTreatmentPlanUseCase. I know I want to use Sequelize ORM for database. I inject AbstractTreatmentPlanRepository to CreateNewTreatmentPlanUseCase.

In my infrastructure I have sequelize directory defining all the models and connection.

But I cannot figure out which layer I need to create my SequelizeTreatmentPlanRepository. Some say it needs to be in the interface adapters and some say it needs to be in the application layer. I would put that into the infrastructure directory but I cannot import anything from domain since this is the most inner layer of the structure.

Any help would be appreciated.

z0mbieKale
  • 129
  • 2
  • Some ORMs, including Sequelize (also EF in .NET) are 'Repository' implementations in the way they decouple common operations such as simple database CRUD and many queries from the application, exposing an entirely a database-agnostic interface which generally doesn't need further wrapping for ordinary use-cases. The people who built Sequelize/EF already hide that implementation detail. Of course, it has limitations and for more advanced cases you may still need to write your own database logic, otherwise be careful that your repositories don't just become simple "pass-through" wrappers. – Ben Cottrell Oct 10 '22 at 08:42
  • I would put that into the infrastructure directory but I cannot import anything from domain since this is the most inner layer of the structure.

    Why can't you import the interface from the domain into the infrastructure? My understanding was the rule was imports can go outwards on the diagram, not inwards.

    – bdsl Oct 10 '22 at 09:56
  • Since the domain doesn't have any UI of it's own, surely it must export /something/ or it would be completely useless. – bdsl Oct 10 '22 at 09:57

0 Answers0