# yunggialyana/rpg-elearn architecture

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

- Interactive diagram: https://gitdiagram.com/yunggialyana/rpg-elearn
- Repository: https://github.com/yunggialyana/rpg-elearn

## Overview

##### Main Components
- Frontend Presentation Layer:
- The “public” directory contains user-facing pages including distinct sections for admin, teacher (dosen), and student (siswa). Also, pages like index.php, battle.php, logout.php, and map.php support core functionalities (e.g., gamification, interactive map).
- The “templates” directory holds reusable UI components (alert, avatar, badge_card, quest_box, xp_bar) and layout files (header, footer, navbar, sidebar).

- Backend/API Layer:
- The “api” directory is subdivided into specific endpoints for functions such as analytics, authentication (login/register), handling quest submissions, accessing/mutating data (user profile, XP), badge management, and course content (materi). These endpoints define the service interfaces between the frontend and the business logic.

- Business Logic & Core Services:
- The “includes” directory encapsulates core functionality: authentication, configuration, session management, middleware, logging, and a “core” folder for gamification logics (achievement, badge, event, inventory, level, map, notification, quest, xp). This acts as the central hub where the application’s rules and processes come together.
- The “includes/db.php” likely handles database connectivity.

- Data Persistence:
- The “database” directory contains the SQL schema (rpg-elearn-schema.sql), representing the underlying data model including tables for users, quests, XP, badges, etc.

- Dev Ops & Utilities:
- The “tools” directory includes scripts for backup, exporting user data, and toggling maintenance mode (helpful for deployments and operations).
- The “tests” directory contains test scripts (dummy_user, quest_test, xp_generator) which provide a view into how critical components are validated.
- The “uploads” directory hints at user-submitted or system-uploaded files (e.g., course materials).

##### Out Relationships & Interactions
- That business logic in the “includes” folder underpins API calls and also interacts directly with the database.
- How user actions (different roles: admin, teacher, student) trigger UI flows that route requests to different API endpoints.
- External utility scripts (“tools”) and “tests” that serve auxiliary functions to support the system.

