# cha4stre/esanar architecture

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

- Interactive diagram: https://gitdiagram.com/cha4stre/esanar
- Repository: https://github.com/cha4stre/esanar

## Overview

##### Project Type and Purpose
- eSanar is a monolithic, full-stack web application built with Spring Boot in Java.
- It follows the traditional MVC pattern to manage medical patient records, role-based access, consultations, and report generation (PDF/Excel).

##### File Structure Analysis
- Top-Level Artifacts
- pom.xml, Maven wrapper, Dockerfile – build and containerization.
- src/main/java/cj/esanar – Java code organized into packages: config, controller, persistence, service, util.
- src/main/resources – Spring Boot properties, static assets (JS/CSS/images), Thymeleaf templates.
- Architectural Layers
- config – Spring Security, data initialization, success handlers, role conversion.
- controller – MVC controllers handling HTTP requests and returning views or JSON.
- service & service/implement – Business logic interfaces and implementations.
- persistence/entity & repository – JPA entities and Spring Data repositories.
- util – pagination utilities and report exporters (PDF/Excel).
- External Integrations
- OMS CIIE API consumption module (in service or util).
- Deployment/Build
- Dockerfile for container image; Maven for build lifecycle.

##### README Insights
- Emphasizes MVC, role-based security, CRUD operations on users/patients/consultations, export to PDF/Excel, external WHO API consumption.
- Targets academic requirements for Software Architecture course; real-world clinic collaboration.

a. Main Components
1. Web Client (Browser) – HTML/JS static assets, interacts over HTTP/S.
2. Spring Boot Application – orchestrates MVC flow.
3. MVC Layers
– Controllers: AuthController, AdminController, ConsultaController, EnfController, WelcomeController
– Services: ConsultaService, PacienteService, HistoriaService, PermissionsService, UserDetailsService
– Repositories: UserRepository, PacienteRepository, ConsultaRepository, etc.
4. Database – relational store (configured in application.properties).
5. External API – WHO CIIE REST service.
6. Reporting Modules – PDF exporter, Excel exporter.

b. Relationships and Data Flow
- Browser → HTTP Request → SecurityFilterChain (SecurityConfig, CustomSuccessHandler)
- Authenticated → Controller
- Controller → Service → Repository → Database
- Service → util/reports → generate PDF/Excel → HTTP Response (download)
- Service → HTTP Client → External WHO API → enrich data → Controller → View
- Controller → Thymeleaf templates → HTTP Response → Browser

c. Architectural Patterns & Principles
- Layered Architecture (Controller → Service → Repository)
- MVC (views with Thymeleaf, controllers handling input, models via entities)
- Dependency Injection via Spring
- Role-based Access Control using Spring Security
- External integration via REST client

