Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Arthurr23/XHealtXperience/llms.txt

Use this file to discover all available pages before exploring further.

XHealtXperience uses stancl/tenancy to implement strict database-level multi-tenancy. Each clinic (tenant) owns a completely isolated SQLite or MySQL database, and Laravel runs a separate set of migrations for every new clinic that is provisioned. Understanding which migration files live where — and what they create — is essential before modifying or extending the schema.

Two migration locations

Central migrations

database/migrations/Run once against the single central database that powers the platform itself: super-admin users, tenant registry, domain routing, and platform-wide permissions.

Tenant migrations

database/migrations/tenant/Run automatically inside each clinic’s isolated database whenever a new tenant is created — and can be re-run across all existing tenants with php artisan tenants:migrate.
Never place clinic-specific tables (patients, appointments, medical records, etc.) in database/migrations/. Conversely, never place tenancy infrastructure tables (tenants, domains) in database/migrations/tenant/. Mixing the two directories breaks tenant isolation and the automatic provisioning pipeline.

Running migrations

# Central database only (run once during setup)
php artisan migrate

# Apply pending central migrations (CI, deploy)
php artisan migrate --force

# Run tenant migrations across ALL existing clinics
php artisan tenants:migrate

# Roll back the last central migration batch
php artisan migrate:rollback
Tenant migrations for a newly created clinic are triggered automatically by stancl/tenancy’s JobPipeline — you do not need to run any command manually when onboarding a new clinic through the UI or API.

Central schema — database/migrations/

These 12 migrations build the central database that manages platform infrastructure.
FileWhat it creates / modifies
0001_01_01_000000_create_users_tableCentral users table plus password_reset_tokens and sessions tables — used by the Super Admin and clinic owners.
0001_01_01_000001_create_cache_tablecache and cache_locks tables used when CACHE_STORE=database.
0001_01_01_000002_create_jobs_tablejobs, job_batches, and failed_jobs tables used when QUEUE_CONNECTION=database.
2019_09_15_000010_create_tenants_tabletenants table — the stancl/tenancy registry; stores each clinic’s unique ID and JSON data column.
2019_09_15_000020_create_domains_tabledomains table — maps hostnames / subdomains to a tenant.
2025_01_01_000002_add_two_factor_columns_to_central_users_tableAdds two_factor_secret and two_factor_recovery_codes to central users.
2025_01_02_000002_add_two_factor_method_to_central_users_tableAdds two_factor_method column (e.g., totp, email) to central users.
2026_03_25_172327_create_permission_tablesCreates Spatie Permission tables (permissions, roles, model_has_permissions, model_has_roles, role_has_permissions) in the central DB for platform-level RBAC.
2026_04_14_193807_create_personal_access_tokens_tablepersonal_access_tokens table for Laravel Sanctum API tokens in the central context.
2026_06_18_000001_add_clinic_fields_to_tenants_tableAdds clinic metadata fields (name, contact info, etc.) to the tenants table.
2026_06_29_000001_add_failed_login_attempts_to_users_tableAdds failed_login_attempts and locked_until columns to central users for brute-force protection.
2026_07_03_000000_add_codigo_clinica_to_tenants_tableAdds codigo_clinica — a short unique identifier for each clinic used in patient record codes.

Tenant schema — database/migrations/tenant/

These 33 migrations are executed inside every clinic’s private database. They cover the full clinical and operational data model.

Infrastructure & security

FileWhat it creates / modifies
0001_01_01_000000_create_users_tablePer-tenant users table for clinic staff (doctors, receptionists, admins).
0001_01_01_000001_create_cache_tablePer-tenant cache and cache lock tables.
0001_01_01_000002_create_jobs_tablePer-tenant job queue tables (jobs, job_batches, failed_jobs).
2025_01_01_000001_add_two_factor_columns_to_users_tableAdds two_factor_secret and two_factor_recovery_codes to tenant users.
2025_01_02_000001_add_two_factor_method_to_users_tableAdds two_factor_method column to tenant users.
2026_06_24_000001_add_login_lockout_to_users_tableAdds failed_login_attempts and locked_until to tenant users.
2026_03_25_172327_create_permission_tablesSpatie Permission tables in the tenant DB — each clinic has its own independent RBAC.
2026_04_14_193807_create_personal_access_tokens_tableSanctum personal access tokens in the tenant context.
2025_07_01_000001_create_audit_logs_tableaudit_logs table — immutable log of sensitive actions taken within the clinic.
2026_06_23_192608_create_tenant_settings_tabletenant_settings key-value store for per-clinic configuration.
2026_06_24_000002_add_max_login_attempts_to_tenant_settingsAdds configurable max_login_attempts setting per clinic.
2026_07_03_000001_add_citas_settings_to_tenant_settings_tableAdds appointment (citas) scheduling configuration columns to tenant_settings.
2026_07_16_000001_add_visitor_checkin_token_to_tenant_settingsAdds visitor_checkin_token — a public token used for the patient self-check-in kiosk feature.

