-
Notifications
You must be signed in to change notification settings - Fork 32
Quick Reference
Azhar Zouhir edited this page Jun 11, 2026
·
6 revisions
A quick reference guide for PCLink developers and contributors.
src/pclink/
├── __main__.py, main.py, launcher.py # Entry points
├── api_server/ # FastAPI Web Server
│ ├── api.py # App factory & assembly
│ ├── middleware.py # Auth & Security layers
│ ├── ws_manager.py # WebSocket orchestration
│ └── routers/ # Modular API endpoints
│ ├── auth.py, pairing.py # Connection & Auth
│ ├── file_browser.py, info.py # Core features
│ ├── system.py, processes.py # System control
│ └── desktop_streaming.py, etc. # Advanced features
├── services/ # Business Logic Layer
│ ├── discovery_service.py # Local network discovery
│ ├── transfer_service.py # File upload/download logic
│ ├── input_service.py # Hardware abstractions
│ └── desktop_streaming_service.py # Screen capture engine
├── core/ # System Core
│ ├── server_controller.py # Lifecycle orchestrator
│ ├── startup.py # Boot persistence
│ ├── state.py # Shared memory state
│ ├── device_manager.py # SQL persistence
│ └── config.py, constants.py # App configuration
└── web_ui/ # Built-in Web Dashboard
├── router.py # Page routing
├── templates/ # Jinja2 HTML templates
└── static/ # Modular JS & CSS assets
-
Web Mode (Default) → Web-based interface served at
https://localhost:38080 - Background Mode → Server runs as a background process with system tray integration
- System Tray → Cross-platform tray integration for quick access
-
Entry Point →
main.pystarts the application -
Lifecycle →
server_controller.pyorchestrates server & services - API Server → FastAPI handles mobile app and Web UI requests
-
State →
state.pymanages devices and connections - Web UI → Dynamic pages rendered via Jinja2 and modular JS
-
main.py→ Startup and mode selection -
server_controller.py→ Central lifecycle coordinator -
startup.py→ Boot persistence manager -
api.py→ REST API and authentication assembly -
state.py→ Thread-safe device state management -
system_tray.py→ System tray integration
# Run as a module (recommended)
python -m pclink
# Headless/background mode
python -m pclink --startup# Install in development mode
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
# Run tests
pytest
pytest --cov=src
# Code formatting
black src tests
isort src tests
# Run all pre-commit checks
pre-commit run --all-files
# Type checking
mypy src# Portable archive (one-dir build)
python scripts/build.py --format portable
# Single executable file
python scripts/build.py --format onefile
# Windows installer
python scripts/build.py --format installer
# Linux packages (.deb and .rpm)
python scripts/build.py --format nfpm
# Python wheel distribution
python scripts/build.py --format wheel
# Debug build with console output
python scripts/build.py --debug
# Clean build artifacts first
python scripts/build.py --clean
# Create release
python scripts/release.py --version 4.3.0-
Model →
state.py(application state) -
View →
web_ui/(Jinja2 templates & modular JS) -
Controller →
services/(business logic) &routers/(API handling)
- Ensures only one PCLink instance runs system-wide
- Implemented in
core/singleton.py - Uses mutex (Windows) or file lock (Linux/macOS)
- WebSocket connections for real-time updates
- State changes broadcast to connected clients
- Device connections trigger notifications
- Dynamic API router creation
- Extension loading via
extension_manager.py
-
api.py→ Core API, WebSockets, pairing -
system.py→ Power commands, volume control -
info.py→ System information (CPU, RAM, disk) -
input.py→ Keyboard and mouse input -
media.py→ Media playback control -
file_browser.py→ File system operations & secure sharing -
processes.py→ Process management -
extensions.py→ Extension management -
terminal.py→ WebSocket terminal access -
desktop_streaming.py→ Real-time screen preview
- Per-Device Token-Auth (UUID)
- Managed via
middleware.pyanddevice_manager.py - Required in
X-API-Keyheader for all REST requests
- HTTPS only (self-signed certificates)
- Certificate generation on first run
- Secure device pairing with approval flow
Located in platform-specific app data directory:
-
config.json→ Server settings (port, auto-start, global service toggles) -
devices.db→ SQLite database of paired devices -
cert.pem/key.pem→ SSL certificates
- Port: 38080 (HTTPS)
- Auto-start: Disabled by default
- Discovery: Enabled after setup
Central orchestrator managing:
- Server lifecycle (start/stop/restart)
- Coordination with system tray
- API server initialization
Handles boot persistence:
- OS-specific auto-start registration
- Pre-flight environment setup
Device lifecycle management:
- Registration and approval
- API key generation
- Hardware ID banning
- Device revocation
Configuration persistence:
- Load/save settings
- Default values
- Global service kill-switches
- Server Architecture - Detailed architecture overview
- API Endpoints - Complete API reference
- Setup and Running - Installation guide
- Building and Development - Build instructions
- Extension Development - Create custom features
- Contributing - Contribution guidelines
- Use
--debugflag when building for console output - Check logs in app data directory (
pclink.log) - Use browser DevTools for Web UI debugging
- Enable verbose logging in
core/logging.py
- Write tests for new features
- Test on multiple platforms
- Use pytest fixtures for common setup
- Mock external dependencies
- Profile with
cProfilefor bottlenecks - Use async/await for I/O operations
- Minimize WebSocket message frequency
- Cache expensive computations
- Never commit API keys or certificates
- Validate all user input
- Use parameterized SQL queries
- Keep dependencies updated