# vulnx1/hospital architecture

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

- Interactive diagram: https://gitdiagram.com/vulnx1/hospital
- Repository: https://github.com/vulnx1/hospital

## Overview

##### Project type and purpose
- This is a full-stack Hospital Management System:
- Frontend: React SPA (with Tailwind CSS) under `frontend/`.
- Backend: Spring Boot monolith under `src/main/java/com/hospital/`.
- Database layer: MySQL (or H2 for dev) via Spring Data JPA.
- External service: OpenAI GPT-3.5 for AI chatbot.
- Purpose: manage users (Admin/Doctor/Patient), appointments, records, prescriptions, inventory, billing, plus chat assistant.

##### File structure
- Top-level directories:
- `frontend/`: React code, components, pages, contexts, hooks, services.
- `src/main/java/com/hospital/`: backend MVC layers:
– `config/`: security & WebSocket config
– `controller/`: REST/WebSocket endpoints
– `dto/`: request/response models
– `entity/`: JPA entities
– `repository/`: Spring Data repositories
– `service/`: business logic, including `OpenAIService`
– `service/impl/`: service implementations
- `src/main/resources/`: application props, SQL scripts, static assets, templates
- `pom.xml` & Maven wrapper: build orchestration
- `.gitignore`, `.gitattributes`: version control rules

##### Insights from README
- Layered architecture with role-based auth (JWT planned)
- APIs for each domain (Auth, Doctors, Patients, Appointments, Billing, Inventory, MedicalRecords, Chat)
- Uses HTTP REST + WebSockets for real-time chat
- Centralized exception handling (`@ControllerAdvice`)
- Technology stack: Java 17, Spring Boot, Spring Security, Spring Data JPA, MySQL/H2, React, Tailwind, OpenAI API

##### Detail
- Two distinct communication channels: REST (synchronous) vs WebSocket (real-time chat)
- How the `OpenAIService` sits inside your service layer and bridges to the external API

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        SPA["React SPA"]:::ui
        UIComp["UI Components"]:::ui
        Pages["Pages (Dashboard, Chat, Patients, etc.)"]:::ui
        useApi["useApi Hook"]:::ui
        AuthCtx["Auth Context"]:::ui
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        Sec["Security Filter (JWT)"]:::backend

        subgraph "Controllers"
            direction TB
            Ctrl["REST Controllers"]:::backend
            WS_Ctrl["WebSocket Controller"]:::backend
        end

        subgraph "Services"
            direction TB
            Svc["Business Logic Services"]:::backend
            Impl["Service Implementations"]:::backend
        end

        subgraph "Repositories"
            direction TB
            Repo["JPA Repositories"]:::backend
        end

        subgraph "Entities & DTOs"
            direction TB
            Ent["JPA Entities"]:::backend
            DTO["DTO Models"]:::backend
        end

        subgraph "Configuration & Resources"
            direction TB
            AppEntry["Application.java"]:::backend
            WebSockCfg["WebSocketConfig"]:::backend
            UserCtx["UserContext"]:::backend
            Props["application.properties"]:::backend
            Schema["schema.sql"]:::backend
            Data["data.sql"]:::backend
            IndexHTML["index.html"]:::backend
            LoginHTML["login.html"]:::backend
        end
    end

    %% Database and External
    DB["MySQL / H2 Database"]:::db
    OpenAI["OpenAI GPT-3.5 API"]:::external

    %% Flows: REST
    SPA -->|"REST calls"| Sec
    Sec --> Ctrl
    Ctrl --> Svc
    Svc --> Repo
    Repo --> DB

    %% Flows: WebSocket Chat
    Pages -->|"WebSocket connect"| WS_Ctrl
    WS_Ctrl --> Svc
    Svc --> OpenAI
    OpenAI --> WS_Ctrl
    WS_Ctrl --> Pages

    %% Click Events Frontend
    click SPA "https://github.com/vulnx1/hospital/tree/main/frontend/src"
    click UIComp "https://github.com/vulnx1/hospital/tree/main/frontend/src/components"
    click Pages "https://github.com/vulnx1/hospital/tree/main/frontend/src/pages"
    click useApi "https://github.com/vulnx1/hospital/blob/main/frontend/src/hooks/useApi.js"
    click AuthCtx "https://github.com/vulnx1/hospital/blob/main/frontend/src/contexts/AuthContext.js"

    %% Click Events Backend
    click AppEntry "https://github.com/vulnx1/hospital/blob/main/src/main/java/com/hospital/Application.java"
    click WebSockCfg "https://github.com/vulnx1/hospital/blob/main/src/main/java/com/hospital/config/WebSocketConfig.java"
    click UserCtx "https://github.com/vulnx1/hospital/blob/main/src/main/java/com/hospital/context/UserContext.java"
    click Ctrl "https://github.com/vulnx1/hospital/tree/main/src/main/java/com/hospital/controller"
    click WS_Ctrl "https://github.com/vulnx1/hospital/blob/main/src/main/java/com/hospital/controller/WebSocketController.java"
    click DTO "https://github.com/vulnx1/hospital/tree/main/src/main/java/com/hospital/dto"
    click Ent "https://github.com/vulnx1/hospital/tree/main/src/main/java/com/hospital/entity"
    click Repo "https://github.com/vulnx1/hospital/tree/main/src/main/java/com/hospital/repository"
    click Svc "https://github.com/vulnx1/hospital/tree/main/src/main/java/com/hospital/service"
    click Impl "https://github.com/vulnx1/hospital/tree/main/src/main/java/com/hospital/service/impl"
    click Props "https://github.com/vulnx1/hospital/blob/main/src/main/resources/application.properties"
    click Schema "https://github.com/vulnx1/hospital/blob/main/src/main/resources/schema.sql"
    click Data "https://github.com/vulnx1/hospital/blob/main/src/main/resources/data.sql"
    click IndexHTML "https://github.com/vulnx1/hospital/blob/main/src/main/resources/static/index.html"
    click LoginHTML "https://github.com/vulnx1/hospital/blob/main/src/main/resources/templates/login.html"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6,stroke-width:1px;
    classDef backend fill:#D6F5D6,stroke:#28A745,stroke-width:1px;
    classDef db fill:#FFE5B4,stroke:#FF8C00,stroke-width:1px;
    classDef external fill:#E1D5E7,stroke:#6F42C1,stroke-width:1px;
```
