Skip to content

Commit d484b26

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 0ef0d98 + 03fb6a8 commit d484b26

27 files changed

+2919
-2123
lines changed

ARCHITECTURE.md

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,26 @@ src/
109109
│ ├─ state.js # Tiny global store (imperative actions)
110110
│ ├─ i18n.js # i18next + detector setup
111111
│ │
112+
│ ├─ features/ # Domain-specific feature modules
113+
│ │ ├─ chat/ # Chat logic, UI, and event handling
114+
│ │ ├─ contact/ # Contact modal logic
115+
│ │ ├─ invite/ # QR generation, sharing logic
116+
│ │ ├─ settings/ # Settings persistence and UI generation
117+
│ │ ├─ theme/ # Dark mode logic
118+
│ │ └─ zip/ # Zip modal logic (selection state)
119+
│ │
112120
│ ├─ network/
113121
│ │ ├─ websocket.js # Signalling client (Render in prod)
114122
│ │ └─ webrtc.js # Peer connection, data channel, screen share
115123
│ │
116124
│ ├─ transfer/
117-
│ │ ├─ fileHandler.js # Queueing, worker IO, OPFS, UI integration
125+
│ │ ├─ fileHandler.js # Facade: orchestrates sender, receiver, queue
126+
│ │ ├─ fileSender.js # Worker management, upload throttling
127+
│ │ ├─ fileReceiver.js # Incoming stream, memory/OPFS storage
128+
│ │ ├─ queueManager.js # Drag-and-drop, file selection, queue state
129+
│ │ ├─ transferUI.js # HTML generation for transfer items
130+
│ │ ├─ opfsHandler.js # Origin Private File System operations
131+
│ │ ├─ etrCalculator.js # Shared speed/time-remaining logic
118132
│ │ └─ zipHandler.js # JSZip integration for “download all”
119133
│ │
120134
│ ├─ preview/
@@ -134,7 +148,7 @@ src/
134148
│ │ ├─ dom.js # Centralised DOM element queries
135149
│ │ ├─ events.js # All event listeners + drag‑and‑drop
136150
│ │ ├─ view.js # Small “render” helpers (no framework)
137-
│ │ ├─ modals.js # Modals, settings, theme/consent UX
151+
│ │ ├─ modals.js # Orchestrator for modals (delegates to features/)
138152
│ │ ├─ onboarding.js # Welcome/invite overlays & positioning
139153
│ │ └─ effects.js # Animation quality controller (persists + applies)
140154
│ │
@@ -167,11 +181,11 @@ served as‑is by Vite.
167181

168182
Where should new things go?
169183

184+
- New feature slice: `js/features/newFeature/`.
170185
- New network logic: `js/network/`.
171-
- New transfer features: `js/transfer/`.
186+
- New transfer logic: `js/transfer/` (if core logic) or `js/features/` (if UI heavy).
172187
- New preview type: `js/preview/handlers/` plus `previewConfig.js` entry.
173188
- New UI behaviour: bind in `js/ui/events.js`, render helpers in `js/ui/view.js`.
174-
- New settings: `js/ui/modals.js` (UI), `js/ui/effects.js` (persistence/application).
175189
- Small pure helpers: `js/utils/`.
176190
- New CSS: follow the existing split (base/layout/components/utilities).
177191

@@ -180,6 +194,9 @@ Where should new things go?
180194

181195
- ES Modules everywhere; avoid globals. The only intentional global is
182196
`window.videoPlayer` for the self‑contained player in `public/video.js`.
197+
- **Feature Modules**: Logic that owns a specific UI domain (Chat, Settings, Invite)
198+
lives in `js/features/`. These modules should export setup/teardown functions
199+
used by the main `ui/` orchestrators.
183200
- Separate DOM concerns from logic:
184201
- `ui/dom.js` owns querying and exposes a stable `uiElements` map.
185202
- `ui/events.js` attaches listeners and calls actions/helpers.
@@ -255,45 +272,46 @@ WebRTC client (`js/network/webrtc.js`):
255272

