-
Notifications
You must be signed in to change notification settings - Fork 32
Quick Reference
Azhar Zouhir edited this page Dec 4, 2025
·
6 revisions
A quick reference guide for PCLink developers and contributors.
src/pclink/
├── __main__.py, main.py, launcher.py # Entry points
├── headless.py # Headless/background mode
├── api_server/ # FastAPI REST API
│ ├── api.py # Main routes & auth
│ ├── discovery.py # Device pairing
│ ├── file_browser.py # File operations
│ ├── process_manager.py # Process control
│ ├── applications_router.py # App discovery & launch
│ ├── macro_router.py # Macro execution
│ └── terminal.py # Shell access
├── core/ # Business logic
│ ├── controller.py # Main orchestrator
│ ├── state.py # Global state management
│ ├── device_manager.py # Connection tracking
│ ├── constants.py # App configuration
│ ├── system_tray.py # System tray integration
│ └── utils.py, etc. # Utilities
├── web_ui/ # Web interface
│ ├── router.py # Web UI router
│ └── static/ # HTML, CSS, JS files
└── assets/ # Icons & resources
-
Web Mode (Default) → Web-based interface served at
https://localhost:38080 -
Headless Mode → Background server with
HeadlessAppand system tray - System Tray → Cross-platform tray integration for quick access
-
Entry Point →
main.pystarts the application -
Controller →
controller.pyorchestrates server & services - API Server → FastAPI handles mobile app requests
-
State →
state.pymanages devices and connections - Web UI → Real-time updates via WebSocket connections
-
main.py→ Startup and mode selection -
headless.py→ Headless application manager -
controller.py→ Central coordinator -
api.py→ REST API and authentication -
state.py→ Thread-safe device state management -
system_tray.py→ System tray integration
# Run as a module (recommended)
python -m pclink
# Direct execution
python src/pclink/main.py
# Headless/background mode
python -m pclink --startup
# Using convenience script
python run_pclink.py# Install in development mode
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
# Run tests
pytest
pytest tests/unit/
pytest tests/integration/
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 1.2.0-
Model →
state.py(application state) -
View →
web_ui/(web interface) -
Controller →
controller.py(business logic)
- 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
- Dialog creation based on context
-
api.py→ Core API, WebSockets, pairing -
system_router.py→ Power commands, volume control -
info_router.py→ System information (CPU, RAM, disk) -
input_router.py→ Keyboard and mouse input -
media_router.py→ Media playback control -
utils_router.py→ Clipboard, screenshots -
file_browser.py→ File system operations -
process_manager.py→ Process management -
terminal.py→ WebSocket terminal access
- API key-based authentication (UUID)
- Stored in device database
- Required in
X-API-Keyheader for all 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, etc.) -
devices.db→ SQLite database of paired devices -
cert.pem/key.pem→ SSL certificates -
api_key.txt→ Main API key
- Port: 38080 (HTTPS)
- Auto-start: Disabled by default
- Discovery: Enabled after setup
- Insecure shell: Disabled by default
Central orchestrator managing:
- Server lifecycle (start/stop/restart)
- Device connections
- Discovery service
- Configuration changes
Thread-safe state management:
- Connected devices list
- Server status
- Real-time updates via WebSocket
Device lifecycle management:
- Registration and approval
- API key generation
- Connection tracking
- Device revocation
Configuration persistence:
- Load/save settings
- Default values
- Platform-specific paths
- Server Architecture - Detailed architecture overview
- API Endpoints - Complete API reference
- Setup and Running - Installation guide
- Building and Development - Build instructions
- 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