# dromara/sa-token architecture

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

- Interactive diagram: https://gitdiagram.com/dromara/sa-token
- Repository: https://github.com/dromara/sa-token

## Overview

##### Main project purpose and modules
- At the core is the “sa-token-core” module. This contains the fundamental APIs and components (authentication, session management, annotations, error-handling, security utilities, logging, etc.) that form the basis of the framework.
- Surrounding the core are various supporting modules:
– “sa-token-bom”: A Maven BOM to manage dependency versions.
– “sa-token-demo”: Contains many demo applications showing integrations with Redis, Dubbo, OAuth2, WebFlux, Solon, and more. These samples showcase how Sa-Token is applied in different architectures.
– “sa-token-doc”: Keeps the documentation, API descriptions, and usage guides.
– “sa-token-plugin”: Contains numerous plugins (for Dubbo, jwt, oauth2, SSO, redisson integration, etc.) that extend or integrate the core framework with various external technologies.
– “sa-token-test”: Contains unit and integration tests verifying framework functionality.
- Additionally, there are separate starter modules and third-party integration modules which act as adapters for various frameworks (Spring Boot, JFinal, Solon, etc.) and for different runtime environments.

##### File structure to capture architectural patterns
- The multi-module Maven layout (each module having its own pom.xml) indicates a layered, pluggable architecture.
- The core module’s packages show a clean separation by concerns – annotations (for declarative security), context management (thread local/session management), DAO interfaces (for persistence and state), and error/exception handling.
- The presence of many sub-folders (such as “annotation/handler”, “context/model”, “dao”, etc.) within “sa-token-core” implies an internal architectural pattern built around the separation of authentication logic, context propagation, and extension points.
- Plugin modules further highlight an extensible design pattern, where integrations with external frameworks (dubbo, grpc, oauth2, JWT, etc.) are provided as separate pluggable components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% High-level Modules
    BOM["Dependency Management (BOM)"]:::bom
    DOC["Documentation & Guides"]:::doc

    %% Core Authentication Engine with internal components
    subgraph "sa-token-core"
        CORE["Core Authentication Engine"]:::core
        ANNOTATION["Annotation Support"]:::core_internal
        SESSION["Session/Context Manager"]:::core_internal
        DAO["DAO Layer"]:::core_internal
        SECURITY["Security Utilities"]:::core_internal
        EVENT["Event Listeners & Loggers"]:::core_internal
    end

    %% Plugin/Extension Modules with specific plugins
    subgraph "sa-token-plugin"
        PLUGIN["Plugin/Extension Modules"]:::plugin
        SSO["SSO Module"]:::plugin_internal
        OAUTH2["OAuth2 Module"]:::plugin_internal
        JWT["JWT Module"]:::plugin_internal
        DUBBO["Dubbo/gRPC Integration"]:::plugin_internal
    end

    %% Demo and Testing modules
    DEMO["Demo & Integration Applications"]:::demo
    TEST["Testing Module"]:::test

    %% Internal connections within sa-token-core
    CORE -->|"includes"| ANNOTATION
    CORE -->|"includes"| SESSION
    CORE -->|"includes"| DAO
    CORE -->|"includes"| SECURITY
    CORE -->|"includes"| EVENT

    %% Internal connections within sa-token-plugin
    PLUGIN -->|"extends"| SSO
    PLUGIN -->|"extends"| OAUTH2
    PLUGIN -->|"extends"| JWT
    PLUGIN -->|"extends"| DUBBO

    %% Inter-module relationships
    DEMO -->|"utilizes"| CORE
    DEMO -->|"integrates with"| PLUGIN
    TEST -->|"verifies"| CORE
    TEST -->|"verifies"| PLUGIN
    PLUGIN -->|"adapts core"| CORE

    %% Supporting modules connections
    BOM -->|"manages versions for"| CORE
    BOM -->|"manages versions for"| PLUGIN
    DOC -->|"describes"| CORE
    DOC -->|"describes"| PLUGIN
    DOC -->|"describes"| DEMO

    %% Technology and External Integration Note
    TECH["Technologies: Java, Maven, Redis, Spring Boot, WebFlux, Solon, Dubbo, gRPC, Thymeleaf"]:::note

    %% Connecting note to BOM (as an example of central tech stack)
    DOC --- TECH

    %% Click Events
    click CORE "https://github.com/dromara/sa-token/tree/dev/sa-token-core/"
    click PLUGIN "https://github.com/dromara/sa-token/tree/dev/sa-token-plugin/"
    click BOM "https://github.com/dromara/sa-token/tree/dev/sa-token-bom/"
    click DEMO "https://github.com/dromara/sa-token/tree/dev/sa-token-demo/"
    click DOC "https://github.com/dromara/sa-token/tree/dev/sa-token-doc/"
    click TEST "https://github.com/dromara/sa-token/tree/dev/sa-token-test/"

    %% Styles
    classDef core fill:#fde2e2,stroke:#b30000,stroke-width:2px;
    classDef core_internal fill:#fff0f0,stroke:#cc0000,stroke-width:1px;
    classDef plugin fill:#e2f0fd,stroke:#0033cc,stroke-width:2px;
    classDef plugin_internal fill:#f0f8ff,stroke:#3366ff,stroke-width:1px;
    classDef demo fill:#e2fde2,stroke:#009933,stroke-width:2px;
    classDef test fill:#fff4cc,stroke:#cc9900,stroke-width:2px;
    classDef bom fill:#f2e6ff,stroke:#6600cc,stroke-width:2px;
    classDef doc fill:#e6f9e6,stroke:#009966,stroke-width:2px;
    classDef note fill:#ffffff,stroke:#999999,stroke-dasharray: 5 5,stroke-width:1px;
```
