# linskay/space-sql architecture

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

- Interactive diagram: https://gitdiagram.com/linskay/space-sql
- Repository: https://github.com/linskay/space-sql

## Overview

##### Project type and purpose
- This is a monolithic full-stack web application (“SQL Космический Тренажер”) for interactive SQL training.
- Frontend is plain HTML/CSS/JavaScript (with Thymeleaf templates in /templates and static assets in /static).
- Backend is a Spring Boot REST API with OAuth2 security, database migrations, service/repository layers, and automatic SQL-query checking.

##### File structure
- Top-level: pom.xml, README.md, src/main/java, src/main/resources
- src/main/java/com/spacesql:
- config: JacksonConfig, SecurityConfig (OAuth2/GitHub), SwaggerConfig
- controller: LessonController, TaskExampleController, QueryController, UserController
- service: LessonService, TaskService, TaskExampleService, QueryService
- repository: LessonRepository, TaskRepository, TaskExampleDataRepository, UserRepository
- entity + dto: domain model vs. API payloads
- exception: GlobalExceptionHandler, custom exceptions
- util: SqlValidator
- src/main/resources:
- application.properties (DB, OAuth, etc.)
- db/changelog: Liquibase XML scripts for schema and seed data
- static: index.html, practice.html, profile.html, JS, CSS, images, 404 page
- templates: Thymeleaf views

##### README for additional insights
- Confirms frontend stack (HTML/CSS/JS), backend (Java 17 + Spring Web + REST + Lombok), DB (PostgreSQL, H2 for tests), OAuth2 via GitHub.
- Emphasis on interactive lessons, query checking, progress tracking, gamification.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)"
        Static["Static Assets"]:::frontend
        Templates["Thymeleaf Templates"]:::frontend
    end

    %% Application Server
    subgraph "Spring Boot App"
        App["SpaceSqlApplication"]:::app

        subgraph "Configuration"
            Jackson["JacksonConfig"]:::config
            Security["SecurityConfig"]:::config
            Swagger["SwaggerConfig"]:::config
        end

        subgraph "Controllers"
            LessonC["LessonController"]:::controller
            QueryC["QueryController"]:::controller
            TaskExC["TaskExampleController"]:::controller
            UserC["UserController"]:::controller
        end

        subgraph "Services"
            LessonS["LessonService"]:::service
            QueryS["QueryService"]:::service
            TaskS["TaskService"]:::service
            TaskExS["TaskExampleService"]:::service
        end

        subgraph "Repositories"
            LessonR["LessonRepository"]:::repository
            TaskR["TaskRepository"]:::repository
            TaskExR["TaskExampleDataRepository"]:::repository
            UserR["UserRepository"]:::repository
        end

        subgraph "Util & Exceptions"
            Validator["SqlValidator"]:::util
            GHHandler["GlobalExceptionHandler"]:::exception
        end
    end

    %% Database & External
    DB["PostgreSQL / H2"]:::db
    Liquibase["Liquibase Migrations"]:::db
    OAuth["GitHub OAuth2"]:::external

    %% Data Flows
    Static -->|serves static files| App
    Templates -->|renders views| App

    App -->|initializes| Jackson
    App -->|initializes| Security
    App -->|initializes| Swagger

    Security -->|OAuth2 flow| OAuth

    LessonC -->|calls| LessonS
    QueryC -->|calls| QueryS
    TaskExC -->|calls| TaskExS
    UserC -->|calls| UserR

    LessonS -->|uses| LessonR
    QueryS -->|validates SQL via| Validator
    QueryS -->|executes queries| DB
    TaskS -->|uses| TaskR
    TaskExS -->|uses| TaskExR

    LessonR -->|JPA/Hibernate| DB
    TaskR -->|JPA/Hibernate| DB
    TaskExR -->|JPA/Hibernate| DB
    UserR -->|JPA/Hibernate| DB

    GHHandler -->|handles errors| App

    Liquibase -->|runs migrations| DB

    %% Click Events
    click Static "https://github.com/linskay/space-sql/tree/master/src/main/resources/static"
    click Templates "https://github.com/linskay/space-sql/tree/master/src/main/resources/templates"
    click App "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/SpaceSqlApplication.java"
    click Jackson "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/config/JacksonConfig.java"
    click Security "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/config/SecurityConfig.java"
    click Swagger "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/config/SwaggerConfig.java"
    click LessonC "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/controller/LessonController.java"
    click QueryC "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/controller/QueryController.java"
    click TaskExC "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/controller/TaskExampleController.java"
    click UserC "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/controller/UserController.java"
    click LessonS "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/service/LessonService.java"
    click QueryS "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/service/QueryService.java"
    click TaskS "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/service/TaskService.java"
    click TaskExS "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/service/TaskExampleService.java"
    click LessonR "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/repository/LessonRepository.java"
    click TaskR "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/repository/TaskRepository.java"
    click TaskExR "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/repository/TaskExampleDataRepository.java"
    click UserR "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/repository/UserRepository.java"
    click Validator "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/util/SqlValidator.java"
    click GHHandler "https://github.com/linskay/space-sql/blob/master/src/main/java/com/spacesql/exception/GlobalExceptionHandler.java"
    click Liquibase "https://github.com/linskay/space-sql/tree/master/src/main/resources/db/changelog"
    click DB "https://github.com/linskay/space-sql/blob/master/src/main/resources/application.properties"

    %% Styles
    classDef frontend fill:#ccf,stroke:#669,stroke-width:1px
    classDef app fill:#eee,stroke:#666,stroke-width:1px
    classDef config fill:#fcf,stroke:#933,stroke-width:1px
    classDef controller fill:#f96,stroke:#933,stroke-width:1px
    classDef service fill:#ff9,stroke:#993,stroke-width:1px
    classDef repository fill:#9f9,stroke:#393,stroke-width:1px
    classDef util fill:#cff,stroke:#099,stroke-width:1px
    classDef exception fill:#fdd,stroke:#933,stroke-width:1px
    classDef db fill:#2f6,stroke:#060,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#ccc,stroke:#666,stroke-width:1px,stroke-dasharray: 2 2
```
