How noph8/dnh works
Project type and purpose
• This is a monolithic full-stack web application built with Flask.
• Purpose: a VPN routing helper (“dnh”) that lets admins register domain names and IP-ranges via a web UI (Flask-Admin) and exposes a REST API endpoint to fetch the consolidated list for VPN routing.
• It also runs a periodic scheduler to refresh DNS lookups of domain names against configured DNS servers.
High-level components
a. Clients
• Admin user’s browser (Web UI)
• API consumer (e.g., router or script calling /api/v1/ip_list)
b. Backend
• Flask application (app/) organized into:
– Blueprints: app/api for REST API; app/dashboard.py + templates/static for Admin UI
– Models: app/models.py (SQLAlchemy ORM)
– Management commands: app/management.py (e.g., createsuperuser)
– Scheduler/tasks: app/scheduler.py, app/tasks.py to periodically resolve domains
– Utilities: app/tools/* (network, datetime, JSON helpers)
• Configuration: config.py + environment variables (.env.template)
c. Data store
• SQLite database (file specified by DB_PATH/DB_NAME)
d. External services
• Upstream DNS servers (configured via DNS_SERVERS)
• Deployment target (Docker container via Dockerfile/docker-compose)
• Optional: OpenWRT/WireGuard router consuming the API
Interactions and data flow
1. Admin logs into Web UI → Flask renders templates (app/templates) → Admin creates/edits domain and IP-range records → writes to SQLite
2. Scheduler (via APScheduler or RQ) wakes every DNS_UPDATE_INTERVAL → tasks use app/tools/network to query DNS servers → updates records/timestamps in DB
3. API client calls /api/v1/ip_list?api_key= → request hits Flask API blueprint → validators check API key → views query DB → response serialized (app/formatters, app/api/v1/validators) → JSON list returned
4. Dockerized deployment: Dockerfile builds image; docker-compose.yml sets up container with .env, mounts volume for DB
Architectural patterns & design principles
• MVC / Blueprint separation:
• Models in app/models.py
• Views & controllers in app/api/* and app/dashboard.py
• Templates & static assets under app/templates + app/static
• Layered services: data layer (SQLite), business logic (tasks, formatters), presentation (templates/API responses)
• Config-over-code: all behavior driven by environment variables via config.py
• Modular utilities: app/tools for cross-cutting concerns
• Call out the main frameworks/libs: “Flask + Flask-Security”, “SQLite”, “APScheduler (or RQ)”.
• Docker boundary and the mounting of the DB file and .env.