# tobychui/arozos architecture

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

- Interactive diagram: https://gitdiagram.com/tobychui/arozos
- Repository: https://github.com/tobychui/arozos

## Overview

1. **What this repository is**
   - ArozOS is a Go-based “web desktop” platform: one backend process serves a full browser UI, manages users and permissions, and exposes OS-like services for files, storage, networking, and device control.
   - The architecture is not a single web app; it is a host operating system shell plus a service framework for multiple built-in apps.

2. **Top-level runtime model**
   - The main executable is in `src/` (`main.go`, `startup.go`, `main.router.go`, `main.flags.go`).
   - At startup it loads flags, initializes system paths/config, brings up HTTP/TLS listeners, and wires routers to module handlers.
   - The process also coordinates background subsystems such as nightly tasks, discovery, networking, and storage initialization.

3. **Backend layering**
   - Core logic is organized as Go modules under `src/mod/`.
   - Each domain area has a module package with its own handler/state logic, while the root-level files in `src/` act as the central orchestration layer.
   - This creates a clear boundary between platform services and the web UI: the browser talks to Go handlers, not directly to the host OS.

4. **Web desktop shell and applications**
   - The browser-facing UI lives mostly under `src/web/` and includes a desktop shell, login/reset pages, system settings, and many app folders such as File Manager, Photo, Music, Video, NotepadA, OfficeViewer, SystemAO, and others.
   - Apps are served as static frontend bundles plus app-specific backend scripts or endpoints.
   - `src/web/desktop.html`, `login.html`, `mobile.html`, and `manifest.webmanifest` indicate a desktop/mobile responsive shell with PWA support.

5. **File and storage architecture**
   - The core storage abstraction is in `src/mod/storage/` and `src/mod/filesystem/`.
   - The system supports local filesystems, remote filesystems, and protocol bridges such as FTP, SFTP, SMB, and WebDAV.
   - Storage pools and virtual file paths are central concepts: the UI and apps operate on abstracted roots, while the backend maps them to real host mounts or remote endpoints.

6. **Filesystem-driven data flow**
   - User actions in the file manager and other apps flow from the browser UI to backend handlers, then into the virtual filesystem layer, then down to local disk or network filesystem adapters.
   - Supporting packages handle permissions, hidden files, sorting, metadata extraction, thumbnails, shortcuts, and file operations.
   - This layer is the main boundary where application logic meets host OS files and mounted external storage.

7. **File sharing and network file servers**
   - The repository includes built-in sharing/export subsystems under `src/mod/fileservers/` and `src/mod/share/`.
   - Supported services include FTP, SFTP, TFTP, WebDAV, Samba, and a lightweight directory server for legacy browser access.
   - The share system is separate from normal file browsing: it exposes selected storage content through controlled access modes and service-specific handlers.

8. **Authentication, identity, and security**
   - Authentication is handled under `src/mod/auth/` with support for local login flows, account switching, auto-login, batch operations, public registration, LDAP, and OAuth2 providers.
   - Security controls include CSRF protection, IP white/blacklists, access control, session/token management, and login timeout logic.
   - Permissions and quotas are first-class modules, so authorization is enforced across file, share, and admin operations rather than only at the UI layer.

9. **Network and discovery services**
   - Networking features are grouped under `src/mod/network/` and include mDNS, SSDP, UPnP, reverse proxying, gzip middleware, websocket support, Wi-Fi management, neighbor discovery, and network statistics.
   - These services support both local LAN discovery and exposure of subservices or web apps to other hosts.
   - The architecture treats LAN visibility and port forwarding as platform services, not app-level concerns.

10. **System management and device control**
   - Administrative and hardware-facing logic lives in modules such as `src/mod/disk/`, `src/mod/info/`, `src/mod/console/`, `src/mod/cluster/`, `src/mod/updates/`, `src/mod/user/`, and `src/mod/permission/`.
   - These cover disk health/RAID/SMART, hardware and usage stats, console access, clustering/wake-on-LAN, user/group management, and OTA update flows.
   - The `src/system/` tree contains the static templates, binary helpers, config files, and platform-specific resources these modules rely on.

