Three-Layer Architecture of AI Coding Desktop Apps: A Static Analysis Guide

    This article explains how static analysis of an AI coding desktop application's installer can reveal the broad outline of a three-layer architecture and help evaluate local command execution security. It covers authorized and reproducible analysis steps, frontend configuration validation, layer boundaries and failure isolation, and practical controls such as command allowlists, shell-free argument passing, user confirmation, timeouts, cancellation, and audit logging. The article emphasizes that static evidence provides structural inference only and should be combined with runtime verification before conclusions are published.

    1. Problem and Scope

    Many developers want to know what an AI coding desktop application actually does locally. Does it only wrap a web page in a window, or does it also manage command execution, model conversations, and plugins? Static analysis of an AI coding desktop application’s installer can answer some of these questions and identify the approximate outline of a three-layer architecture. Static analysis means examining the installation directory, packaged files, and configuration without running the program. This article uses a typical desktop application built on an Electron-like framework as an example to explain the analysis steps, architecture division, and secure practices for local execution.

    The analysis scope has three boundaries. First, analyze only your own applications or applications for which you have authorization, and comply with their license agreements. Do not copy, distribute, or bypass protection mechanisms. Second, unpacking and reading code may be restricted by license agreements. Before publishing a report, sanitize the content and ask legal counsel to confirm what can be cited. Third, static analysis can provide only structural inferences; it cannot prove runtime behavior. Conclusions about network requests and inter-process communication need to be verified again through runtime methods such as process monitoring or packet capture.

    2. Static Analysis Steps

    Follow the sequence below. Each step can leave evidence that can be reviewed later. Before starting, copy the entire installation directory to a workspace. Perform all unpacking and reading on the copy to avoid modifying the original files.

    Step Location to Inspect What It Can Show Confidence Evidence Retention
    1 Common Windows default: %LOCALAPPDATA%\Programs\<AppName>; it may also be in Program Files or a custom directory. On macOS, typically /Applications/<AppName>.app/Contents; user-level installations may be in ~/Applications. On Linux, commonly /opt/<AppName> or /usr/lib/<AppName>; AppImage is a single file Location of the executable entry point and resource directories Confirmed if the files exist Record the directory tree (tree or dir /s output)
    2 resources/app.asar or app.asar.unpacked Whether frontend code is packed into a compressed archive Confirmed if the file exists Record file size and SHA-256 hash
    3 package.json after unpacking with npx @electron/asar extract app.asar ./out The main entry point and dependency declarations for frameworks and build tools Declarations confirmed if present, but still compare with the lockfile Save a copy of package.json
    4 Unpacked bundle files and source maps Bundler naming conventions and code organization Inference; cross-validate with other evidence Extract string features and note the file name and line number
    5 *_percent.pak files in the installation directory, such as 100_percent.pak Chromium resource packs loaded by scale factor Confirmed if the files exist Record the list of pak files
    6 Snapshot files such as v8_context_snapshot.bin V8 precompiled snapshot, indicating script startup optimization Confirmed if the file exists Record the file list and hashes
    7 Library files such as ffmpeg dynamic libraries, vk_swiftshader, or libGLESv2 Media decoding and rendering fallback paths Confirmed if the files exist Record the library file list and version attributes

    The paths in step 1 are only common defaults. For custom installation directories, locate the application from three sources. First, the shortcut target path. Second, the path of a running process. On Windows, select “Open file location” in Task Manager; on Linux, use readlink -f /proc/<PID>/exe; on macOS, use ps -p <PID> -o comm=. Third, installation records. On Windows, the Uninstall registry entry contains an InstallLocation field; on macOS, use mdfind to search by the application bundle identifier.

    These files can prove that the application is built on the Chromium engine and the Node.js runtime. They cannot prove a specific version, nor can they prove that the frontend definitely uses a particular bundler. Version information should be read from package.json or the executable file properties and compared with official release records.

    3. Frontend Engineering: Check Configuration Before Drawing Conclusions

    The unpacked package.json can reveal a lot. Below is an illustrative configuration in which package names are placeholders, not real dependencies:

    1. {
    2. "main": "dist/main.js",
    3. "dependencies": {
    4. "<desktop-framework>": "38.2.1",
    5. "<code-highlighting-component>": "9.4.0",
    6. "<editor-adapter>": "0.12.3"
    7. },
    8. "devDependencies": {
    9. "<build-tool>": "7.1.0",
    10. "typescript": "5.4.5"
    11. }
    12. }

    Declarations in package.json are not the same as actual dependencies. The package names in the example above are placeholders and do not represent any real technology stack. You must cross-validate with the lockfile or output bundle to determine whether a dependency is actually installed and bundled into the application.

    Lockfiles (package-lock.json or pnpm-lock.yaml) are more reliable than package.json because they record the exact installed versions. If only bundled output remains, you can rely only on string features for inference. In a report, clearly mark such findings as inferences and state the basis.

    4. How to Divide the Three Layers

    The three-layer division is a common pattern used to explain responsibilities; it does not represent the actual code structure of any specific application. Static analysis can only infer its existence. The specific boundaries of each layer must be determined by combining module names in the bundle, IPC channel names, and the process list. The following table lists the responsibilities and boundaries of the three layers. “Observables” in the table refer to information that can be confirmed through logs or the process list.

    Layer Main Responsibilities Inputs Outputs Failure Isolation Observables
    Desktop shell layer Create and manage windows, menus, and tray icons; load frontend pages; forward inter-process messages User actions, system events, messages returned by the runtime layer Window UI, requests forwarded to other layers A shell crash brings down the entire application, so the shell should keep minimal logic; business code should not live in this layer Main process PID, window list, main process logs
    Standalone runtime layer Run Node.js or a standalone service process; host model conversations, plugin loading, and file indexing Requests forwarded by the shell, model service configuration Model replies, tool call results Runs as a separate child process; after a crash, the shell can restart it without exiting the UI Child process list, listening ports, heartbeat logs
    Local orchestration layer Decide when to call which tool; validate permissions; execute commands; handle timeouts and user confirmation Model-generated tool call requests, user confirmation results, policy configuration Execution results, audit logs, denial records A single command failure affects only the current task; after a timeout, terminate the process tree for that task Command audit logs, confirmation records, timeout events

    Failure isolation can be judged with a simple method: assume a layer crashes, then check item by item whether user data is lost and whether any command continues without confirmation. Here are several examples.

    • If the window renderer process in the desktop shell layer crashes, the UI can reload, and running tasks should remain in the runtime layer rather than being terminated together.
    • If the standalone runtime layer crashes, chat and plugin functionality degrade. The orchestration layer should stop accepting new tasks and prompt the user to restart the runtime.
    • If the confirmation service in the local orchestration layer is unavailable, all high-risk commands must be rejected. This design is called fail closed.

    Secure Implementation of Local Command Execution

    The local orchestration layer is the part that most needs tightened permissions. Model-generated commands may be wrong, and they may also be misled by prompt injection. Therefore, an independent policy decision is required before execution. The practices below are organized by control category.

    Permission Containment

    • Run child processes with ordinary user privileges, not administrator or root privileges.
    • Allow only commands and argument templates on an allowlist. Commands outside the allowlist are rejected directly; do not attempt automatic correction.
    • Pass arguments as an array, not by concatenating them into a shell string. For example, in Node.js use spawn(cmd, args, { shell: false }), so semicolons, pipes, and backticks are not interpreted as shell syntax.
    • Limit the working directory to the project directory. Normalize the path first, resolve .. and symbolic links, and then check whether it starts with the project root prefix.
    • Pass only the environment variables required for execution, and filter out sensitive variables such as API keys and tokens.

    Secondary Confirmation for High-Risk Commands

    • Classify commands by impact: read-only, project write, delete or overwrite, permission modification, network egress, and deployment or publishing. The last four categories are considered high-risk.
    • Before executing a high-risk command, the UI must display the full command, working directory, and expected impact, and the user must explicitly confirm.
    • If a confirmation request times out without a response, treat it as a denial.
    • Confirmation results can only be produced by the user interface. Model output cannot write to the confirmation field.

    Timeouts and Cancellation

    • Set a default timeout for each command. Use values appropriate to the command type; for example, build tasks can be given longer timeouts, while query tasks should be shorter.
    • After a timeout, send a termination signal first. If the process does not exit within a short period, force-kill the entire process tree. On Windows, use taskkill /T /F /PID <PID>; on Linux and macOS, send a signal to the process group.
    • Users can cancel a task at any time. Cancellation uses the same termination flow as timeout.
    • Limit the output size of a single command. Truncate and log the excess to prevent logs or memory from being exhausted.

    Audit Logging

    • Record the time, initiator, command, arguments, working directory, confirmation result, exit code, and duration for every execution.
    • Tokens, passwords, and personal information in logs must be redacted and should not be written in plaintext.
    • Audit logs should be append-only, and file permissions should be tightened to prevent tampering or accidental deletion.

    Checklist and Conclusion

    The following checklist can be reused for each analysis.

    Static analysis phase:

    • Work was performed on a copy, and hashes and screenshots were recorded for each step
    • The installation path was confirmed; custom paths were located through shortcuts, processes, or installation records
    • Asar unpacking was completed, and the main entry in package.json was checked
    • Dependencies were cross-validated with lockfiles or bundles; placeholders were not treated as a real technology stack
    • Every framework and version conclusion notes the strength of the evidence

    Three-layer architecture phase:

    • Candidate boundaries for the shell layer, runtime layer, and orchestration layer were identified
    • Inputs, outputs, and observables for each layer have corresponding evidence
    • A crash was simulated for each layer, and records show which functions degraded and which commands were rejected

    Security control phase:

    • Commands use an allowlist, and arguments are not concatenated through a shell
    • Working directory restrictions are in effect and have been tested against symbolic link bypasses
    • High-risk commands require user confirmation, and confirmation timeout defaults to denial
    • Every command has a timeout and cancellation path, and the process tree can be fully terminated
    • Audit logs are complete, and sensitive fields are redacted

    Static analysis can quickly determine whether a desktop application is built on Chromium and Node.js and identify the approximate boundaries of a three-layer architecture. It provides structural inference. The actual behavior of inter-process communication, network requests, and command execution still needs to be confirmed through process monitoring, packet capture, and testing. Static evidence and runtime evidence should be considered together before conclusions can be publicly cited.