How remnawave/backend works
Project type and purpose
• This is a NestJS-based modular monolith providing the entire backend for the Remnawave panel.
• It exposes a HTTP/REST API, a CLI, scheduled tasks, and background processors. It uses Prisma/PostgreSQL for persistence, Redis/Bull for job queues, and integrates with external services (Telegram Bot API, Prometheus, webhooks).
File structure at a high level
• Top-level:
• Docker & compose files for local, DB, production
• src/main.ts → starts Nest app
• src/modules/* → domain modules (auth, users, hosts, nodes, subscription, system, etc.)
• src/common/* → cross-cutting utilities (config, database, guards, exception filters, helpers)
• src/integration-modules/* → optional adapters (Prometheus metrics, Telegram Bot, webhook)
• src/queue/* → Bull queue definitions, processors, services
• src/scheduler/* → cron-style task enqueuers and interval tasks
• src/bin/* → CLI tools for docs generation and other command-line operations
• libs/contract → shared DTOs, commands, constants and schemas for frontend & backend
• Persistence layer: prisma/schema.prisma + migrations + prisma.service
• Config: @nestjs/config schemas, .env samples
• Build & CI pipelines: GitHub workflows, Dockerfiles
README for context
• Confirms that this is the backend service for the Remnawave panel.
Main components
A. API Server (NestJS Application)
• HTTP Controller Layer (src/modules/*/…controllers)
• Business & Domain Services (services, converters, builders)
• CQRS Commands & Queries (commands/handlers + queries/handlers)
• Shared modules: config, database (Prisma), exception filters, guards, interceptors
B. Persistence (PostgreSQL via Prisma)
C. Job Queue (Redis + Bull)
• Queue module & service
• Multiple processors (bulk operations, notifications, node-health, record usage, etc.)
D. Scheduler
• Cron/interval tasks that enqueue jobs into Redis queues
E. CLI Tools
• bin/cli and bin/gen-doc for manual invocation
F. Integration Modules (loaded into Nest as modules)
• Prometheus reporter → pushes metrics to Prometheus or exports via Pull endpoint
• Telegram Bot → communicates with Telegram Bot API
• Webhook module → sends HTTP callbacks to configured endpoints
G. External Services
• Telegram Bot API
• Prometheus server
• Webhook targets
• (Optional) Cloudflare, third-party APIs as configured
Relationships and data flows
1. Clients (Browser/Panel frontend) → HTTP(S) → API Server (controllers)
2. API Server ↔ Database (PostgreSQL via Prisma service)
3. API Server → Redis queues (via QueueService) → background processors → Database or external calls
4. Scheduler → Redis queues (schedules recurring jobs)
5. CLI → direct internal Nest command handlers → Database or queue
6. Integration modules subscribe to internal events or are invoked by controllers → External Services
7. Processors may emit application events (e.g., user-expired) for other modules to handle
Architectural patterns and principles
• Modular Monolith: clear separation by domain modules under src/modules
• CQRS: separate commands vs. queries in libs/contract and modules
• Event-driven: Nest’s EventEmitter for cross-module events; queue for async jobs
• Dependency Injection: NestJS providers for services, repositories, converters
• Layered design: Controllers → Services → Repositories → Database
• Infrastructure abstraction: common database, config, and queue modules
Relevant technologies & frameworks
• Node.js, TypeScript, NestJS (modules, controllers, providers, guards, interceptors)
• Prisma ORM + PostgreSQL
• Bull (or BullMQ) + Redis
• GitHub Actions for CI/CD, Docker, docker-compose for local/production
• @nestjs/Config for environment & schemas
• Swagger/OpenAPI (push-openapi-specs workflow)
• Hygen for code scaffolding
Detail is essential
• Piece: controllers, services, repositories, processors, tasks.
• Do not over-abstract—split into as many logical components as needed.