# acode-foundation/acode architecture

> Architecture diagram of the GitHub repository acode-foundation/acode, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/acode-foundation/acode
- Repository: https://github.com/acode-foundation/acode

## Overview

#### Purpose and Runtime
Acode is an Android-first code editor packaged as a Cordova application: a JavaScript/TypeScript UI runs in a WebView and calls Android-native plugins for filesystem, terminal, networking, browser preview, purchases, and ads. The browser document entry is `www/index.html`; application initialization is centered on `src/boot.js` and `src/main.js`. Cordova app metadata and native integration are declared in `config.xml`.

#### Application Shell and State
`src/main.js` composes the editor workspace, pages, sidebar applications, dialogs, and event handlers. `src/lib/acode.js` is the likely public/global application facade; stateful services for settings, project/session persistence, commands, notifications, and themes reside under `src/lib/`, notably `src/lib/settings.js`, `src/lib/saveState.js`, and `src/lib/commands.js`. UI code should consume these service boundaries rather than directly reaching Cordova APIs.

#### Editor Workspace
The editor subsystem uses CodeMirror extensions and a tab/file manager. `src/lib/editorManager.js` and `src/lib/editorFile.js` model open documents and editor lifecycle; `src/handlers/editorFileTab.js` coordinates tabs. CodeMirror configuration, language selection, and editor behavior are consolidated in `src/cm/mainEditorExtensions.ts`, `src/cm/baseExtensions.ts`, and `src/cm/supportedModes.ts`. Commands flow through `src/cm/commandRegistry.js` and the application command service.

#### Files, Projects, and Remote Storage
The filesystem abstraction selects internal/device and remote implementations through `src/fileSystem/index.js`, with concrete local storage in `src/fileSystem/internalFs.js` and remote FTP/SFTP adapters in `src/fileSystem/ftp.js` and `src/fileSystem/sftp.js`. File opening and saving pass through `src/lib/openFile.js`, `src/lib/saveFile.js`, and project/recent-workspace services such as `src/lib/projects.js`. Native bridges include SD-card, FTP, and SFTP Cordova plugins under `src/plugins/sdcard/`, `src/plugins/ftp/`, and `src/plugins/sftp/`.

#### Language Intelligence and Execution
LSP is an independently structured layer: `src/cm/lsp/index.ts` exposes editor integration; `src/cm/lsp/clientManager.ts` manages language-server clients; `src/cm/lsp/transport.ts` and `src/cm/lsp/serverLauncher.ts` bridge to runtimes. Built-in Alpine/proot and external WebSocket runtimes are represented by `src/cm/lsp/runtimes/builtinAlpine.ts` and `src/cm/lsp/runtimes/externalWebSocket.ts`. The terminal UI (`src/components/terminal/terminalManager.js`) calls the Android process runtime in `src/plugins/terminal/`; bundled Alpine root files in `src/plugins/proot/` support local execution and LSP servers.

#### UI Surfaces and Extensibility
Reusable UI components live in `src/components/`, while major workflows are pages in `src/pages/`—especially file browsing (`src/pages/fileBrowser/fileBrowser.js`), plugin management (`src/pages/plugins/plugins.js`), and Markdown preview (`src/pages/markdownPreview/renderer.js`). The sidebar hosts files, extensions, notifications, and worker-backed search-in-files via `src/sidebarApps/index.js` and `src/sidebarApps/searchInFiles/worker.js`. Third-party/community extensions are loaded and managed through `src/lib/loadPlugins.js`, `src/lib/loadPlugin.js`, and `src/lib/installPlugin.js`.

#### Native Services and Monetization Boundaries
Cordova plugins form a strict JS-to-Android boundary. Important platform services include embedded browser preview (`src/plugins/browser/`), local HTTP server (`src/plugins/server/`), advanced HTTP (`src/plugins/cordova-plugin-advanced-http/`), and WebSockets (`src/plugins/websocket/`). Authentication, in-app purchases, and AdMob are separated in `src/plugins/auth/`, `src/plugins/iap/`, and `src/plugins/admob/`; JS policy/workflow code is in `src/lib/auth.js`, `src/handlers/purchase.js`, and `src/lib/adRewards.js`.

