# gothinkster/spring-boot-realworld-example-app architecture

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

- Interactive diagram: https://gitdiagram.com/gothinkster/spring-boot-realworld-example-app
- Repository: https://github.com/gothinkster/spring-boot-realworld-example-app

## Overview

##### Project type and purpose
- This is a backend‐only service implementing the RealWorld API spec.
- It exposes both REST (Spring MVC controllers) and GraphQL (Netflix DGS) adapters over the same domain.
- It uses Spring Boot, MyBatis (Data Mapper pattern), DDD layering, CQRS (separate read/write models), JWT security, and an embedded SQLite/H2 database.

##### File structure
- Top-level layers under src/main/java/io/spring:
1. api      → REST controllers (ArticleApi, UsersApi, etc.)
2. graphql  → GraphQL resolvers, mutations, data fetchers
3. application → High-level use-case services (QueryService, CommandService, DTOs, paging utilities)
4. core     → Domain entities, repositories (interfaces), services (authorization, JWT)
5. infrastructure → MyBatis mappers & read services, repository implementations, JWT service, DB type handlers
- Config files:
- WebSecurityConfig.java, JwtTokenFilter.java
- MyBatisConfig.java
- application.properties
- Build and deployment:
- Gradle wrapper, Docker build image via Spring Boot plugin

##### README for additional insights
- Emphasis on DDD: “api” and “graphql” as adapters, “application” as use‐cases, “core” as business model, “infrastructure” as technical details.
- CQRS: read models (QueryService + MyBatis read mappers) vs write models (CommandService + Repository).
- GraphQL schema in resources/schema/schema.graphqls using Netflix DGS.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    Frontend["External Frontend"]:::external

    %% Security Layer
    subgraph "Security Layer"
        JwtFilter["JwtTokenFilter"]:::security
        WebSecurity["WebSecurityConfig"]:::security
    end

    %% Adapters Layer
    subgraph "Adapters Layer"
        REST["REST Controllers"]:::adapter
        GraphQL["GraphQL Resolvers/Mutations"]:::adapter
    end

    %% Application Layer
    subgraph "Application Layer"
        subgraph "Query Services"
            AQS["ArticleQueryService"]:::application
            CQS["CommentQueryService"]:::application
            PQS["ProfileQueryService"]:::application
            TQS["TagsQueryService"]:::application
            UQS["UserQueryService"]:::application
        end
        subgraph "Command Services"
            ACS["ArticleCommandService"]:::application
            UCS["UserService"]:::application
        end
    end

    %% Domain Layer
    subgraph "Domain Layer"
        subgraph "Entities & Repositories"
            DomainArticles["Article, ArticleRepository"]:::domain
            DomainComments["Comment, CommentRepository"]:::domain
            DomainFavorites["ArticleFavorite, ArticleFavoriteRepository"]:::domain
            DomainUsers["User, UserRepository, FollowRelation"]:::domain
        end
        subgraph "Domain Services"
            AuthService["AuthorizationService"]:::domain
            JwtService["JwtService"]:::domain
        end
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        MyBatisCfg["MyBatisConfig"]:::infra
        TypeHandler["DateTimeHandler"]:::infra
        Mappers["Mapper Interfaces"]:::infra
        ReadImpl["ReadService Implementations"]:::infra
        RepoImpl["Repository Implementations"]:::infra
        DefaultJwt["DefaultJwtService"]:::infra
    end

    %% Database
    DB[(Embedded SQLite/H2 Database)]:::db

    %% Connections
    Frontend --> JwtFilter
    JwtFilter --> REST
    JwtFilter --> GraphQL
    WebSecurity --> JwtFilter

    REST --> AQS
    REST --> CQS
    REST --> PQS
    REST --> TQS
    REST --> UQS
    REST --> ACS
    REST --> UCS

    GraphQL --> AQS
    GraphQL --> CQS
    GraphQL --> PQS
    GraphQL --> TQS
    GraphQL --> UQS
    GraphQL --> ACS
    GraphQL --> UCS

    AQS --> DomainArticles
    CQS --> DomainComments
    PQS --> DomainUsers
    TQS --> DomainArticles
    UQS --> DomainUsers

    ACS --> DomainArticles
    UCS --> DomainUsers

    DomainArticles --> RepoImpl
    DomainComments --> RepoImpl
    DomainFavorites --> RepoImpl
    DomainUsers --> RepoImpl

    RepoImpl --> DB
    ReadImpl --> DB

    JwtFilter --> JwtService
    JwtService --> DefaultJwt

    %% Click Events
    click REST "https://github.com/gothinkster/spring-boot-realworld-example-app/tree/master/src/main/java/io/spring/api"
    click GraphQL "https://github.com/gothinkster/spring-boot-realworld-example-app/tree/master/src/main/java/io/spring/graphql"
    click JwtFilter "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/api/security/JwtTokenFilter.java"
    click WebSecurity "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/api/security/WebSecurityConfig.java"
    click AQS "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/application/ArticleQueryService.java"
    click CQS "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/application/CommentQueryService.java"
    click PQS "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/application/ProfileQueryService.java"
    click TQS "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/application/TagsQueryService.java"
    click UQS "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/application/UserQueryService.java"
    click ACS "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/application/article/ArticleCommandService.java"
    click UCS "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/application/user/UserService.java"
    click DomainArticles "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/core/article/Article.java"
    click DomainComments "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/core/comment/Comment.java"
    click DomainFavorites "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/core/favorite/ArticleFavorite.java"
    click DomainUsers "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/core/user/User.java"
    click AuthService "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/core/service/AuthorizationService.java"
    click JwtService "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/core/service/JwtService.java"
    click MyBatisCfg "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/MyBatisConfig.java"
    click TypeHandler "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/infrastructure/mybatis/DateTimeHandler.java"
    click Mappers "https://github.com/gothinkster/spring-boot-realworld-example-app/tree/master/src/main/java/io/spring/infrastructure/mybatis/mapper"
    click ReadImpl "https://github.com/gothinkster/spring-boot-realworld-example-app/tree/master/src/main/java/io/spring/infrastructure/mybatis/readservice"
    click RepoImpl "https://github.com/gothinkster/spring-boot-realworld-example-app/tree/master/src/main/java/io/spring/infrastructure/repository"
    click DefaultJwt "https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/infrastructure/service/DefaultJwtService.java"

    %% Styles
    classDef external fill:#ddeeff,stroke:#333,stroke-width:1px;
    classDef security fill:#f9e79f,stroke:#333,stroke-width:1px;
    classDef adapter fill:#aed6f1,stroke:#333,stroke-width:1px;
    classDef application fill:#abebc6,stroke:#333,stroke-width:1px;
    classDef domain fill:#f5cba7,stroke:#333,stroke-width:1px;
    classDef infra fill:#d7bde2,stroke:#333,stroke-width:1px;
    classDef db fill:#a3e4d7,stroke:#333,stroke-width:1px;
```
