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.
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