# Development Guide > [简体中文](../zh/DEVELOPMENT.md) | English ## Architecture ``` host (zero build, node:crypto / node:http) ├── index.js # Cordis plugin entry: gateway lifecycle, tapIndex injection (randomUUID + authenticated LAN trust), security-event & login-audit wiring, first-run initial password ├── lib/gateway.js # Auth gateway: HTTP/WS interception & forwarding, auth state machine, three-layer brute-force protection, replay protection, basePath routing/redirect/forward stripping, login-audit events, static-asset pass-through ├── lib/gateway-otp.js # OTP route handlers (/otp/setup|enable|verify-setup|verify|verify-backup|disable, split out of gateway.js) ├── lib/forward.js # HTTP/WS forwarding plumbing (loopback Host/Origin rewrite, upgrade piping, lanAddresses) ├── lib/upstream-auth.js # dsh ≥ 0.1.2 upstream browser-auth bridge (secret via the credentials service, minted loopback-hop cookie; record-late fast retry / background probing and rotation re-mint) ├── lib/auth.js # Session table & cookies: in-memory 256-bit tokens, onboarding/OTP state flags, revocation on password change ├── lib/audit-log.js # Audit-log file sink (JSONL, $DSH_HOME/auth-gateway/log/audit.log, daily rotation, 90-day retention) ├── lib/page-shell.js # Shared page scaffolding (base CSS, HTML skeleton, script head: ERRORS + post) ├── lib/errors.js # Master page-error dictionary (zh/en; errorsFor selects per page with overrides) ├── lib/locale.js # Page language resolution (dsh preference > Accept-Language > zh) ├── lib/store.js # Password storage (async scrypt hash, $DSH_HOME/auth-gateway/password.json) ├── lib/otp-store.js # OTP storage (secret + hashed backup codes + lastCounter watermark) ├── lib/otp-crypto.js # OTP secret encryption/decryption (AES-256-GCM; master key from env var or key file) ├── lib/totp.js # TOTP (RFC 6238/4226): base32, generate/verify, replay protection, otpauth URI, backup codes ├── lib/qr-svg.js # Zero-dependency QR SVG generation (Reed-Solomon, mask evaluation) ├── lib/otp-page.js # OTP setup/verify pages (self-contained HTML) ├── lib/login-page.js # Login/settings/change-password page ├── lib/onboarding-page.js # Onboarding page (set a personal password + optional OTP binding) ├── lib/policy.js # Password-strength policy ├── lib/version.js # Own version/repository (package.json) + SemVer-subset comparison ├── lib/update-check.js # New-version check (the only outbound request; TTL-cached, never throws) └── lib/config.js # Standard Schema config validation (incl. the basePath sub-path prefix) client (optional, source-built) ├── client/src/index.jsx # Panel container: all state/handlers, the api factory, slot registration (settings.section) ├── client/src/locales.js # zh/en dictionaries (own namespace) ├── client/src/styles.js # dsh design tokens + shared style objects ├── client/src/ui.jsx # Button / Pill / StatusBanner primitives ├── client/src/*-card.jsx # Presentational cards (OTP/password/session/cookie-Secure/about): props in, no state or requests ├── client/src/otp-setup-dialog.jsx # OTP setup dialog (scan / verify / one-time backup codes) ├── client/src/cookie-secure.js # Cookie-Secure state derivation (pure, unit-tested) ├── client/src/update-notice.js # Update-notice derivation (pure, unit-tested) └── client/build.mjs # esbuild build → client/index.js (served by dsh via exports["./client"]) scripts / tests ├── scripts/deploy.sh # Deploy pipeline: syntax check → full tests → sync to the DSH install dir → post-install verification (--restart optionally restarts) ├── scripts/e2e.mjs # Playwright end-to-end (real dsh web: login/2FA/password-change flows) ├── scripts/screenshots.mjs # README UI screenshots (docs/assets/*.png) ├── scripts/verify.sh # curl gate verification (401/302/WS rejection/lockout) ├── scripts/reset.mjs # dsh-auth-gateway-reset: deletes only password.json (bilingual output) ├── scripts/uninstall.mjs # dsh-auth-gateway-uninstall: deletes the whole auth-gateway/ (bilingual output) └── tests/ # gateway / config / policy / otp / locale / basepath / patch-ports / plugin-contract / client-contract / audit-log ``` Design points: - **Zero runtime dependencies**: the host uses only Node built-ins; the client build artifact only externally references modules provided by the dsh runtime. Both `@deepseek-ai/dsh-client-ui-slots` and `@deepseek-ai/dsh-client-ui-primitives` (the official UI primitives — the panel's dropdown uses its `Menu` rather than a native `