# arelius-d/lucid architecture

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

- Interactive diagram: https://gitdiagram.com/arelius-d/lucid
- Repository: https://github.com/arelius-d/lucid

## Overview

#### Purpose and entry points
LucID is a self-hosted encrypted Markdown notes application. The browser owns encryption, editing, rendering, search, import/export, and session state; the server only serves assets and persists an opaque vault blob. Primary runtime entry points are `server.js` for Node/Express and `public/index.html` → `public/app.js` for the browser application.

#### Browser application and vault boundary
`public/app.js` is the main client controller: it initializes the lock/onboarding flow, derives a non-extractable Web Crypto key from the passphrase, encrypts/decrypts vault fields, and coordinates UI state and API synchronization. The server must never receive the passphrase or plaintext note data. UI markup and styles are centralized in `public/index.html` and `public/styles.css`.

#### Note authoring pipeline
After unlock, decrypted notes, folders, tags, pin state, and trash state are managed in browser memory. Markdown editing feeds a rendered preview; rendered HTML is sanitized before DOM insertion. Search operates over decrypted titles, tags, and bodies locally. Imports parse supported document formats in-browser and convert them to Markdown before encryption. Locally hosted runtime dependencies are prepared by `scripts/vendor.js` and served from `public/assets`/vendored public content.

#### Persistence API and atomic storage
The Express service in `server.js` exposes the narrow application API, static-file delivery, health/version behavior, and CORS policy. Its persistence boundary is `data/store.json` (or `DATA_DIR`): the client sends an encrypted vault payload, and the backend performs guarded atomic replacement using temporary write, fsync, and rename. It preserves malformed/unparseable vault data rather than overwriting it.

#### Client/server control flow
1. Browser loads static UI and locally served assets from `public/`.
2. User passphrase is processed exclusively through browser Web Crypto; PBKDF2-derived AES-GCM keys encrypt vault fields.
3. Browser reads/writes ciphertext through the Express API in `server.js`.
4. Server atomically reads/writes the opaque store under `data/`.
5. On reload or another device, ciphertext is fetched and decrypted only after local unlock. Idle lock clears session/key material.

#### Deployment and network boundary
`Dockerfile` packages the Node application. `docker-compose.yml` runs it loopback-bound on port 58243, with `Caddyfile` configuring Caddy as the sole public ingress on HTTP/HTTPS and TLS certificate manager. The optional DDNS Updater sidecar integrates dynamic-DNS providers such as DuckDNS. This separation keeps the unauthenticated app API off the public interface and requires HTTPS for Web Crypto.

#### Operations and installation
`install.sh` is the host bootstrap and teardown entry point: it fetches deployment files, selects stable/dev branch image channels, configures firewall/DDNS inputs, and manages purge behavior. Persistent encrypted application data is bind-mounted through `data/`; Caddy certificate/config state is managed as Docker volumes. CI publication infrastructure is under `.github/workflows/docker-publish.yml`.

