# dalrho/daibetes architecture

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

- Interactive diagram: https://gitdiagram.com/dalrho/daibetes
- Repository: https://github.com/dalrho/daibetes

## Overview

1. This repository is split into two main deployable parts: a JavaFX desktop application in `java-application` and a separate Python AI inference service in `python-ai-service`. The Java side is the primary user-facing system; the Python side is an internal analysis boundary for model-based diagnosis.

2. The Java application is a modular desktop app built with Java 17+, Maven, JavaFX/FXML, and JDBC/MySQL. `module-info.java` and the many `*.fxml` views show a classic UI-driven desktop architecture rather than a web app.

3. The UI is organized around multiple portals and workflows: login/register, doctor dashboard, patient dashboard, image upload/camera capture, image processing, records, results, inbox, and report review. There are also several standalone launcher classes, which suggests each screen or feature can be started independently during development.

4. The newer, more structured code lives under `org.example.daibetes`, which contains the core architecture. That package is split into `core` (domain + database), `modules` (auth, detection, doctor, ai), and `shared` utilities. The flat top-level packages like `login`, `register`, `patientsdashboard`, and `doctorDashboard` look like older or parallel UI implementations.

5. The domain layer models the main actors and their relationships: `User`, `Doctor`, and `Patient`, with factory classes for object creation. This aligns with the README’s OOP goal of shared user behavior plus role-specific permissions and attributes.

6. Authentication and registration are isolated in `modules/auth`, with controller classes for doctor/patient registration and a `LoginViewModel`. Validation and password handling are centralized in `shared/utils`, which keeps credential logic out of the UI controllers.

7. Persistence is handled through `core/database`, which contains a `MySQLConnection` singleton-style connector plus DAO classes for specific areas such as doctor dashboard, patient dashboard, images, reports, and tests. The presence of generic CRUD helpers (`CreateData`, `RetrieveData`, `UpdateData`, `DeleteData`) and an SQL script (`dbdaibetes.sql`) indicates a relational MySQL-backed workflow for users, scans, and diagnostic records.

8. The retinal image pipeline is in `modules/detection`. It is divided into image preprocessing, camera capture UI, and a scan analysis service. The preprocessing layer uses a decorator-based design (`BasePreprocessor`, `BrightnessDecorator`, `CLAHEDecorator`, `DenoiseDecorator`, `GrayscaleDecorator`, `ResizeDecorator`, `SharpenerDecorator`), matching the README’s goal of chaining filters dynamically before analysis.

9. The AI boundary is explicit: `AIInferenceService` on the Java side corresponds to a standalone Python service containing `inference_controller.py`, `dr_classification_service.py`, `model_loader.py`, `image_preprocessor.py`, and a trained model file (`diabetic_retinopathy_full_model.pth`). This service is likely where image tensors are prepared and passed through the ML model, while the Java app stays responsible for orchestration and UI.

10. The Python service is layered too: API layer, application services, domain result objects, and infrastructure for preprocessing and loading the model. The presence of `gemini_service.py` and `prompt_builder.py` suggests an additional text-generation or narrative-report step alongside classification, which would feed doctor-facing summaries.

11. The doctor workflow appears to be: upload or capture retinal image, preprocess/analyze it, review the AI output, and generate/approve results for the patient. The doctor dashboard, generate-results screen, records, report review, and inbox screens support that approval-and-delivery loop.

12. The patient workflow is separate and simpler: authentication, dashboard access, and viewing finalized diagnosis/results. `PatientDashboard*`, `records`, `results`, and `reviewResults` form the patient-facing boundary for consuming approved reports rather than generating them.

13. The resource layout reinforces the UI architecture: each screen has its own FXML file, with CSS in `styles/` and image assets in `resources/images`. That makes the architecture highly view-driven, with controllers acting as the glue between the FXML views and the services/DAOs.

