# xdmdcp/hospital architecture

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

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

## Overview

##### Project type and purpose
- This is a full-stack, RESTful appointment and registration management system for hospitals.
- The backend is a Spring Boot + MyBatis Java service (“hospital” repo) providing REST APIs; frontends include a WeChat/Alipay/H5 mini-app and a web admin portal (in separate repos).

##### File structure
- Top-level:
- pom.xml – Maven build definition.
- src/main/java – application source code under cn.yujian95.hospital.
- src/main/resources – configuration: application.yml, MyBatis XML mappers, SQL, Redis settings.
- doc/ – demo screenshots and deployment instructions.
- Within java/…/hospital:
- common/api, common/security – API result wrappers, error codes, RESTful auth handlers, JWT support.
- component – external integrations (Ali SMS, Qiniu file storage, WeChat messages, web logging).
- config – Spring configurations (security, MyBatis, Swagger).
- controller – REST controllers (HospitalClinicController, UserBasicInfoController, VisitAppointmentController, etc.).
- service & service/impl – business logic interfaces and implementations (e.g. IVisitAppointmentService → VisitAppointmentServiceImpl).
- mapper & mapper/dao – MyBatis mappers and custom DAOs.
- entity – database entities (e.g. VisitPlan, PowerAccount) and Example classes for queries.
- dto & dto/param – data transfer and parameter objects for request/response.
- Patterns: Layered MVC (Controller → Service → Mapper → Database), JWT-based stateless security, MyBatis Generator for codegen, Redis for caching, external service adapters.

##### Extract insights from README
- Purpose: “simple hospital appointment registration management system”.
- Tech stack:
- Spring Boot + MyBatis (RESTful API)
- Spring Security + JWT (role-based dynamic permissions)
- MyBatis Generator, Swagger/Knife4j (API docs)
- Redis (2nd-level cache)
- Aliyun SMS, Qiniu Cloud Storage

##### Components
a. Main components
- Clients: Mini-app (WeChat/Alipay/H5), Web Admin portal
- API Layer: Spring Boot REST Controllers
- Security Layer: Spring Security + JWT filters (authentication entry point, access denied handler, dynamic security filter)
- Business Layer: Service interfaces and implementations
- Data Access Layer: MyBatis mappers & DAOs, MyBatis Generator config
- Database: MySQL (hospital.sql schema)
- Cache: Redis for hot data, session/permissions caching
- External Services:
– Aliyun SMS (AliSendSmsComponent)
– Qiniu Cloud Storage (QiniuComponent)
- Documentation: Swagger/Knife4j UI
b. Relationships & data flows
1. User interacts with Mini-app or Web UI
2. Requests → Spring Boot REST endpoints
3. JWT filter validates token; SecurityConfig routes by roles & dynamic metadata
4. Controller invokes Service layer
5. Service uses Mapper/DAO to read/write MySQL; optionally reads/writes Redis cache
6. Service calls external components for SMS or file storage
7. Response wrapped in CommonResult/CommonPage and returned to client
c. Architectural patterns
- Layered (Presentation → Business → Persistence)
- JWT-stateless authentication with dynamic permission checks
- MyBatis Generator for automating entity & SQL mapping
- Cache-Aside with Redis (service checks cache → if miss, DB → populate cache)
d. Key technologies & libraries
- Spring Boot, Spring Web, Spring Security, Spring Data Redis
- MyBatis, MyBatis Generator
- JWT (custom JwtTokenUtil, JwtAuthenticationTokenFilter)
- RedisTemplate (RedisServiceImpl)
- Lombok
- Knife4j/Swagger for API docs
- Aliyun SMS SDK, Qiniu Storage SDK