256273
## 7) File transfers (worker + OPFS + flow control)
257274

258-
Sender:
275+
The transfer logic is modularized under `js/transfer/`, with `fileHandler.js` acting as a facade to coordinate the specific modules.
276+
277+
Sender (`js/transfer/fileSender.js`):
259278

260-
- `fileHandler.startFileSend()`:
279+
- `startFileSend()`:
261280
- Spawns `sender.worker.js` to read the file in chunks (default 256 KB, user
262281
tunable).
263282
- Sends JSON metadata, then ArrayBuffers, then `"EOF"`.
264283
- Throttles on `getBufferedAmount()` against `HIGH_WATER_MARK`.
265-
- Updates UI progress and an ETA based on moving‑average speed samples.
284+
- Updates UI using `transferUI.js` and calculates ETA via `etrCalculator.js`.
266285
- Worker (`sender.worker.js`):
267286
- Reads slices with `FileReader`, transfers underlying buffers to main thread
268287
(zero‑copy), and posts `chunk` messages.
269288
- Self‑terminates on `done`.
270289

271-
Receiver:
290+
Receiver (`js/transfer/fileReceiver.js`):
272291

273-
- `fileHandler.handleDataChannelMessage()`:
274-
- If metadata JSON: initialises receive state; possibly enables OPFS “safe
275-
mode” if large and supported.
292+
- `handleDataChannelMessage()`:
293+
- If metadata JSON: initialises receive state; delegates to `opfsHandler.js` if
294+
"safe mode" is active (large file + supported browser).
276295
- If ArrayBuffer:
277-
- Writes to OPFS writer if active, else pushes to memory.
278-
- Tracks speed/ETA and updates UI.
296+
- Writes via `opfsHandler` (if safe mode) or pushes to memory array.
297+
- Tracks speed/ETA via `etrCalculator.js`.
279298
- On `"EOF"`:
280299
- Finalises writer (OPFS) or creates a `Blob` from parts.
281300
- Adds file to `store.receivedFiles`.
282-
- Updates UI buttons (preview/save) with a brief “Complete!” animation.
301+
- Updates UI actions (preview/save/complete).
283302
- Optional auto‑download if enabled and below a size threshold.
284303

285-
OPFS safe mode:
304+
OPFS Safe Mode (`js/transfer/opfsHandler.js`):
286305

287-
- Controlled by `localStorage('dropsilk-use-opfs-buffer')` and a size threshold
288-
(`OPFS_THRESHOLD`).
289-
- Uses `navigator.storage.getDirectory()` to create a per‑file writer.
290-
- Cleans up stale OPFS entries on reset and between files.
306+
- Encapsulates all Origin Private File System operations.
307+
- `initOpfsForFile`: Get directory handle, remove stale files, create writer.
308+
- `writeOpfsChunk`: Writes stream directly to disk.
309+
- `finalizeOpfsFile`: Closes writer, returns File handle as Blob.
291310

292-
Flow control:
311+
UI & Queue (`js/transfer/transferUI.js`, `js/transfer/queueManager.js`):
293312

294-
- DataChannel backpressure:
295-
- Only send chunks when `bufferedAmount <= HIGH_WATER_MARK`.
296-
- React quickly to `onbufferedamountlow` by draining any queued chunks.
313+
- `transferUI.js` contains all HTML generation templates for queue items to keep logic files clean.
314+
- `queueManager.js` handles file selection, folder limits, and drag-and-drop reordering.
297315

298316