11. **Media, IoT, and other optional subsystems**
   - Media-related capabilities are split into `src/mod/media/` and app-specific frontend code under `src/web/Music`, `src/web/Video`, `src/web/Photo`, and `src/web/PDF Viewer`.
   - IoT support is in `src/mod/iot/` and connects to device discovery/control logic exposed through the UI and AGI scripts.
   - These are add-on domains built on top of the same backend routing and storage primitives.

12. **Extensibility model**
   - `src/mod/agi/` is the scripting/runtime extension layer: apps and examples show ECMA5-style scripts invoking backend capabilities like file, HTTP, image, and IoT operations.
   - `src/mod/subservice/` and the “serverless”/proxy-related packages provide a way to mount third-party Go/Python services behind the platform.
   - This is a key architectural boundary: core platform services are stable, while features can be extended through scripts, modules, or proxied subservices.

13. **Assets, examples, and deployment**
   - `examples/` contains AGI examples that document the app-extension contract and typical backend operations.
   - `installer/` provides shell-based deployment/uninstall logic for Linux targets; `src/system/` includes platform-specific binaries and templates used after installation.
   - The project is designed to run self-contained on the host, with most UI assets and supporting libraries shipped in-repo rather than fetched from external services.

14. **How to read the architecture diagram**
   - A useful diagram would place the browser desktop UI on one side, the Go backend orchestration layer in the center, and the host OS plus mounted local/remote storage on the other side.
   - Around the backend core, group modules into: auth/security, filesystem/storage, file services, networking/discovery, system/admin, media/IoT, and extensibility.
   - The main flows are: browser request → router/module handler → auth/permission check → domain service → host OS/storage/network operation → response back to the frontend.

