A production-ready, high-performance load balancer and API Gateway written in Python with async/await architecture. Supports multiple protocols (TCP, UDP, HTTP, HTTPS, HTTP/2, HTTP/3) with advanced routing, caching, health checking, and comprehensive monitoring.
  • Rust 77.7%
  • JavaScript 13.7%
  • CSS 2.5%
  • Python 2.3%
  • HTML 1.7%
  • Other 1.9%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Derek Demuro 6cde7962dd
CI: use dependencies instead of needs
The takelan GitLab instance rejects the needs keyword (a job may need 0 others), so
the pipeline could not be created. Jobs follow stage order and fetch artifacts with
dependencies.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-18 00:42:45 -05:00
.cargo Reduce build load and disk: mold, no incremental, shared target, nextest 2026-11-17 21:36:48 -05:00
.claude Remove invalid wildcard allow rule from local Claude settings 2026-10-05 22:54:35 -04:00
.github/workflows Run the nginx differential suites in CI 2026-11-06 21:26:39 -05:00
.superpowers/sdd Merge HK: housekeeping, harness resource caps, deviation table 2026-11-07 20:25:16 -05:00
config Remove the Python implementation, tests and packaging 2026-10-05 18:00:51 -04:00
contract Merge branch 'worktree-agent-a2eb8c1ac3a76ed6e' into port_to_rust 2026-11-18 00:08:44 -05:00
crates Parse JSON floats exactly so replicated timestamps keep their fingerprint 2026-11-18 00:23:12 -05:00
dashboard Merge branch 'worktree-agent-a2eb8c1ac3a76ed6e' into port_to_rust 2026-11-18 00:08:44 -05:00
docs Merge branch 'worktree-agent-a4d6d47cec11ee547' into port_to_rust 2026-11-18 00:08:45 -05:00
grafana-dashboards Serve dashboard metrics on the Prometheus scrape target; add check script, docs and dashboard fixes 2026-10-05 18:26:29 -04:00
helm-charts/takelan-helm Document high availability: gossip and shared-store clusters 2026-11-06 23:32:56 -05:00
icons Add SVG/PNG icons and PyInstaller frozen executables 2026-02-04 18:04:16 -05:00
monitoring Add Rust multi-stage Dockerfile and update compose, Helm, Grafana and CI 2026-10-05 16:05:35 -04:00
observability-stack Cleanup repo 2025-10-26 04:46:19 -04:00
packaging Add release pipeline: packages, CDN publish, installer, CI 2026-11-17 23:43:27 -05:00
scripts Add release pipeline: packages, CDN publish, installer, CI 2026-11-17 23:43:27 -05:00
terraform Terraform parity: docs, verified example, bridge private-CA trust 2026-10-06 10:06:40 -04:00
test_configs Add dashboard redesign and nginx config importer 2026-10-05 15:14:08 -04:00
.dockerignore Fix doc links broken by the Python removal and by earlier doc moves 2026-10-05 18:12:16 -04:00
.editorconfig Finished fixing linting and other stupid stuff 2025-07-28 21:28:35 -04:00
.env.example Document the release publishing variables in .env.example 2026-11-17 23:34:15 -05:00
.gitignore Stop tracking the target symlink and ignore it 2026-11-17 22:16:50 -05:00
.gitlab-ci.yml CI: use dependencies instead of needs 2026-11-18 00:42:45 -05:00
.markdownlint.json Finished fixing linting and other stupid stuff 2025-07-28 21:28:35 -04:00
.pre-commit-config.yaml Replace Python CI, compose, pre-commit and ignore files with Rust equivalents 2026-10-05 18:04:03 -04:00
Cargo.lock Fix merged task list length and apply fmt after the W3/W5 merges 2026-11-17 13:47:02 -05:00
Cargo.toml Parse JSON floats exactly so replicated timestamps keep their fingerprint 2026-11-18 00:23:12 -05:00
CLAUDE.md Add release pipeline: packages, CDN publish, installer, CI 2026-11-17 23:43:27 -05:00
CONTRIBUTING.md Rewrite README, CLAUDE.md and CONTRIBUTING for the Rust project 2026-10-05 18:11:06 -04:00
docker-compose-ha.yml Document high availability: gossip and shared-store clusters 2026-11-06 23:32:56 -05:00
docker-compose-performance.yml Replace Python CI, compose, pre-commit and ignore files with Rust equivalents 2026-10-05 18:04:03 -04:00
docker-compose.test.yml Replace Python CI, compose, pre-commit and ignore files with Rust equivalents 2026-10-05 18:04:03 -04:00
docker-compose.yml Document high availability: gossip and shared-store clusters 2026-11-06 23:32:56 -05:00
Dockerfile Add Docker monitor and cleanup warnings (W7) 2026-11-16 23:21:27 -05:00
LICENSE Add license 2025-08-29 03:55:22 -04:00
POSSIBLE_FIXES.md Cut per-request allocations in the proxy path; add CPU pinning to the bench gate 2026-11-06 02:34:32 -05:00
README.md Add release pipeline: packages, CDN publish, installer, CI 2026-11-17 23:43:27 -05:00

