# cuonglmptit/sad-health-management-system architecture

> Architecture diagram of the GitHub repository cuonglmptit/sad-health-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cuonglmptit/sad-health-management-system
- Repository: https://github.com/cuonglmptit/sad-health-management-system

## Overview

##### Project Type and Purpose
- The README indicates “SAD-health-management-system” with a note on databases (MongoDB, MySQL) and a single command (run_all_server.py) to start the system. This points to a full-blown health management system that is split into multiple service components.
- The system supports functionalities related to appointments, clinics, doctors, employees, health records, patients, and overall system orchestration via an “hms” component.

##### File Structure
- There are several major directories each representing a Django project/service:
- appointment_service: Manages appointment-related functionality.
- clinic_service: Handles clinic information.
- doctor_service: Manages doctor profiles and details.
- employee_service: Deals with employee management.
- healthrecord_service: Manages patient health records.
- patient_service: Manages patient data.
- hms: Provides the frontend and main integration layer (UI templates, static files, and a separate Django project).
- Each service project contains the typical Django layout (an inner service folder with settings, urls, wsgi/asgi, and an app folder with models, views, serializers, and migrations).
- There’s a run_all_server.py at the root level used to start all the services and bring up the unified application, likely orchestrating the microservices.

##### README Insights
- The README highlights the entry point (run_all_server.py) and the deployed URL (http://127.0.0.1:1300/hms/home), indicating that the “hms” project might be acting as the main gateway for the entire system.
- It confirms that the application leverages both MongoDB and MySQL. This suggests different components may use different databases based on the data they handle.

a. Main Components:
- Service Components: Appointment Service, Clinic Service, Doctor Service, Employee Service, HealthRecord Service, and Patient Service.
- Central Integration / Frontend: The hms component.
- Databases: MongoDB and MySQL; assign each service to the appropriate DB if known (or denote that some services might choose one based on data type).
- Orchestration Entry Point: run_all_server.py as the initializer or orchestrator.

b. Relationships and Data Flow:
- Each service component runs as a separate Django project exposing its own REST API endpoints (as seen by the urls.py in each folder).
- That the run_all_server.py is responsible for launching all these services.
- If there is any inter-service communication (for example, appointments might tie patients, doctors, and clinics), represent these dependencies as well.

c. Architectural Patterns:
- Microservices-Oriented Architecture: Each healthcare domain (appointment, clinic, etc.) is separated into its own service.
- RESTful Communication: With each service exposing its endpoints for CRUD operations.
- Layered/Django MVC pattern: Inside each microservice, the typical separation between models, views, and serializers indicates structured internal design.
- Database Segregation: Use of both MongoDB and MySQL to possibly separate high transaction relational data from more flexible storage (document based) data.

d. Relevant Technologies and Frameworks:
- Django: All service components are Django applications (as indicated by the manage.py, settings.py, views.py, etc.).
- MongoDB and MySQL for data storage.
- Likely Django REST Framework for API endpoints (inferred by serializers and views).
- Frontend rendering and static content management through the hms/frontend module.

##### Summary
- Pay extra attention to how the frontend hms integrates and orchestrates across these discrete services, ensuring a seamless flow of data and functionality across the system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Orchestration Layer
    subgraph "Orchestration Layer"
        run_all("run_all_server.py")
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        hms1("HMS")
    end

    %% Microservices (Backend)
    subgraph "Microservices"
        A("Appointment Service")
        C("Clinic Service")
        D("Doctor Service")
        E("Employee Service")
        H("HealthRecord Service")
        P("Patient Service")
    end

    %% Databases
    subgraph "Databases"
        mysql("MySQL Database")
        mongo("MongoDB")
    end

    %% Orchestration launching services
    run_all -->|"launches"| hms1
    run_all -->|"launches"| A
    run_all -->|"launches"| C
    run_all -->|"launches"| D
    run_all -->|"launches"| E
    run_all -->|"launches"| H
    run_all -->|"launches"| P

    %% HMS calling microservices via REST API
    hms1 -->|"REST_API_call"| A
    hms1 -->|"REST_API_call"| C
    hms1 -->|"REST_API_call"| D
    hms1 -->|"REST_API_call"| E
    hms1 -->|"REST_API_call"| H
    hms1 -->|"REST_API_call"| P

    %% Microservices persisting data into databases
    A -->|"data_persistence"| mysql
    C -->|"data_persistence"| mysql
    D -->|"data_persistence"| mysql
    E -->|"data_persistence"| mysql
    P -->|"data_persistence"| mysql
    H -->|"data_persistence"| mongo

    %% Styles
    classDef orchestration fill:#fff2cc, stroke:#d4a017, stroke-width:2px;
    classDef frontend fill:#ccf2ff, stroke:#0177d4, stroke-width:2px;
    classDef backend fill:#ccffcc, stroke:#2d7a2d, stroke-width:2px;
    classDef database fill:#ffcccc, stroke:#d41717, stroke-width:2px, stroke-dasharray: 5,5;

    class run_all orchestration;
    class hms1 frontend;
    class A,C,D,E,H,P backend;
    class mysql,mongo database;

    %% Click Events for Component Mapping
    click A "https://github.com/cuonglmptit/sad-health-management-system/tree/main/appointment_service/appointment"
    click A "https://github.com/cuonglmptit/sad-health-management-system/tree/main/appointment_service/appointment_service"
    click C "https://github.com/cuonglmptit/sad-health-management-system/tree/main/clinic_service/clinic"
    click C "https://github.com/cuonglmptit/sad-health-management-system/tree/main/clinic_service/clinic_service"
    click D "https://github.com/cuonglmptit/sad-health-management-system/tree/main/doctor_service/doctor"
    click D "https://github.com/cuonglmptit/sad-health-management-system/tree/main/doctor_service/doctor_service"
    click E "https://github.com/cuonglmptit/sad-health-management-system/tree/main/employee_service/employee"
    click E "https://github.com/cuonglmptit/sad-health-management-system/tree/main/employee_service/employee_service"
    click H "https://github.com/cuonglmptit/sad-health-management-system/tree/main/healthrecord_service/record"
    click H "https://github.com/cuonglmptit/sad-health-management-system/tree/main/healthrecord_service/healthrecord_service"
    click P "https://github.com/cuonglmptit/sad-health-management-system/tree/main/patient_service/patient"
    click P "https://github.com/cuonglmptit/sad-health-management-system/tree/main/patient_service/patient_service"
    click hms1 "https://github.com/cuonglmptit/sad-health-management-system/tree/main/hms/frontend"
    click hms1 "https://github.com/cuonglmptit/sad-health-management-system/tree/main/hms/hms"
    click run_all "https://github.com/cuonglmptit/sad-health-management-system/blob/main/run_all_server.py"
```
