PeerLink is a peer-to-peer file sharing application that allows users to share files directly between devices using a simple invite code system.
src/main/java/p2p: Java backend codeApp.java: Main application entry pointcontroller/: API controllersservice/: Business logic servicesutils/: Utility classes
ui/: Next.js frontend applicationsrc/app: Next.js app router pagessrc/components: React components
- Drag and drop file upload
- File sharing via invite codes (port numbers)
- File downloading using invite codes
- Modern, responsive UI
- Direct peer-to-peer file transfer
- Java 11+ (for the backend)
- Node.js 18+ and npm (for the frontend)
- Maven (for building the Java project)
./start.shstart.batThese scripts will build the Java backend, start the server, and launch the frontend development server.
-
Build the Java project:
mvn clean package
-
Run the backend server:
java -jar target/p2p-1.0-SNAPSHOT.jar
The backend server will start on port 8080.
-
Install dependencies:
cd ui npm install -
Run the development server:
npm run dev
The frontend will be available at http://localhost:3000.
-
File Upload:
- User uploads a file through the UI
- The file is sent to the Java backend
- The backend assigns a unique port number (invite code)
- The backend starts a file server on that port
-
File Sharing:
- The user shares the invite code with another user
- The other user enters the invite code in their UI
-
File Download:
- The UI connects to the specified port
- The file is transferred directly from the host to the recipient
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ │ │ │ │ │
│ Next.js UI │◄────►│ Java Server │◄────►│ Peer Device │
│ │ │ │ │ │
└─────────────┘ └─────────────┘ └─────────────┘
classDiagram
%% Frontend Components
class NextJSApp {
+handleFileUpload()
+handleFileDownload()
+connectToPeer()
}
class FileUploadComponent {
+handleDragDrop()
+validateFile()
+uploadFile()
}
class FileDownloadComponent {
+enterInviteCode()
+downloadFile()
+showProgress()
}
%% Backend Components
class App {
+main()
+startServer()
}
class FileController {
+uploadFile()
+generateInviteCode()
+validateInviteCode()
}
class FileService {
+storeFile()
+createFileServer()
+handleFileTransfer()
}
class FileUtils {
+validateFile()
+generatePort()
+cleanupResources()
}
%% Relationships
NextJSApp --> FileUploadComponent
NextJSApp --> FileDownloadComponent
FileUploadComponent --> FileController
FileDownloadComponent --> FileController
FileController --> FileService
FileService --> FileUtils
%% Data Flow
class DataFlow {
FileUpload
FileDownload
InviteCode
PortNumber
}
%% Component Notes
note for NextJSApp "Handles UI state and user interactions"
note for FileController "REST API endpoints for file operations"
note for FileService "Core business logic for file handling"
note for FileUtils "Utility functions for file operations"
-
Frontend Components
NextJSApp: Main application component managing state and routingFileUploadComponent: Handles drag-and-drop file uploadsFileDownloadComponent: Manages file downloads using invite codes
-
Backend Components
App: Main application entry point and server initializationFileController: REST API endpoints for file operationsFileService: Core business logic for file handlingFileUtils: Utility functions for file validation and port management
-
Data Flow
- File uploads are handled through drag-and-drop
- Invite codes (port numbers) are generated for sharing
- Direct peer-to-peer file transfer using WebSocket connections
- This is a demo application and does not include encryption or authentication
- For production use, consider adding:
- File encryption
- User authentication
- HTTPS support
- Port validation and security
For detailed deployment instructions, see DEPLOYMENT.md.
Options include:
- Local network deployment
- Docker deployment (using provided Dockerfile.backend, Dockerfile.frontend, and docker-compose.yml)
- Cloud deployment (Heroku, Railway, Vercel, Netlify)
- VPS deployment
MIT