TakeLAN Load Balancer & API Gateway

A load balancer and API gateway written in Rust, with a React dashboard, Prometheus metrics and Grafana dashboards. It started as a Python application; the Rust port is behavior-compatible with it (see docs/rust-port/PARITY.md).

Features

Load balancing

  • TCP, UDP, HTTP/HTTPS (HTTP/1.1 and HTTP/2) and WebSocket proxying
  • Round robin, weighted, least connections and IP hash balancing
  • Active health checks per protocol with automatic failover and recovery
  • Sticky sessions, circuit breaker and retries

API gateway

  • Routing by path, regex, host, header and query parameter; per-route timeouts and rate limits
  • Blake2-keyed response cache (memory, Redis, disk or hybrid) and a CDN mode for static assets (LRU, gzip/brotli)
  • TLS termination in edge, bridge and passthrough modes
  • OpenAPI import, header and body transformation, request mirroring, gRPC support
  • AutoDNS: generated subdomains published through a hosts-file, systemd-resolved or DNS API backend

Security

  • WAF with default SQL injection, XSS, traversal, LFI, RCE and command injection rules
  • DDoS, abuse and bot protection, IP reputation, banning and whitelisting, geo-blocking
  • JWT / API-key / OAuth authentication, users and roles, audit logging, customizable error pages

Operations

  • Management REST API (about 540 operations, described by contract/openapi.json)
  • Dashboard served from the API port, Prometheus metrics, Grafana dashboards
  • nginx configuration and certificate import, blue-green and canary deployments
  • Docker discovery: containers with takelan.* labels register themselves (tgatedocker)
  • MCP server (tgate-mcp): manage everything from Claude Code or opencode in plain language, with confirmation for destructive actions and a read-only mode (docs/guides/MCP.md)

Install

Static Linux binaries (x86_64, aarch64), .deb, .rpm, .tar.gz, AppImage and container images: curl -fsSL https://cdn.takelan.com/tgate/install.sh | sh (--version X.Y.Z, --only tgatedocker). Artifacts, verification and how releases are cut: docs/guides/RELEASING.md.

Quick start

Everything runs in Docker; you do not need Rust or Node.js installed.

docker compose up -d --build        # tgate, redis, prometheus, grafana
What Where
Dashboard and REST API http://localhost:8000
OpenAPI document http://localhost:8000/openapi.json
Prometheus http://localhost:9090
Grafana http://localhost:3000 (admin / admin; dashboards are imported automatically)

Logging in

There is no default password. On first start tgate generates a random admin password and prints it once:

docker compose logs tgate | grep -A3 "generated admin credentials"    # username: admin

Only its argon2id hash is stored, in the account store (users.json in the tgate-data volume, together with a generated JWT signing secret), so later starts reuse it silently. The account is flagged must_change_password (reported in the login response) until you change it with POST /api/v1/auth/change-password.

Accounts are durable: users, password changes, API keys and the account audit trail survive restarts, crashes and kill -9 (an acknowledged change is on disk). Changing a password signs out every session of that user. The stored account wins over the environment, so TGATE_ADMIN_PASSWORD only sets the first admin password. Lost it? docker compose exec tgate tgate config users reset-admin prints a new one. Back up users.json and audit.jsonl in the data volume; use TGATE_USERS_STORE=redis to share accounts between replicas. Details: Authentication guide.

