# cherryshine/pashare architecture

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

- Interactive diagram: https://gitdiagram.com/cherryshine/pashare
- Repository: https://github.com/cherryshine/pashare

## Overview

##### Project type and purpose
- PaShare is a monolithic, full-stack web application built on Spring Boot.
- It follows a classic server-side MVC pattern with Thymeleaf templates for the UI, a REST-style API for text operations, persistent storage in MySQL, JWT-based admin auth, and Cloudflare Turnstile CAPTCHA integration.

##### File structure
- Top-level build files (build.gradle, Gradle wrapper) → standard Spring Boot build.
- src/main/java/com/jeesoo/pashare:
- config/ (WebConfig) → servlet mappings, resource handlers
- controller/ (MainController, TextController, AdminController, CaptchaController) → HTTP endpoints
- service/ (TextService, AdminService) → business logic
- repository/ (TextRepository) → Spring Data JPA interface to MySQL
- entity/ (Text) → JPA @Entity model
- filter/ (TurnstileCaptchaFilter) → pre-controller CAPTCHA validation
- util/ (JwtUtil) → JWT generation/validation
- dto/ → request/response payload classes
- src/main/resources:
- templates/ (Thymeleaf HTML views: index, shared-text, admin, turnstile)
- static/ (assets, site.webmanifest)
- src/test/java → integration/unit tests

##### README for additional insights
- Confirms use of Spring Boot 3.x, Spring Data JPA, MySQL, Thymeleaf, JWT, Cloudflare Turnstile.
- Describes key REST endpoints (/api/save-text, /api/get-text, /api/share-via-link, admin APIs, CAPTCHA API).
- Notes admin panel UI, 24-hour link expiry logic, 4-digit code sharing.

##### Essential architectural elements
- Validity window (24h link expiry) as a note on the “share-via-link” flow.
- Security-sensitive flows (admin login → JWT issuance → JWT-protected endpoints).

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Side
    subgraph "Client (Browser)"
        direction TB
        UI1["index.html"]:::frontend
        UI2["shared-text.html"]:::frontend
        UI3["turnstile.html"]:::frontend
        UI4["admin.html"]:::frontend
    end

    %% Server Entry Point & Config
    subgraph "Server (Spring Boot)"
        direction TB
        App["PashareApplication"]:::backend
        Config["WebConfig"]:::backend

        %% Filter Layer
        subgraph "Filter Layer"
            direction TB
            Filter["TurnstileCaptchaFilter"]:::backend
        end

        %% Controller Layer
        subgraph "Controller Layer"
            direction TB
            C1["MainController"]:::backend
            C2["TextController"]:::backend
            C3["AdminController"]:::backend
            C4["CaptchaController"]:::backend
        end

        %% Service Layer
        subgraph "Service Layer"
            direction TB
            S1["TextService"]:::backend
            S2["AdminService"]:::backend
            Util["JwtUtil"]:::backend
        end

        %% Repository Layer
        subgraph "Data Access Layer"
            direction TB
            Repo["TextRepository"]:::persistence
            Entity["Text (JPA Entity)"]:::persistence
        end

        %% Database
        DB["MySQL Database"]:::persistence
    end

    %% External Service
    CF["Cloudflare Turnstile"]:::external

    %% Relationships
    UI1 -->|"HTTP GET/POST"| Filter
    UI2 -->|"HTTP GET"| C1
    UI3 -->|"HTTP GET/POST"| Filter
    UI4 -->|"HTTP GET/POST"| Filter

    Filter -->|"passes"| C4
    Filter -->|"passes"| C1
    Filter -->|"passes"| C2
    Filter -->|"passes"| C3

    C1 -->|"serves Thymeleaf views"| UI1
    C1 -->|"serves Thymeleaf views"| UI2
    C1 -->|"serves Thymeleaf views"| UI3
    C1 -->|"serves Thymeleaf views"| UI4

    C2 -->|"calls"| S1
    C3 -->|"calls"| S2
    C3 -->|"uses JwtUtil"| Util
    C4 -->|"calls"| CF

    S1 -->|"CRUD operations"| Repo
    S2 -->|"CRUD operations"| Repo
    S1 -->|"maps Entity"| Entity
    Repo -->|"JDBC"| DB

    App --> Config
    App --> Filter
    App --> C1
    App --> C2
    App --> C3
    App --> C4
    App --> S1
    App --> S2
    App --> Repo
    App --> Util

    %% Click Events
    click App "https://github.com/cherryshine/pashare/blob/main/src/main/java/com/jeesoo/pashare/PashareApplication.java"
    click Config "https://github.com/cherryshine/pashare/blob/main/src/main/java/com/jeesoo/pashare/config/WebConfig.java"
    click Filter "https://github.com/cherryshine/pashare/blob/main/src/main/java/com/jeesoo/pashare/filter/TurnstileCaptchaFilter.java"
    click C1 "https://github.com/cherryshine/pashare/blob/main/src/main/java/com/jeesoo/pashare/controller/MainController.java"
    click C2 "https://github.com/cherryshine/pashare/blob/main/src/main/java/com/jeesoo/pashare/controller/TextController.java"
    click C3 "https://github.com/cherryshine/pashare/blob/main/src/main/java/com/jeesoo/pashare/controller/AdminController.java"
    click C4 "https://github.com/cherryshine/pashare/blob/main/src/main/java/com/jeesoo/pashare/controller/CaptchaController.java"
    click S1 "https://github.com/cherryshine/pashare/blob/main/src/main/java/com/jeesoo/pashare/service/TextService.java"
    click S2 "https://github.com/cherryshine/pashare/blob/main/src/main/java/com/jeesoo/pashare/service/AdminService.java"
    click Repo "https://github.com/cherryshine/pashare/blob/main/src/main/java/com/jeesoo/pashare/repository/TextRepository.java"
    click Entity "https://github.com/cherryshine/pashare/blob/main/src/main/java/com/jeesoo/pashare/entity/Text.java"
    click Util "https://github.com/cherryshine/pashare/blob/main/src/main/java/com/jeesoo/pashare/util/JwtUtil.java"
    click UI1 "https://github.com/cherryshine/pashare/blob/main/src/main/resources/templates/index.html"
    click UI2 "https://github.com/cherryshine/pashare/blob/main/src/main/resources/templates/shared-text.html"
    click UI3 "https://github.com/cherryshine/pashare/blob/main/src/main/resources/templates/turnstile.html"
    click UI4 "https://github.com/cherryshine/pashare/blob/main/src/main/resources/templates/admin.html"
    click CF "https://github.com/cherryshine/pashare/tree/main/external/Cloudflare Turnstile"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#1E90FF,color:#000
    classDef backend fill:#DFFFD0,stroke:#34A853,color:#000
    classDef persistence fill:#FFE5B4,stroke:#DB8B00,color:#000
    classDef external fill:#E1D5E7,stroke:#9B59B6,color:#000
```
