# komjaur/runescape-clone-study-js-html-css-web architecture

> Architecture diagram of the GitHub repository komjaur/runescape-clone-study-js-html-css-web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/komjaur/runescape-clone-study-js-html-css-web
- Repository: https://github.com/komjaur/runescape-clone-study-js-html-css-web

## Overview

##### Project Type and Purpose
- This is a lightweight full-stack web application: a browser-based game prototype front end (HTML, CSS, JavaScript) paired with a simple PHP backend that persists user state in MySQL.
- Its purpose is to demonstrate RuneScape-style mechanics (combat, skills, adventures, shop, quests, housing) in the browser, with persistent saves via server APIs.

##### File Structure
Top-level layout:
- RunescapeWebGame/
– html/index.php (main game UI)
– css/style.css (styling)
– js/*.js (game logic modules: main.js, skills.js, entities.js, adventure.js, quests.js, shop.js, units.js, house.js)
- php/
– login.php, logout.php (authentication)
– load.php, save.php (state persistence endpoints)
– db.php (DB connection config)
– schema.sql (DB schema)
- README.md (project description)

Architectural hints:
– Clear frontend vs. backend separation
– REST-style PHP endpoints for login/load/save
– In-memory game state on client, synchronized via AJAX calls

##### Extract Key Insights from README
- Frontend: object-oriented JS classes for units, items, drop tables, timed adventures.
- Backend: PHP scripts invoked automatically by the game UI to persist or retrieve user progress in MySQL.
- Workflow: user logs in → UI loads saved state → user actions update the client state and trigger save.php → DB updates → UI updates.

##### Main Components & Their Relationships
a. Components:
- Browser / Client
– UI Layer: HTML/CSS
– Game Engine: JS modules (main.js orchestrates skills.js, entities.js, adventure.js, shop.js, quests.js, units.js, house.js)
- Web Server (PHP)
– Authentication APIs: login.php, logout.php
– Data APIs: load.php, save.php
– DB Connector: db.php
- Database
– MySQL database defined in schema.sql (users, stats, inventory tables)

b. Interactions:
1. Client → login.php (POST username) → Server → DB → return session/userID
2. Client loads index.php → JS issues AJAX to load.php → Server retrieves saved game state → Client initializes UI
3. Client UI events (Train, Attack, Adventure, Shop, Quest, House) update in-memory state → JS issues AJAX to save.php with new state → Server writes to DB
4. logout.php invalidates session

c. Architectural Patterns & Principles
- Client-Side MVC-ish separation: main.js updates Views (DOM) and delegates to Model modules (skills, entities, adventures)
- Stateless REST APIs on backend (each request carries user context via session or token)
- Single responsibility: each PHP script does one job (login, load, save)
- Data persistence via relational DB

d. Key Technologies
- Frontend: HTML5, CSS, Vanilla JavaScript (ES5-style OOP modules)
- Backend: PHP 7+, MySQL
- AJAX calls (XMLHttpRequest or fetch) between JS and PHP

##### Diagramming Recommendations
- Browser → login.php → DB → login.php → Browser
- Browser → load.php → DB → load.php → Browser
- Browser → save.php → DB → save.php → Browser

##### Essential Details to Capture
- The JS module clustering: group skills.js, entities.js, adventure.js, shop.js, quests.js, units.js, house.js under “Game Engine”.
- The single-file CSS and single HTML entry point.
- The PHP scripts’ roles and how they connect to the DB via db.php.
- The automatic save/load after each action.
- The DB schema (users table for credentials/session, progress table(s) for state).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        direction TB
        subgraph UI
            direction TB
            HTML["index.php"]:::frontend
            CSS["style.css"]:::frontend
        end
        subgraph "Game Engine"
            direction TB
            Main["main.js"]:::frontend
            Skills["skills.js"]:::frontend
            Entities["entities.js"]:::frontend
            Adventure["adventure.js"]:::frontend
            Shop["shop.js"]:::frontend
            Quests["quests.js"]:::frontend
            Units["units.js"]:::frontend
            House["house.js"]:::frontend
        end
    end

    subgraph "Application Layer"
        direction TB
        Login["login.php"]:::backend
        Logout["logout.php"]:::backend
        Load["load.php"]:::backend
        Save["save.php"]:::backend
        DBConn["db.php"]:::backend
    end

    DB["MySQL DB<br/>users, stats, inventory tables"]:::db

    HTML -->|"loads UI"| Main
    Main -->|"POST /login"| Login
    Main -->|"GET /load"| Load
    Main -->|"POST /save"| Save
    Main -->|"POST /logout"| Logout

    Login --> DBConn
    Load --> DBConn
    Save --> DBConn
    Logout --> DBConn

    DBConn --> DB
    DB --> Login
    DB --> Load
    DB --> Save
    DB --> Logout

    Login -->|"200 OK, session"| Main
    Load -->|"200 OK, state"| Main
    Save -->|"200 OK"| Main
    Logout -->|"200 OK"| Main

    click HTML "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/RunescapeWebGame/html/index.php"
    click CSS "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/RunescapeWebGame/css/style.css"
    click Main "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/RunescapeWebGame/js/main.js"
    click Skills "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/RunescapeWebGame/js/skills.js"
    click Entities "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/RunescapeWebGame/js/entities.js"
    click Adventure "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/RunescapeWebGame/js/adventure.js"
    click Shop "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/RunescapeWebGame/js/shop.js"
    click Quests "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/RunescapeWebGame/js/quests.js"
    click Units "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/RunescapeWebGame/js/units.js"
    click House "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/RunescapeWebGame/js/house.js"
    click Login "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/php/login.php"
    click Logout "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/php/logout.php"
    click Load "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/php/load.php"
    click Save "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/php/save.php"
    click DBConn "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/php/db.php"
    click DB "https://github.com/komjaur/runescape-clone-study-js-html-css-web/blob/main/php/schema.sql"

    classDef frontend fill:#D2E3FC,stroke:#0366d6
    classDef backend fill:#E6F4EA,stroke:#2C8E1F
    classDef db fill:#FFE4B5,stroke:#D2691E
```