Main entry points: [`public/app.js`](https://github.com/arelius-d/lucid/blob/main/public/app.js) (Client controller), [`docker-compose.yml`](https://github.com/arelius-d/lucid/blob/main/docker-compose.yml) (Service topology), [`server.js`](https://github.com/arelius-d/lucid/blob/main/server.js) (Express API and static server), [`Dockerfile`](https://github.com/arelius-d/lucid/blob/main/Dockerfile) (Node application image)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser client"]
  node_html["App shell<br/>HTML UI<br/>[index.html]"]
  node_styles["UI styles<br/>CSS<br/>[styles.css]"]
  node_app["Client controller<br/>browser runtime<br/>[app.js]"]
  node_crypto{{"Vault cryptography<br/>Web Crypto"}}
  node_authoring["Authoring and local search<br/>Markdown pipeline"]
  node_vendoring["Runtime dependency build<br/>vendor script<br/>[vendor.js]"]
  node_assets["Local public assets<br/>vendored assets"]
end

subgraph group_backend["Application service"]
  node_express["Express API and static server<br/>Node/Express<br/>[server.js]"]
  node_atomic["Guarded atomic store<br/>persistence layer<br/>[server.js]"]
  node_store[("Encrypted vault blob<br/>persistent JSON")]
end

subgraph group_deployment["Deployment and operations"]
  node_container["Node application image<br/>container build"]
  node_compose["Service topology<br/>Docker Compose<br/>[docker-compose.yml]"]
  node_caddy["Public HTTPS ingress<br/>Caddy reverse proxy"]
  node_ddns["DDNS updater<br/>optional sidecar"]
  node_install["Host installer<br/>bootstrap script<br/>[install.sh]"]
  node_ci["Image publishing CI<br/>GitHub Actions workflow<br/>[docker-publish.yml]"]
end

node_html -->|"loads"| node_app
node_styles -->|"styles"| node_html
node_vendoring -->|"prepares"| node_assets
node_assets -->|"local dependencies"| node_app
node_app -->|"derives key and encrypts"| node_crypto
node_app -->|"manages decrypted notes"| node_authoring
node_app -->|"reads/writes ciphertext"| node_express
node_express -->|"vault API"| node_atomic
node_atomic -->|"atomic replacement"| node_store
node_container -->|"packages"| node_express
node_compose -->|"runs"| node_container
node_compose -->|"bind-mounts data"| node_store
node_caddy -->|"proxies HTTPS to loopback app"| node_compose
node_ddns -.->|"supports public address"| node_caddy
node_install -->|"bootstraps"| node_compose
node_ci -->|"publishes image"| node_container

click node_html "https://github.com/arelius-d/lucid/blob/main/public/index.html"
click node_styles "https://github.com/arelius-d/lucid/blob/main/public/styles.css"
click node_app "https://github.com/arelius-d/lucid/blob/main/public/app.js"
click node_vendoring "https://github.com/arelius-d/lucid/blob/main/scripts/vendor.js"
click node_assets "https://github.com/arelius-d/lucid/tree/main/public/assets"
click node_express "https://github.com/arelius-d/lucid/blob/main/server.js"
click node_atomic "https://github.com/arelius-d/lucid/blob/main/server.js"
click node_container "https://github.com/arelius-d/lucid/blob/main/Dockerfile"
click node_compose "https://github.com/arelius-d/lucid/blob/main/docker-compose.yml"
click node_caddy "https://github.com/arelius-d/lucid/blob/main/Caddyfile"
click node_install "https://github.com/arelius-d/lucid/blob/main/install.sh"
click node_ci "https://github.com/arelius-d/lucid/blob/main/.github/workflows/docker-publish.yml"

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_html,node_styles,node_app,node_crypto,node_authoring,node_vendoring,node_assets toneBlue
class node_express,node_atomic,node_store toneAmber
class node_container,node_compose,node_caddy,node_ddns,node_install,node_ci toneMint
```

## Components

### Browser client

All note data handling occurs locally after unlock.

- [App shell](https://github.com/arelius-d/lucid/blob/main/public/index.html): HTML UI · `public/index.html`
- [UI styles](https://github.com/arelius-d/lucid/blob/main/public/styles.css): CSS · `public/styles.css`
- [Client controller](https://github.com/arelius-d/lucid/blob/main/public/app.js): browser runtime · Coordinates unlock, UI state, and vault synchronization. · `public/app.js`
- **Vault cryptography**: Web Crypto · PBKDF2-derived non-extractable AES-GCM key remains in the browser.
- **Authoring and local search**: Markdown pipeline · Edits, sanitizes previews, searches decrypted data, and imports to Markdown.
- [Runtime dependency build](https://github.com/arelius-d/lucid/blob/main/scripts/vendor.js): vendor script · Prepares locally hosted browser dependencies. · `scripts/vendor.js`
- [Local public assets](https://github.com/arelius-d/lucid/tree/main/public/assets): vendored assets · `public/assets`

### Application service

Persists only opaque encrypted vault data.

- [Express API and static server](https://github.com/arelius-d/lucid/blob/main/server.js): Node/Express · Serves public content and exposes the narrow vault API, health/version, and CORS policy. · `server.js`
- [Guarded atomic store](https://github.com/arelius-d/lucid/blob/main/server.js): persistence layer · Uses temporary write, fsync, and rename without replacing malformed vault data. · `server.js`
- **Encrypted vault blob**: persistent JSON · Opaque ciphertext stored at the default data location or DATA_DIR.

### Deployment and operations

Public ingress and host lifecycle.

- [Node application image](https://github.com/arelius-d/lucid/blob/main/Dockerfile): container build · `Dockerfile`
- [Service topology](https://github.com/arelius-d/lucid/blob/main/docker-compose.yml): Docker Compose · Runs the app loopback-bound on port 58243 with persistent mounts. · `docker-compose.yml`
- [Public HTTPS ingress](https://github.com/arelius-d/lucid/blob/main/Caddyfile): Caddy reverse proxy · Sole public ingress and TLS certificate manager. · `Caddyfile`
- **DDNS updater**: optional sidecar · Updates supported dynamic-DNS providers.
- [Host installer](https://github.com/arelius-d/lucid/blob/main/install.sh): bootstrap script · Fetches deployment files and configures branch, firewall, DDNS, and purge behavior. · `install.sh`
- [Image publishing CI](https://github.com/arelius-d/lucid/blob/main/.github/workflows/docker-publish.yml): GitHub Actions workflow · `.github/workflows/docker-publish.yml`

## Connections

- App shell → Client controller: loads
- UI styles → App shell: styles
- Runtime dependency build → Local public assets: prepares
- Local public assets → Client controller: local dependencies
- Client controller → Vault cryptography: derives key and encrypts
- Client controller → Authoring and local search: manages decrypted notes
- Client controller → Express API and static server: reads/writes ciphertext
- Express API and static server → Guarded atomic store: vault API
- Guarded atomic store → Encrypted vault blob: atomic replacement
- Node application image → Express API and static server: packages
- Service topology → Node application image: runs
- Service topology → Encrypted vault blob: bind-mounts data
- Public HTTPS ingress → Service topology: proxies HTTPS to loopback app
- DDNS updater → Public HTTPS ingress: supports public address
- Host installer → Service topology: bootstraps
- Image publishing CI → Node application image: publishes image
