# yukionishi1129/kotlin-server-side-programming-practice architecture

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

- Interactive diagram: https://gitdiagram.com/yukionishi1129/kotlin-server-side-programming-practice
- Repository: https://github.com/yukionishi1129/kotlin-server-side-programming-practice

## Overview

##### Project type and purpose
- This is a multi‐module sample‐code repository for the book “Kotlin サーバーサイドプログラミング実践開発.”
- It contains small standalone demos (part1 and part3 chapters) plus one full‐stack application (“book-manager” in part2) and its accompanying front-end (Vue.js SPA under part2/front).

##### File structure
- Top‐level folders:
- part1 – chapter01–03: simple console‐app demos in Kotlin/Java
- part2 – chapter04–05 demos, plus book-manager back-end and its front-end
- part3 – chapter09–12: gRPC demos, Ktor routing, DSLs, testing
- The “book-manager” subfolder under part2 is a Spring Boot application with clearly separated layers:
- presentation (controllers, AOP, config, handlers)
- application (services)
- domain (models, repositories interfaces)
- infrastructure (MyBatis mappers, records, repository implementations)
- src/main/resources (application.yml, generatorConfig.xml)
- src/test – unit and integration tests
- The “front/book-manager” folder under part2 is a typical Vue.js project (webpack, src/api, src/components, router, main.js).

##### README
- Confirms the structure and shows that chapters 6–8 are implemented as one “book-manager” application with a back-end and front-end.

