# kokoa454/medishare architecture

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

- Interactive diagram: https://gitdiagram.com/kokoa454/medishare
- Repository: https://github.com/kokoa454/medishare

## Overview

##### Project Type and Purpose
- This is a full-stack web application (PWA) for managing personal and family medication schedules.
- It’s built on Spring Boot (Java) with a Thymeleaf/HTML/CSS/JS front end, backed by MySQL and Elasticsearch, and integrates external notification services (LINE API, Gmail SMTP).
- A standalone Python scraper ingests medicine data from “くすりのしおり” and populates the database.

##### Main Architectural Layers and Components
a. Client / Frontend (PWA)
- Static assets: HTML templates (Thymeleaf), CSS, JavaScript, service worker (sw.js), manifest.json
- Responsible for rendering views (login, dashboard, edit medicine, etc.) and PWA offline support
b. Web Server / Reverse Proxy
- Nginx sits at the edge (not in codebase) to terminate HTTPS and proxy to the Spring Boot app
c. Application / Backend
- Controllers (HTTP entrypoints) – located under controller/ (e.g., LoginController, SearchController)
- Service layer – business logic in service/ (e.g., MedicineService, NotificationService, MailService, LineService)
- Data access layer (DAO/Repository) – JPA Repositories for MySQL, ElasticsearchDocumentRepository
- Configuration – SecurityConfig, ElasticsearchConfig, PasswordConfig
- Application entrypoint – MediShareApplication.java
d. Data Stores
- Primary relational store: MySQL (JPA Entities in model/)
- Secondary search index: Elasticsearch (document/ + DocumentRepository)
e. External Services
- Gmail SMTP for email notifications (MailService)
- LINE Messaging API for family notifications (LineService)
f. Offline ETL
- Python scripts under scripts/scrapeKusurinoshiori
- Scrape + transform “くすりのしおり” → medicine.json → MySQL ingestion

##### Component Interactions and Data Flows
- Browser ↔ Nginx ↔ Spring Boot Controllers (HTTP/HTTPS)
- Controller → Service → Repository → MySQL / Elasticsearch
- On schedule or event (e.g., reminder): Service triggers NotificationService → MailService (SMTP) and/or LineService (LINE API)
- Python scraper writes to MySQL directly (out of band)
- PWA assets served by Spring Boot’s static resource handler

##### Architectural Patterns and Principles
- Layered architecture: Presentation → Controller → Service → Repository → Database
- MVC within Spring MVC + Thymeleaf
- Use of external search index (Elasticsearch) for fuzzy search, fallback to MySQL
- PWA design pattern: manifest + service worker for offline caching
- Secure by Spring Security (form login, password encoding, reset tokens)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client / Frontend" 
        direction TB
        Browser["Browser (PWA)"]:::frontend
        subgraph "PWA Assets (Offline Capable)" 
            direction TB
            Templates["Thymeleaf Templates"]:::frontend
            CSS["CSS Files"]:::frontend
            JS["JS Files"]:::frontend
            SW["Service Worker (sw.js)"]:::frontend
            Manifest["manifest.json"]:::frontend
        end
    end

    %% Web Proxy
    NGINX["Nginx (HTTPS Reverse Proxy)"]:::proxy

    %% Application Layer
    subgraph "Spring Boot Application" 
        direction TB
        Entry["MediShareApplication.java"]:::app
        subgraph "HTTP API (Controllers)"
            direction TB
            Controllers["Controller Layer"]:::app
        end
        subgraph "Business Logic (Services)"
            direction TB
            Services["Service Layer"]:::app
            NotificationService["NotificationService"]:::app
            MailServiceNode["MailService"]:::external
            LineServiceNode["LineService"]:::external
        end
        subgraph "Data Access"
            direction TB
            Repositories["JPA Repositories (MySQL)"]:::db
            DocRepo["MedicineDocumentRepository"]:::db
        end
        subgraph "Configuration"
            direction TB
            Config["Security, Elasticsearch, Password Config"]:::app
        end
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        MySQL["MySQL"]:::database
        Elasticsearch["Elasticsearch"]:::database
    end

    %% External Services
    subgraph "External Services"
        direction TB
        SMTP["Gmail SMTP"]:::external
        LINEAPI["LINE Messaging API"]:::external
    end

    %% ETL / Batch
    subgraph "ETL / Batch (Python Scraper)"
        direction TB
        Scraper["scrapeKusurinoshiori.py"]:::etl
        Output["outputDatabase.py"]:::etl
    end

    %% Connections
    Browser -->|"HTTPS"| NGINX
    NGINX -->|"HTTP"| Controllers
    Controllers -->|"calls"| Services
    Services -->|"uses"| Repositories
    Repositories -->|"JDBC"| MySQL
    Services -->|"indexes/search"| DocRepo
    DocRepo -->|"HTTP"| Elasticsearch
    DocRepo -->|"fallback"| MySQL
    NotificationService -->|"SMTP"| SMTP
    NotificationService -->|"REST"| LINEAPI
    Scraper -->|"writes"| MySQL

    %% Click Events
    click Templates "https://github.com/kokoa454/medishare/tree/main/src/main/resources/templates"
    click CSS "https://github.com/kokoa454/medishare/tree/main/src/main/resources/static/css"
    click JS "https://github.com/kokoa454/medishare/tree/main/src/main/resources/static/js"
    click SW "https://github.com/kokoa454/medishare/blob/main/src/main/resources/static/sw.js"
    click Manifest "https://github.com/kokoa454/medishare/blob/main/src/main/resources/static/manifest.json"
    click Entry "https://github.com/kokoa454/medishare/blob/main/src/main/java/com/medishare/MediShareApplication.java"
    click Controllers "https://github.com/kokoa454/medishare/tree/main/src/main/java/com/medishare/controller"
    click Services "https://github.com/kokoa454/medishare/tree/main/src/main/java/com/medishare/service"
    click Repositories "https://github.com/kokoa454/medishare/tree/main/src/main/java/com/medishare/repository"
    click DocRepo "https://github.com/kokoa454/medishare/blob/main/src/main/java/com/medishare/repository/MedicineDocumentRepository.java"
    click DocRepo "https://github.com/kokoa454/medishare/blob/main/src/main/java/com/medishare/document/MedicineDocument.java"
    click Config "https://github.com/kokoa454/medishare/tree/main/src/main/java/com/medishare/config"
    click MailServiceNode "https://github.com/kokoa454/medishare/blob/main/src/main/java/com/medishare/service/MailService.java"
    click LineServiceNode "https://github.com/kokoa454/medishare/blob/main/src/main/java/com/medishare/service/LineService.java"
    click Scraper "https://github.com/kokoa454/medishare/blob/main/scripts/scrapeKusurinoshiori/scrapeKusurinoshiori.py"
    click Output "https://github.com/kokoa454/medishare/blob/main/scripts/scrapeKusurinoshiori/outputDatabase.py"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#1E88E5,color:#1E88E5
    classDef proxy fill:#ECEFF1,stroke:#90A4AE,color:#37474F
    classDef app fill:#E8F5E9,stroke:#43A047,color:#1B5E20
    classDef db fill:#FFF3E0,stroke:#FB8C00,color:#E65100
    classDef database fill:#FFF3E0,stroke:#FB8C00,color:#E65100
    classDef external fill:#ECEFF1,stroke:#90A4AE,color:#37474F
    classDef etl fill:#F3E5F5,stroke:#8E24AA,color:#4A148C
```