To choose your own, copy .env.example to .env and set TGATE_ADMIN_PASSWORD (at least 8 characters, not admin/password) and TGATE_JWT_SECRET (openssl rand -hex 32). tgate refuses to start with a weak admin password or with the old hardcoded JWT secret. POST /api/v1/auth/register is closed (403) unless TGATE_ALLOW_REGISTRATION=true; an authenticated admin can always create users. Helm: see the auth: values in helm-charts/takelan-helm/values.yaml (a Secret with random values is created by default).

Create a pool, a gateway and a route (this is what scripts/perf/load.js automates):

curl -s -X POST localhost:8000/api/v1/upstreams/pools -H 'content-type: application/json' \
  -d '{"name":"web","protocol":"http","algorithm":"round_robin"}'
# then POST /api/v1/upstreams/pools/{id}/servers, /api/v1/gateway/gateways and /api/v1/gateway/gateways/{id}/routes

Building and testing

All cargo commands go through a Docker wrapper that caches into target/ and .cargo-home/ (both gitignored):

./scripts/cargo.sh build --release            # binaries land in target/release/
./scripts/cargo.sh test --workspace           # run with TGATE_STRICT_CONTRACT=1 to require every contract operation to be routed
./scripts/cargo.sh clippy --workspace --all-targets -- -D warnings
./scripts/cargo.sh fmt --all
docker build --target tgate -t tgate .        # runtime image (also targets: tgatedocker, dashboard)

Binaries

Binary Purpose
tgate tgate serve runs the API, dashboard and proxy listeners; tgate config ... edits the local YAML (upstreams, gateways, routes)
tgatecli REST client for a running tgate: status, hosts, deployments, security, ratelimit, health, metrics, config, service
tgatedocker Docker integration daemon (setup, daemon, status, logs)
tgate-install Post-install setup (systemd unit, user and directories)

Configuration

The config file is the first one found of: $LB_CONFIG_PATH, config/default.yaml, config/config.yaml, /etc/tgate/config.yaml, ~/.config/tgate/config.yaml. Environment variables override it:

Variable Meaning
LB_API_HOST, LB_API_PORT API and dashboard bind address (default 0.0.0.0:8000)
LB_LOG_LEVEL, LB_LOG_FILE, LB_LOG_JSON Logging
LB_DB_TYPE, LB_REDIS_URL, LB_REDIS_PASSWORD, LB_REDIS_DB Storage backend (memory or redis)
LB_METRICS_ENABLED, LB_METRICS_PORT Metrics
LB_API_KEY, LB_CORS_ORIGINS / TGATE_CORS_ORIGINS API key and CORS (CORS is off unless set)
TGATE_ADMIN_PASSWORD, TGATE_JWT_SECRET Admin password and token signing secret; generated and persisted in TGATE_DATA_DIR when unset (see Logging in)
TGATE_USERS_STORE file (default, users.json in TGATE_DATA_DIR), redis (shared; uses LB_REDIS_URL; also chosen by LB_DB_TYPE=redis) or memory (accounts forgotten on restart)
TGATE_ALLOW_REGISTRATION true lets anyone call POST /api/v1/auth/register (default closed)
TGATE_DASHBOARD_DIR Directory of the built dashboard (the image sets /app/dashboard/build)
TGATE_DATA_DIR Generated credentials, imported certificates, nginx config backups and uploads (default ./data; /var/lib/takelan in the image)
TGATE_IMPORT_ALLOWED_DIRS :-separated extra roots that POST /api/v1/config/import-nginx-directory may read, e.g. /etc/nginx (default: only the data-dir upload, backup and certificate folders; see nginx import)
TGATE_PEERS Comma-separated peer host:port addresses for cluster sync (last-writer-wins state replicated over TCP gossip, persisted to an op-log and snapshot in TGATE_DATA_DIR; no external store); unset = standalone
TGATE_SYNC_PORT TCP port the cluster sync gossip listener binds (default 7420)
TGATE_SYNC_SECRET Shared secret (at least 32 bytes, the same on every node) that authenticates and encrypts cluster gossip; required when TGATE_PEERS/TGATE_SYNC_PORT is set
TGATE_SYNC_INSECURE 1 runs cluster gossip in plaintext without a secret (trusted networks only)
TGATE_CLUSTER_ID, TGATE_CLUSTER_NODE_TTL_SECS, TGATE_CLUSTER_LEADER, TGATE_SYNC_INTERVAL_MS, TGATE_SYNC_TOMBSTONE_TTL_HOURS High availability tuning (cluster name, liveness, leadership rule, gossip timing); see docs/guides/HA.md
TGATE_STATE_REFRESH_MS With TGATE_STATE_STORE=redis: how often replicas poll for each other's changes (default 1000)
TGATE_NODE_ID Cluster sync node id; generated once and persisted in TGATE_DATA_DIR when unset
TGATE_WEBHOOK_DELIVERY on (default) runs the built-in webhook delivery worker (backoff retries, HMAC signatures); off restores the queue-only behaviour

