- Rust 77.7%
- JavaScript 13.7%
- CSS 2.5%
- Python 2.3%
- HTML 1.7%
- Other 1.9%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
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> |
||
| .cargo | ||
| .claude | ||
| .github/workflows | ||
| .superpowers/sdd | ||
| config | ||
| contract | ||
| crates | ||
| dashboard | ||
| docs | ||
| grafana-dashboards | ||
| helm-charts/takelan-helm | ||
| icons | ||
| monitoring | ||
| observability-stack | ||
| packaging | ||
| scripts | ||
| terraform | ||
| test_configs | ||
| .dockerignore | ||
| .editorconfig | ||
| .env.example | ||
| .gitignore | ||
| .gitlab-ci.yml | ||
| .markdownlint.json | ||
| .pre-commit-config.yaml | ||
| Cargo.lock | ||
| Cargo.toml | ||
| CLAUDE.md | ||
| CONTRIBUTING.md | ||
| docker-compose-ha.yml | ||
| docker-compose-performance.yml | ||
| docker-compose.test.yml | ||
| docker-compose.yml | ||
| Dockerfile | ||
| LICENSE | ||
| POSSIBLE_FIXES.md | ||
| README.md | ||
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.
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
- Docker Compose: docker-compose.yml
- Kubernetes: Helm chart in helm-charts/takelan-helm
- Terraform: terraform/
- Guides: docs/guides/DEPLOYMENT.md, PRODUCTION_DEPLOYMENT_GUIDE.md (some guides still describe the Python version and carry a note saying so)
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.






