# m-fo2sh-f/clinic_erp_server_side architecture

> Architecture diagram of the GitHub repository m-fo2sh-f/clinic_erp_server_side, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/m-fo2sh-f/clinic_erp_server_side
- Repository: https://github.com/m-fo2sh-f/clinic_erp_server_side

## Overview

This is a multi-tenant clinic-management API with clinic-branch operations and a separate platform-admin surface. The central clinic workflow covers patient records, appointments, live queue, clinical encounters, and billing/payment. The tree and source index support those domain stages and several service relationships; unsampled controllers and route wiring are represented conservatively. The README describes Laravel generally, not this product’s capabilities.

Main entry points: [`app/Services/Clinic/BillingService.php`](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/BillingService.php) (Billing service), [`app/Http/Controllers/Api/V1/Clinic`](https://github.com/m-fo2sh-f/clinic_erp_server_side/tree/main/app/Http/Controllers/Api/V1/Clinic) (Clinic endpoints), [`app/Services/Clinic/LiveQueueService.php`](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/LiveQueueService.php) (Live queue service), [`app/Services/Clinic/EncounterService.php`](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/EncounterService.php) (Encounter service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clinic_api["Clinic API"]
  node_clinic_endpoints["Clinic endpoints"]
  node_patient_api["Patient API"]
  node_billing_api["Billing API"]
end

subgraph group_clinic_domain["Clinic Operations"]
  node_patient_service["Patient service<br/>[PatientService.php]"]
  node_appointment_service["Appointment service"]
  node_queue_service["Live queue service"]
  node_encounter_service["Encounter service"]
  node_billing_service["Billing service<br/>[BillingService.php]"]
  node_patient_records[("Patient records<br/>[Patient.php]")]
  node_appointment_records[("Appointment records<br/>[Appointment.php]")]
  node_queue_records[("Queue records<br/>[LiveQueue.php]")]
  node_encounter_records[("Encounter records<br/>[Encounter.php]")]
  node_invoice_records[("Invoice records<br/>[Invoice.php]")]
  node_service_catalog[("Service catalog<br/>[Service.php]")]
  node_branch_pricing[("Branch pricing<br/>[BranchService.php]")]
end

subgraph group_platform["Platform Admin"]
  node_tenant_api["Tenant API"]
  node_branch_admin_api["Branch admin API"]
  node_staff_admin_api["Staff admin API"]
  node_tenant_service["Tenant service"]
  node_branch_admin_service["Branch service"]
  node_staff_admin_service["Staff service"]
end

subgraph group_identity["Tenant Access"]
  node_access_middleware["Tenant access"]
  node_branch_context["Branch context"]
  node_user_records[("User records<br/>[User.php]")]
  node_branch_records[("Branch records<br/>[Branch.php]")]
end

node_clinic_user(("Clinic staff"))
node_platform_user(("Platform administrator"))

node_clinic_user -->|"uses"| node_clinic_endpoints
node_clinic_endpoints -.->|"routes to"| node_patient_api
node_clinic_endpoints -.->|"routes to"| node_billing_api
node_patient_api -->|"delegates to"| node_patient_service
node_patient_service -->|"reads/writes"| node_patient_records
node_appointment_service -.->|"uses"| node_appointment_records
node_queue_service -->|"uses"| node_queue_records
node_queue_service -->|"delegates to"| node_patient_service
node_queue_service -->|"delegates to"| node_billing_service
node_queue_service -->|"delegates to"| node_encounter_service
node_encounter_service -->|"uses"| node_encounter_records
node_encounter_service -->|"delegates to"| node_billing_service
node_billing_api -->|"delegates to"| node_billing_service
node_billing_service -->|"creates/updates"| node_invoice_records
node_billing_service -->|"reads"| node_service_catalog
node_billing_service -->|"reads"| node_branch_pricing
node_platform_user -->|"uses"| node_tenant_api
node_platform_user -->|"uses"| node_branch_admin_api
node_tenant_api -->|"delegates to"| node_tenant_service
node_branch_admin_api -->|"delegates to"| node_branch_admin_service
node_staff_admin_api -.->|"delegates to"| node_staff_admin_service
node_tenant_service -->|"uses"| node_user_records
node_tenant_service -->|"uses"| node_branch_records
node_staff_admin_service -->|"uses"| node_user_records
node_access_middleware -.->|"guards"| node_clinic_endpoints
node_branch_context -.->|"sets context"| node_clinic_endpoints

click node_clinic_endpoints "https://github.com/m-fo2sh-f/clinic_erp_server_side/tree/main/app/Http/Controllers/Api/V1/Clinic"
click node_patient_api "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Controllers/Api/V1/Clinic/PatientController.php"
click node_billing_api "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Controllers/Api/V1/Clinic/BillingController.php"
click node_patient_service "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/PatientService.php"
click node_appointment_service "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/AppointmentService.php"
click node_queue_service "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/LiveQueueService.php"
click node_encounter_service "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/EncounterService.php"
click node_billing_service "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/BillingService.php"
click node_patient_records "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/Patient.php"
click node_appointment_records "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/Appointment.php"
click node_queue_records "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/LiveQueue.php"
click node_encounter_records "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/Encounter.php"
click node_invoice_records "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/Invoice.php"
click node_service_catalog "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/Service.php"
click node_branch_pricing "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/BranchService.php"
click node_tenant_api "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Controllers/Api/V1/Platform/PlatformTenantController.php"
click node_branch_admin_api "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Controllers/Api/V1/Platform/PlatformTenantBranchController.php"
click node_staff_admin_api "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Controllers/Api/V1/Platform/PlatformTenantStaffController.php"
click node_tenant_service "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Platform/PlatformTenantService.php"
click node_branch_admin_service "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Platform/PlatformTenantBranchService.php"
click node_staff_admin_service "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Platform/PlatformTenantStaffService.php"
click node_access_middleware "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Middleware/EnsureUserBelongsToTenant.php"
click node_branch_context "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Middleware/SetBranchContext.php"
click node_user_records "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/User.php"
click node_branch_records "https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/Branch.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_clinic_endpoints,node_patient_api,node_billing_api toneBlue
class node_patient_service,node_appointment_service,node_queue_service,node_encounter_service,node_billing_service,node_patient_records,node_appointment_records,node_queue_records,node_encounter_records,node_invoice_records,node_service_catalog,node_branch_pricing toneAmber
class node_tenant_api,node_branch_admin_api,node_staff_admin_api,node_tenant_service,node_branch_admin_service,node_staff_admin_service toneMint
class node_access_middleware,node_branch_context,node_user_records,node_branch_records toneRose
class node_clinic_user,node_platform_user toneIndigo
```

## Components

### Clinic API

- [Clinic endpoints](https://github.com/m-fo2sh-f/clinic_erp_server_side/tree/main/app/Http/Controllers/Api/V1/Clinic): `app/Http/Controllers/Api/V1/Clinic`
- [Patient API](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Controllers/Api/V1/Clinic/PatientController.php): `app/Http/Controllers/Api/V1/Clinic/PatientController.php`
- [Billing API](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Controllers/Api/V1/Clinic/BillingController.php): `app/Http/Controllers/Api/V1/Clinic/BillingController.php`

### Clinic Operations

- [Patient service](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/PatientService.php): `app/Services/Clinic/PatientService.php`
- [Appointment service](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/AppointmentService.php): `app/Services/Clinic/AppointmentService.php`
- [Live queue service](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/LiveQueueService.php): `app/Services/Clinic/LiveQueueService.php`
- [Encounter service](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/EncounterService.php): `app/Services/Clinic/EncounterService.php`
- [Billing service](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Clinic/BillingService.php): `app/Services/Clinic/BillingService.php`
- [Patient records](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/Patient.php): `app/Models/Patient.php`
- [Appointment records](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/Appointment.php): `app/Models/Appointment.php`
- [Queue records](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/LiveQueue.php): `app/Models/LiveQueue.php`
- [Encounter records](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/Encounter.php): `app/Models/Encounter.php`
- [Invoice records](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/Invoice.php): `app/Models/Invoice.php`
- [Service catalog](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/Service.php): `app/Models/Service.php`
- [Branch pricing](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/BranchService.php): `app/Models/BranchService.php`

### Platform Admin

- [Tenant API](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Controllers/Api/V1/Platform/PlatformTenantController.php): `app/Http/Controllers/Api/V1/Platform/PlatformTenantController.php`
- [Branch admin API](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Controllers/Api/V1/Platform/PlatformTenantBranchController.php): `app/Http/Controllers/Api/V1/Platform/PlatformTenantBranchController.php`
- [Staff admin API](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Controllers/Api/V1/Platform/PlatformTenantStaffController.php): `app/Http/Controllers/Api/V1/Platform/PlatformTenantStaffController.php`
- [Tenant service](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Platform/PlatformTenantService.php): `app/Services/Platform/PlatformTenantService.php`
- [Branch service](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Platform/PlatformTenantBranchService.php): `app/Services/Platform/PlatformTenantBranchService.php`
- [Staff service](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Services/Platform/PlatformTenantStaffService.php): `app/Services/Platform/PlatformTenantStaffService.php`

### Tenant Access

- [Tenant access](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Middleware/EnsureUserBelongsToTenant.php): `app/Http/Middleware/EnsureUserBelongsToTenant.php`
- [Branch context](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Http/Middleware/SetBranchContext.php): `app/Http/Middleware/SetBranchContext.php`
- [User records](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/User.php): `app/Models/User.php`
- [Branch records](https://github.com/m-fo2sh-f/clinic_erp_server_side/blob/main/app/Models/Branch.php): `app/Models/Branch.php`

### Other components

- **Clinic staff**
- **Platform administrator**

## Connections

- Clinic staff → Clinic endpoints: uses
- Clinic endpoints → Patient API: routes to
- Clinic endpoints → Billing API: routes to
- Patient API → Patient service: delegates to (evidence: `app/Http/Controllers/Api/V1/Clinic/PatientController.php`)
- Patient service → Patient records: reads/writes (evidence: `app/Services/Clinic/PatientService.php`)
- Appointment service → Appointment records: uses
- Live queue service → Queue records: uses (evidence: `app/Services/Clinic/LiveQueueService.php`)
- Live queue service → Patient service: delegates to (evidence: `app/Services/Clinic/LiveQueueService.php`)
- Live queue service → Billing service: delegates to (evidence: `app/Services/Clinic/LiveQueueService.php`)
- Live queue service → Encounter service: delegates to (evidence: `app/Services/Clinic/LiveQueueService.php`)
- Encounter service → Encounter records: uses (evidence: `app/Services/Clinic/EncounterService.php`)
- Encounter service → Billing service: delegates to (evidence: `app/Services/Clinic/EncounterService.php`)
- Billing API → Billing service: delegates to (evidence: `app/Http/Controllers/Api/V1/Clinic/BillingController.php`)
- Billing service → Invoice records: creates/updates (evidence: `app/Services/Clinic/BillingService.php`)
- Billing service → Service catalog: reads (evidence: `app/Services/Clinic/BillingService.php`)
- Billing service → Branch pricing: reads (evidence: `app/Services/Clinic/BillingService.php`)
- Platform administrator → Tenant API: uses
- Platform administrator → Branch admin API: uses
- Tenant API → Tenant service: delegates to (evidence: `app/Http/Controllers/Api/V1/Platform/PlatformTenantController.php`)
- Branch admin API → Branch service: delegates to (evidence: `app/Http/Controllers/Api/V1/Platform/PlatformTenantBranchController.php`)
- Staff admin API → Staff service: delegates to
- Tenant service → User records: uses (evidence: `app/Services/Platform/PlatformTenantService.php`)
- Tenant service → Branch records: uses (evidence: `app/Services/Platform/PlatformTenantService.php`)
- Staff service → User records: uses (evidence: `app/Services/Platform/PlatformTenantStaffService.php`)
- Tenant access → Clinic endpoints: guards
- Branch context → Clinic endpoints: sets context