Clinical records

FileWhat it creates / modifies
2026_03_09_174621_create_pacientes_tablepacientes — the patient registry: demographics, contact data, ID document info.
2026_03_10_000000_create_expedientes_clinicos_tableexpedientes_clinicos — the main medical record linked to each patient.
2026_06_08_192551_add_reverso_to_pacientes_tableAdds reverso column to pacientes for the reverse side of an ID document image.
2026_07_03_000002_add_codigo_paciente_and_notificaciones_to_pacientes_tableAdds codigo_paciente (clinic-scoped patient code) and notification-preference columns to pacientes.
2026_07_03_000003_create_medico_perfiles_tablemedico_perfiles — extended professional profile for physician users (specialty, schedule defaults, etc.).

Services & workflows

FileWhat it creates / modifies
2026_07_03_000004_create_servicios_tableservicios — catalogue of medical/aesthetic services the clinic offers.
2026_07_07_000001_create_lineas_servicio_tablelineas_servicio — service lines / categories that group related services.
2026_07_07_000003_create_servicio_staff_perfiles_tableservicio_staff_perfiles — links staff roles / profiles to the services they can deliver.
2026_07_07_000004_create_servicio_etapas_tableservicio_etapas — defines the ordered stages (etapas) within a service workflow.
2026_07_07_000005_create_paciente_servicios_tablepaciente_servicios — enrolment of a patient into a service.
2026_07_07_000006_create_paciente_servicio_etapas_tablepaciente_servicio_etapas — tracks each patient’s progress through service stages, including deadline and notification timestamps.
2026_07_10_000001_add_gestion_servicios_fields_to_servicios_tableAdds management fields (pricing, duration, active flag, etc.) to servicios.
2026_07_03_000005_create_procedimientos_quirurgicos_tableprocedimientos_quirurgicos — catalogue of surgical procedures linked to services.

Appointments & scheduling

FileWhat it creates / modifies
2026_07_03_000006_create_salas_tablesalas — clinic rooms / operating theatres available for booking.
2026_07_03_000007_create_citas_tablecitas — appointment records: patient, doctor, room, service, date/time, status.
2026_07_03_000008_create_cita_equipo_tablecita_equipo — the medical team members assigned to a given appointment.
2026_07_03_000009_create_bloqueos_agenda_tablebloqueos_agenda — schedule blocks (vacations, maintenance, etc.) that prevent bookings.
2026_07_04_000001_add_conflicto_pendiente_to_citas_tableAdds conflicto_pendiente flag to citas — marks appointments that have an unresolved scheduling conflict.
2026_07_14_000000_add_tipo_to_bloqueos_agenda_tableAdds a tipo discriminator column to bloqueos_agenda (e.g., personal, sala, doctor).
2026_07_20_000001_add_email_to_cita_equipo_tableAdds an email column to cita_equipo for external team members who don’t have a user account.

Schema groups at a glance

GroupCentralTenant
User accounts
Two-factor authentication
Role-based access control (Spatie)
Queue & cache infrastructure
Tenant / domain registry
Clinic settings
Audit log
Patient records & expedientes
Services & stage workflows
Appointments & scheduling
Surgical procedures & rooms

Artisan commands for schema management

roles:clean-stale {--dry-run}

Scans every tenant database and removes residual Admin and Super Admin roles that should not exist in tenant context. Use --dry-run to preview which tenants are affected without making any changes.
# Preview what would be removed
php artisan roles:clean-stale --dry-run

# Remove stale roles
php artisan roles:clean-stale

Build docs developers (and LLMs) love