#### Build and Delivery
The web bundle is built with Rspack/Webpack configuration (`rspack.config.js`, `webpack.config.js`) and packaged by Cordova/Gradle for Android (`config.xml`, `build-extras.gradle`). Build setup and lifecycle scripts under `utils/scripts/` plus repository hooks in `hooks/` modify generated Cordova/Android artifacts. Fastlane metadata supports Android store delivery in `fastlane/metadata/android/`.

Main entry points: [`src/main.js`](https://github.com/acode-foundation/acode/blob/main/src/main.js) (Application shell), [`config.xml`](https://github.com/acode-foundation/acode/blob/main/config.xml) (Cordova manifest), [`src/lib/editorManager.js`](https://github.com/acode-foundation/acode/blob/main/src/lib/editorManager.js) (Editor lifecycle), [`src/cm/mainEditorExtensions.ts`](https://github.com/acode-foundation/acode/blob/main/src/cm/mainEditorExtensions.ts) (CodeMirror extensions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["WebView application"]
  node_document["Browser entry<br/>HTML entry<br/>[index.html]"]
  node_boot["Boot initialization<br/>startup<br/>[boot.js]"]
  node_shell["Application shell<br/>workspace composition<br/>[main.js]"]
  node_facade["Acode facade<br/>application API<br/>[acode.js]"]
  node_state["State services<br/>settings and session<br/>[settings.js]"]
  node_editor["Editor lifecycle<br/>document manager<br/>[editorManager.js]"]
  node_tabs["File tabs<br/>editor handler<br/>[editorFileTab.js]"]
  node_codemirror["CodeMirror extensions<br/>editor configuration"]
  node_commands["Command registry<br/>editor commands<br/>[commandRegistry.js]"]
  node_files["Filesystem abstraction<br/>storage gateway<br/>[index.js]"]
  node_fileworkflows["Open/save and projects<br/>file workflows<br/>[openFile.js]"]
  node_lsp["LSP integration<br/>language intelligence<br/>[index.ts]"]
  node_lspclients["LSP client manager<br/>language-server clients<br/>[clientManager.ts]"]
  node_surfaces["Pages and sidebar<br/>UI workflows<br/>[fileBrowser.js]"]
  node_extensions["Extension loader<br/>plugin management<br/>[loadPlugins.js]"]
  node_terminalui["Terminal UI<br/>terminal manager<br/>[terminalManager.js]"]
end

subgraph group_native["Cordova native layer"]
  node_cordova["Cordova manifest<br/>platform integration<br/>[config.xml]"]
  node_storageplugins["Storage plugins<br/>Cordova filesystem"]
  node_runtime["Process and Alpine runtime<br/>local execution"]
  node_platformservices["Platform services<br/>Cordova services"]
end

subgraph group_delivery["Build and delivery"]
  node_bundle["Web bundle<br/>Rspack/Webpack build<br/>[rspack.config.js]"]
  node_androidbuild["Android package<br/>Cordova Gradle build"]
  node_store["Store delivery metadata<br/>Fastlane metadata"]
end

node_document -->|"loads"| node_boot
node_boot -->|"initializes"| node_shell
node_shell -->|"uses"| node_facade
node_shell -->|"uses services"| node_state
node_shell -->|"hosts"| node_editor
node_shell -->|"composes"| node_surfaces
node_editor -->|"coordinates"| node_tabs
node_editor -->|"configures"| node_codemirror
node_commands -->|"routes through"| node_state
node_codemirror -->|"registers commands"| node_commands
node_codemirror -->|"integrates"| node_lsp
node_lsp -->|"uses"| node_lspclients
node_lspclients -->|"launches local servers"| node_runtime
node_files -->|"bridges device and remote I/O"| node_storageplugins
node_fileworkflows -->|"opens and saves through"| node_files
node_editor -->|"reads and persists files"| node_fileworkflows
node_surfaces -->|"manages extensions"| node_extensions
node_terminalui -->|"executes processes"| node_runtime
node_shell -->|"hosts"| node_terminalui
node_facade -->|"accesses via Cordova"| node_platformservices
node_cordova -->|"declares"| node_storageplugins
node_cordova -->|"declares"| node_runtime
node_cordova -->|"declares"| node_platformservices
node_bundle -->|"builds web assets"| node_document
node_bundle -->|"feeds"| node_androidbuild
node_cordova -->|"drives packaging"| node_androidbuild
node_androidbuild -->|"publishes with"| node_store

click node_document "https://github.com/acode-foundation/acode/blob/main/www/index.html"
click node_boot "https://github.com/acode-foundation/acode/blob/main/src/boot.js"
click node_shell "https://github.com/acode-foundation/acode/blob/main/src/main.js"
click node_facade "https://github.com/acode-foundation/acode/blob/main/src/lib/acode.js"
click node_state "https://github.com/acode-foundation/acode/blob/main/src/lib/settings.js"
click node_editor "https://github.com/acode-foundation/acode/blob/main/src/lib/editorManager.js"
click node_tabs "https://github.com/acode-foundation/acode/blob/main/src/handlers/editorFileTab.js"
click node_codemirror "https://github.com/acode-foundation/acode/blob/main/src/cm/mainEditorExtensions.ts"
click node_commands "https://github.com/acode-foundation/acode/blob/main/src/cm/commandRegistry.js"
click node_files "https://github.com/acode-foundation/acode/blob/main/src/fileSystem/index.js"
click node_fileworkflows "https://github.com/acode-foundation/acode/blob/main/src/lib/openFile.js"
click node_lsp "https://github.com/acode-foundation/acode/blob/main/src/cm/lsp/index.ts"
click node_lspclients "https://github.com/acode-foundation/acode/blob/main/src/cm/lsp/clientManager.ts"
click node_surfaces "https://github.com/acode-foundation/acode/blob/main/src/pages/fileBrowser/fileBrowser.js"
click node_extensions "https://github.com/acode-foundation/acode/blob/main/src/lib/loadPlugins.js"
click node_terminalui "https://github.com/acode-foundation/acode/blob/main/src/components/terminal/terminalManager.js"
click node_cordova "https://github.com/acode-foundation/acode/blob/main/config.xml"
click node_storageplugins "https://github.com/acode-foundation/acode/tree/main/src/plugins/sdcard"
click node_runtime "https://github.com/acode-foundation/acode/tree/main/src/plugins/terminal"
click node_platformservices "https://github.com/acode-foundation/acode/tree/main/src/plugins/browser"
click node_bundle "https://github.com/acode-foundation/acode/blob/main/rspack.config.js"
click node_androidbuild "https://github.com/acode-foundation/acode/blob/main/build-extras.gradle"
click node_store "https://github.com/acode-foundation/acode/tree/main/fastlane/metadata/android"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_document,node_boot,node_shell,node_facade,node_state,node_editor,node_tabs,node_codemirror,node_commands,node_files,node_fileworkflows,node_lsp,node_lspclients,node_surfaces,node_extensions,node_terminalui toneBlue
class node_cordova,node_storageplugins,node_runtime,node_platformservices toneAmber
class node_bundle,node_androidbuild,node_store toneMint
```

## Components

### WebView application

JavaScript and TypeScript editor application.

- [Browser entry](https://github.com/acode-foundation/acode/blob/main/www/index.html): HTML entry · `www/index.html`
- [Boot initialization](https://github.com/acode-foundation/acode/blob/main/src/boot.js): startup · `src/boot.js`
- [Application shell](https://github.com/acode-foundation/acode/blob/main/src/main.js): workspace composition · Composes workspace, pages, sidebar apps, dialogs, and handlers. · `src/main.js`
- [Acode facade](https://github.com/acode-foundation/acode/blob/main/src/lib/acode.js): application API · Public/global application service boundary. · `src/lib/acode.js`
- [State services](https://github.com/acode-foundation/acode/blob/main/src/lib/settings.js): settings and session · Settings, persisted session, commands, notifications, and themes. · `src/lib/settings.js`
- [Editor lifecycle](https://github.com/acode-foundation/acode/blob/main/src/lib/editorManager.js): document manager · Owns open documents and editor lifecycle. · `src/lib/editorManager.js`
- [File tabs](https://github.com/acode-foundation/acode/blob/main/src/handlers/editorFileTab.js): editor handler · `src/handlers/editorFileTab.js`
- [CodeMirror extensions](https://github.com/acode-foundation/acode/blob/main/src/cm/mainEditorExtensions.ts): editor configuration · Configures editor behavior, languages, and extensions. · `src/cm/mainEditorExtensions.ts`
- [Command registry](https://github.com/acode-foundation/acode/blob/main/src/cm/commandRegistry.js): editor commands · `src/cm/commandRegistry.js`
- [Filesystem abstraction](https://github.com/acode-foundation/acode/blob/main/src/fileSystem/index.js): storage gateway · Selects device and remote filesystem implementations. · `src/fileSystem/index.js`
- [Open/save and projects](https://github.com/acode-foundation/acode/blob/main/src/lib/openFile.js): file workflows · Coordinates file operations and recent workspaces. · `src/lib/openFile.js`
- [LSP integration](https://github.com/acode-foundation/acode/blob/main/src/cm/lsp/index.ts): language intelligence · Editor-facing language server integration. · `src/cm/lsp/index.ts`
- [LSP client manager](https://github.com/acode-foundation/acode/blob/main/src/cm/lsp/clientManager.ts): language-server clients · Launches and manages server transports and runtimes. · `src/cm/lsp/clientManager.ts`
- [Pages and sidebar](https://github.com/acode-foundation/acode/blob/main/src/pages/fileBrowser/fileBrowser.js): UI workflows · File browsing, plugin management, previews, and search. · `src/pages/fileBrowser/fileBrowser.js`
- [Extension loader](https://github.com/acode-foundation/acode/blob/main/src/lib/loadPlugins.js): plugin management · Loads, installs, and manages community extensions. · `src/lib/loadPlugins.js`
- [Terminal UI](https://github.com/acode-foundation/acode/blob/main/src/components/terminal/terminalManager.js): terminal manager · `src/components/terminal/terminalManager.js`

### Cordova native layer

Android plugin boundary and local runtimes.

- [Cordova manifest](https://github.com/acode-foundation/acode/blob/main/config.xml): platform integration · Declares app metadata and Android-native integration. · `config.xml`
- [Storage plugins](https://github.com/acode-foundation/acode/tree/main/src/plugins/sdcard): Cordova filesystem · SD-card, FTP, and SFTP native bridges. · `src/plugins/sdcard`
- [Process and Alpine runtime](https://github.com/acode-foundation/acode/tree/main/src/plugins/terminal): local execution · Android terminal runtime with bundled proot Alpine files. · `src/plugins/terminal`
- [Platform services](https://github.com/acode-foundation/acode/tree/main/src/plugins/browser): Cordova services · Browser preview, HTTP server, network, WebSockets, auth, purchases, and ads. · `src/plugins/browser`

### Build and delivery

Web bundling and Android packaging pipeline.

- [Web bundle](https://github.com/acode-foundation/acode/blob/main/rspack.config.js): Rspack/Webpack build · `rspack.config.js`
- [Android package](https://github.com/acode-foundation/acode/blob/main/build-extras.gradle): Cordova Gradle build · Packages the web bundle for Android. · `build-extras.gradle`
- [Store delivery metadata](https://github.com/acode-foundation/acode/tree/main/fastlane/metadata/android): Fastlane metadata · `fastlane/metadata/android`

## Connections

- Browser entry → Boot initialization: loads
- Boot initialization → Application shell: initializes
- Application shell → Acode facade: uses
- Application shell → State services: uses services
- Application shell → Editor lifecycle: hosts
- Application shell → Pages and sidebar: composes
- Editor lifecycle → File tabs: coordinates
- Editor lifecycle → CodeMirror extensions: configures
- Command registry → State services: routes through
- CodeMirror extensions → Command registry: registers commands
- CodeMirror extensions → LSP integration: integrates
- LSP integration → LSP client manager: uses
- LSP client manager → Process and Alpine runtime: launches local servers
- Filesystem abstraction → Storage plugins: bridges device and remote I/O
- Open/save and projects → Filesystem abstraction: opens and saves through
- Editor lifecycle → Open/save and projects: reads and persists files
- Pages and sidebar → Extension loader: manages extensions
- Terminal UI → Process and Alpine runtime: executes processes
- Application shell → Terminal UI: hosts
- Acode facade → Platform services: accesses via Cordova
- Cordova manifest → Storage plugins: declares
- Cordova manifest → Process and Alpine runtime: declares
- Cordova manifest → Platform services: declares
- Web bundle → Browser entry: builds web assets
- Web bundle → Android package: feeds
- Cordova manifest → Android package: drives packaging
- Android package → Store delivery metadata: publishes with
