How meganz/webclient works
1. This repository is the MEGA web client: a large client-side application served as static assets, not a traditional server-rendered app. The main architectural boundary is between browser-executed UI/logic and MEGA’s backend APIs, with the client responsible for encryption, state management, and most UI rendering.
2. Bootstrapping is centered on secureboot.js, which loads versioned HTML/JS/CSS/resources from static content servers and verifies their hashes before execution. The repo’s index.html, html/*.html, and top-level secureboot.js form the entry-point layer; the live site is generated from this repo into hash-stamped assets.
3. The app is organized as a multi-surface frontend rather than one single view. Major surfaces include:
- File Manager (js/fm.js, js/mega.js, js/fm/*, html/fm.html)
- Chat/Meetings (js/chat/*, worker.sfuClient.bundle.js, worker.recorder.bundle.js)
- Mobile (js/mobile/*, html/mobile.html)
- Public/marketing/transactional pages such as login, signup, pricing, recovery, download, embed player, etc. (html/*.html, html/js/*)
4. The File Manager is the core application subsystem. js/mega.js holds the MegaData model and most data handling; js/fm/* contains file/folder operations, dialogs, devices, gallery, shares, S4 object storage UI, recents, versioning, and account-related views. This subsystem binds the remote node metadata model to the visible file tree, dialogs, and action menus.
5. Data persistence and caching are handled client-side through js/mDB.js, js/idbkvstorage.js, and related utilities. The client caches metadata and other state in IndexedDB/local storage to support responsiveness and offline-ish behavior, while js/utils/* provides shared abstractions for storage, events, network, locale, and DOM helpers.
6. End-to-end encryption is a first-class architectural boundary. js/crypto.js, js/keymgr.js, js/security.js, js/paycrypt.js, sjcl.js, aesasm.js, rsaasm.js, nacl-fast.js, and naclworker.js support key generation, content encryption/decryption, authentication, and secure transfer flows. Encryption is not just a transport concern; it is embedded into upload/download, thumbnail generation, chat, and password-manager features.
7. Upload and download are separate pipelines with their own workers and transport strategies. encrypter.js and decrypter.js run as web workers for file processing; js/transfers/* contains chunking, queueing, retry, filesystem/indexeddb/memory backends, and XHR/WebSocket helpers. This is the main data plane for moving encrypted file content between the browser and MEGA storage.
8. Chat and meetings are a distinct subsystem with its own runtime model and UI tree. js/chat/chat.jsx, js/chat/ui/*, and plugins under js/chat/plugins/* implement messaging, search, reactions, rich previews, presence, notifications, and MEGAchat-specific workflows. Audio/video calling is split into an SFU client (js/chat/sfuClient.js) and worker bundles for crypto and recording, which isolates realtime media/signaling concerns from the main app.
9. The mobile client is not just responsive CSS; it has dedicated code paths. js/mobile/* and css/mobile/* provide mobile-specific navigation, dialogs, cloud browsing, account flows, recovery, transfer overlays, and settings. This suggests a separate interaction model and routing layer for smaller devices rather than a single adaptive UI.
10. UI composition is shared but layered. Generic UI primitives live under js/ui/* and js/ui/components/*, while product-specific widgets live in js/chat/ui/*, js/fm/*, js/mobile/*, and js/ui/pwm/*. Styling is equally segmented with large CSS bundles for core app, chat, mobile, transfers, password manager, and feature-specific pages.
11. There is a public-transfer/site subsystem separate from the main cloud-drive UI. js/ui/transfer/* contains its own boot, pages, dialogs, overlays, subpages, fonts, and CSS, indicating an independently themed transfer experience with its own navigation and content pages. The html/download.html, html/embedplayer.html, html/planpricing.html, and related files fit the same “public-facing app surface” pattern.
12. The repository also includes specialized product modules that should appear as separate boxes in an architecture diagram:
- Password manager UI under js/ui/pwm/* and css/pwm/*
- S4/object-storage management under js/fm/s4/* and js/utils/s4.js
- Rewind/history features under js/rewind/*
- Document/image viewers and previews via pdf.worker.js, js/ui/docx.viewer.js, js/ui/xlsx.viewer.js, and related HTML/CSS
13. Workers and background helpers are important architectural nodes. Besides encryption/decryption workers, the repo contains pdf.worker.js, worklet.js, worker.sfuClient.bundle.js, worker.recorder.bundle.js, and service-worker support in sw.js. These offload CPU-heavy or asynchronous tasks from the main UI thread.
14. Build, QA, and deployment are client-build oriented. Gruntfile.js, webpack.config.js, karma.conf.js, Makefile, scripts/*, and test/* indicate a build/test pipeline for bundling assets, generating language files, running unit/integration tests, and preparing deployable static outputs. The dont-deploy/ tree contains prototypes and manual test artifacts excluded from production packaging.
15. In infrastructure terms, the app expects to be hosted as static content behind Apache/nginx or MEGA’s own static servers, with routing handled by HTML entry points and client-side code. The README’s local setup instructions and the presence of .htaccess, manifest.json, sw.js, and many versioned asset directories show a deployment model optimized for cached static delivery and browser-side application logic.
Main entry points: html HTML surfaces · fm.js File manager · chat.jsx Chat app · crypto.js Crypto stack
Components 19
Boot & delivery
Static entry points, secure loading, and generated asset delivery.
- Index · Main browser entry page for the client.
index.html - Secure boot · Verifies and loads versioned static assets before app execution.
secureboot.js - HTML surfaces · Top-level HTML entry points for major app and public surfaces.
html
Core cloud client
File manager, shared data model, UI primitives, and client-side state.
- File manager · Main cloud-drive interface and orchestration layer.
js/fm.js - MegaData · Primary data model and node/account state handling.
js/mega.js - FM modules · File operations, dialogs, galleries, shares, recents, devices, S4, and account views.
js/fm - UI core · Reusable UI primitives, dialogs, renderers, and view composition.
js/ui
Media & collaboration
Chat, meetings, viewers, and related realtime media features.
- Chat app · Messaging, routing, conversations, and chat app bootstrap.
js/chat/chat.jsx - Chat UI · Conversation panels, lists, overlays, search, and meeting UI.
js/chat/ui - Chat plugins · Presence, notifications, rich previews, reactions, and formatting helpers.
js/chat/plugins - Meetings SFU · Audio/video calling client and SFU signaling runtime.
js/chat/sfuClient.js
Public surfaces
Standalone login, pricing, recovery, download, and transfer experiences.
- Mobile app · Dedicated mobile navigation, account flows, and cloud browsing.
js/mobile/mobile.js - Transfer UI · Standalone transfer/product experience with its own pages and theming.
js/ui/transfer/boot.js - Public pages · Login, signup, pricing, recovery, download, embed, and similar web pages.
html/login.html
Platform services
Crypto, persistence, transfers, workers, and build tooling.
- Crypto stack · Key management, authentication, and file/message encryption primitives.
js/crypto.js - Storage cache · IndexedDB/local storage abstractions and cached client state.
js/mDB.js - Transfer pipeline · Chunking, queuing, retries, and upload/download transport logic.
js/transfers - Workers · Encryption, decryption, SFU, recording, PDF, and service-worker execution.
encrypter.js - Build tools · Bundling, testing, localization, and deployment preparation.
webpack.config.js
Connections 26
- Index → Secure boot: loads · The entry page hands off to secure boot for asset verification.
- Secure boot → HTML surfaces: boots · Secure boot resolves the versioned HTML and resource surfaces.
- HTML surfaces → File manager: opens · The main HTML shell can launch the cloud-drive client.
- HTML surfaces → Chat app: opens · Chat-specific entry points load the messaging runtime.
- HTML surfaces → Mobile app: opens · Mobile HTML entry points load the mobile client.
- HTML surfaces → Public pages: renders · Standalone HTML pages serve login, recovery, pricing, and related flows.
- HTML surfaces → Transfer UI: renders · Public transfer pages are bootstrapped from their own HTML bundle.
- File manager → MegaData: uses · The file manager is driven by the central application data model.
- File manager → FM modules: delegates · File manager behavior is split across feature modules and dialogs.
- File manager → UI core: composes · The file manager renders through shared UI primitives and containers.
- File manager → Crypto stack: protects · Uploads, downloads, and node actions depend on client-side encryption.
- MegaData → Storage cache: persists · Client state and metadata are cached locally for responsiveness.
- FM modules → Transfer pipeline: moves data · File operations connect to upload/download and chunk transport flows.
- Chat app → Chat UI: composes · Chat runtime renders conversation, sidebar, and meeting interfaces.
- Chat app → Chat plugins: extends · Plugins provide message processing, presence, and notifications.
- Chat app → Meetings SFU: coordinates · Chat integrates with the realtime calling and SFU subsystem.
- Chat app → Crypto stack: secures · Chat message and call flows rely on the shared crypto boundary.
- Mobile app → UI core: reuses · Mobile-specific screens still rely on shared UI building blocks.
- Mobile app → Crypto stack: secures · Mobile recovery, login, and transfers use the encryption stack.
- Transfer UI → UI core: reuses · The transfer site uses its own themed UI layer built from shared ideas.
- Transfer UI → Transfer pipeline: drives · Transfer pages orchestrate upload/link creation workflows.
- Transfer pipeline → Workers: offloads · Heavy file processing and async transport work is pushed into workers.
- Crypto stack → Workers: accelerates · Crypto primitives are also executed in worker contexts.
- Build tools → Index: packages · Build tooling produces the deployable static entry pages and assets.
- Build tools → HTML surfaces: bundles · The build pipeline generates the HTML-backed surface bundles.
- Build tools → Workers: builds · Worker bundles are compiled and packaged as part of the client build.