How pasarguard/panel works
Project Type and Purpose
• PasarGuard is a full-stack, proxy-management platform combining:
• A Python-based REST API backend (FastAPI or similar)
• A React.js dashboard frontend
• A CLI and TUI client
• Multi-node support via Xray-core agents
• Notification integrations (Telegram, Discord, Webhook)
File Structure
• Top-level directories:
• app/ → Core backend service (routers, DB models, business logic, jobs, notification clients)
• dashboard/ → React.js SPA (Vite, Tailwind CSS) for the web UI
• cli/ → Command-line interface for administrative operations
• tui/ → Text-UI client for terminal use
• tests/ → API and functional tests
• config files → Dockerfile, docker-compose.yml, alembic.ini, pyproject.toml
• scripts → install_service.sh, start.sh, build_dashboard.sh
• Key backend substructures:
• app/routers → HTTP endpoints grouping (authentication, admin, host, user, etc.)
• app/operation → Application services layer (business use-cases)
• app/core → Low-level integrations (Xray control, host manager)
• app/db → Database schema (SQLAlchemy), CRUD, Alembic migrations
• app/notification → Clients for Telegram, Discord, Webhook
• app/subscription → Logic to build and share proxy subscription links
• app/jobs → Periodic tasks (cleanup, notifications, usage recording)
• Frontend structure:
• src/pages, src/components → Visual pages, UI components, charts, dialogs
• src/service/api → HTTP client to backend
• Deployment:
• Dockerfile & docker-compose.yml
• .env files, Makefile, CI workflows (.github/workflows)
README for Additional Insights
• Describes multi-node proxy distribution via Xray-core
• REST API + Web UI + CLI + Telegram Bot + Discord support
• Supports Vmess, VLESS, Trojan, Shadowsocks protocols
• Subscription link generator (Clash, Singbox, Outline) and QR code creation
a. Main Components
• Web Dashboard (React.js SPA)
• REST API Backend (Python service)
• Database (PostgreSQL / TimescaleDB / MySQL / SQLite)
• Xray-core Proxy Nodes (multiple distributed agents)
• CLI & TUI Clients (pasarguard CLI, TUI)
• Notification Services (Telegram Bot, Discord Bot, Webhook endpoint)
b. Relationships & Data Flows
• Dashboard ↔ Backend: HTTPS REST calls (GET/POST)
• Backend ↔ Database: SQLAlchemy ORM queries & migrations
• Backend ↔ Xray-core Nodes: RPC or file-based config deployment
• Backend ↔ Notification Clients: HTTP API calls (Telegram Bot API, Discord webhooks)
• CLI/TUI ↔ Backend: Direct Python modules or REST API calls
• Subscription Generation: Backend reads DB & node data → builds subscription payload → served via API
c. Architectural Patterns & Principles
• Layered architecture: Routers → Operation (services) → Core integrations → DB layer
• Modular plugins: notification clients, subscription formats
• Asynchronous jobs for periodic tasks (cleanup, stats, notifications)
• Infrastructure as code: Docker, Compose, CI pipelines
d. Key Technologies
• Backend: Python 3.x, FastAPI (or similar), SQLAlchemy, Alembic, Xray-core
• Frontend: React.js, Vite, TypeScript, Tailwind CSS
• CLI/TUI: Python click / textual (TUI)
• Database: PostgreSQL / TimescaleDB / MySQL / SQLite
• Notifications: Telegram Bot API, Discord Webhooks
• Deployment: Docker, docker-compose, shell scripts