##### Final advice
- Every major module: security, logging, API docs, SMS/file storage, caching.
- Dynamic permission enforcement by showing the SecurityFilter chain before Controllers.
- Flows: Client → JWT Auth → Controller → Service → Mapper → DB/Redis → back to Client.
- With technology names (Spring Boot, MyBatis, Redis, Qiniu, Aliyun SMS).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients" 
        A["Mini-app (WeChat/Alipay/H5)"]:::client
        B["Web Admin Portal"]:::client
    end

    %% Backend Service Layers
    subgraph "Backend Service"
        subgraph "Security Layer"
            SF["JwtAuthenticationTokenFilter"]:::security
            AE["RestfulAuthenticationEntryPoint"]:::security
            AD["RestfulAccessDeniedHandler"]:::security
            DS["DynamicSecurityFilter"]:::security
            SC["SecurityConfig"]:::security
            HSC["HospitalSecurityConfig"]:::security
        end

        subgraph "API Layer"
            CTRL["REST Controllers"]:::controller
        end

        subgraph "Business Services"
            SI["Service Interfaces"]:::service
            SI2["Service Implementations"]:::service
            IR["IRedisService"]:::service
            RI["RedisServiceImpl"]:::service
        end

        subgraph "Data Access Layer"
            MI["MyBatis Mappers"]:::data
            DAO["Custom DAOs"]:::data
            XML["MyBatis XML Mappers"]:::data
            DAOXML["DAO XMLs"]:::data
        end

        SW["SwaggerConfig (Swagger/Knife4j)"]:::config
        APP["HospitalApplication"]:::config
        MBG["MyBatis Generator Classes"]:::config
        MBGC["MyBatis Generator Config"]:::config
    end

    %% Persistence & Cache
    subgraph "Persistence & Cache"
        DB["MySQL Database"]:::db
        RED["Redis Cache"]:::redis
    end

    %% External Services
    subgraph "External Services"
        SMS["Aliyun SMS Component"]:::external
        QN["Qiniu Cloud Storage"]:::external
        WX["WeChat Messaging Component"]:::external
    end

    %% Data Flows
    A -->|REST API Request| SF
    B -->|REST API Request| SF
    SF -->|authenticate| AE
    SF -->|authorize| DS
    SF -->|access denied| AD
    SF -->|uses config| SC
    SC --> HSC
    SF -->|forward| CTRL
    CTRL -->|invoke| SI2
    SI -->|implemented by| SI2
    SI2 -->|calls mapper| MI
    SI2 -->|calls DAO| DAO
    MI -->|reads/writes| DB
    DAO -->|reads/writes| DB
    SI2 -->|cache get/put| RED
    SI2 -->|send SMS| SMS
    SI2 -->|upload file| QN
    SI2 -->|send message| WX
    CTRL -->|API docs| SW
    APP --> CTRL
    MBG --> XML
    MBGC --> XML

    %% Click Events
    click CTRL "https://github.com/xdmdcp/hospital/tree/master/src/main/java/cn/yujian95/hospital/controller"
    click SF "https://github.com/xdmdcp/hospital/blob/master/src/main/java/cn/yujian95/hospital/common/security/JwtAuthenticationTokenFilter.java"
    click AE "https://github.com/xdmdcp/hospital/blob/master/src/main/java/cn/yujian95/hospital/common/api/RestfulAuthenticationEntryPoint.java"
    click AD "https://github.com/xdmdcp/hospital/blob/master/src/main/java/cn/yujian95/hospital/common/api/RestfulAccessDeniedHandler.java"
    click DS "https://github.com/xdmdcp/hospital/blob/master/src/main/java/cn/yujian95/hospital/common/security/DynamicSecurityFilter.java"
    click SC "https://github.com/xdmdcp/hospital/blob/master/src/main/java/cn/yujian95/hospital/common/security/SecurityConfig.java"
    click HSC "https://github.com/xdmdcp/hospital/blob/master/src/main/java/cn/yujian95/hospital/config/HospitalSecurityConfig.java"
    click SI "https://github.com/xdmdcp/hospital/tree/master/src/main/java/cn/yujian95/hospital/service"
    click SI2 "https://github.com/xdmdcp/hospital/tree/master/src/main/java/cn/yujian95/hospital/service/impl"
    click IR "https://github.com/xdmdcp/hospital/blob/master/src/main/java/cn/yujian95/hospital/service/IRedisService.java"
    click RI "https://github.com/xdmdcp/hospital/blob/master/src/main/java/cn/yujian95/hospital/service/impl/RedisServiceImpl.java"
    click MI "https://github.com/xdmdcp/hospital/tree/master/src/main/java/cn/yujian95/hospital/mapper"
    click DAO "https://github.com/xdmdcp/hospital/tree/master/src/main/java/cn/yujian95/hospital/mapper/dao"
    click XML "https://github.com/xdmdcp/hospital/tree/master/src/main/resources/cn/yujian95/hospital/mapper"
    click DAOXML "https://github.com/xdmdcp/hospital/tree/master/src/main/resources/cn/yujian95/hospital/mapper/dao"
    click SW "https://github.com/xdmdcp/hospital/blob/master/src/main/java/cn/yujian95/hospital/config/SwaggerConfig.java"
    click APP "https://github.com/xdmdcp/hospital/blob/master/src/main/java/cn/yujian95/hospital/HospitalApplication.java"
    click MBG "https://github.com/xdmdcp/hospital/tree/master/src/main/java/cn/yujian95/hospital/common/mbg"
    click MBGC "https://github.com/xdmdcp/hospital/blob/master/src/main/resources/config/MybatisGeneratorConfig.xml"

    %% Styles
    classDef client fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32;
    classDef backend fill:#E3F2FD,stroke:#1565C0,color:#1565C0;
    classDef security fill:#FFF3E0,stroke:#EF6C00,color:#EF6C00;
    classDef controller fill:#E1F5FE,stroke:#0277BD,color:#0277BD;
    classDef service fill:#F3E5F5,stroke:#6A1B9A,color:#6A1B9A;
    classDef data fill:#FFFDE7,stroke:#F9A825,color:#F9A825;
    classDef config fill:#ECEFF1,stroke:#455A64,color:#455A64;
    classDef db fill:#FFEBEE,stroke:#C62828,color:#C62828;
    classDef redis fill:#E0F7FA,stroke:#0097A7,color:#0097A7;
    classDef external fill:#F1F8E9,stroke:#558B2F,color:#558B2F;
    classDef storage fill:#FAFAFA,stroke:#9E9E9E,color:#616161;
    class Clients,BackendService,PersistenceCache,ExternalServices backend;
```
