# de0811/spring-docs architecture

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

- Interactive diagram: https://gitdiagram.com/de0811/spring-docs
- Repository: https://github.com/de0811/spring-docs

## Overview

##### Main Components
- Backend Application: Representing the core of the project, the DocsApplication.java (located in src/main/java/com/sdm/docs) acts as the primary entry point.
- API Controllers: Include components such as SwaggerTestController.java within the controller package. These manage the API endpoints that are both tested (to produce documentation) and later used for testing via Swagger UI.
- Security Configuration: The SecurityConfig.java component is used to set up CORS and any other security measures.
- API Documentation Generation Module: This aspect comes into play through the test code (e.g., DocsApplicationTests, SwaggerControllerSupportTest) and the Gradle build script (build.gradle). When the “openapi3” Gradle task runs, it produces the openapi3.json file in the build/api-spec directory.
- External Swagger UI Service: The system uses Docker (or docker-compose) to run a Swagger UI container that loads the generated openapi3.json file, allowing interactive API testing.

##### Establish Relationships and Interactions
- The Backend Application (DocsApplication) exposes various REST endpoints managed by the controller (SwaggerTestController).
- During testing, the restdocs-api-spec functionality (through Gradle tasks) triggers test cases that produce API documentation (openapi3.json). The tests simulate API calls to generate accurate documentation.
- The SecurityConfig component ensures proper CORS and security settings for interactions between the Swagger UI and the backend API.

##### Architectural Patterns and Key Technologies
- Modular Separation: Although it’s a monolithic application, note the clear separation between configuration, controllers, DTOs, and tests.
- Build & Deployment Practices: Gradle is used for building and testing; Docker/Docker Compose is used for deploying the Swagger UI environment.
- Technology Stack: Spring Boot for the backend, Spring Rest Docs combined with Swagger UI, and Gradle for builds. Additionally, Docker plays a role in running the Swagger UI container.

## Diagram (Mermaid)

```mermaid
flowchart TD 
    %% Backend Layer
    subgraph "Backend Layer"
        backendapp["Backend Server (DocsApplication)"]:::backend
        apicontroller["API Controller (SwaggerTestController)"]:::controller
        securitycfg["Security Configuration (SecurityConfig)"]:::config
    end

    %% Documentation & Generation Layer
    subgraph "Documentation & Generation Layer"
        gradlebuild["Gradle Build Script"]:::build
        test1["Test Suite (DocsApplicationTests)"]:::test
        test2["Test Suite (SwaggerControllerSupportTest)"]:::test
        openapispec["Generated OpenAPI Spec (openapi3.json)"]:::spec
    end

    %% External Infrastructure Layer
    subgraph "External Infrastructure"
        swaggercontainer["Swagger UI Container (Docker)"]:::external
    end

    %% Relationships
    backendapp --> apicontroller
    backendapp --> securitycfg
    apicontroller -->|"simulate"| test2
    gradlebuild -->|"triggers"| test1
    gradlebuild -->|"triggers"| test2
    test1 -->|"produces"| openapispec
    test2 -->|"produces"| openapispec
    openapispec -->|"feeds"| swaggercontainer

    %% Click Events
    click backendapp "https://github.com/de0811/spring-docs/blob/master/src/main/java/com/sdm/docs/DocsApplication.java"
    click apicontroller "https://github.com/de0811/spring-docs/blob/master/src/main/java/com/sdm/docs/controller/SwaggerTestController.java"
    click securitycfg "https://github.com/de0811/spring-docs/blob/master/src/main/java/com/sdm/docs/config/SecurityConfig.java"
    click gradlebuild "https://github.com/de0811/spring-docs/blob/master/build.gradle"
    click test1 "https://github.com/de0811/spring-docs/blob/master/src/test/java/com/sdm/docs/DocsApplicationTests.java"
    click test2 "https://github.com/de0811/spring-docs/blob/master/src/test/java/com/sdm/docs/controller/SwaggerControllerSupportTest.java"

    %% Styles
    classDef backend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef controller fill:#bbf,stroke:#333,stroke-width:2px;
    classDef config fill:#bfb,stroke:#333,stroke-width:2px;
    classDef build fill:#fbf,stroke:#333,stroke-width:2px;
    classDef test fill:#ffb,stroke:#333,stroke-width:2px;
    classDef spec fill:#aff,stroke:#333,stroke-width:2px;
    classDef external fill:#faa,stroke:#333,stroke-width:2px;
```
