# guiilopes97/countries_and_capitals architecture

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

- Interactive diagram: https://gitdiagram.com/guiilopes97/countries_and_capitals
- Repository: https://github.com/guiilopes97/countries_and_capitals

## Overview

##### Project Type and Purpose
- This is a monolithic, full-stack web application built with Laravel 12.x.
- It implements an MVC quiz game (Countries & Capitals) that delivers pages via Blade, tracks answers in session or storage, and renders results.

##### File Structure
- Top-level directories:
- app/ (Controllers, View Components, Providers)
- resources/ (Blade views, CSS/JS assets)
- public/ (entry point index.php, compiled assets)
- config/, bootstrap/, storage/ (framework config, cache, sessions)
- No separate microservices—single codebase with MVC pattern.
- app/app_data.php is the in-memory data provider for questions.
- Sessions are file-based by default (storage/framework/sessions).

##### README
- Confirms MVC, Laravel Components, Bootstrap for UI.
- No external APIs or databases explicitly used—game history likely in session or could be persisted via Laravel’s database if configured.

##### Main Components
a. Client Browser (UI Layer)
- Blade templates + Bootstrap CSS/JS
- User actions (start game, answer question)
b. Web Server (Apache/Nginx)
- Serves public/index.php and static assets (public/assets)
c. Laravel Application Layer
- HTTP Kernel & Middleware
- Router (routes/web.php → MainController)
- Controllers (app/Http/Controllers/MainController.php)
- View Components (app/View/Components/*.php and Blade files)
- Service Providers (AppServiceProvider)
- app_data.php (question data provider)
d. Persistence Layer
- Session Store (file driver in storage/framework/sessions)
- (Optional) Database (if later enabled in config/database.php)
- File Storage (logs in storage/logs)
e. Static Asset Store
- CSS, JS, images served from public/assets & resources

##### Relationships & Data Flows
1. Client → Web Server: HTTP GET / POST requests
2. Web Server → Laravel front controller (public/index.php)
3. Kernel → Router → MainController
4. MainController reads app_data.php for questions, reads/writes session, applies business rules
5. Controller → Blade templating engine renders HTML (injects View Components)
6. Laravel response → Web Server → Browser
7. Browser loads CSS/JS/images directly from public/assets
8. On user interactions, repeat the cycle for form POSTs to /answer or /history endpoints

##### Architectural Patterns & Principles
- MVC separation: Controllers handle HTTP logic, Views (Blade + Components) handle presentation.
- Single Responsibility: each View Component (Answer, Question, MainLayout) encapsulates its HTML + data.
- Service Container & Providers for dependency injection and bootstrapping.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Tier 1: Client Browser
    subgraph "Client Browser" 
        direction TB
        B1["Resources Views"]:::frontend
        B2["Component Views"]:::frontend
        B3["CSS/JS Assets"]:::frontend
        B4["Public Assets"]:::frontend
    end

    %% Tier 2: Web Server
    subgraph "Web Server" 
        direction TB
        S1["public/index.php"]:::webserver
        S2["public/.htaccess"]:::webserver
        S3["public/assets/"]:::webserver
    end

    %% Tier 3: Laravel Application
    subgraph "Laravel App" 
        direction TB
        subgraph "HTTP Layer"
            direction TB
            K1["bootstrap/app.php"]:::backend
            K2["bootstrap/providers.php"]:::backend
            R["routes/web.php"]:::backend
        end
        subgraph "Controllers"
            direction TB
            C1["MainController.php"]:::backend
            C2["Controller.php"]:::backend
        end
        subgraph "Service Providers"
            direction TB
            P["AppServiceProvider.php"]:::backend
        end
        subgraph "View Components"
            direction TB
            VC1["Answer.php"]:::backend
            VC2["Question.php"]:::backend
            VC3["MainLayout.php"]:::backend
        end
        subgraph "Blade Component Views"
            direction TB
            V1["answer.blade.php"]:::backend
            V2["question.blade.php"]:::backend
            V3["main-layout.blade.php"]:::backend
            V4["logo.blade.php"]:::backend
            V5["footer.blade.php"]:::backend
        end
        DP["app_data.php"]:::backend
    end

    %% Tier 4: Persistence
    subgraph "Persistence & Storage"
        direction TB
        PS["storage/framework/sessions/"]:::storage
        DB["config/database.php"]:::storage
        LG["storage/logs/"]:::storage
    end

    %% Static Asset Build Config
    SB["vite.config.js\npackage.json"]:::backend

    %% Connections
    B1 -->|renders UI| S1
    B3 -->|loads assets| S3
    B4 -->|loads assets| S3
    B2 -->|renders UI| S1

    S1 -->|"HTTP Request"| K1
    K1 -->|bootstraps| K2
    K2 -->|registers routes| R
    R -->|"dispatch"| C1
    C1 -->|"uses"| DP
    C1 -->|"reads/writes"| PS
    C1 -->|"calls"| VC1
    C1 -->|"calls"| VC2
    C1 -->|"calls"| VC3
    VC1 -->|"renders"| V1
    VC2 -->|"renders"| V2
    VC3 -->|"renders"| V3
    VC3 -->|"renders"| V4
    VC3 -->|"renders"| V5
    C1 -->|"optionally uses"| DB
    C1 -->|"logs to"| LG
    SB -->|"builds assets"| B3

    %% Response flow
    C1 -->|returns View| S1
    S1 -->|HTTP Response| B1

    %% Click Events
    click B1 "https://github.com/guiilopes97/countries_and_capitals/tree/011/resources/views/"
    click B2 "https://github.com/guiilopes97/countries_and_capitals/tree/011/resources/views/components/"
    click B3 "https://github.com/guiilopes97/countries_and_capitals/blob/011/resources/css/app.css"
    click B3 "https://github.com/guiilopes97/countries_and_capitals/blob/011/resources/js/app.js"
    click B3 "https://github.com/guiilopes97/countries_and_capitals/blob/011/resources/js/bootstrap.js"
    click B4 "https://github.com/guiilopes97/countries_and_capitals/tree/011/public/assets/"
    click S1 "https://github.com/guiilopes97/countries_and_capitals/blob/011/public/index.php"
    click S2 "https://github.com/guiilopes97/countries_and_capitals/blob/011/public/.htaccess"
    click S3 "https://github.com/guiilopes97/countries_and_capitals/tree/011/public/assets/"
    click R "https://github.com/guiilopes97/countries_and_capitals/blob/011/routes/web.php"
    click C1 "https://github.com/guiilopes97/countries_and_capitals/blob/011/app/Http/Controllers/MainController.php"
    click C2 "https://github.com/guiilopes97/countries_and_capitals/blob/011/app/Http/Controllers/Controller.php"
    click K1 "https://github.com/guiilopes97/countries_and_capitals/blob/011/bootstrap/app.php"
    click K2 "https://github.com/guiilopes97/countries_and_capitals/blob/011/bootstrap/providers.php"
    click P "https://github.com/guiilopes97/countries_and_capitals/blob/011/app/Providers/AppServiceProvider.php"
    click VC1 "https://github.com/guiilopes97/countries_and_capitals/blob/011/app/View/Components/Answer.php"
    click VC2 "https://github.com/guiilopes97/countries_and_capitals/blob/011/app/View/Components/Question.php"
    click VC3 "https://github.com/guiilopes97/countries_and_capitals/blob/011/app/View/Components/MainLayout.php"
    click V1 "https://github.com/guiilopes97/countries_and_capitals/blob/011/resources/views/components/answer.blade.php"
    click V2 "https://github.com/guiilopes97/countries_and_capitals/blob/011/resources/views/components/question.blade.php"
    click V3 "https://github.com/guiilopes97/countries_and_capitals/blob/011/resources/views/components/main-layout.blade.php"
    click V4 "https://github.com/guiilopes97/countries_and_capitals/blob/011/resources/views/components/logo.blade.php"
    click V5 "https://github.com/guiilopes97/countries_and_capitals/blob/011/resources/views/components/footer.blade.php"
    click DP "https://github.com/guiilopes97/countries_and_capitals/blob/011/app/app_data.php"
    click PS "https://github.com/guiilopes97/countries_and_capitals/tree/011/storage/framework/sessions/"
    click DB "https://github.com/guiilopes97/countries_and_capitals/blob/011/config/database.php"
    click LG "https://github.com/guiilopes97/countries_and_capitals/tree/011/storage/logs/"
    click SB "https://github.com/guiilopes97/countries_and_capitals/blob/011/vite.config.js"

    %% Styles
    classDef frontend fill:#D6E9FE,stroke:#333,stroke-width:1px
    classDef webserver fill:#C6F7D9,stroke:#333,stroke-width:1px
    classDef backend fill:#E0FFE0,stroke:#333,stroke-width:1px
    classDef storage fill:#FFF8D6,stroke:#333,stroke-width:1px
```
