# maituyet04/datn_2026_dscms_luumaituyet architecture

> Architecture diagram of the GitHub repository maituyet04/datn_2026_dscms_luumaituyet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/maituyet04/datn_2026_dscms_luumaituyet
- Repository: https://github.com/maituyet04/datn_2026_dscms_luumaituyet

## Overview

1. This is a Django-based backend for a dermatology/spa clinic management system. The repository is organized as a layered application: HTTP/API boundary, application services, feature/use-case handlers, repositories, and domain entities/DTOs.

2. The runtime entry points are the standard Django `manage.py`, plus `config/asgi.py` and `config/wsgi.py`. `config/settings.py`, `config/urls.py`, and `src/api/urls.py` define the application wiring and request routing.

3. The HTTP/API layer lives under `src/api`. It contains endpoint modules for each business area: appointments, attachments, audit, auth, customers, invoices, medical records, notifications, prescriptions, resources, services, spa workflows, treatments, visits, and wallets. Shared API concerns such as exception handling, pagination, permissions, response formatting, and serializers are also centralized here.

4. The application core is split into `src/services` and `src/features`. The service layer appears to coordinate business rules and cross-cutting operations such as auth, payments, check-in, escalation, transactions, and clinic workflows. The feature folders represent use-case implementations like “create appointment”, “start examination”, “create invoice”, “add payment”, “deduct wallet”, and similar actions.

5. Data access is isolated in `src/repositories`. Each major aggregate has its own repository module, which suggests the system keeps persistence logic separate from business logic. The repositories likely wrap Django ORM operations against the database schema in `database/database.sql`.

6. The domain model is expressed in `src/entities`. These modules define core business objects such as Customer, Appointment, Visit, Invoice, MedicalRecord, Prescription, Wallet, Service, Treatment, Resource, Notification, Attachment, User, and Audit. This layer is the main boundary for business state and relationships.

7. DTOs in `src/dtos` provide structured data transfer between API/services/features/entities. They likely shape inbound/outbound payloads and help decouple the HTTP contract from the internal domain model. The presence of dedicated DTOs per aggregate indicates a strong separation between transport and business objects.

8. The main business subdomains are:
   - Patient/customer management
   - Appointment scheduling and check-in
   - Visit flow and clinical orders/examinations
   - Medical records and prescriptions
   - Invoicing, payments, refunds, and wallet balances
   - Service catalog and treatment planning
   - Spa/dermatology session workflows
   - Audit logging and notifications

9. Several workflows span multiple subsystems. For example, an appointment can be created, updated, checked in, and converted into a visit; a visit can create clinical orders and progress through examination to completion; medical record actions can create prescriptions or lock records; invoicing can interact with wallet/payment logic; spa-related actions can escalate to a doctor and record skin conditions.

10. Cross-cutting utilities are collected under `src/utils`, including code generation, constants, date and phone helpers, file handling, logging, permissions, validators, pagination, and response helpers. These support consistent behavior across the API and business layers.

11. `src/services/transaction.py` suggests explicit transaction handling around multi-step business operations. That matters architecturally because several clinic workflows likely need atomic updates across multiple tables or aggregates.

12. The repository also includes `src/admin.py`, which indicates Django admin integration for internal management, and `src/apps.py`/`src/migrations` for app registration and schema evolution. `pyproject.toml` and `uv.lock` show the project is managed with `uv` and Python packaging tooling.

13. For an architecture diagram, the clearest flow is: HTTP request enters Django/API routing, API modules validate/serialize and enforce permissions, services/features execute the business use case, repositories persist/retrieve entities, and responses are shaped back through serializers/response helpers. The database is the primary external persistence boundary shown in the repo.

