# sfgfdsd/qingsios architecture

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

- Interactive diagram: https://gitdiagram.com/sfgfdsd/qingsios
- Repository: https://github.com/sfgfdsd/qingsios

## Overview

1. **Repository shape**
   - This repo is effectively a **single-page browser application**: the only runtime artifact shown is `index.html`, with `README.md` documenting the system and its architecture.
   - There is **no backend service**, no build pipeline visible, and **zero third-party dependencies**. Everything runs in the browser using native Web APIs.

2. **System boundary**
   - The product is **“青丝 OS · HybridFS”**, a browser-resident OS-like interface whose core responsibility is persistent file/memory management inside the browser sandbox.
   - The important architectural boundary is not between services, but between **UI shells** and the **storage engine**.

3. **Core engine**
   - The central subsystem is **HybridFS**, a file-system API exposed to the UI through a `QingSi.fs`-style interface.
   - It provides the main file operations: initialize, mkdir, write/read, delete, rename, move, copy, search, stats, and recursive directory handling.

4. **Four storage tiers**
   - The architecture is a **quad-core hybrid storage stack**:
     - **OPFS**: primary binary file layer, used for real file content when available.
     - **IndexedDB**: authoritative metadata store and fallback content store.
     - **localStorage**: hot cache for directory snapshots, drafts, preferences, and cross-tab signals.
     - **Cookie**: tiny identity/session/one-time-state layer.
   - This is the main diagram-worthy structure in the repo.

5. **Data ownership rules**
   - **File metadata always belongs to IndexedDB** (`nodes` table), even when file content lives in OPFS.
   - **Binary content prefers OPFS** and falls back to **IndexedDB `blobs`** when OPFS is unavailable.
   - **localStorage never stores canonical file content**; it only holds transient accelerators and user state.
   - **Cookie only stores tiny, expiry-sensitive values** like identity flags and “show once” markers.

6. **Read/write flow**
   - File writes flow from the UI into HybridFS, which:
     - updates metadata in IndexedDB,
     - writes content to OPFS or fallback blobs,
     - refreshes hot caches in localStorage,
     - broadcasts change signals to other tabs.
   - File reads are optimized in the opposite direction:
     - UI can render from localStorage cache immediately,
     - then HybridFS reconciles against IndexedDB and storage-backed content.

7. **Cross-tab synchronization**
   - `localStorage` is used as a **signal bus** via the browser `storage` event.
   - This lets one tab notify other tabs of file creation, deletion, move, or write events without polling.
   - This is a clear architectural boundary: **state changes propagate through storage events, not a central server**.

8. **Startup and recovery sequence**
   - On initialization, HybridFS:
     - opens/creates the IndexedDB database,
     - probes OPFS support,
     - ensures the root filesystem exists,
     - injects default/example content on first run.
   - The UI can then render instantly from cached tree snapshots while the authoritative store is checked in the background.

9. **UI subsystems implied by the README**
   - The browser app is more than a file store; it includes several OS-like UI modules:
     - a **file manager** for tree browsing,
     - an **editor** with draft autosave and crash recovery,
     - a **terminal** with shell-like commands,
     - a **settings/storage panel** for preferences and storage status.
   - These modules all sit on top of the same HybridFS and persistence services.

10. **Operational resilience**
   - The main reliability design is **graceful degradation**:
     - OPFS available → full performance and large-file support.
     - OPFS unavailable → IndexedDB becomes the fallback file store.
     - Private/incognito or restricted environments still run, but persistence may be reduced.
   - This makes storage capability adaptive rather than brittle.

11. **What matters for an architecture diagram**
   - Draw one **browser-only boundary** containing:
     - the OS/UI layer,
     - the HybridFS engine,
     - the four storage tiers,
     - the sync/caching/prefs helpers.
   - Show **OPFS as primary content storage**, **IndexedDB as metadata authority**, **localStorage as cache/event layer**, and **Cookie as identity/session layer**.
   - No external APIs beyond browser storage and file-system capabilities are part of the architecture.

12. **Concise repo interpretation**
   - This repository is a **client-side persistence system wrapped in an OS-like browser UI**, packaged as a single HTML application.
   - The distinguishing architectural idea is the **split of responsibilities across four browser storage primitives**, each used only where its characteristics are strongest.

