# nemo720/c1se.62-clinicbooking-be architecture

> Architecture diagram of the GitHub repository nemo720/c1se.62-clinicbooking-be, 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/nemo720/c1se.62-clinicbooking-be
- Repository: https://github.com/nemo720/c1se.62-clinicbooking-be

## Overview

##### Project Type and Purpose
- The project is a Java Spring Boot backend application (Maven project) designed for a clinic booking system. It handles appointments, user authentication, department and doctor management, prescription handling, and even integrates with ChatGPT as well as speech-to-text services.
- The README (“Đồ án Capstone 1”) implies that this is a capstone project, so it’s likely designed as a full-fledged backend system for a clinic booking application.

##### File Structure
- The top-level structure shows standard Maven files (pom.xml, mvnw, etc.) and the “src” directory, which indicates a Java project.
- Inside src/main/java, the code is organized in clear packages:
- “controller” package: Contains various controllers (e.g., AppointmentController, AuthController, ChatGPTController, etc.) which serve as the “presentation layer.”
- “dto” package: Holds data transfer objects for requests and responses to and from the API.
- “entity” package: Defines the domain models such as Appointment, Doctor, Department, etc.
- “repository” package: Contains repository interfaces for persistence access, indicating integration with a database (likely via Spring Data JPA).
- “service” package: Contains services for business logic; each module (Appointment, Authentication, ChatGPT, Department, Doctor, Medicine, etc.) has both interfaces and implementations and even Email and Security services.
- “config” package: Contains configuration classes (ApplicationConfig, OpenAIConfig, SecurityConfig) to configure the application, external APIs, and security.
- “exception” package: For global exception handling.
- The structure suggests use of layered architecture (Controller → Service → Repository) common in Spring Boot applications, with additional configuration and integration layers.

##### README for Extra Insights
- While the README is minimal, its title confirms the project’s focus on clinic booking.

a. Main Components to Represent:
- Client / API Consumers: External users (likely via HTTP/REST).
- Controllers: Different endpoints for Appointment, Authentication, Department, Doctor, ChatGPT, etc.
- Service Layer: Business logic components for each domain area (appointments, authentication, chat handling, email, etc.)
- Repository Layer: Data access components interacting with the database.
- Domain / Entity layer: Business objects such as Appointment, Doctor, Department, PatientRecord, etc.
- Configuration Components: SecurityConfig, OpenAIConfig, and ApplicationConfig which wire up security, external API configurations, and overall application settings.
- External Services/Integrations: ChatGPTService (including SpeechToTextService) and EmailService, which integrate with external APIs or services.

b. Relationships and Interactions:
- Incoming requests hit the Controllers, which accept data transfer objects (DTOs) and delegate to the corresponding Service.
- The Service layer implements business logic and, where needed, calls the Repository layer to persist or retrieve data.
- Exceptions are managed by the GlobalExceptionHandler, ensuring a consistent error response.
- Security is enforced using SecurityConfig and related SecurityService implementations.
- Calls to external APIs are abstracted through services like ChatGPTService.
- Controllers also handle authentication operations using their dedicated AuthenticationService.

c. Architectural Patterns:
- Layered (or n-tier) architecture is prominent: Controllers (presentation) → Services (business logic) → Repositories (data/persistence).
- Use of DTOs is a good practice for data encapsulation and transfers between layers.
- Configuration classes separate cross-cutting concerns (security, external service configuration).
- Exception handling with GlobalExceptionHandler centralizes error management.

d. Technologies, Frameworks, and Libraries:
- Java with Spring Boot (controllers, dependency injection, security).
- Maven as the build tool.
- Likely use of Spring Data JPA for ORM, given the repository interfaces.
- Integration with external APIs (OpenAI ChatGPT, Speech-to-Text) as indicated by the ChatGPT and SpeechToText services.
- Email service indicates possible integration with an SMTP or third-party email provider.
- Security-related configurations, which suggest possible use of Spring Security.

##### Elements
- Use clear labels for each component. For example:
- “Controller Layer” with sub-components: AppointmentController, AuthController, ChatGPTController, etc.
- “Service Layer” with modules: AppointmentService, AuthenticationService, ChatGPTService, DepartmentService, DoctorService, EmailService, SecurityService, etc.
- “Repository Layer” listing key repositories: AppointmentRepository, DoctorRepository, etc.
- “Domain Model” for entities such as Appointment, Doctor, and Department.
- “Configuration Layer” for SecurityConfig, ApplicationConfig, OpenAIConfig.
- “External Integrations” for ChatGPT API and Email/SpeechToText services.

