# minhtumtn/theduckhospital architecture

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

- Interactive diagram: https://gitdiagram.com/minhtumtn/theduckhospital
- Repository: https://github.com/minhtumtn/theduckhospital

## Overview

- Clients: Separate the client applications clearly:
- Web Client (ReactJS web app)
- Mobile Client (React Native app)
- SMS OTP Android App for authentication
- Back-end Server: Java Spring Boot REST API that includes multiple layers (controllers, services, repositories, security, error handling) managing different domain models (patients, staff, appointments, medical records, etc.).
- Database: Microsoft SQL Server handling persistent storage.
- External Services: Show integrations with external systems:
- Cloudinary (for file and image storage)
- Microsoft Graph API (used to generate and manage email accounts for staff)
- Google App Password/Email service (for sending OTP emails)
- CI/CD Tools: These include GitHub workflows for Firebase hosting, Jenkins (as defined by Jenkinsfile), and Docker (using Dockerfile) to containerize/deploy components.
- Automation Testing: Automation test modules and scripts (the automation-test folder) that ensure system integrity.

##### Relationships and interactions
- That the back-end communicates with the database for data persistence.
- Back-end making outbound calls to external services (Cloudinary, Microsoft Graph, and Gmail/OTP service).
- Optionally, illustrate the CI/CD pipeline – from code commit to automated testing and deployment (using GitHub, Jenkins, Docker, Firebase hosting).

##### Important architectural patterns and design principles
- Layered architecture and separation of concerns: Highlight the Controller-Service-Repository pattern in the Spring Boot back-end.
- Security aspects: Illustrate the use of JWT, custom user details, and security configuration.
- Front-end separation: Differentiate between web and mobile clients and show how they interface with the same API.
- Integration and configuration management: Show how environment-specific configurations (like application.properties for the back-end and the .env file for web clients) are used.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients Layer"
        A1["ReactJS Web Client"]:::client
        A2["React Native Mobile Client"]:::client
        A3["SMS OTP Android App"]:::client
    end

    %% API Layer
    subgraph "API Layer"
        B["Spring Boot API"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        C["MS SQL Server"]:::database
    end

    %% External Services
    subgraph "External Services"
        D["Cloudinary"]:::external
        E["Microsoft Graph API"]:::external
        F["Email/OTP Service"]:::external
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        G["GitHub Workflows"]:::cicd
        H["Jenkins"]:::cicd
        I["Docker Containerization"]:::cicd
        J["Automation Testing"]:::test
    end

    %% Connections from Clients to API
    A1 -->|"API_Request"| B
    A2 -->|"API_Request"| B
    A3 -->|"Auth_Request"| B

    %% API to Database connections
    B -- "DB_Query&Update" --> C
    C -- "Return_Data" --> B

    %% API to External Services connections
    B -->|"File_Upload"| D
    B -->|"Graph_Query"| E
    B -->|"OTP_Email"| F

    %% CI/CD Pipeline integrations
    G -->|"Trigger_Build"| B
    G -->|"Deploy_Web_App"| A1
    H -->|"Pipeline_Exec"| B
    I -->|"Containerize"| B
    I -->|"Deploy_Mobile_App"| A2
    J -->|"Automated_Tests"| B

    %% Click Events
    click A1 "https://github.com/minhtumtn/theduckhospital/tree/main/the-duck-hospital-ui"
    click A2 "https://github.com/minhtumtn/theduckhospital/tree/main/TheDuckHospitalReactNative"
    click A3 "https://github.com/minhtumtn/theduckhospital/tree/main/TheDuckMobile_SMSOTP"
    click B "https://github.com/minhtumtn/theduckhospital/tree/main/TheDuckHospitalAPI"
    click C "https://github.com/minhtumtn/theduckhospital/blob/main/TheDuckHospitalAPI/src/main/resources/application.properties"
    click D "https://github.com/minhtumtn/theduckhospital/blob/main/TheDuckHospitalAPI/src/main/java/com/theduckhospital/api/services/impl/CloudinaryServicesImpl.java"
    click E "https://github.com/minhtumtn/theduckhospital/blob/main/TheDuckHospitalAPI/src/main/java/com/theduckhospital/api/services/impl/MSGraphServicesImpl.java"
    click F "https://github.com/minhtumtn/theduckhospital/blob/main/TheDuckHospitalAPI/src/main/java/com/theduckhospital/api/services/impl/OTPServicesImpl.java"
    click G "https://github.com/minhtumtn/theduckhospital/tree/main/.github/workflows"
    click H "https://github.com/minhtumtn/theduckhospital/tree/main/Jenkinsfile"
    click I "https://github.com/minhtumtn/theduckhospital/tree/main/Dockerfile"
    click J "https://github.com/minhtumtn/theduckhospital/tree/main/automation-test"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef database fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef external fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef cicd fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef test fill:#FFA07A,stroke:#000,stroke-width:2px;
```