Main entry points: [`index.html`](https://github.com/sfgfdsd/qingsios/blob/main/index.html) (App Shell), [`README.md`](https://github.com/sfgfdsd/qingsios/blob/main/README.md) (README)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_repo["Browser App"]
  node_readme["README<br/>docs<br/>[README.md]"]
  node_index["App Shell<br/>html app<br/>[index.html]"]
end

subgraph group_ui["OS UI"]
  node_file_manager["File Manager<br/>ui module"]
  node_editor["Editor<br/>ui module"]
  node_terminal["Terminal<br/>ui module"]
  node_settings["Settings<br/>ui module"]
end

subgraph group_fs["HybridFS"]
  node_qingsi_fs["QingSi.fs<br/>fs api"]
  node_init["Init<br/>startup"]
  node_ops["FS Ops<br/>file operations"]
  node_tree_cache["Tree Cache<br/>snapshot cache"]
  node_sync["Broadcast Sync<br/>cross-tab sync"]
end

subgraph group_storage["Browser Storage"]
  node_opfs[("OPFS<br/>binary store")]
  node_idb[("IndexedDB<br/>metadata store")]
  node_local[("localStorage<br/>hot cache")]
  node_cookie[("Cookie<br/>identity state")]
  node_blobs[("Blobs<br/>fallback content")]
end

node_readme -->|"documents"| node_index
node_index -->|"hosts"| node_file_manager
node_index -->|"hosts"| node_editor
node_index -->|"hosts"| node_terminal
node_index -->|"hosts"| node_settings
node_file_manager -->|"uses"| node_qingsi_fs
node_editor -->|"uses"| node_qingsi_fs
node_terminal -->|"uses"| node_qingsi_fs
node_settings -->|"inspects"| node_qingsi_fs
node_qingsi_fs -->|"starts with"| node_init
node_qingsi_fs -->|"exposes"| node_ops
node_qingsi_fs -->|"hydrates"| node_tree_cache
node_ops -->|"writes metadata"| node_idb
node_ops -->|"writes content"| node_opfs
node_ops -->|"fallback content"| node_blobs
node_tree_cache -->|"stores"| node_local
node_sync -->|"signals"| node_local
node_ops -->|"broadcasts"| node_sync
node_init -->|"opens"| node_idb
node_init -->|"probes"| node_opfs
node_init -->|"reads/writes"| node_cookie
node_init -->|"seeds cache"| node_local
node_ops -->|"refreshes cache"| node_local
node_ops -.->|"touches"| node_cookie

click node_readme "https://github.com/sfgfdsd/qingsios/blob/main/README.md"
click node_index "https://github.com/sfgfdsd/qingsios/blob/main/index.html"

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_readme,node_index toneBlue
class node_file_manager,node_editor,node_terminal,node_settings toneAmber
class node_qingsi_fs,node_init,node_ops,node_tree_cache,node_sync toneMint
class node_opfs,node_idb,node_local,node_cookie,node_blobs toneRose
```

## Components

### Browser App

Single-page browser-resident application boundary

- [README](https://github.com/sfgfdsd/qingsios/blob/main/README.md): docs · Architecture and behavior overview · `README.md`
- [App Shell](https://github.com/sfgfdsd/qingsios/blob/main/index.html): html app · Single runtime entrypoint for the browser app · `index.html`

### OS UI

User-facing shell and tools built on the shared file system

- **File Manager**: ui module · Tree browsing and file operations
- **Editor**: ui module · Text editing with draft recovery
- **Terminal**: ui module · Shell-like command interface
- **Settings**: ui module · Preferences and storage status panel

### HybridFS

Core browser file system and persistence engine

- **QingSi.fs**: fs api · UI-facing file system interface
- **Init**: startup · Opens database, probes capabilities, and seeds first run
- **FS Ops**: file operations · mkdir, read, write, delete, rename, move, copy, search, stats
- **Tree Cache**: snapshot cache · Fast directory snapshots and immediate UI render state
- **Broadcast Sync**: cross-tab sync · Propagates file changes through storage events

### Browser Storage

Four-tier persistence model and synchronization surface

- **OPFS**: binary store · Primary file content storage when available
- **IndexedDB**: metadata store · Authoritative metadata and fallback content blobs
- **localStorage**: hot cache · Drafts, snapshots, preferences, and signal bus
- **Cookie**: identity state · Tiny expiry-sensitive identity and one-time flags
- **Blobs**: fallback content · IndexedDB fallback for file content when OPFS is unavailable

## Connections

- README → App Shell: documents · README describes the single-page browser app
- App Shell → File Manager: hosts · App shell loads the file manager
- App Shell → Editor: hosts · App shell loads the editor
- App Shell → Terminal: hosts · App shell loads the terminal
- App Shell → Settings: hosts · App shell loads settings and storage status
- File Manager → QingSi.fs: uses · Browsing and file actions go through the shared API
- Editor → QingSi.fs: uses · Editing and draft persistence go through the shared API
- Terminal → QingSi.fs: uses · Shell commands execute against the shared API
- Settings → QingSi.fs: inspects · Storage status and preferences reflect the same engine
- QingSi.fs → Init: starts with · Filesystem lifecycle begins at initialization
- QingSi.fs → FS Ops: exposes · Provides core file and directory operations
- QingSi.fs → Tree Cache: hydrates · Reads and refreshes cached directory snapshots
- FS Ops → IndexedDB: writes metadata · Metadata always belongs to IndexedDB
- FS Ops → OPFS: writes content · Primary binary content goes to OPFS when available
- FS Ops → Blobs: fallback content · IndexedDB blobs store content when OPFS is unavailable
- Tree Cache → localStorage: stores · Hot snapshots and drafts live in localStorage
- Broadcast Sync → localStorage: signals · Cross-tab notifications ride on storage events
- FS Ops → Broadcast Sync: broadcasts · File changes are propagated to other tabs
- Init → IndexedDB: opens · Database is created or opened on startup
- Init → OPFS: probes · Startup checks OPFS availability
- Init → Cookie: reads/writes · Session and one-time flags are kept in cookies
- Init → localStorage: seeds cache · Initial tree snapshots and preferences are warmed into localStorage
- FS Ops → localStorage: refreshes cache · Write operations update hot caches and UI state
- FS Ops → Cookie: touches · Tiny identity and expiry-sensitive state may be updated
