# muratlevent/quizapp architecture

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

- Interactive diagram: https://gitdiagram.com/muratlevent/quizapp
- Repository: https://github.com/muratlevent/quizapp

## Overview

Based on our analysis of the provided file tree and README, this project is a Java Spring Boot web application for running a quiz game. Its primary purpose is to let users register, log in, choose quiz categories, answer questions, and view their results along with a scoreboard. The project uses a standard Spring Boot layered architecture with controllers, services, repositories, and model classes, while Thymeleaf templates render the user interface connected to RESTful endpoints, and MySQL serves as the database backend.

##### Main Components
- User Interface Layer:
- Web Browser clients interacting with HTML/CSS/JavaScript rendered via Thymeleaf templates.
- Templates located under src/main/resources/templates.
- Static files (CSS, images, JS) from src/main/resources/static and media folder.

- Backend Application Layer:
- The Spring Boot Application (entry point: QuizGameApplication.java).
- RESTful Controllers such as HomeController, LoginController, RegistrationController, QuestionController, ScoreController, ScoreboardController. Mark these clearly as “Presentation/Controller Layer.”
- Service Layer: Services (RandomQuestionService, QuestionRetrievalService, ScoreService, CustomUserDetailsService) that contain the business logic.
- Repository Layer: Interfaces (UserRepository, QuestionRepository, AnswerRepository, ScoreRepository) that abstract database operations.
- Model (Domain) Layer: Classes like User, Question, Answer, and Score.
- Security: The SecurityConfig and custom authentication/handler components (CustomLoginSuccessHandler) managing authentication and authorization.

- Data Layer:
- The MySQL database component. Indicate that the database contains tables for questions, answers, users, and scores.
- Database schema and initial data SQL files under the database folder.

##### Relationships and Interactions
- Services interact with Repositories (data access objects) which in turn perform CRUD operations with the MySQL database.
- Return flow: Repository → Service → Controller → Web Browser.
- For security, show that incoming requests are routed through a security configuration (SecurityConfig) which consults authentication/authorization providers before reaching controllers.

##### Architectural Patterns and Design Principles
- Layered Architecture: Show the clear separation between presentation (UI/Controller), business logic (Service), and data access (Repository) layers.
- RESTful Service Architecture: Demonstrate that the application exposes RESTful endpoints.
- MVC Pattern (Model-View-Controller): Emphasize how the Thymeleaf templates serve as the view in conjunction with the controllers.
- Dependency Injection: Although typically implicit, indicate that services and repository instances are injected into controllers in a Spring-managed environment.

