How acode-foundation/acode works
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: main.js Application shell · config.xml Cordova manifest · editorManager.js Editor lifecycle · mainEditorExtensions.ts CodeMirror extensions
Components 23
WebView application
JavaScript and TypeScript editor application.
- Browser entry
www/index.html - Boot initialization
src/boot.js - Application shell · Composes workspace, pages, sidebar apps, dialogs, and handlers.
src/main.js - Acode facade · Public/global application service boundary.
src/lib/acode.js - State services · Settings, persisted session, commands, notifications, and themes.
src/lib/settings.js - Editor lifecycle · Owns open documents and editor lifecycle.
src/lib/editorManager.js - File tabs
src/handlers/editorFileTab.js - CodeMirror extensions · Configures editor behavior, languages, and extensions.
src/cm/mainEditorExtensions.ts - Command registry
src/cm/commandRegistry.js - Filesystem abstraction · Selects device and remote filesystem implementations.
src/fileSystem/index.js - Open/save and projects · Coordinates file operations and recent workspaces.
src/lib/openFile.js - LSP integration · Editor-facing language server integration.
src/cm/lsp/index.ts - LSP client manager · Launches and manages server transports and runtimes.
src/cm/lsp/clientManager.ts - Pages and sidebar · File browsing, plugin management, previews, and search.
src/pages/fileBrowser/fileBrowser.js - Extension loader · Loads, installs, and manages community extensions.
src/lib/loadPlugins.js - Terminal UI
src/components/terminal/terminalManager.js
Cordova native layer
Android plugin boundary and local runtimes.
- Cordova manifest · Declares app metadata and Android-native integration.
config.xml - Storage plugins · SD-card, FTP, and SFTP native bridges.
src/plugins/sdcard - Process and Alpine runtime · Android terminal runtime with bundled proot Alpine files.
src/plugins/terminal - Platform 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
rspack.config.js - Android package · Packages the web bundle for Android.
build-extras.gradle - Store delivery metadata
fastlane/metadata/android
Connections 27
- 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