Main entry points: [`src/api/urls.py`](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/urls.py) (API URLs), [`database/database.sql`](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/database/database.sql) (Database), [`src/services/payment_service.py`](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/services/payment_service.py) (Payments), [`src/entities/appointment.py`](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/entities/appointment.py) (Appointment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime & config"]
  node_manage_py["manage.py<br/>entrypoint<br/>[manage.py]"]
  node_config_settings["Settings<br/>django config<br/>[settings.py]"]
  node_config_urls["Project URLs<br/>django routing<br/>[urls.py]"]
end

subgraph group_api["HTTP/API layer"]
  node_api_urls["API URLs<br/>api router<br/>[urls.py]"]
  node_api_common["API core<br/>shared api<br/>[serializers.py]"]
  node_appointment_api["Appointments<br/>endpoint module<br/>[appointment_api.py]"]
  node_customer_api["Customers<br/>endpoint module<br/>[customer_api.py]"]
  node_invoice_api["Invoices<br/>endpoint module<br/>[invoice_api.py]"]
  node_medical_api["Medical<br/>endpoint module"]
  node_spa_api["Spa<br/>endpoint module<br/>[spa_api.py]"]
  node_visit_api["Visits<br/>endpoint module<br/>[visit_api.py]"]
end

subgraph group_app["Application core"]
  node_service_appointment["Appt service"]
  node_service_payment["Payments<br/>[payment_service.py]"]
  node_service_spa["Spa service<br/>[spa_service.py]"]
  node_service_tx["Transactions<br/>[transaction.py]"]
  node_feature_create_appt["Create appt<br/>use case"]
  node_feature_checkin["Start exam<br/>use case"]
  node_feature_invoice["Create invoice<br/>use case<br/>[create_invoice.py]"]
  node_feature_escalate["Escalate<br/>use case"]
end

subgraph group_data["Domain & persistence"]
  node_repo_appointment["Appt repo"]
  node_repo_invoice["Invoice repo"]
  node_entity_appointment["Appointment<br/>domain entity<br/>[appointment.py]"]
  node_entity_visit["Visit<br/>domain entity<br/>[visit.py]"]
  node_entity_invoice["Invoice<br/>domain entity<br/>[invoice.py]"]
  node_entity_customer["Customer<br/>domain entity<br/>[customer.py]"]
  node_database_sql[("Database<br/>schema<br/>[database.sql]")]
end

node_manage_py -->|"loads"| node_config_settings
node_config_settings -->|"wires"| node_config_urls
node_config_urls -->|"routes"| node_api_urls
node_api_urls -->|"maps"| node_appointment_api
node_api_urls -->|"maps"| node_customer_api
node_api_urls -->|"maps"| node_invoice_api
node_api_urls -->|"maps"| node_medical_api
node_api_urls -->|"maps"| node_spa_api
node_api_urls -->|"maps"| node_visit_api
node_appointment_api -->|"uses"| node_api_common
node_invoice_api -->|"uses"| node_api_common
node_service_appointment -->|"orchestrates"| node_feature_create_appt
node_service_appointment -->|"persists via"| node_repo_appointment
node_service_payment -->|"orchestrates"| node_feature_invoice
node_service_payment -->|"persists via"| node_repo_invoice
node_service_payment -->|"wraps"| node_service_tx
node_service_spa -->|"orchestrates"| node_feature_escalate
node_feature_create_appt -->|"builds"| node_entity_appointment
node_feature_checkin -->|"advances"| node_entity_visit
node_feature_invoice -->|"builds"| node_entity_invoice
node_feature_escalate -->|"updates"| node_entity_customer
node_repo_appointment -->|"stores"| node_entity_appointment
node_repo_invoice -->|"stores"| node_entity_invoice
node_entity_appointment -->|"mapped to"| node_database_sql
node_entity_visit -->|"mapped to"| node_database_sql
node_entity_invoice -->|"mapped to"| node_database_sql
node_entity_customer -->|"mapped to"| node_database_sql

click node_manage_py "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/manage.py"
click node_config_settings "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/config/settings.py"
click node_config_urls "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/config/urls.py"
click node_api_urls "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/urls.py"
click node_api_common "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/serializers.py"
click node_appointment_api "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/appointment_api.py"
click node_customer_api "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/customer_api.py"
click node_invoice_api "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/invoice_api.py"
click node_medical_api "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/medical_record_api.py"
click node_spa_api "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/spa_api.py"
click node_visit_api "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/visit_api.py"
click node_service_appointment "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/services/appointment_service.py"
click node_service_payment "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/services/payment_service.py"
click node_service_spa "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/services/spa_service.py"
click node_service_tx "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/services/transaction.py"
click node_feature_create_appt "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/features/appointment/create_appointment.py"
click node_feature_checkin "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/features/visit/start_examination.py"
click node_feature_invoice "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/features/invoice/create_invoice.py"
click node_feature_escalate "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/features/spa/escalate_to_doctor.py"
click node_repo_appointment "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/repositories/appointment_repository.py"
click node_repo_invoice "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/repositories/invoice_repository.py"
click node_entity_appointment "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/entities/appointment.py"
click node_entity_visit "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/entities/visit.py"
click node_entity_invoice "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/entities/invoice.py"
click node_entity_customer "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/entities/customer.py"
click node_database_sql "https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/database/database.sql"

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_manage_py,node_config_settings,node_config_urls toneBlue
class node_api_urls,node_api_common,node_appointment_api,node_customer_api,node_invoice_api,node_medical_api,node_spa_api,node_visit_api toneAmber
class node_service_appointment,node_service_payment,node_service_spa,node_service_tx,node_feature_create_appt,node_feature_checkin,node_feature_invoice,node_feature_escalate toneMint
class node_repo_appointment,node_repo_invoice,node_entity_appointment,node_entity_visit,node_entity_invoice,node_entity_customer,node_database_sql toneRose
```

## Components

### Runtime & config

Django entry points and project wiring

- [manage.py](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/manage.py): entrypoint · Django management entry point · `manage.py`
- [Settings](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/config/settings.py): django config · Project settings and environment wiring · `config/settings.py`
- [Project URLs](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/config/urls.py): django routing · Top-level URL routing for the project · `config/urls.py`

### HTTP/API layer

Routing, endpoint modules, and shared API concerns

- [API URLs](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/urls.py): api router · Routes API endpoints to business modules · `src/api/urls.py`
- [API core](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/serializers.py): shared api · Serializers, permissions, responses, pagination, and exception handling · `src/api/serializers.py`
- [Appointments](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/appointment_api.py): endpoint module · Appointment-related HTTP endpoints · `src/api/appointment_api.py`
- [Customers](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/customer_api.py): endpoint module · Customer-related HTTP endpoints · `src/api/customer_api.py`
- [Invoices](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/invoice_api.py): endpoint module · Invoice and payment HTTP endpoints · `src/api/invoice_api.py`
- [Medical](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/medical_record_api.py): endpoint module · Medical record and prescription HTTP endpoints · `src/api/medical_record_api.py`
- [Spa](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/spa_api.py): endpoint module · Spa workflow HTTP endpoints · `src/api/spa_api.py`
- [Visits](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/api/visit_api.py): endpoint module · Visit workflow HTTP endpoints · `src/api/visit_api.py`

### Application core

Services and feature/use-case handlers

- [Appt service](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/services/appointment_service.py): service · Coordinates appointment lifecycle rules · `src/services/appointment_service.py`
- [Payments](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/services/payment_service.py): service · Handles payment and refund flows · `src/services/payment_service.py`
- [Spa service](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/services/spa_service.py): service · Coordinates spa workflow and escalation · `src/services/spa_service.py`
- [Transactions](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/services/transaction.py): service · Explicit transaction boundaries for multi-step operations · `src/services/transaction.py`
- [Create appt](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/features/appointment/create_appointment.py): use case · Create appointment use case · `src/features/appointment/create_appointment.py`
- [Start exam](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/features/visit/start_examination.py): use case · Check-in and examination start workflow · `src/features/visit/start_examination.py`
- [Create invoice](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/features/invoice/create_invoice.py): use case · Invoice creation use case · `src/features/invoice/create_invoice.py`
- [Escalate](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/features/spa/escalate_to_doctor.py): use case · Spa-to-doctor escalation use case · `src/features/spa/escalate_to_doctor.py`

### Domain & persistence

Entities, repositories, and database schema

- [Appt repo](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/repositories/appointment_repository.py): repository · Appointment persistence boundary · `src/repositories/appointment_repository.py`
- [Invoice repo](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/repositories/invoice_repository.py): repository · Invoice persistence boundary · `src/repositories/invoice_repository.py`
- [Appointment](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/entities/appointment.py): domain entity · Core appointment model · `src/entities/appointment.py`
- [Visit](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/entities/visit.py): domain entity · Core visit model · `src/entities/visit.py`
- [Invoice](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/entities/invoice.py): domain entity · Core invoice model · `src/entities/invoice.py`
- [Customer](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/src/entities/customer.py): domain entity · Core customer model · `src/entities/customer.py`
- [Database](https://github.com/maituyet04/datn_2026_dscms_luumaituyet/blob/main/database/database.sql): schema · Persistent schema and tables · `database/database.sql`

## Connections

- manage.py → Settings: loads · Bootstraps Django configuration
- Settings → Project URLs: wires · Registers project routing
- Project URLs → API URLs: routes · Dispatches API traffic into the application API router
- API URLs → Appointments: maps · Appointment endpoint routes
- API URLs → Customers: maps · Customer endpoint routes
- API URLs → Invoices: maps · Invoice endpoint routes
- API URLs → Medical: maps · Medical endpoint routes
- API URLs → Spa: maps · Spa endpoint routes
- API URLs → Visits: maps · Visit endpoint routes
- Appointments → API core: uses · Shares serializers, permissions, and response handling
- Invoices → API core: uses · Shares serializers, permissions, and response handling
- Appt service → Create appt: orchestrates · Delegates appointment creation use case
- Appt service → Appt repo: persists via · Reads and writes appointment data
- Payments → Create invoice: orchestrates · Coordinates invoice/payment work
- Payments → Invoice repo: persists via · Reads and writes invoice data
- Payments → Transactions: wraps · Uses explicit transaction boundaries
- Spa service → Escalate: orchestrates · Coordinates spa escalation workflow
- Create appt → Appointment: builds · Creates appointment domain state
- Start exam → Visit: advances · Starts visit/examination state
- Create invoice → Invoice: builds · Creates invoice domain state
- Escalate → Customer: updates · Uses customer context during escalation
- Appt repo → Appointment: stores · Persists appointment aggregates
- Invoice repo → Invoice: stores · Persists invoice aggregates
- Appointment → Database: mapped to · Appointment data is stored in the database schema
- Visit → Database: mapped to · Visit data is stored in the database schema
- Invoice → Database: mapped to · Invoice data is stored in the database schema
- Customer → Database: mapped to · Customer data is stored in the database schema