299317
## 8) Preview subsystem
@@ -376,10 +394,9 @@ Security:
376394
- Small pure-ish functions that read from the store and mutate view state.
377395
- Manages queue expansion, metrics UI, panels, pulses, and stream views.
378396
- `ui/modals.js`:
379-
- All modals (invite, zip, settings, donate, about/contact/terms/privacy/
380-
security/FAQ, preview).
381-
- Settings modal doubles as a host for preferences and “advanced” options.
382-
- Updates theme, fonts, analytics consent, chunk size, OPFS mode, etc.
397+
- Acts as an orchestrator for global modals (About, Donate, etc.).
398+
- For complex modals (Settings, Zip, Invite), it delegates logic to the relevant
399+
modules in `js/features/`.
383400
- `ui/onboarding.js`:
384401
- Welcome/Invite overlays; computes safe positions using VisualViewport and
385402
re‑positions on orientation/resize.
@@ -458,7 +475,11 @@ Security posture:
458475
- No files are uploaded except optional PPTX previews and then only to the
459476
configured UploadThing endpoint, with auto‑clean up (server‑side).
460477
- WebRTC data paths are end‑to‑end encrypted (DTLS/SRTP).
461-
- Signalling server receives only metadata and discards it after session ends.
478+
- Markdown is sanitised.
479+
- reCAPTCHA is loaded on demand only for the contact email.
480+
- QR scanner accepts only our URL schema; invalid scans are rejected.
481+
- Do not include secrets in the client; use `VITE_` prefix for safe public
482+
env vars only.
462483

463484

464485
## 14) Build system and environments
@@ -591,10 +612,10 @@ Add a new WebSocket message:
591612
592613
Add a new setting:
593614
594-
1. Add UI in `populateSettingsModal()` in `ui/modals.js`.
615+
1. Add UI in `populateSettingsModal()` in `js/features/settings/settingsUI.js`.
595616
2. Persist to `localStorage` (use a `dropsilk-*` key).
596617
3. If it affects performance/animations, wire it up in `js/ui/effects.js`.
597-
4. Apply in `saveSettingsPreferences()` and reflect in the UI.
618+
4. Apply in `js/features/settings/settingsData.js` and reflect in the UI.
598619
599620
Add a new language:
600621
@@ -610,7 +631,8 @@ Add a new language:
610631
- Create `xx.json`, minimally copying the shape from `en.json`.
611632
- Run `scripts/update-locales.js` to update imports/resources/options and to
612633
seed language names across JSONs.
613-
- In HTML, use `data-i18n` attributes; in code, `i18next.t('key', options)`.
634+
- In HTML, use `data-i18n` attributes; in code, `i18next.t(key, options)` or
635+
`[data-i18n]` where possible.
614636
- For dynamic text (e.g., toasts) always use `i18next.t()`.
615637
616638
@@ -631,8 +653,9 @@ Add a new language:
631653
If you’re unsure where something belongs:
632654
633655
- Is it view code that touches the DOM? `ui/…`
656+
- Is it a feature slice (chat, settings)? `features/…`
634657
- Is it a network edge (signalling or peer)? `network/…`
635658
- Is it file transfer orchestration or IO? `transfer/…`
636659
- Is it a one‑off helper? `utils/…`
637660
- Is it a file preview? `preview/…`
638-
- Is it global app wiring? `app.js`
661+
- Is it global app wiring? `app.js`

README.md

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<br />
77
<i>Instantly share files and screen, device-to-device. No cloud. No limits.</i>
88
</p>
9-
9+
1010
<p>
1111
<a href="https://dropsilk.xyz"><strong>Production Deployment »</strong></a> <br />
1212
<a href="https://dropsilk.vercel.app"><strong>Mirror »</strong></a> <br />
1313
<a href="https://github.com/medy17/DropSilk_Backend"><strong>Backend Code »</strong></a>
1414
</p>
15-
15+
1616
<div>
1717
<img src="https://img.shields.io/github/license/medy17/dropsilk?style=for-the-badge" alt="License"/>
1818
<img src="https://img.shields.io/github/last-commit/medy17/dropsilk?style=for-the-badge" alt="Last Commit"/>
@@ -87,8 +87,8 @@ DropSilk is built on a few key architectural principles to ensure performance, p
8787