##### Architectural Patterns & Design Principles
- MVC or layered separation: Although not a strict MVC framework, the clear separation between frontend pages (views), API endpoints (controllers/services), and business logic/data access layers (models via “includes” and database) is apparent.
- Role-based access: Distinct folder structures for admin, teacher, and student pages indicate separation of concerns and specialized access controls.
- Modularity and reusability: The components in the “templates” and “includes/core” directories emphasize reusable UI and core business logic components.
- Utility/maintenance scripts are separated out to simplify operations and maintenance.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Presentation Layer
    subgraph "Frontend Presentation Layer"
        FP1["Public Pages\n(index.php, battle.php, logout.php, map.php)"]:::frontend
        FP2["Admin Interface\n(public/admin)"]:::frontend
        FP3["Teacher Interface\n(public/dosen)"]:::frontend
        FP4["Student Interface\n(public/siswa)"]:::frontend
        FP5["UI Components\n(templates/components)"]:::frontend
        FP6["Layout Templates\n(templates/layout)"]:::frontend
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        API1["API - Auth\n(login.php, register.php)"]:::api
        API2["API - Quest\n(submit_quest.php)"]:::api
        API3["API - Badge\n(unlock_badge.php)"]:::api
        API4["API - Materi\n(fetch_materi.php)"]:::api
        API5["API - Analytics\n(progress.php)"]:::api
        API6["API - User\n(get_profile.php, update_avatar.php)"]:::api
        API7["API - XP\n(get_xp.php, update_xp.php)"]:::api
    end

    %% Business Logic & Core Services
    subgraph "Business Logic & Core Services"
        %% Core Services
        BL1["Core: Auth\n(includes/auth.php)"]:::core
        BL2["Core: Config\n(includes/config.php)"]:::core
        BL3["Core: DB\n(includes/db.php)"]:::core
        BL4["Core: Logger\n(includes/logger.php)"]:::core
        BL5["Core: Middleware\n(includes/middleware.php)"]:::core
        BL6["Core: Roles\n(includes/roles.php)"]:::core
        BL7["Core: Session\n(includes/session.php)"]:::core

        %% Gamification & Application Logic
        subgraph "Gamification Core (includes/core)"
            GC1["Achievement\n(achievement.php)"]:::core
            GC2["Badge\n(badge.php)"]:::core
            GC3["Event\n(event.php)"]:::core
            GC4["Inventory\n(inventory.php)"]:::core
            GC5["Level\n(level.php)"]:::core
            GC6["Map\n(map.php)"]:::core
            GC7["Notification\n(notification.php)"]:::core
            GC8["Quest\n(quest.php)"]:::core
            GC9["XP\n(xp.php)"]:::core
        end
    end

    %% Data Persistence
    subgraph "Data Persistence"
        DB["Database Schema\n(rpg-elearn-schema.sql)"]:::db
    end

    %% Dev Ops & Utilities
    subgraph "Dev Ops & Utilities"
        UT1["Tools\n(backup_db.php, export_user_data.php, maintenance_mode.php)"]:::util
        UT2["Tests\n(dummy_user.php, quest_test.php, xp_generator.php)"]:::util
        UT3["Uploads\n(uploads/materi)"]:::util
    end

    %% Connections: Frontend to API Layer
    FP1 -->|"user actions"| API1
    FP1 -->|"user actions"| API2
    FP1 -->|"user actions"| API3
    FP1 -->|"user actions"| API4
    FP1 -->|"user actions"| API5
    FP1 -->|"user actions"| API6
    FP1 -->|"user actions"| API7
    FP2 -->|"admin actions"| API1
    FP3 -->|"teacher actions"| API4
    FP4 -->|"student actions"| API7

    FP5 --- FP6

    %% Connections: API Layer to Business Logic
    API1 -->|"auth validation"| BL1
    API2 -->|"quest processing"| GC8
    API3 -->|"badge unlock"| GC2
    API4 -->|"materi retrieval"| BL2
    API5 -->|"progress analytics"| BL4
    API6 -->|"user data management"| BL6
    API7 -->|"xp update"| GC9

    %% Connections: Business Logic to Database
    BL1 -->|"data access"| BL3
    BL2 -->|"configuration"| BL3
    BL4 --> BL3
    BL5 --> BL3
    BL7 --> BL3
    GC1 -->|"store achievement"| DB
    GC2 -->|"store badges"| DB
    GC3 --> DB
    GC4 --> DB
    GC5 --> DB
    GC6 --> DB
    GC7 --> DB
    GC8 --> DB
    GC9 --> DB

    %% Connections: Tools and Tests support Business Logic and Database
    UT1 -->|"maintenance backup"| DB
    UT2 -->|"system testing"| BL3
    UT3 -->|"file resource"| FP1

    %% Click Events for Frontend Presentation Layer
    click FP1 "https://github.com/yunggialyana/rpg-elearn/tree/main/public"
    click FP2 "https://github.com/yunggialyana/rpg-elearn/tree/main/public/admin"
    click FP3 "https://github.com/yunggialyana/rpg-elearn/tree/main/public/dosen"
    click FP4 "https://github.com/yunggialyana/rpg-elearn/tree/main/public/siswa"
    click FP5 "https://github.com/yunggialyana/rpg-elearn/tree/main/templates/components"
    click FP6 "https://github.com/yunggialyana/rpg-elearn/tree/main/templates/layout"

    %% Click Events for Backend/API Layer
    click API1 "https://github.com/yunggialyana/rpg-elearn/tree/main/api/auth"
    click API2 "https://github.com/yunggialyana/rpg-elearn/tree/main/api/quest"
    click API3 "https://github.com/yunggialyana/rpg-elearn/tree/main/api/badge"
    click API4 "https://github.com/yunggialyana/rpg-elearn/tree/main/api/materi"
    click API5 "https://github.com/yunggialyana/rpg-elearn/tree/main/api/analytics"
    click API6 "https://github.com/yunggialyana/rpg-elearn/tree/main/api/user"
    click API7 "https://github.com/yunggialyana/rpg-elearn/tree/main/api/xp"

    %% Click Events for Business Logic & Core Services - Core Files
    click BL1 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/auth.php"
    click BL2 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/config.php"
    click BL3 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/db.php"
    click BL4 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/logger.php"
    click BL5 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/middleware.php"
    click BL6 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/roles.php"
    click BL7 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/session.php"

    %% Click Events for Gamification Core
    click GC1 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/core/achievement.php"
    click GC2 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/core/badge.php"
    click GC3 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/core/event.php"
    click GC4 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/core/inventory.php"
    click GC5 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/core/level.php"
    click GC6 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/core/map.php"
    click GC7 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/core/notification.php"
    click GC8 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/core/quest.php"
    click GC9 "https://github.com/yunggialyana/rpg-elearn/blob/main/includes/core/xp.php"

    %% Click Events for Data Persistence
    click DB "https://github.com/yunggialyana/rpg-elearn/tree/main/database"

    %% Click Events for Dev Ops & Utilities
    click UT1 "https://github.com/yunggialyana/rpg-elearn/tree/main/tools"
    click UT2 "https://github.com/yunggialyana/rpg-elearn/tree/main/tests"
    click UT3 "https://github.com/yunggialyana/rpg-elearn/tree/main/uploads"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef api fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef core fill:#A9DFBF,stroke:#117A65,stroke-width:2px;
    classDef db fill:#F5B7B1,stroke:#922B21,stroke-width:2px,stroke-dasharray: 5 5;
    classDef util fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
```