d. Key Technologies
- Java 11+, Spring Boot, Spring MVC, Spring Security, Spring Data JPA
- Thymeleaf templates, static JS/CSS
- Maven, Docker
- Apache POI (Excel), iText or Jasper (PDF)
- REST template or WebClient for WHO API

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        Browser["Web Browser"]:::client
        Static["Static Assets"]:::client
        Templates["Thymeleaf Templates"]:::client
    end

    Browser -->|requests| Static
    Browser -->|requests| Templates

    %% Server Side
    subgraph "Server Side"
        ES["ESanarApplication"]:::app

        subgraph "Security Layer"
            SecCfg["SecurityConfig"]:::config
            Success["CustomSuccessHandler"]:::config
            RoleConv["RoleConverter"]:::config
            DataInit["DataInitializer"]:::config
        end

        subgraph "Controllers"
            AuthC["AuthController"]:::controller
            AdminC["AdminController"]:::controller
            ConsultaC["ConsultaController"]:::controller
            EnfC["EnfController"]:::controller
            WelcomeC["WelcomeController"]:::controller
        end

        subgraph "Service Interfaces"
            ConsultaS["ConsultaService"]:::service
            PacienteS["PacienteService"]:::service
            HistoriaS["HistoriaService"]:::service
            PermS["PermissionsService"]:::service
            UserDetS["CustomUserDetailsService"]:::service
        end

        subgraph "Service Implementations"
            ConsultaSI["ConsultaServiceImpl"]:::serviceimpl
            PacienteSI["PacienteServiceImpl"]:::serviceimpl
            HistoriaSI["HistoriaServiceImpl"]:::serviceimpl
            PermSI["PermissionsServiceImpl"]:::serviceimpl
            UserDetSI["UserDetailServiceImpl"]:::serviceimpl
        end

        subgraph "Persistence Layer"
            subgraph Entities
                Entities["JPA Entities"]:::entity
            end
            subgraph Repositories
                Repos["Spring Data Repositories"]:::repo
            end
        end

        subgraph "Utilities"
            PdfU["ExportarConsultaPdf"]:::util
            ExU["ExportarPacientesExcel"]:::util
            PageItem["PageItem"]:::util
            PageRender["PageRender"]:::util
        end

        DB["Database"]:::db
        WHO["External WHO CIIE API"]:::external
    end

    %% Interactions
    Browser -->|HTTP/S| SecCfg
    SecCfg -->|auth filter| AuthC
    SecCfg -->|auth filter| AdminC
    SecCfg -->|auth filter| ConsultaC
    SecCfg -->|auth filter| EnfC
    SecCfg -->|auth filter| WelcomeC

    AuthC -->|"login, session"| UserDetS
    AdminC -->|"manage users"| PacienteS
    ConsultaC -->|"consultation ops"| ConsultaS
    EnfC -->|"nurse actions"| HistoriaS
    WelcomeC -->|"permissions check"| PermS

    ConsultaS -->|impl| ConsultaSI
    PacienteS -->|impl| PacienteSI
    HistoriaS -->|impl| HistoriaSI
    PermS -->|impl| PermSI
    UserDetS -->|impl| UserDetSI

    ConsultaSI -->|uses| Repos
    PacienteSI -->|uses| Repos
    HistoriaSI -->|uses| Repos
    PermSI -->|uses| Repos
    UserDetSI -->|uses| Repos

    Repos -->|retrieve/store| DB

    ConsultaSI -->|generate| PdfU
    PacienteSI -->|generate| ExU
    ConsultaSI -->|pagination| PageItem
    ConsultaSI -->|pagination| PageRender

    ConsultaSI -->|REST call| WHO
    PacienteSI -->|REST call| WHO

    AuthC -->|view| Templates
    AdminC -->|view| Templates
    ConsultaC -->|view| Templates
    EnfC -->|view| Templates
    WelcomeC -->|view| Templates

    Templates -->|HTML response| Browser

    %% Click Events
    click Static "https://github.com/cha4stre/esanar/tree/master/src/main/resources/static"
    click Templates "https://github.com/cha4stre/esanar/tree/master/src/main/resources/templates"
    click ES "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/ESanarApplication.java"
    click SecCfg "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/config/SecurityConfig.java"
    click Success "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/config/CustomSuccessHandler.java"
    click RoleConv "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/config/RoleConverter.java"
    click DataInit "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/config/DataInitializer.java"
    click AuthC "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/controller/AuthController.java"
    click AdminC "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/controller/AdminController.java"
    click ConsultaC "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/controller/ConsultaController.java"
    click EnfC "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/controller/EnfController.java"
    click WelcomeC "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/controller/WelcomeController.java"
    click ConsultaS "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/service/ConsultaService.java"
    click PacienteS "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/service/PacienteService.java"
    click HistoriaS "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/service/HistoriaService.java"
    click PermS "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/service/PermissionsService.java"
    click ConsultaSI "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/service/implement/ConsultaServiceImpl.java"
    click PacienteSI "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/service/implement/PacienteServiceImpl.java"
    click HistoriaSI "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/service/implement/HistoriaServiceImpl.java"
    click PermSI "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/service/implement/PermissionsServiceImpl.java"
    click UserDetSI "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/service/implement/UserDetailServiceImpl.java"
    click PdfU "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/util/reports/ExportarConsultaPdf.java"
    click ExU "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/util/reports/ExportarPacientesExel.java"
    click PageItem "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/util/pagination/PageItem.java"
    click PageRender "https://github.com/cha4stre/esanar/blob/master/src/main/java/cj/esanar/util/pagination/PageRender.java"
    click DB "https://github.com/cha4stre/esanar/blob/master/src/main/resources/application.properties"

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:1px
    classDef app fill:#bbf,stroke:#333,stroke-width:1px
    classDef config fill:#fcf,stroke:#333,stroke-width:1px
    classDef controller fill:#cff,stroke:#333,stroke-width:1px
    classDef service fill:#cfc,stroke:#333,stroke-width:1px
    classDef serviceimpl fill:#9f9,stroke:#333,stroke-width:1px
    classDef entity fill:#ff9,stroke:#333,stroke-width:1px
    classDef repo fill:#f96,stroke:#333,stroke-width:1px
    classDef util fill:#ccf,stroke:#333,stroke-width:1px
    classDef db fill:#f99,stroke:#333,stroke-width:1px
    classDef external fill:#999,stroke:#333,stroke-width:1px
```