8888
1. **WebRTC for Peer-to-Peer Communication:** Instead of a traditional client-server upload/download model, DropSilk uses WebRTC. This creates a direct, encrypted connection between the two users' browsers. This means files never touch our server, dramatically enhancing privacy and speed, especially on a local network.
8989
2. **Decoupled Signaling:** A lightweight WebSocket server acts as a "rendezvous" point. Its only job is to help two peers find each other and exchange the metadata needed to establish the direct WebRTC connection. Once the connection is made, the signaling server is no longer involved in the transfer itself.
90-
3. **Non-Blocking File Processing with Web Workers:** Reading large files on the main browser thread can freeze the UI. DropSilk delegates all file reading and chunking to a dedicated Web Worker. The main thread simply sends the file object to the worker and receives ready-to-send chunks, ensuring the interface remains fluid and responsive at all times.
91-
4. **OPFS for Stability (Safe Mode):** Browsers have memory limits. Attempting to buffer a multi-gigabyte file in RAM can cause the tab to crash. The "Safe Mode" feature leverages the **Origin Private File System (OPFS)** to stream incoming file chunks directly to disk instead of memory, making the application robust enough to handle massive files.
90+
3. **Non-Blocking File Processing with Web Workers:** Reading large files on the main browser thread can freeze the UI. DropSilk delegates all file reading and chunking to a dedicated Web Worker. The main thread simply sends the file object to the worker and receives ready-to-send chunks, ensuring the interface remains fluid and responsive at all times. This logic is cleanly separated into dedicated modules like `fileSender.js` and `queueManager.js` for improved maintainability.
91+
4. **OPFS for Stability (Safe Mode):** Browsers have memory limits. Attempting to buffer a multi-gigabyte file in RAM can cause the tab to crash. The "Safe Mode" feature leverages the **Origin Private File System (OPFS)** to stream incoming file chunks directly to disk instead of memory, making the application robust enough to handle massive files. This is managed by a dedicated `opfsHandler.js` module, which keeps the main receiving logic simple and focused on orchestration.
9292
5. **Performance-First UI Rendering:** The application is engineered to feel fast, not just transfer files fast. Hidden UI elements with infinite animations (like loading spinners) are paused to prevent background CPU usage. All browser resources are hence dedicated to the user's current interaction for a smooth, lag-free experience.
9393

