Summary
Implement a "Reverse P2P" file receiving feature where a logged-in user (User A) can create a receive session and share a URL or QR code with an unregistered user (User B). User B can then select files from their device and send them directly to User A via P2P connection, without the files touching Phuppi servers.
Background
Currently, the P2P file sharing feature allows a logged-in user to send files to another person. This feature implements the reverse scenario: a logged-in user wants to receive files from someone who doesn't have a Phuppi account.
Use cases:
- A teacher receiving homework files from students
- A doctor receiving medical files from patients
- A business owner receiving documents from clients
- Anyone needing to receive files from guests without requiring them to create an account
Feature Requirements
Core Functionality
| Requirement |
Description |
| Receive Session |
User A creates a P2P receive session |
| Share URL/QR |
User A gets shareable URL or QR code |
| Guest Sender |
User B (no login required) opens receive page |
| File Selection |
User B selects files from their device |
| P2P Transfer |
Files transfer directly browser-to-browser via WebRTC |
| No Server Upload |
Files never touch Phuppi servers |
| Download to User A |
User A receives downloaded files |
| Session Expiry |
Receive sessions expire after configurable time |
User Flow
- User A (logged in) clicks "Receive Files" and creates a session
- Phuppi Server generates unique token, shortcode, and PIN
- User A sees QR code, share URL, and PIN displayed
- User A shares URL or shows QR code to User B (external)
- User B accesses receive URL or scans QR code
- User B sees "Send Files" page, enters PIN
- User B selects files to send
- P2P Connection established between browsers
- Files transferred directly (P2P) from User B to User A
- User A downloads received files
Technical Implementation
Database Schema
New table p2p_receive_sessions:
CREATE TABLE p2p_receive_sessions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
token VARCHAR(64) NOT NULL UNIQUE,
shortcode VARCHAR(12) NOT NULL UNIQUE,
peerjs_id VARCHAR(64) NULL,
pin VARCHAR(2) NOT NULL,
pin_attempts TINYINT DEFAULT 0,
pin_locked_at DATETIME NULL,
files_metadata TEXT NULL,
created_at DATETIME NOT NULL,
expires_at DATETIME NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT 1,
FOREIGN KEY (user_id) REFERENCES users(id)
);
API Endpoints
| Method |
Endpoint |
Description |
Auth |
| POST |
/api/p2p/receive/create |
Create P2P receive session |
Required |
| GET |
/api/p2p/receive/@token |
Get session metadata |
Public |
| GET |
/p2p/receive/@shortcode |
Render receive page |
Public |
| DELETE |
/api/p2p/receive/@token |
Cancel session |
Required (owner) |
| POST |
/api/p2p/receive/@token/verify-pin |
Verify PIN |
Public |
| POST |
/api/p2p/receive/@token/connect |
Register PeerJS |
Public |
| POST |
/api/p2p/receive/@token/complete |
Complete & save metadata |
Public |
| GET |
/api/p2p/receive |
List user's receive sessions |
Required |
Technical Notes
- Works in offline/local network mode only (same as existing P2P)
- Uses WebRTC with STUN for same-WiFi connections
- Uses PeerJS for different networks (same as existing P2P)
- 2-digit PIN required for MITM protection (same as existing P2P)
- No file size or quantity limits at this stage
- Files never touch Phuppi servers
Files to Create
src/migrations/013_add_p2p_receive_sessions_table.php
src/Phuppi/P2PReceiveSession.php
src/views/p2p-receive-create.latte
src/views/p2p-receive-waiting.latte
src/views/p2p-send.guest.latte
Files to Modify
src/Phuppi/Controllers/P2PController.php - Add receive session methods
src/routes.php - Add routes for receive endpoints
public/assets/js/phuppi-p2p.js - Add receive mode support
Components to Reuse
- QR code generation (
qrcode.js)
- WebRTC/P2P engine (
phuppi-p2p.js)
- PIN verification logic
- PeerJS integration
- STUN server configuration
Implementation Plan
Phase 1: Database & Backend Foundation
Phase 2: Receiver Interface (User A)
Phase 3: Sender Interface (User B - Guest)
Phase 4: P2P Transfer Engine
Phase 5: Polish & Testing
Benefits
| Benefit |
Description |
| No guest account needed |
Anyone can send files without logging in |
| Privacy |
Files never touch Phuppi servers |
| No internet required |
Works over local network |
| Fast |
Limited only by WiFi speed |
| Secure |
PIN-based MITM protection |
| Convenient |
QR code + URL sharing options |
Future Enhancements (Post-MVP)
- Transfer resume for interrupted transfers
- Multiple senders to same session
- Folder support for bulk file transfer
Dependencies
| Library |
Purpose |
Source |
| qrcode.js |
QR code generation |
Bundled |
| peerjs |
WebRTC signaling |
CDN |
| JSZip |
ZIP file creation |
Bundled |
| FileSaver.js |
Save downloaded files |
Bundled |
| qrcode-scanner |
Camera QR scanning |
Bundled |
Summary
Implement a "Reverse P2P" file receiving feature where a logged-in user (User A) can create a receive session and share a URL or QR code with an unregistered user (User B). User B can then select files from their device and send them directly to User A via P2P connection, without the files touching Phuppi servers.
Background
Currently, the P2P file sharing feature allows a logged-in user to send files to another person. This feature implements the reverse scenario: a logged-in user wants to receive files from someone who doesn't have a Phuppi account.
Use cases:
Feature Requirements
Core Functionality
User Flow
Technical Implementation
Database Schema
New table
p2p_receive_sessions:API Endpoints
/api/p2p/receive/create/api/p2p/receive/@token/p2p/receive/@shortcode/api/p2p/receive/@token/api/p2p/receive/@token/verify-pin/api/p2p/receive/@token/connect/api/p2p/receive/@token/complete/api/p2p/receiveTechnical Notes
Files to Create
src/migrations/013_add_p2p_receive_sessions_table.phpsrc/Phuppi/P2PReceiveSession.phpsrc/views/p2p-receive-create.lattesrc/views/p2p-receive-waiting.lattesrc/views/p2p-send.guest.latteFiles to Modify
src/Phuppi/Controllers/P2PController.php- Add receive session methodssrc/routes.php- Add routes for receive endpointspublic/assets/js/phuppi-p2p.js- Add receive mode supportComponents to Reuse
qrcode.js)phuppi-p2p.js)Implementation Plan
Phase 1: Database & Backend Foundation
013_add_p2p_receive_sessions_table.phpP2PReceiveSessionmodel classP2PControllerPhase 2: Receiver Interface (User A)
p2p-receive-create.lattetemplatePhase 3: Sender Interface (User B - Guest)
p2p-send.guest.lattetemplatePhase 4: P2P Transfer Engine
phuppi-p2p.jsfor receive modePhase 5: Polish & Testing
Benefits
Future Enhancements (Post-MVP)
Dependencies