# dovyski/codebot architecture

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

- Interactive diagram: https://gitdiagram.com/dovyski/codebot
- Repository: https://github.com/dovyski/codebot

## Overview

##### Project type and purpose
- Codebot is a full-stack, web-based IDE focused on game development.
- It also ships as a Chrome App/Extension and a desktop NW.js (“node-webkit”) app, reusing much of the same front-end code.
- Back-end is PHP-based, persisting state in MySQL and the server’s file system.

##### File structure
Top-level directories of interest:
- Root: static assets (index.html, css/, img/, js/, manifest.json) for the web client
- js/chrome: Chrome App code (background.js, filesystem bridge)
- js/node-webkit: NW.js bootstrap and FS bridge
- js/web: web-only bootstrap and FS emulation
- plugins/: each subfolder is a self-contained plugin, some with backend (PHP), some front-end only
- plugins/ide-web/app & api: the PHP application’s MVC-style structure
- plugins/ide-web/login: OAuth authentication via Opauth (GitHub strategy)
- package.json, manifest.json: defines Node dependencies and Chrome App manifest

##### Extract insights from the README
- Front-end: HTML5 + CSS3 + JavaScript (Ace Editor, jQuery, Bootstrap, custom UI modules)
- Back-end: PHP + MySQL, REST-style API under /plugins/ide-web/api/*
- Deployment: runs on any PHP-capable web server with MySQL; desktop variants use local FS

##### Main components & their relationships
a. Front-end Client(s)
– Web App: served by the PHP webserver; assets under root/js/web & root/css
– Chrome App: communicates over Chrome filesystem API, code in js/chrome
– NW.js App: communicates via Node FS API, code in js/node-webkit
– UI modules: panels (files, SFX, asset-finder), context menus, tabs, preferences
– Editor core: Ace Editor wrapper (js/codebot.editor.*)
b. Back-end Server
– PHP application (plugins/ide-web/app/controllers, models, views)
– REST API endpoints (plugins/ide-web/api/endpoints/*.php)
– Authentication: Opauth module under plugins/ide-web/login/inc/lib/Opauth
– Data storage: MySQL database (structure.sql) and file-system project storage
c. Database
– MySQL holds users, projects metadata, plugin settings
d. Plugin System
– Front-end plugins: located under plugins/* with js/panel.* files
– CLI tools (e.g. asset-finder CLI) invoke PHP scripts via shebang or HTTP calls
– Backend plugins: under plugins/*/backend with PHP logic, sometimes tied to API
e. External Services
– OAuth provider (GitHub) for login
– Asset-finder queries to curated list or opengameart.org
– Potential future Haxe compiler service

##### Data flows & interactions
- Web client ↔ PHP API: AJAX/HTTP(S) calls
- Chrome/NW apps ↔ local file system: FS APIs → optional backend FS fallback
- PHP back-end ↔ MySQL: SQL queries for persistence
- PHP back-end ↔ file system: read/write project files, settings, plugin assets
- Plugins ↔ core: front-end event bus (codebot.signal.js), back-end via API hooks

##### Architectural patterns & design principles
- Modular plugin architecture: loosely-coupled front-end and back-end extension points
- MVC-style organization in PHP back-end (controllers vs. endpoints vs. views)
- Event-driven front-end (custom signal/pub-sub)
- Progressive enhancement: same codebase adapts to Web, Chrome, and NW.js