Main entry points: [`src/web/SystemAO/desktop/personalization.html`](https://github.com/tobychui/arozos/blob/master/src/web/SystemAO/desktop/personalization.html) (SystemAO), [`src/main.router.go`](https://github.com/tobychui/arozos/blob/master/src/main.router.go) (Router), [`src/mod/agi/agi.go`](https://github.com/tobychui/arozos/blob/master/src/mod/agi/agi.go) (AGI Runtime), [`src/mod/auth/auth.go`](https://github.com/tobychui/arozos/blob/master/src/mod/auth/auth.go) (Auth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["Main<br/>go entrypoint<br/>[main.go]"]
  node_startup["Startup<br/>boot config<br/>[startup.go]"]
  node_router["Router<br/>http routing<br/>[main.router.go]"]
end

subgraph group_backend["Backend Core"]
  node_modules["Modules<br/>module host<br/>[module.go]"]
end

subgraph group_security["Security & Identity"]
  node_auth["Auth<br/>identity<br/>[auth.go]"]
  node_perm["Permissions<br/>acl<br/>[permission.go]"]
  node_quota["Quota<br/>limits<br/>[quota.go]"]
  node_csrf["CSRF<br/>web protection<br/>[csrf.go]"]
end

subgraph group_storage["Storage & Files"]
  node_fs["Filesystem<br/>virtual fs<br/>[filesystem.go]"]
  node_storagepool["Storage Pool<br/>pool bridge<br/>[storage.pool.go]"]
  node_bridge["Bridge<br/>[bridge.go]"]
  node_localfs["Local FS<br/>adapter<br/>[localfs.go]"]
  node_remotefs["Remote FS<br/>adapter<br/>[webdavfs.go]"]
end

subgraph group_network["Network & Sharing"]
  node_share["Share<br/>file sharing<br/>[share.go]"]
  node_fileservers["File Servers<br/>protocol servers<br/>[fileservers.go]"]
  node_net["Network<br/>discovery/proxy<br/>[network.go]"]
end

subgraph group_system["System Admin"]
end

subgraph group_web["Web Desktop"]
  node_desktop["Desktop UI<br/>web shell<br/>[desktop.html]"]
  node_systemao["SystemAO<br/>admin UI"]
  node_fileapp["File Manager<br/>file app<br/>[file_explorer.html]"]
  node_mediaapps["Media Apps<br/>[index.html]"]
end

subgraph group_ext["Extensibility"]
  node_agi["AGI Runtime<br/>script engine<br/>[agi.go]"]
  node_subservice["Subservice<br/>proxy mount<br/>[subservice.go]"]
  node_extapps["Example Apps<br/>app contract<br/>[hello world.js]"]
end

node_main -->|"boot"| node_startup
node_main -->|"wire routes"| node_router
node_startup -->|"load"| node_modules
node_router -->|"login"| node_auth
node_router -->|"authorize"| node_perm
node_router -->|"protect"| node_csrf
node_router -->|"file ops"| node_fs
node_modules -->|"extend"| node_agi
node_modules -->|"mount"| node_subservice
node_agi -->|"file api"| node_fs
node_agi -->|"share api"| node_share
node_agi -->|"net api"| node_net
node_auth -->|"sessions"| node_perm
node_auth -->|"limits"| node_quota
node_fs -->|"roots"| node_storagepool
node_storagepool -->|"map"| node_bridge
node_bridge -->|"local"| node_localfs
node_bridge -->|"remote"| node_remotefs
node_share -->|"publish"| node_fileservers
node_net -->|"expose"| node_fileservers
node_desktop -->|"launch"| node_systemao
node_systemao -->|"manage files"| node_fileapp
node_systemao -->|"sharing"| node_share
node_systemao -->|"network"| node_net
node_systemao -->|"identity"| node_auth
node_systemao -->|"access"| node_perm
node_mediaapps -->|"browse media"| node_fs
node_extapps -->|"contract"| node_agi

click node_main "https://github.com/tobychui/arozos/blob/master/src/main.go"
click node_startup "https://github.com/tobychui/arozos/blob/master/src/startup.go"
click node_router "https://github.com/tobychui/arozos/blob/master/src/main.router.go"
click node_modules "https://github.com/tobychui/arozos/blob/master/src/mod/modules/module.go"
click node_agi "https://github.com/tobychui/arozos/blob/master/src/mod/agi/agi.go"
click node_subservice "https://github.com/tobychui/arozos/blob/master/src/mod/subservice/subservice.go"
click node_auth "https://github.com/tobychui/arozos/blob/master/src/mod/auth/auth.go"
click node_perm "https://github.com/tobychui/arozos/blob/master/src/mod/permission/permission.go"
click node_quota "https://github.com/tobychui/arozos/blob/master/src/mod/quota/quota.go"
click node_csrf "https://github.com/tobychui/arozos/blob/master/src/mod/security/csrf/csrf.go"
click node_fs "https://github.com/tobychui/arozos/blob/master/src/mod/filesystem/filesystem.go"
click node_storagepool "https://github.com/tobychui/arozos/blob/master/src/storage.pool.go"
click node_bridge "https://github.com/tobychui/arozos/blob/master/src/mod/storage/bridge/bridge.go"
click node_localfs "https://github.com/tobychui/arozos/blob/master/src/mod/filesystem/abstractions/localfs/localfs.go"
click node_remotefs "https://github.com/tobychui/arozos/blob/master/src/mod/filesystem/abstractions/webdavfs/webdavfs.go"
click node_share "https://github.com/tobychui/arozos/blob/master/src/mod/share/share.go"
click node_fileservers "https://github.com/tobychui/arozos/blob/master/src/mod/fileservers/fileservers.go"
click node_net "https://github.com/tobychui/arozos/blob/master/src/mod/network/network.go"
click node_desktop "https://github.com/tobychui/arozos/blob/master/src/web/desktop.html"
click node_systemao "https://github.com/tobychui/arozos/blob/master/src/web/SystemAO/desktop/personalization.html"
click node_fileapp "https://github.com/tobychui/arozos/blob/master/src/web/SystemAO/file_system/file_explorer.html"
click node_mediaapps "https://github.com/tobychui/arozos/blob/master/src/web/Music/index.html"
click node_extapps "https://github.com/tobychui/arozos/blob/master/examples/agi_examples/basics/hello world.js"

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_main,node_startup,node_router,node_desktop,node_systemao,node_fileapp,node_mediaapps toneBlue
class node_modules,node_agi,node_subservice,node_extapps toneAmber
class node_auth,node_perm,node_quota,node_csrf toneMint
class node_fs,node_storagepool,node_bridge,node_localfs,node_remotefs toneRose
class node_share,node_fileservers,node_net toneIndigo
```

## Components

### Runtime

Startup and process orchestration

- [Main](https://github.com/tobychui/arozos/blob/master/src/main.go): go entrypoint · Process startup, flags, listeners, and orchestration · `src/main.go`
- [Startup](https://github.com/tobychui/arozos/blob/master/src/startup.go): boot config · Initializes paths, config, and boot sequence · `src/startup.go`
- [Router](https://github.com/tobychui/arozos/blob/master/src/main.router.go): http routing · Wires HTTP routes to backend handlers · `src/main.router.go`

### Backend Core

Central Go modules and request routing

- [Modules](https://github.com/tobychui/arozos/blob/master/src/mod/modules/module.go): module host · Loads and coordinates feature modules · `src/mod/modules/module.go`

### Security & Identity

Authentication, permissions, quotas, and sessions

- [Auth](https://github.com/tobychui/arozos/blob/master/src/mod/auth/auth.go): identity · Login flows, account switching, LDAP, OAuth2, tokens · `src/mod/auth/auth.go`
- [Permissions](https://github.com/tobychui/arozos/blob/master/src/mod/permission/permission.go): acl · Group, permission, and request authorization · `src/mod/permission/permission.go`
- [Quota](https://github.com/tobychui/arozos/blob/master/src/mod/quota/quota.go): limits · User and storage quota enforcement · `src/mod/quota/quota.go`
- [CSRF](https://github.com/tobychui/arozos/blob/master/src/mod/security/csrf/csrf.go): web protection · Anti-forgery protection for browser requests · `src/mod/security/csrf/csrf.go`

### Storage & Files

Virtual filesystem, adapters, and file operations

- [Filesystem](https://github.com/tobychui/arozos/blob/master/src/mod/filesystem/filesystem.go): virtual fs · Virtual paths, operations, hidden files, metadata, shortcuts · `src/mod/filesystem/filesystem.go`
- [Storage Pool](https://github.com/tobychui/arozos/blob/master/src/storage.pool.go): pool bridge · Abstracts roots, pools, and storage mappings · `src/storage.pool.go`
- [Bridge](https://github.com/tobychui/arozos/blob/master/src/mod/storage/bridge/bridge.go): fs bridge · Connects storage backends to virtual paths · `src/mod/storage/bridge/bridge.go`
- [Local FS](https://github.com/tobychui/arozos/blob/master/src/mod/filesystem/abstractions/localfs/localfs.go): adapter · Local disk filesystem adapter · `src/mod/filesystem/abstractions/localfs/localfs.go`
- [Remote FS](https://github.com/tobychui/arozos/blob/master/src/mod/filesystem/abstractions/webdavfs/webdavfs.go): adapter · FTP, SFTP, SMB, and WebDAV filesystem adapters · `src/mod/filesystem/abstractions/webdavfs/webdavfs.go`

### Network & Sharing

Discovery, proxies, and file-serving protocols

- [Share](https://github.com/tobychui/arozos/blob/master/src/mod/share/share.go): file sharing · Share entries and public access controls · `src/mod/share/share.go`
- [File Servers](https://github.com/tobychui/arozos/blob/master/src/mod/fileservers/fileservers.go): protocol servers · FTP, SFTP, TFTP, Samba, WebDAV, and dir serving · `src/mod/fileservers/fileservers.go`
- [Network](https://github.com/tobychui/arozos/blob/master/src/mod/network/network.go): discovery/proxy · mDNS, SSDP, UPnP, reverse proxy, websocket, Wi-Fi, stats · `src/mod/network/network.go`

### Web Desktop

Browser shell and built-in apps

- [Desktop UI](https://github.com/tobychui/arozos/blob/master/src/web/desktop.html): web shell · Browser desktop, login, reset, mobile shell, manifest · `src/web/desktop.html`
- [SystemAO](https://github.com/tobychui/arozos/blob/master/src/web/SystemAO/desktop/personalization.html): admin UI · System settings, users, storage, network, security, updates, info · `src/web/SystemAO/desktop/personalization.html`
- [File Manager](https://github.com/tobychui/arozos/blob/master/src/web/SystemAO/file_system/file_explorer.html): file app · Browser file explorer, operations, sharing, trash, permissions · `src/web/SystemAO/file_system/file_explorer.html`
- [Media Apps](https://github.com/tobychui/arozos/blob/master/src/web/Music/index.html): apps · Music, Video, Photo, PDF Viewer, and utilities · `src/web/Music/index.html`

### Extensibility

AGI scripts and subservices

- [AGI Runtime](https://github.com/tobychui/arozos/blob/master/src/mod/agi/agi.go): script engine · Scripted extension layer for app backends · `src/mod/agi/agi.go`
- [Subservice](https://github.com/tobychui/arozos/blob/master/src/mod/subservice/subservice.go): proxy mount · Hosts external Go or Python services behind the platform · `src/mod/subservice/subservice.go`
- [Example Apps](https://github.com/tobychui/arozos/blob/HEAD/examples/agi_examples/basics/hello%20world.js): app contract · AGI examples and backend contract samples · `examples/agi_examples/basics/hello world.js`

## Connections

- Main → Startup: boot · Main initializes startup sequence
- Main → Router: wire routes · Main attaches request routing
- Startup → Modules: load · Boot sequence loads feature modules
- Router → Auth: login · Routes pass through authentication handlers
- Router → Permissions: authorize · Routes enforce permissions
- Router → CSRF: protect · Browser requests are CSRF-checked
- Router → Filesystem: file ops · HTTP handlers expose filesystem services
- Modules → AGI Runtime: extend · Modules expose scripted extension hooks
- Modules → Subservice: mount · Modules can proxy external services into the platform
- AGI Runtime → Filesystem: file api · Scripts call filesystem capabilities
- AGI Runtime → Share: share api · Scripts can create or inspect shares
- AGI Runtime → Network: net api · Scripts can invoke web/network capabilities
- Auth → Permissions: sessions · Identity feeds authorization decisions
- Auth → Quota: limits · Accounts may be subject to quotas
- Filesystem → Storage Pool: roots · Virtual paths resolve through storage pools
- Storage Pool → Bridge: map · Pools map to storage bridges
- Bridge → Local FS: local · Bridges can target local filesystem adapters
- Bridge → Remote FS: remote · Bridges can target remote filesystem adapters
- Share → File Servers: publish · Selected content is exported via file-serving protocols
- Network → File Servers: expose · Network services support hosting and discovery of services
- Desktop UI → SystemAO: launch · Desktop shell opens system administration views
- SystemAO → File Manager: manage files · Admin UI links into file manager flows
- SystemAO → Share: sharing · Admin UI configures sharing and exports
- SystemAO → Network: network · Admin UI configures discovery, proxying, and Wi-Fi
- SystemAO → Auth: identity · Admin UI configures login and account systems
- SystemAO → Permissions: access · Admin UI manages permissions and groups
- Media Apps → Filesystem: browse media · Media apps read content through the filesystem layer
- Example Apps → AGI Runtime: contract · Examples document the AGI extension contract