##### Main components
a. Front-end SPA (Vue.js)
– Components: Login.vue, BookList.vue, etc.
– API layer (src/api/*.js) connecting to back-end’s REST endpoints
b. Back-end Spring Boot application
– HTTP layer: Controllers (BookController, RentalController, AdminBookController)
– Security layer: SecurityConfig, custom UserDetailsService, handlers, AOP logging
– Application services: BookService, RentalService, AuthenticationService, AdminBookService
– Domain layer: Entities/Models (Book, Rental, User), Repository interfaces
– Infrastructure layer: MyBatis mappers & records, RepositoryImpl classes
– Database: relational DB (MySQL/PostgreSQL), SQL schema (book_manager.sql), MyBatis generatorConfig.xml
c. Persistence
– External database (depicted as a container or managed service)
– Docker Compose (docker/docker-compose.yml) for local dev
d. Optional: gRPC demos (chapter09), Ktor server (chapter10), DSL examples (chapter11), testing (chapter12) as separate, isolated “micro‐demos.”

##### Relationships and interactions
- Front-end → (HTTPS/REST) → Back-end Controllers
- Controllers → Application Services → Domain → Infrastructure → Database
- Security filters wrap Controller calls, consult AuthenticationService & UserDetailsService
- AOP LoggingAdvice intercepts service/controller calls for logging
- Docker Compose orchestrates Back-end + Database for local environment
- Build/Gradle scripts manage compilation, packaging, tests for each module

##### Architectural patterns & design principles
- Layered (onion) architecture in back-end
- Hexagonal elements: Controllers (ports), Services (application), Repositories (adapters)
- Separation of concerns: Web, Security, Business, Persistence
- MyBatis generator for mapping low‐level SQL to domain records/mappers
- SPA + REST API integration

##### Essential elements to capture
- Module boundaries (part1/part2/part3) or treat only the book-manager modules for clarity
- All back-end layers and key configuration pieces (security, AOP, ORM)
- Front-end SPA structure (components vs API client)
- Data flow direction and protocols
- Environment orchestration (docker-compose)

## Diagram (Mermaid)

```mermaid
graph TD
    User["User (Browser)"]:::external

    subgraph "Front-end SPA"
        AppVue["App.vue"]:::presentation
        MainJS["main.js"]:::presentation
        APIClient["src/api/*.js"]:::service
        Components["src/components"]:::presentation
        Router["router/index.js"]:::presentation
    end

    subgraph "Back-end Spring Boot"
        AppEntry["BookManagerApplication.kt"]:::service

        subgraph "Presentation Layer"
            BC["BookController"]:::presentation
            RC["RentalController"]:::presentation
            ABC["AdminBookController"]:::presentation
            LoggingAdvice["LoggingAdvice.kt"]:::presentation
            SecurityConfig["SecurityConfig.kt"]:::presentation
            HttpSessionCfg["HttpSessionConfig.kt"]:::presentation
            AuthEntry["BookManagerAuthenticationEntryPoint.kt"]:::presentation
            AuthSuccess["BookManagerAuthenticationSuccessHandler.kt"]:::presentation
            AuthFailure["BookManagerAuthenticationFailureHandler.kt"]:::presentation
            AccessDenied["BookManagerAccessDeniedHandler.kt"]:::presentation
        end

        subgraph "Application Layer"
            BookService["BookService.kt"]:::service
            RentalService["RentalService.kt"]:::service
            AuthService["AuthenticationService.kt"]:::service
            AdminBookService["AdminBookService.kt"]:::service
            UserDetailsSvc["BookManagerUserDetailsService.kt"]:::service
        end

        subgraph "Domain Layer"
            Models["domain/model/*.kt"]:::data
            RepoInterfaces["domain/repository/*.kt"]:::data
        end

        subgraph "Infrastructure Layer"
            Mappers["infrastructure/database/mapper/*.kt"]:::data
            Records["infrastructure/database/record/*.kt"]:::data
            RepoImpl["infrastructure/database/repository/*.kt"]:::data
        end

        Resources["application.yml\n&\ngeneratorConfig.xml"]:::external
        SQL["book_manager.sql"]:::external
    end

    DB["Relational Database"]:::external
    Compose["Docker Compose"]:::external

    User -->|HTTP/JSON| AppVue
    AppVue -->|invokes| APIClient
    APIClient -->|REST| BC

    BC -->|calls| BookService
    RC -->|calls| RentalService
    ABC -->|calls| AdminBookService

    BC --> LoggingAdvice
    RC --> LoggingAdvice
    ABC --> LoggingAdvice

    SecurityConfig --> BC
    HttpSessionCfg --> BC
    AuthEntry --> SecurityConfig
    AuthSuccess --> SecurityConfig
    AuthFailure --> SecurityConfig
    AccessDenied --> SecurityConfig

    BookService --> Models
    RentalService --> Models
    AdminBookService --> Models
    AuthService --> Models
    UserDetailsSvc --> RepoInterfaces

    Models --> RepoInterfaces
    RepoInterfaces --> RepoImpl
    RepoImpl --> Mappers
    Mappers --> Records
    Records --> DB

    Compose --> AppEntry
    Compose --> DB

    click AppVue "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/front/book-manager/src/App.vue"
    click MainJS "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/front/book-manager/src/main.js"
    click APIClient "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/tree/main/part2/front/book-manager/src/api"
    click Components "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/tree/main/part2/front/book-manager/src/components"
    click Router "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/front/book-manager/src/router/index.js"
    click AppEntry "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/BookManagerApplication.kt"
    click BC "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/presentation/controller/BookController.kt"
    click RC "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/presentation/controller/RentalController.kt"
    click ABC "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/presentation/controller/AdminBookController.kt"
    click LoggingAdvice "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/presentation/aop/LoggingAdvice.kt"
    click SecurityConfig "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/presentation/config/SecurityConfig.kt"
    click HttpSessionCfg "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/presentation/config/HttpSessionConfig.kt"
    click AuthEntry "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/presentation/handler/BookManagerAuthenticationEntryPoint.kt"
    click AuthSuccess "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/presentation/handler/BookManagerAuthenticationSuccessHandler.kt"
    click AuthFailure "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/presentation/handler/BookManagerAuthenticationFailureHandler.kt"
    click AccessDenied "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/presentation/handler/BookManagerAccessDeniedHandler.kt"
    click BookService "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/application/service/BookService.kt"
    click RentalService "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/application/service/RentalService.kt"
    click AuthService "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/application/service/AuthenticationService.kt"
    click AdminBookService "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/application/service/AdminBookService.kt"
    click UserDetailsSvc "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/application/service/security/BookManagerUserDetailsService.kt"
    click Models "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/domain/model/Book.kt"
    click RepoInterfaces "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/domain/repository/BookRepository.kt"
    click Mappers "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/tree/main/part2/book-manager/src/main/kotlin/com/book/manager/infrastructure/database/mapper"
    click Records "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/tree/main/part2/book-manager/src/main/kotlin/com/book/manager/infrastructure/database/record"
    click RepoImpl "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/kotlin/com/book/manager/infrastructure/database/repository/BookRepositoryImpl.kt"
    click Resources "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/src/main/resources/application.yml"
    click SQL "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/sql/book_manager.sql"
    click Compose "https://github.com/yukionishi1129/kotlin-server-side-programming-practice/blob/main/part2/book-manager/docker/docker-compose.yml"

    classDef presentation fill:#cce5ff,stroke:#004085,color:#004085
    classDef service fill:#d4edda,stroke:#155724,color:#155724
    classDef data fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