- A clear separation of concerns.
- All logical flows, such as user authentication, appointment management, clinic data management, and external communication via ChatGPT.
- Important design elements like security handling and exception management pathways.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External"
        A["Client / API Consumer"]:::client
    end

    subgraph "Controller Layer"
        B["Controllers"]:::controller
        DTO["Data Transfer Objects"]:::dto
        EX["Global Exception Handler"]:::config
        MP["Mapping Utilities"]:::config
    end

    subgraph "Service Layer"
        S1["Appointment Service"]:::service
        S2["Authentication Service"]:::service
        S3["ChatGPT & Speech-to-Text Service"]:::service
        S4["Department Service"]:::service
        S5["Doctor Service"]:::service
        S6["Doctor Rating Service"]:::service
        S7["Medicine Service"]:::service
        S8["Patient Record Service"]:::service
        S9["TimeSlot Service"]:::service
        S10["User Service"]:::service
        S11["Security Service"]:::service
        S12["Email Service"]:::service
    end

    subgraph "Repository Layer"
        R["Repository Layer"]:::repository
    end

    subgraph "Domain Layer"
        D["Domain Model"]:::domain
    end

    subgraph "Configuration & External"
        subgraph "Configuration Components"
            C1["ApplicationConfig"]:::config
            C2["OpenAIConfig"]:::config
            C3["SecurityConfig"]:::config
        end
        subgraph "External Integrations"
            E1["External ChatGPT API"]:::external
            E2["External Email/Speech Service"]:::external
        end
    end

    %% Relationships
    A -->|"sends_request"| B
    B -->|"uses_DTO"| DTO
    B -->|"delegates_to"| S1
    B -->|"delegates_to"| S2
    B -->|"delegates_to"| S3
    B -->|"delegates_to"| S4
    B -->|"delegates_to"| S5
    B -->|"delegates_to"| S6
    B -->|"delegates_to"| S7
    B -->|"delegates_to"| S8
    B -->|"delegates_to"| S9
    B -->|"delegates_to"| S10
    B -->|"delegates_to"| S11
    B -->|"delegates_to"| S12

    S1 -->|"calls_repo"| R
    S2 -->|"calls_repo"| R
    S3 -->|"calls_repo"| R
    S4 -->|"calls_repo"| R
    S5 -->|"calls_repo"| R
    S6 -->|"calls_repo"| R
    S7 -->|"calls_repo"| R
    S8 -->|"calls_repo"| R
    S9 -->|"calls_repo"| R
    S10 -->|"calls_repo"| R
    S11 -->|"calls_repo"| R
    S12 -->|"calls_repo"| R

    R -->|"maps_to"| D

    DTO -->|"transforms_to"| D

    C1 -->|"configures"| B
    C2 -->|"configures"| S3
    C3 -->|"configures"| S11

    MP -->|"maps_data"| DTO

    S3 -->|"calls"| E1
    S12 -->|"calls"| E2

    EX -->|"handles_errors"| B

    %% Click Events
    click B "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/controller"
    click S1 "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/service/AppointmentServices"
    click S2 "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/service/AuthenticationServices"
    click S3 "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/service/ChatGPTService"
    click S4 "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/service/DepartmentServices"
    click S5 "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/service/DoctorServices"
    click S6 "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/service/DoctorRatingServices"
    click S7 "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/service/MedicineServices"
    click S8 "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/service/PatientRecordServices"
    click S9 "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/service/TimeSlotServices"
    click S10 "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/service/UserServices"
    click S11 "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/service/SecurityServices"
    click S12 "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/service/Email"
    click R "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/repository"
    click D "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/entity"
    click DTO "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/dto"
    click C1 "https://github.com/nemo720/c1se.62-clinicbooking-be/blob/main/src/main/java/com/c1se62/clinic_booking/config/ApplicationConfig.java"
    click C2 "https://github.com/nemo720/c1se.62-clinicbooking-be/blob/main/src/main/java/com/c1se62/clinic_booking/config/OpenAIConfig.java"
    click C3 "https://github.com/nemo720/c1se.62-clinicbooking-be/blob/main/src/main/java/com/c1se62/clinic_booking/config/SecurityConfig.java"
    click EX "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/exception"
    click MP "https://github.com/nemo720/c1se.62-clinicbooking-be/tree/main/src/main/java/com/c1se62/clinic_booking/mapper"

    %% Styles
    classDef client fill:#ffcc99,stroke:#000,stroke-width:1px;
    classDef controller fill:#cce5ff,stroke:#000,stroke-width:1px;
    classDef service fill:#d4edda,stroke:#000,stroke-width:1px;
    classDef repository fill:#ffeeba,stroke:#000,stroke-width:1px;
    classDef domain fill:#d1c4e9,stroke:#000,stroke-width:1px;
    classDef dto fill:#d1f2eb,stroke:#000,stroke-width:1px;
    classDef config fill:#f8d7da,stroke:#000,stroke-width:1px;
    classDef external fill:#fff3cd,stroke:#000,stroke-width:1px;
```