14. For an architecture diagram, the key boundaries to show are: JavaFX UI/controllers at the top, domain and service layers in the middle, MySQL persistence below, and the Python AI service off to the side as an external analysis engine. The central business flow is image intake → preprocessing → AI inference → doctor review → stored result delivery to the patient.

Main entry points: [`java-application/src/main/java/org/example/daibetes/modules/auth`](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/auth) (Auth module), [`java-application/src/main/java`](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java) (Desktop UI), [`java-application/src/main/java/org/example/daibetes/modules/detection`](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/detection) (Detection module), [`java-application/src/main/java/org/example/daibetes/core/database`](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/core/database) (MySQL layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_java_app["JavaFX app"]
  node_java_ui["Desktop UI<br/>JavaFX/FXML shell"]
  node_login_module["Login<br/>legacy UI module"]
  node_register_module["Register<br/>legacy UI module"]
  node_doctor_dashboard["Doctor dashboard<br/>doctor UI"]
  node_patient_dashboard["Patient dashboard<br/>patient UI"]
  node_detection_ui["Image workflow<br/>detection UI"]
  node_auth_module["Auth module<br/>authentication"]
  node_detection_module["Detection module<br/>scan pipeline"]
  node_doctor_module["Doctor flow<br/>review workflow"]
  node_core_domain["Domain model<br/>entities"]
  node_core_db[("MySQL layer<br/>DAO/persistence")]
  node_shared_utils["Shared utils<br/>validation/security"]
  node_ai_client["AI client<br/>inference client"]
  node_login_vm["Login VM<br/>view-model"]
  node_preprocess_chain["Preprocess chain<br/>decorator pipeline"]
  node_scan_service["Scan analysis<br/>analysis service"]
end

subgraph group_python_service["Python AI service"]
  node_python_api["Inference API<br/>FastAPI/endpoint layer"]
  node_python_app["AI services<br/>application services"]
  node_python_infra["Model runtime<br/>infrastructure"]
  node_python_model["Trained model<br/>ML artifact"]
end

node_java_ui -->|"launches"| node_login_module
node_java_ui -->|"launches"| node_register_module
node_java_ui -->|"routes to"| node_doctor_dashboard
node_java_ui -->|"routes to"| node_patient_dashboard
node_java_ui -->|"opens"| node_detection_ui
node_login_module -->|"uses"| node_auth_module
node_register_module -->|"uses"| node_auth_module
node_auth_module -->|"binds"| node_login_vm
node_auth_module -->|"creates users"| node_core_domain
node_auth_module -->|"validates"| node_shared_utils
node_auth_module -->|"persists"| node_core_db
node_detection_ui -->|"drives"| node_detection_module
node_detection_module -->|"applies"| node_preprocess_chain
node_detection_module -->|"coordinates"| node_scan_service
node_scan_service -->|"calls"| node_ai_client
node_ai_client -->|"requests inference"| node_python_api
node_python_api -->|"dispatches"| node_python_app
node_python_app -->|"uses"| node_python_infra
node_python_infra -->|"loads"| node_python_model
node_doctor_dashboard -->|"hosts"| node_doctor_module
node_doctor_module -->|"reads/writes"| node_core_db
node_patient_dashboard -->|"reads"| node_core_db
node_detection_module -->|"stores scans"| node_core_db
node_doctor_module -.->|"delivers results to"| node_patient_dashboard

click node_java_ui "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java"
click node_login_module "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/login"
click node_register_module "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/register"
click node_doctor_dashboard "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/doctor/ui"
click node_patient_dashboard "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/patientsdashboard"
click node_detection_ui "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/detection/ui"
click node_auth_module "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/auth"
click node_detection_module "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/detection"
click node_doctor_module "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/doctor"
click node_core_domain "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/core/domain"
click node_core_db "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/core/database"
click node_shared_utils "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/shared/utils"
click node_ai_client "https://github.com/dalrho/daibetes/blob/main/java-application/src/main/java/org/example/daibetes/modules/ai/service/AIInferenceService.java"
click node_login_vm "https://github.com/dalrho/daibetes/blob/main/java-application/src/main/java/org/example/daibetes/modules/auth/viewmodel/LoginViewModel.java"
click node_preprocess_chain "https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/detection/imageProcessing/implementations"
click node_scan_service "https://github.com/dalrho/daibetes/blob/main/java-application/src/main/java/org/example/daibetes/modules/detection/service/ScanAnalysisService.java"
click node_python_api "https://github.com/dalrho/daibetes/blob/main/python-ai-service/python/app/api/inference_controller.py"
click node_python_app "https://github.com/dalrho/daibetes/tree/main/python-ai-service/python/app/application"
click node_python_infra "https://github.com/dalrho/daibetes/tree/main/python-ai-service/python/app/infrastructure"
click node_python_model "https://github.com/dalrho/daibetes/blob/main/python-ai-service/python/models/diabetic_retinopathy_full_model.pth"

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_java_ui,node_login_module,node_register_module,node_doctor_dashboard,node_patient_dashboard,node_detection_ui,node_auth_module,node_detection_module,node_doctor_module,node_core_domain,node_core_db,node_shared_utils,node_ai_client,node_login_vm,node_preprocess_chain,node_scan_service toneBlue
class node_python_api,node_python_app,node_python_infra,node_python_model toneAmber
```

## Components

### JavaFX app

Primary desktop application with UI, domain, services, and persistence.

- [Desktop UI](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java): JavaFX/FXML shell · Main desktop application surface with multiple screens and launchers. · `java-application/src/main/java`
- [Login](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/login): legacy UI module · Standalone login screen and launcher flow. · `java-application/src/main/java/login`
- [Register](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/register): legacy UI module · Standalone registration flow for account creation. · `java-application/src/main/java/register`
- [Doctor dashboard](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/doctor/ui): doctor UI · Doctor-facing portal for reviewing cases and coordinating results. · `java-application/src/main/java/org/example/daibetes/modules/doctor/ui`
- [Patient dashboard](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/patientsdashboard): patient UI · Patient-facing portal for viewing finalized information. · `java-application/src/main/java/patientsdashboard`
- [Image workflow](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/detection/ui): detection UI · Image upload, capture, and processing screens for retinal scans. · `java-application/src/main/java/org/example/daibetes/modules/detection/ui`
- [Auth module](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/auth): authentication · Login, registration, and credential coordination. · `java-application/src/main/java/org/example/daibetes/modules/auth`
- [Detection module](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/detection): scan pipeline · Retinal image preprocessing, camera capture, and scan analysis. · `java-application/src/main/java/org/example/daibetes/modules/detection`
- [Doctor flow](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/doctor): review workflow · Doctor result-generation and inbox workflow boundary. · `java-application/src/main/java/org/example/daibetes/modules/doctor`
- [Domain model](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/core/domain): entities · Shared user and role model for doctors and patients. · `java-application/src/main/java/org/example/daibetes/core/domain`
- [MySQL layer](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/core/database): DAO/persistence · Database connection, CRUD helpers, and feature-specific DAOs. · `java-application/src/main/java/org/example/daibetes/core/database`
- [Shared utils](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/shared/utils): validation/security · Password hashing, validation, and SQL schema support. · `java-application/src/main/java/org/example/daibetes/shared/utils`
- [AI client](https://github.com/dalrho/daibetes/blob/main/java-application/src/main/java/org/example/daibetes/modules/ai/service/AIInferenceService.java): inference client · Java-side bridge to the external Python inference service. · `java-application/src/main/java/org/example/daibetes/modules/ai/service/AIInferenceService.java`
- [Login VM](https://github.com/dalrho/daibetes/blob/main/java-application/src/main/java/org/example/daibetes/modules/auth/viewmodel/LoginViewModel.java): view-model · Presentation model used to separate login UI from auth logic. · `java-application/src/main/java/org/example/daibetes/modules/auth/viewmodel/LoginViewModel.java`
- [Preprocess chain](https://github.com/dalrho/daibetes/tree/main/java-application/src/main/java/org/example/daibetes/modules/detection/imageProcessing/implementations): decorator pipeline · Composable image preprocessing filters before analysis. · `java-application/src/main/java/org/example/daibetes/modules/detection/imageProcessing/implementations`
- [Scan analysis](https://github.com/dalrho/daibetes/blob/main/java-application/src/main/java/org/example/daibetes/modules/detection/service/ScanAnalysisService.java): analysis service · Coordinates preprocessing and downstream scan analysis requests. · `java-application/src/main/java/org/example/daibetes/modules/detection/service/ScanAnalysisService.java`

### Python AI service

External inference boundary for model-based diabetic retinopathy analysis.

- [Inference API](https://github.com/dalrho/daibetes/blob/main/python-ai-service/python/app/api/inference_controller.py): FastAPI/endpoint layer · HTTP entrypoint for model inference requests. · `python-ai-service/python/app/api/inference_controller.py`
- [AI services](https://github.com/dalrho/daibetes/tree/main/python-ai-service/python/app/application): application services · Classification, prompt building, and optional narrative generation. · `python-ai-service/python/app/application`
- [Model runtime](https://github.com/dalrho/daibetes/tree/main/python-ai-service/python/app/infrastructure): infrastructure · Model loading and image preprocessing infrastructure. · `python-ai-service/python/app/infrastructure`
- [Trained model](https://github.com/dalrho/daibetes/blob/main/python-ai-service/python/models/diabetic_retinopathy_full_model.pth): ML artifact · Saved diabetic retinopathy model used by the service. · `python-ai-service/python/models/diabetic_retinopathy_full_model.pth`

## Connections

- Desktop UI → Login: launches · The desktop application includes a dedicated login flow.
- Desktop UI → Register: launches · The desktop application includes a dedicated registration flow.
- Desktop UI → Doctor dashboard: routes to · Doctors enter the review and results workflow from the UI.
- Desktop UI → Patient dashboard: routes to · Patients enter the read-only results workflow from the UI.
- Desktop UI → Image workflow: opens · The UI exposes image upload and capture screens.
- Login → Auth module: uses · Login screens delegate credential work to the auth module.
- Register → Auth module: uses · Registration screens delegate account creation to auth services.
- Auth module → Login VM: binds · Authentication UI is organized around a login view model.
- Auth module → Domain model: creates users · Authentication and registration operate on user role entities.
- Auth module → Shared utils: validates · Credential and input checks are centralized in shared utilities.
- Auth module → MySQL layer: persists · User accounts are stored through DAO-backed database access.
- Image workflow → Detection module: drives · Image upload and camera screens feed the detection pipeline.
- Detection module → Preprocess chain: applies · Image preprocessing is implemented as a decorator chain.
- Detection module → Scan analysis: coordinates · Detection workflows are orchestrated through scan analysis service logic.
- Scan analysis → AI client: calls · Java-side analysis service invokes the external AI boundary.
- AI client → Inference API: requests inference · The Java app sends images or payloads to the Python service.
- Inference API → AI services: dispatches · API requests flow into classification and prompt services.
- AI services → Model runtime: uses · Application services rely on preprocessing and model loading infrastructure.
- Model runtime → Trained model: loads · The service uses the trained retinopathy model artifact.
- Doctor dashboard → Doctor flow: hosts · Doctor dashboard screens belong to the doctor workflow boundary.
- Doctor flow → MySQL layer: reads/writes · Doctor review and result generation persist records through DAOs.
- Patient dashboard → MySQL layer: reads · Patient views are populated from stored records and reports.
- Detection module → MySQL layer: stores scans · Image and diagnostic data are saved via persistence helpers.
- Doctor flow → Patient dashboard: delivers results to · Approved results flow from the doctor workflow to the patient view.