Default error pages live in config/error-pages; mount your own over /etc/tgate/error-pages.

Dashboard

The dashboard is a React app in dashboard/. The Docker image builds it and tgate serve serves it from the API port.

Dashboard: live request, latency and upstream health overview

Upstream pools: servers, algorithm and health per pool Gateways and routes: path/host routes with cache and pool per route
Upstream pools: backends, balancing algorithm, health checks Gateways and routes: routing by path and host, per-route cache
Security: banned IPs, threat events and DDoS status Setup wizard: guided creation of pool, servers, listener and protection
Security: IP bans, WAF and DDoS status Setup wizard: pool, servers, listener and protection in seven steps
Certificates: ACME and uploaded certificates per listener Docker agent: one-line install and label-driven exposure
Certificates: ACME and uploaded certificates Docker agent: label-driven exposure of containers

The screenshots show a demo instance with three backends; see docs/guides/WIZARD.md and docs/guides/DOCKER_AGENT.md. For development against a running API on localhost:8000:

docker run --rm -it --network host -v "$PWD/dashboard":/app -w /app node:20 \
  sh -c "npm ci --legacy-peer-deps && npm start"      # http://localhost:3000, proxied to :8000

Monitoring

docker-compose.yml starts Prometheus (scraping /api/v1/metrics/prometheus and /api/v1/gateway/metrics/prometheus) and Grafana with the dashboards from grafana-dashboards/ and monitoring/. observability-stack/ is a fuller stack (Loki, Tempo, Mimir, Alertmanager). Metric names and the dashboards' expectations are in docs/rust-port/METRICS_CONTRACT.md.

Load testing: docker compose -f docker-compose.yml -f docker-compose-performance.yml --profile load up --build --abort-on-container-exit load-tester (k6 through the gateway, results visible in Grafana).

Deployment

Repository layout

Cargo.toml, Cargo.lock      Rust workspace
crates/
  tgate-core/               models, config, errors (wire formats cross-checked against contract/openapi.json)
  tgate-engine/             load balancing engine: algorithms, pools, health checks, sessions, protocol proxies
  tgate-gateway/            API gateway: router, cache, CDN, SSL, OpenAPI import, AutoDNS, metrics
  tgate-security/           WAF, DDoS/abuse protection, reputation, rate limiting, auth, error pages
  tgate-storage/            memory and Redis storage backends
  tgate-nginx-import/       nginx config parser and converter
  tgate-api/                axum REST API, dashboard serving (one module per route group)
  tgate-server/             wires engine, gateway, security and API into one process
  tgate-cli/                tgate, tgatecli, tgate-install
  tgatedocker/              Docker discovery daemon
dashboard/                  React dashboard
contract/openapi.json       API contract captured from the Python implementation
config/                     default config and error page templates
grafana-dashboards/, monitoring/, observability-stack/   Grafana, Prometheus and the full observability stack
helm-charts/, terraform/, docker-compose*.yml, Dockerfile
scripts/                    cargo.sh (Docker cargo), parity harness, perf test, helpers
docs/                       documentation (docs/rust-port/ covers the port)

The Python reference

The original Python implementation is kept at the git tag python-reference. It is only needed to regenerate test fixtures and to run the parity harness; scripts/parity/with-python-reference.sh handles both. docs/rust-port/NOT_PORTED.md lists what was not carried over.

License

GNU Affero General Public License v3. See LICENSE.