9494
### Project Structure
@@ -112,6 +112,7 @@ The following is a list of most of the important files and folders.
112112
<summary>scripts/</summary>
113113
<ul>
114114
<li>update-locales.js</li>
115+
<li>generate-version.js</li>
115116
</ul>
116117
</details>
117118
</li>
@@ -178,6 +179,19 @@ The following is a list of most of the important files and folders.
178179
<details>
179180
<summary>js/</summary>
180181
<ul>
182+
<li>
183+
<details>
184+
<summary>features/</summary>
185+
<ul>
186+
<li>chat/</li>
187+
<li>contact/</li>
188+
<li>invite/</li>
189+
<li>settings/</li>
190+
<li>theme/</li>
191+
<li>zip/</li>
192+
</ul>
193+
</details>
194+
</li>
181195
<li>
182196
<details>
183197
<summary>network/</summary>
@@ -201,7 +215,13 @@ The following is a list of most of the important files and folders.
201215
<details>
202216
<summary>transfer/</summary>
203217
<ul>
218+
<li>etrCalculator.js</li>
204219
<li>fileHandler.js</li>
220+
<li>fileReceiver.js</li>
221+
<li>fileSender.js</li>
222+
<li>opfsHandler.js</li>
223+
<li>queueManager.js</li>
224+
<li>transferUI.js</li>
205225
<li>zipHandler.js</li>
206226
</ul>
207227
</details>
@@ -211,10 +231,12 @@ The following is a list of most of the important files and folders.
211231
<summary>ui/</summary>
212232
<ul>
213233
<li>dom.js</li>
234+
<li>drawer.js</li>
214235
<li>effects.js</li>
215236
<li>events.js</li>
216237
<li>modals.js</li>
217238
<li>onboarding.js</li>
239+
<li>streaming.js</li>
218240
<li>view.js</li>
219241
</ul>
220242
</details>
@@ -225,6 +247,7 @@ The following is a list of most of the important files and folders.
225247
<ul>
226248
<li>audioManager.js</li>
227249
<li>helpers.js</li>
250+
<li>security.js</li>
228251
<li>toast.js</li>
229252
<li>uploadHelper.js</li>
230253
</ul>
@@ -234,6 +257,7 @@ The following is a list of most of the important files and folders.
234257
<li>config.js</li>
235258
<li>i18n.js</li>
236259
<li>state.js</li>
260+
<li>version.gen.js</li>
237261
</ul>
238262
</details>
239263
</li>
@@ -262,6 +286,7 @@ The following is a list of most of the important files and folders.
262286
<li>audio.css</li>
263287
<li>boarding.css</li>
264288
<li>buttons.css</li>
289+
<li>chat.css</li>
265290
<li>connections.css</li>
266291
<li>dashboard.css</li>
267292
<li>docx.css</li>
@@ -303,6 +328,22 @@ The following is a list of most of the important files and folders.
303328
</ul>
304329
</details>
305330
</li>
331+
<li>
332+
<details>
333+
<summary>locales/</summary>
334+
<ul>
335+
<li>en.json</li>
336+
<li>es.json</li>
337+
<li>fr.json</li>
338+
<li>it.json</li>
339+
<li>ja.json</li>
340+
<li>ms.json</li>
341+
<li>pt.json</li>
342+
<li>sw.json</li>
343+
<li>zh.json</li>
344+
</ul>
345+
</details>
346+
</li>
306347
</ul>
307348
</details>
308349
</li>
@@ -370,17 +411,17 @@ Open your browser and navigate to `http://localhost:5173` (or the address provid
370411
When the user clicks “View Email” in the Contact modal, the app renders a reCAPTCHA challenge and, on success, exchanges the token with the backend to retrieve the email address.
371412
372413
- Env vars:
373-
- `VITE_RECAPTCHA_SITE_KEY` must be set at build time (Vite only injects `VITE_*` variables).
374-
- `VITE_API_BASE_URL` must be a full URL (include `http://` or `https://`).
414+
- `VITE_RECAPTCHA_SITE_KEY` must be set at build time (Vite only injects `VITE_*` variables).
415+
- `VITE_API_BASE_URL` must be a full URL (include `http://` or `https://`).
375416
- Client request:
376-
- `POST ${VITE_API_BASE_URL}/request-email`
377-
- Headers: `Content-Type: application/json`, `Accept: application/json`
378-
- Body: `{"token":"<recaptcha_token_from_client>"}`
379-
- No credentials/cookies.
417+
- `POST ${VITE_API_BASE_URL}/request-email`
418+
- Headers: `Content-Type: application/json`, `Accept: application/json`
419+
- Body: `{"token":"<recaptcha_token_from_client>"}`
420+
- No credentials/cookies.
380421
- Backend response contract:
381-
- Success 200: `{"email":"you@domain.com"}`
382-
- Failure 4xx/5xx: `{"error":"<string_reason>"}`
383-
- Possible values currently: `reCAPTCHA token is required`, `recaptcha_failed`, `server_not_configured`, `internal_error`.
422+
- Success 200: `{"email":"you@domain.com"}`
423+
- Failure 4xx/5xx: `{"error":"<string_reason>"}`
424+
- Possible values currently: `reCAPTCHA token is required`, `recaptcha_failed`, `server_not_configured`, `internal_error`.
384425
- CORS: the backend should allow your dev/staging/production origins for `POST` with `Content-Type`.
385426
386427
## License
@@ -391,4 +432,4 @@ This project is licensed under the **GPLv3**. See the `LICENSE` file for more in
391432
392433
Thanks to Jihah in particular for her contribution in adding coherent ms-MY support.
393434
394-
Ahmed - [GitHub](https://github.com/medy17)
435+
Ahmed - [GitHub](https://github.com/medy17)

0 commit comments

Comments
 (0)