ClinicFlow’s application layer is built on the Command Query Responsibility Segregation (CQRS) pattern, mediated by the MediatR library. Every user-facing operation is expressed as either a command (mutates state) or a query (reads state) — the two never mix. This separation makes the intent of each operation explicit, keeps handler classes small, and makes the pipeline easy to extend with cross-cutting behaviors.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/0Crazy-0/ClinicFlow/llms.txt
Use this file to discover all available pages before exploring further.
Commands vs. Queries
| Aspect | Command | Query |
|---|---|---|
| Return type | Guid (new entity ID) or Unit (void) | A DTO or list of DTOs |
| Side effects | Yes — persists through IUnitOfWork | No — read-only repository calls |
| Validation | ValidationBehavior runs before the handler | ValidationBehavior runs before the handler |
| Example | ScheduleByPatientCommand → Guid | GetAppointmentTypeByIdQuery → AppointmentTypeDto |
The MediatR Pipeline
Every request — command or query — travels through the same pipeline before reaching its handler.Client dispatches a request
The caller (host application, test, or integration entry point) calls
mediator.Send(command). MediatR resolves the matching IPipelineBehavior chain and IRequestHandler.ValidationBehavior intercepts the request
All
IValidator<TRequest> implementations registered in the DI container are discovered. Each validator runs asynchronously in parallel via Task.WhenAll. If any failures are found, a ValidationException is thrown immediately — the handler is never invoked.Handler executes domain logic
The handler loads aggregates from repositories, calls domain services, and appends new entities to repositories. Domain events are registered on aggregates during this phase.
ValidationBehavior
All validators in ClinicFlow extend
AbstractValidator<T> from the FluentValidation library. They are automatically discovered and registered in DI by scanning the Application assembly. You do not need to register them manually.A Concrete Command: ScheduleByPatient
record — immutable, structurally equatable, and self-documenting. It implements IRequest<Guid>, meaning the handler will return the new appointment’s Id.
Validator
Handler
UnitOfWork Pattern
All repository mutations are flushed through a singleIUnitOfWork.SaveChangesAsync() call at the end of every command handler. Repositories themselves only stage changes in memory — nothing is written to the database until SaveChangesAsync is called. This guarantees that a command is either fully committed or fully rolled back.
Command Groups
ClinicFlow organises commands by the aggregate they operate on. The table below lists every command namespace in the Application layer.Users
Users
RegisterUser, RegisterDoctorUser, RegisterReceptionistUser, RegisterAdminUser, LoginUser, LogoutUser, ChangePassword, RequestPasswordReset, ResetPassword, SendPhoneVerification, VerifyPhone, DeactivateUser, ReactivateUserAppointments
Appointments
ScheduleByPatient, ScheduleByDoctor, ScheduleByStaff, RescheduleByPatient, RescheduleByDoctor, RescheduleByStaff, CancelAppointmentByPatient, CancelAppointmentByDoctor, CancelAppointmentByStaff, CheckInAppointmentByStaff, StartAppointmentByDoctor, MarkAppointmentAsNoShowByDoctor, MarkAppointmentAsNoShowByStaff, ReassignAppointment, CleanExpiredDisplacedAppointments, UpdatePatientNotesByPatient, UpdatePatientNotesByStaff, UpdateReceptionistNotesByStaffDoctors
Doctors
CreateDoctorProfile, UpdateDoctorProfile, SuspendDoctorProfile, ReactivateDoctorProfilePatients
Patients
CreatePatientProfile, CreateCompletePatientProfile, UpdatePatientProfile, AddFamilyMember, AddCompleteFamilyMember, RemoveFamilyMember, ClosePatientAccountSchedules
Schedules
CreateSchedule, SetupWeeklySchedule, UpdateSchedule, DeactivateSchedulePenalties
Penalties
BlockPatient, RemovePenaltyMedical Records
Medical Records
CompleteMedicalEncounter, AddClinicalDetailToMedicalRecordAppointment Types
Appointment Types
CreateAppointmentType, UpdateAppointmentType, ChangeAppointmentTypeAgePolicy, RestrictAppointmentTypeToSpecialties, MakeAppointmentTypeUnrestricted, AddAllowedSpecialtyToAppointmentType, RemoveAllowedSpecialtyFromAppointmentType, AddRequiredTemplateToAppointmentType, RemoveRequiredTemplateFromAppointmentType, DeactivateAppointmentType, ReactivateAppointmentTypeClinical Form Templates
Clinical Form Templates
CreateClinicalFormTemplate, UpdateClinicalFormTemplate, DeactivateClinicalFormTemplate, ReactivateClinicalFormTemplateMedical Specialties
Medical Specialties
CreateMedicalSpecialty, UpdateMedicalSpecialty, DeactivateMedicalSpecialty, ReactivateMedicalSpecialty