##### Additional Specifics
- Entry point of the application (QuizGameApplication.java) as the bootstrapper of the system.
- Optionally, indicate testing components (e.g., src/test) to denote that unit tests exist, though they are not part of the runtime flow.
- Build/deployment aspect by noting Maven as the build tool, which manages dependencies via pom.xml.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Browser["Web Browser"]:::browser

    %% User Interface Layer
    subgraph "User Interface Layer"
        Thymeleaf["Thymeleaf Templates"]:::ui
        StaticAssets["Static Assets"]:::ui
    end

    %% Application Bootstrap
    subgraph "Application Bootstrap"
        App["QuizGame Application"]:::bootstrap
    end

    %% Security Layer
    subgraph "Security"
        SecurityCfg["SecurityConfig"]:::security
        LoginSuccess["CustomLoginSuccessHandler"]:::security
    end

    %% Presentation/Controller Layer
    subgraph "Presentation/Controller Layer"
        HomeCtrl["HomeController"]:::controller
        LoginCtrl["LoginController"]:::controller
        RegistrationCtrl["RegistrationController"]:::controller
        QuestionCtrl["QuestionController"]:::controller
        ScoreCtrl["ScoreController"]:::controller
        ScoreboardCtrl["ScoreboardController"]:::controller
        SessionHelper["Session Helper"]:::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        RandomService["RandomQuestionService"]:::service
        QuestionRetrieval["QuestionRetrievalService"]:::service
        ScoreService["ScoreService"]:::service
        UserDetails["CustomUserDetailsService"]:::service
    end

    %% Repository Layer
    subgraph "Repository Layer"
        UserRepo["UserRepository"]:::repository
        QuestionRepo["QuestionRepository"]:::repository
        AnswerRepo["AnswerRepository"]:::repository
        ScoreRepo["ScoreRepository"]:::repository
    end

    %% Model (Domain) Layer
    subgraph "Model (Domain) Layer"
        UserModel["User"]:::model
        QuestionModel["Question"]:::model
        AnswerModel["Answer"]:::model
        ScoreModel["Score"]:::model
    end

    %% Data Layer (MySQL Database and Files)
    subgraph "Data Layer (MySQL Database)"
        DB["MySQL Database"]:::database
        AnswersSchema["Answers Schema"]:::database
        QuestionsSchema["Questions Schema"]:::database
        AnswersData["Answers Data"]:::database
        QuestionsData["Questions Data"]:::database
    end

    %% Connections: Bootstrap and Security
    App -->|"Initializes"| SecurityCfg
    App -->|"Bootstraps"| HomeCtrl
    App -->|"Bootstraps"| LoginCtrl
    App -->|"Bootstraps"| RegistrationCtrl
    App -->|"Bootstraps"| QuestionCtrl
    App -->|"Bootstraps"| ScoreCtrl
    App -->|"Bootstraps"| ScoreboardCtrl
    App -->|"Bootstraps"| SessionHelper

    %% Incoming Requests from Browser through Security to Controllers
    Browser -->|"HTTP_request"| SecurityCfg
    SecurityCfg -->|"Forwards"| HomeCtrl
    SecurityCfg -->|"Forwards"| LoginCtrl
    SecurityCfg -->|"Forwards"| RegistrationCtrl
    SecurityCfg -->|"Forwards"| QuestionCtrl
    SecurityCfg -->|"Forwards"| ScoreCtrl
    SecurityCfg -->|"Forwards"| ScoreboardCtrl
    SecurityCfg -->|"Forwards"| SessionHelper

    %% Controllers calling Services
    HomeCtrl -->|"calls"| RandomService
    LoginCtrl -->|"calls"| UserDetails
    RegistrationCtrl -->|"calls"| ScoreService
    QuestionCtrl -->|"calls"| QuestionRetrieval
    ScoreCtrl -->|"calls"| ScoreService
    ScoreboardCtrl -->|"calls"| ScoreService
    SessionHelper -->|"assists"| HomeCtrl

    %% Services calling Repositories
    RandomService -->|"queries"| QuestionRepo
    QuestionRetrieval -->|"queries"| QuestionRepo
    ScoreService -->|"queries"| ScoreRepo
    UserDetails -->|"queries"| UserRepo

    %% Repositories performing DB operations
    UserRepo -->|"CRUD"| DB
    QuestionRepo -->|"CRUD"| DB
    AnswerRepo -->|"CRUD"| DB
    ScoreRepo -->|"CRUD"| DB

    %% Database linked with Schema and Data Files
    AnswersSchema -->|"defines"| DB
    QuestionsSchema -->|"defines"| DB
    AnswersData -->|"populates"| DB
    QuestionsData -->|"populates"| DB

    %% UI rendering flow: Thymeleaf and Static assets served to Browser 
    Thymeleaf -->|"renders view"| Browser
    StaticAssets -->|"serves assets"| Browser

    %% Styles
    classDef browser fill:#ffdd99,stroke:#885500,stroke-width:2px;
    classDef ui fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef bootstrap fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef controller fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef service fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef repository fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef model fill:#e2e3e5,stroke:#383d41,stroke-width:2px;
    classDef security fill:#f5c6cb,stroke:#721c24,stroke-width:2px;
    classDef database fill:#d4edda,stroke:#155724,stroke-width:2px;

    %% Click Events
    click Thymeleaf "https://github.com/muratlevent/quizapp/tree/main/src/main/resources/templates"
    click StaticAssets "https://github.com/muratlevent/quizapp/tree/main/src/main/resources/static"
    click App "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/QuizGame.java"
    click HomeCtrl "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/controller/HomeController.java"
    click LoginCtrl "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/controller/LoginController.java"
    click RegistrationCtrl "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/controller/RegistrationController.java"
    click QuestionCtrl "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/controller/QuestionController.java"
    click ScoreCtrl "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/controller/ScoreController.java"
    click ScoreboardCtrl "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/controller/ScoreboardController.java"
    click SessionHelper "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/controller/SessionHelper.java"
    click RandomService "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/service/RandomQuestionService.java"
    click QuestionRetrieval "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/service/QuestionRetrievalService.java"
    click ScoreService "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/service/ScoreService.java"
    click UserDetails "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/service/CustomUserDetailsService.java"
    click UserRepo "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/repository/UserRepository.java"
    click QuestionRepo "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/repository/QuestionRepository.java"
    click AnswerRepo "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/repository/AnswerRepository.java"
    click ScoreRepo "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/repository/ScoreRepository.java"
    click UserModel "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/model/User.java"
    click QuestionModel "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/model/Question.java"
    click AnswerModel "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/model/Answer.java"
    click ScoreModel "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/model/Score.java"
    click SecurityCfg "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/security/SecurityConfig.java"
    click LoginSuccess "https://github.com/muratlevent/quizapp/blob/main/src/main/java/com/example/QuizGame/handler/CustomLoginSuccessHandler.java"
    click AnswersSchema "https://github.com/muratlevent/quizapp/blob/main/database/schema/answers_schema.sql"
    click QuestionsSchema "https://github.com/muratlevent/quizapp/blob/main/database/schema/questions_schema.sql"
    click AnswersData "https://github.com/muratlevent/quizapp/blob/main/database/data/answers_data.sql"
    click QuestionsData "https://github.com/muratlevent/quizapp/blob/main/database/data/questions_data.sql"
```