##### Elements
- Clear, descriptive labels on each component and subcomponent
- A zoomed-in inset for the plugin system, showing how a plugin registers UI panels and API endpoints

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Web Client"
        WC_HTML["Index.html & CSS"]:::client
        CSS["CSS (style & 3rdparty)"]:::client
        WC_BOOT["Web Bootstrap"]:::client
        WC_FS["Web FS Emulation"]:::client
        WC_HTML -->|"loads"| WC_BOOT
        CSS --> WC_BOOT
        WC_BOOT -->|"uses FS"| WC_FS
        WC_BOOT -->|"initializes UI"| UI_CORE
    end
    click WC_HTML "https://github.com/dovyski/codebot/blob/master/index.html"
    click CSS "https://github.com/dovyski/codebot/tree/master/css/"
    click WC_BOOT "https://github.com/dovyski/codebot/blob/master/js/web/codebot.bootstrap.web.js"
    click WC_FS "https://github.com/dovyski/codebot/blob/master/js/web/codebot.web.filesystem.js"

    subgraph "Chrome App"
        CH_APP["App.js"]:::client
        CH_BG["Background.js"]:::client
        CH_FS["Chrome FS Bridge"]:::client
        MANI["manifest.json"]:::client
        CH_APP -->|"initializes UI"| UI_CORE
    end
    click CH_APP "https://github.com/dovyski/codebot/blob/master/js/chrome/app.js"
    click CH_BG "https://github.com/dovyski/codebot/blob/master/js/chrome/background.js"
    click CH_FS "https://github.com/dovyski/codebot/blob/master/js/chrome/codebot.chrome.filesystem.js"
    click MANI "https://github.com/dovyski/codebot/blob/master/manifest.json"

    subgraph "NW.js App"
        NW_BOOT["NW Bootstrap"]:::client
        NW_FS2["NW FS Bridge"]:::client
        NW_BOOT -->|"initializes UI"| UI_CORE
    end
    click NW_BOOT "https://github.com/dovyski/codebot/blob/master/js/node-webkit/codebot.bootstrap.nw.js"
    click NW_FS2 "https://github.com/dovyski/codebot/blob/master/js/node-webkit/codebot.nw.filesystem.js"

    %% UI & Editor Modules
    subgraph "UI & Editor Modules"
        UI_SIGNAL["Event Bus"]:::plugin
        SIGNALS["Signals"]:::plugin
        PLUGINC["Plugin Loader"]:::plugin
        PLUGINS["Plugins Manager"]:::plugin

        UI_CORE["UI Core"]:::plugin
        UI_PANEL["UI Panels"]:::plugin
        UI_CTX["Context Menu"]:::plugin
        UI_FILES["Files Panel"]:::plugin
        UI_TABS["Tabs"]:::plugin

        ED_BASE["Editor Base"]:::plugin
        ED_ACE["Ace Adapter"]:::plugin
        ED_EXT["Editors Entry"]:::plugin

        UI_CORE --> UI_PANEL
        UI_CORE --> UI_CTX
        UI_CORE --> UI_FILES
        UI_CORE --> UI_TABS
        UI_CORE --> ED_BASE
        ED_BASE --> ED_ACE
        ED_ACE --> ED_EXT

        UI_SIGNAL --> PLUGINC --> PLUGINS
        UI_PANEL --> SET_MAIN
    end
    click UI_SIGNAL "https://github.com/dovyski/codebot/blob/master/js/codebot.signal.js"
    click SIGNALS "https://github.com/dovyski/codebot/blob/master/js/codebot.signals.js"
    click PLUGINC "https://github.com/dovyski/codebot/blob/master/js/codebot.plugin.js"
    click PLUGINS "https://github.com/dovyski/codebot/blob/master/js/codebot.plugins.js"
    click UI_CORE "https://github.com/dovyski/codebot/blob/master/js/codebot.ui.js"
    click UI_PANEL "https://github.com/dovyski/codebot/blob/master/js/codebot.ui.panel.js"
    click UI_CTX "https://github.com/dovyski/codebot/blob/master/js/codebot.ui.contextmenu.js"
    click UI_FILES "https://github.com/dovyski/codebot/blob/master/js/codebot.ui.filespanel.js"
    click UI_TABS "https://github.com/dovyski/codebot/blob/master/js/codebot.ui.tabs.js"
    click ED_BASE "https://github.com/dovyski/codebot/blob/master/js/codebot.editor.base.js"
    click ED_ACE "https://github.com/dovyski/codebot/blob/master/js/codebot.editor.ace.js"
    click ED_EXT "https://github.com/dovyski/codebot/blob/master/js/codebot.editors.js"

    %% Settings Module
    subgraph "Settings"
        SET_MAIN["Settings Core"]:::plugin
        SET_ED["Editor Panel"]:::plugin
        SET_MAINP["Main Panel"]:::plugin
        SET_PLP["Plugins Panel"]:::plugin
        SET_SHORT["Shortcuts Panel"]:::plugin
        SET_UIP["UI Panel"]:::plugin
        SET_MAIN --> SET_ED
        SET_MAIN --> SET_MAINP
        SET_MAIN --> SET_PLP
        SET_MAIN --> SET_SHORT
        SET_MAIN --> SET_UIP
    end
    click SET_MAIN "https://github.com/dovyski/codebot/blob/master/js/settings/codebot.settings.js"
    click SET_ED "https://github.com/dovyski/codebot/blob/master/js/settings/codebot.settings.panel.editor.js"
    click SET_MAINP "https://github.com/dovyski/codebot/blob/master/js/settings/codebot.settings.panel.main.js"
    click SET_PLP "https://github.com/dovyski/codebot/blob/master/js/settings/codebot.settings.panel.plugins.js"
    click SET_SHORT "https://github.com/dovyski/codebot/blob/master/js/settings/codebot.settings.panel.shortcuts.js"
    click SET_UIP "https://github.com/dovyski/codebot/blob/master/js/settings/codebot.settings.panel.ui.js"

    %% PHP Server / API
    subgraph "PHP Server / API"
        PHP_APP["MVC App"]:::backend
        PHP_INC["App Inc (controllers/models/views)"]:::backend
        API_INDEX["API Index"]:::backend
        API_END["API Endpoints"]:::backend
        API_INC["API Inc"]:::backend
        AUTH_IDX["Auth Entry"]:::backend
        AUTH_RET["OAuth Return"]:::backend
        AUTH_LIB["Opauth Lib"]:::backend
        AUTH_STR["GitHub Strategy"]:::backend

        PHP_APP --> PHP_INC
        API_INDEX --> API_END
        API_INDEX --> API_INC
        API_INDEX --> PHP_APP
        AUTH_IDX --> AUTH_LIB --> AUTH_STR
        AUTH_IDX --> AUTH_RET
    end
    click PHP_APP "https://github.com/dovyski/codebot/blob/master/plugins/ide-web/app/index.php"
    click PHP_INC "https://github.com/dovyski/codebot/tree/master/plugins/ide-web/app/inc/"
    click API_INDEX "https://github.com/dovyski/codebot/blob/master/plugins/ide-web/api/index.php"
    click API_END "https://github.com/dovyski/codebot/tree/master/plugins/ide-web/api/endpoints/"
    click API_INC "https://github.com/dovyski/codebot/tree/master/plugins/ide-web/api/inc/"
    click AUTH_IDX "https://github.com/dovyski/codebot/blob/master/plugins/ide-web/login/index.php"
    click AUTH_RET "https://github.com/dovyski/codebot/blob/master/plugins/ide-web/login/oauth_return.php"
    click AUTH_LIB "https://github.com/dovyski/codebot/blob/master/plugins/ide-web/login/inc/lib/Opauth/Opauth.php"
    click AUTH_STR "https://github.com/dovyski/codebot/blob/master/plugins/ide-web/login/inc/lib/Opauth/Strategy/github/GitHubStrategy.php"

    %% Persistence
    DB["MySQL Database"]:::persistence
    FS["File System"]:::persistence
    click DB "https://github.com/dovyski/codebot/blob/master/plugins/ide-web/api/resources/structure.sql"

    API_INDEX -->|"SQL"| DB
    PHP_APP -->|"FS"| FS

    %% External Services
    subgraph "External Services"
        OAUTH["GitHub OAuth"]:::external
        ASSET["Asset-Finder Service"]:::external
        COMP["Haxe Compiler (Future)"]:::external
    end
    API_INDEX -->|"OAuth"| OAUTH
    API_INDEX -->|"Asset Query"| ASSET

    %% Asset-Finder Plugin
    subgraph "Asset-Finder Plugin"
        AF_BE["Backend Logic"]:::plugin
        AF_PANEL["Panel UI"]:::plugin
        AF_CLI["CLI Scripts"]:::plugin

        AF_BE --> API_INDEX
        AF_PANEL --> UI_PANEL
        AF_CLI --> AF_BE
        AF_PANEL -->|"Event"| UI_SIGNAL
        AF_PANEL -->|"HTTP"| API_INDEX
    end
    click AF_BE "https://github.com/dovyski/codebot/tree/master/plugins/asset-finder/backend/"
    click AF_PANEL "https://github.com/dovyski/codebot/blob/master/plugins/asset-finder/js/panel.main.js"
    click AF_CLI "https://github.com/dovyski/codebot/tree/master/plugins/asset-finder/cli/"

    %% Class Definitions
    classDef client fill:#CEF,stroke:#036,stroke-width:1px
    classDef backend fill:#CFC,stroke:#060,stroke-width:1px
    classDef persistence fill:#FDD,stroke:#C00,stroke-width:1px
    classDef plugin fill:#EFC,stroke:#708,stroke-width:1px
    classDef external fill:#DDD,stroke:#999,stroke-width:1px
```
