9.7 KiB
AI Context for D3V-Server
This file is the fast-start map for AI agents working in this repository. Read this first. Do not scan the entire repo unless the task actually requires it.
1. What this project is
D3V-Server is a custom fork of Nginx Proxy Manager / xGat3 with an added
WireGuard management module and some project-specific admin features.
Canonical repository:
https://src.d3v.ac/xtcnet/D3V-Server
Treat that repository as the source of truth for this project. If another upstream is mentioned, assume it is a historical ancestor or reference, not the primary project remote, unless the task says otherwise.
At a high level:
backend/is the API server and system orchestration layer.frontend/is the admin web UI.docker/is the production runtime assembly.test/contains Cypress and API-spec checks.docs/is a separate VitePress docs site.
The production app is not "just backend" or "just frontend": Docker assembles the backend and the prebuilt frontend into one image.
2. Repo map
D3V-Server/
|- backend/ Node.js + Express API, DB, WireGuard logic
| |- routes/ REST endpoints
| |- internal/ background/system services
| |- models/ Objection models
| |- migrations/ Knex migrations
| |- schema/ API schema compilation
| |- templates/ config/template generation
| |- app.js Express app wiring
| `- index.js backend startup entry
|- frontend/ React + TypeScript + Vite SPA
| |- src/
| | |- pages/ top-level screens
| | |- components/ shared UI
| | |- hooks/ data and UI hooks
| | |- api/ backend API wrappers
| | |- modals/ modal flows
| | |- context/ auth/theme/locale providers
| | |- Router.tsx route table
| | `- main.tsx frontend entry
| `- vite.config.ts dev/build config
|- docker/ production image and runtime scripts
|- docs/ VitePress docs site
|- test/ Cypress E2E and swagger lint
|- scripts/ helper scripts
|- install.sh install/update/reset automation for deployment
`- README.md user-facing overview
3. Runtime architecture
flowchart LR
A["Browser"] --> B["Frontend SPA<br/>frontend/src/main.tsx"]
B --> C["React Router + pages<br/>frontend/src/Router.tsx"]
C --> D["Backend API<br/>backend/app.js"]
D --> E["Route handlers<br/>backend/routes/*"]
E --> F["Models / DB<br/>Knex + Objection"]
D --> G["Internal services<br/>backend/internal/*"]
G --> H["WireGuard CLI / system state"]
I["docker/Dockerfile"] --> D
I --> B
4. First files to open for orientation
If a new session needs project understanding, open these files in order:
AI_CONTEXT.mdREADME.mdbackend/index.jsbackend/app.jsbackend/routes/main.jsfrontend/src/main.tsxfrontend/src/App.tsxfrontend/src/Router.tsxdocker/Dockerfile- the relevant package manifest for the area being changed
That is usually enough to understand the system without scanning everything.
5. How the backend starts
Main entry: backend/index.js
Startup flow:
- Run DB migrations via
migrateUp() - Run setup/bootstrap via
setup() - Compile/load schema via
getCompiledSchema() - Optionally fetch IP ranges
- Start timers for internal certificate/IP-range jobs
- If
WG_ENABLED != false, start WireGuard service hooks - Start Express server on port
3000
Important implication:
- Many issues that look like "API bugs" can actually come from startup/setup/migration state.
- WireGuard startup failure is logged, but the backend may continue without WireGuard functionality.
6. How the backend is organized
Core files:
backend/index.js: process startup and shutdownbackend/app.js: Express middleware, helmet, rate limit, auth, route mountingbackend/routes/main.js: root API routerbackend/db.js: DB handle creationbackend/lib/config.js: database/config/env resolutionbackend/setup.js: instance bootstrap/setup flow
Important route groups from backend/routes/main.js:
/api/schema/api/tokens/api/users/api/audit-log/api/reports/api/settings/api/version/api/nginx/proxy-hosts/api/nginx/redirection-hosts/api/nginx/dead-hosts/api/nginx/streams/api/nginx/access-lists/api/nginx/certificates/api/wireguard/api/database
Public WireGuard portal:
backend/app.jsmountswg_publicbefore JWT middleware at/wg-public- frontend has a dedicated route branch for
/wg-public
7. How the frontend is organized
Entry path:
frontend/src/main.tsx->frontend/src/App.tsx->frontend/src/Router.tsx
Frontend routing model:
Router.tsxchecks health/setup/auth before rendering the main app/wg-public/*bypasses the standard authenticated admin shell- most admin pages are lazy-loaded from
frontend/src/pages/*
Useful places by task:
- New screen or route:
frontend/src/Router.tsxandfrontend/src/pages/ - Backend API bindings:
frontend/src/api/ - Server state/query logic:
frontend/src/hooks/ - Shared app state:
frontend/src/context/ - Reusable UI:
frontend/src/components/ - Modal workflows:
frontend/src/modals/
8. Build, test, lint commands
This repo is multi-package. There is no obvious root workspace command. Run commands in the relevant subdirectory.
Backend
Working directory: backend/
yarn lintyarn prettieryarn validate-schemayarn regenerate-config- likely local start:
node index.js
Frontend
Working directory: frontend/
yarn devyarn buildyarn lintyarn previewyarn testyarn locale-extractyarn locale-compileyarn locale-sort
Docs
Working directory: docs/
yarn devyarn buildyarn preview
Test
Working directory: test/
yarn cypressyarn cypress:headlessyarn cypress:devyarn swagger-lint
Full build
The production Docker build expects the frontend to be built first.
Common flow:
- build frontend in
frontend/ - build image with
docker/Dockerfile
Helper script:
scripts/build-project.sh
9. Key technologies
- Backend: Node.js, Express 5, Knex, Objection, AJV
- Databases: SQLite by default, MySQL/Postgres supported
- Frontend: React, TypeScript, Vite, React Router, TanStack Query, Tabler UI
- Testing: Vitest for frontend, Cypress for E2E
- Packaging/runtime: Docker, nginx, s6 overlay
- System integration: WireGuard CLI tools inside the container/runtime
10. Configuration model
The backend resolves configuration in this order:
- JSON config file from
NODE_CONFIG_DIR/config/*.json - environment variables
- SQLite fallback using
/data/database.sqlite
Important file:
backend/lib/config.js
Notes:
- JWT keys are persisted to
/data/keys.json - default DB fallback is SQLite
- production behavior often depends on mounted volumes and env vars, not just source code
11. WireGuard-specific map
When the task is specifically about WireGuard, start here:
backend/internal/wireguard.jsbackend/routes/wireguard.jsbackend/routes/wg_public.jsfrontend/src/pages/WireGuard/frontend/src/api/backend/wireguard.tsfrontend/src/hooks/useWireGuard.ts- relevant migration files in
backend/migrations/
Operational assumptions:
WG_ENABLEDcontrols whether WireGuard startup hooks run- runtime requires container/network capabilities such as
NET_ADMIN - some behavior only makes sense inside the Dockerized runtime
12. Production packaging model
Production image definition:
docker/Dockerfile
Important facts:
- it copies
backend/into/app - it copies
frontend/distinto/app/frontend - it installs runtime dependencies inside the image
- it relies on s6-overlay and rootfs scripts
This means:
- frontend must be built before image build
- Docker/runtime files are part of app behavior, not just deployment plumbing
13. Known gotchas
docker/Dockerfileassumesfrontend/distalready exists- several scripts are shell-oriented and may be awkward on native Windows
- docs and names are inherited from upstream in places, so naming is mixed:
nginx-proxy-manager,xGat3,D3V-Server,D3V-NPMWG README.mdcurrently has encoding artifacts; do not assume every displayed character is trustworthy- backend package has no clear
startscript, so usebackend/index.jsas the canonical runtime entry - do not treat this as a simple SPA-only repo or API-only repo; the Docker assembly matters
14. Change strategy for AI agents
When handling a task:
- Read this file
- Open only the subsystem entry files for the relevant area
- Avoid broad repo scans unless the task is cross-cutting
- Verify whether the change affects Docker/runtime assumptions
- If the task touches WireGuard, include container/runtime implications in reasoning
Open only what you need:
- backend bug:
backend/index.js,backend/app.js, matching route/service/model files - frontend bug:
frontend/src/main.tsx,App.tsx,Router.tsx, matching page/hook/api files - build/deploy bug:
docker/Dockerfile,scripts/build-project.sh,install.sh - auth/setup issue:
backend/setup.js,backend/routes/tokens.js,frontend/src/context/
15. Fast summary
If you only remember one thing:
D3V-Server is a Docker-assembled full-stack app where:
- backend runs the API and system logic
- frontend is a Vite React admin UI
- WireGuard is an integrated subsystem, not a separate service
- Docker/runtime files are part of the product behavior
backend/index.js,backend/app.js,backend/routes/main.js,frontend/src/main.tsx,frontend/src/App.tsx,frontend/src/Router.tsx, anddocker/Dockerfileare the core orientation files