This repository contains the backend implementation of the FluxGate feature flag management system. The main service is the Rust backend in feature-toggle-backend, but the workspace also includes the evaluation engine, edge server, shared types, and API tests that support the full control plane and data plane.
The backend is responsible for:
- managing teams, environments, contexts, clients, features, stages, criteria, variants, approvals, and notifications
- authenticating users and system clients
- enforcing RBAC and team-scoped authorization policies
- serving the REST admin API and OpenAPI spec
- serving the gRPC API used by the edge server
- broadcasting feature updates to connected edge nodes
- collecting and aggregating evaluation and experiment metrics
- enforcing rollout safety, kill switches, approval workflows, and canary rollback gates
The workspace is defined in Cargo.toml and currently contains four Rust crates:
feature-toggle-backend: the control-plane service and source of truthevaluation-engine: the pure evaluation library used by backend and edgefeature-edge-server: the low-latency evaluation gateway that subscribes to backend updatesfeature-toggle-shared: shared types/utilities used across crates
There is also an api-tests folder for end-to-end API coverage and a docs folder for contract and integration documentation.
The backend entrypoint is main.rs, which delegates to lib.rs. On startup the service:
- loads configuration
- opens a PostgreSQL pool from
DATABASE_URL - runs SQLx migrations automatically
- constructs repositories and logic services
- initializes JWT secret state
- starts the gRPC server on a separate task
- starts background schedulers for rollback, metrics, approvals, and canary governance
- starts the Actix REST server
Implementation is organized into these layers:
src/database: SQLx-backed repositories and database-facing modelssrc/logic: application services and domain workflowssrc/rest: REST handlers, DTOs, OpenAPI registration, and websocket streamssrc/grpc: gRPC service definitions and backend-to-edge streamingsrc/middleware: access logging, admin bootstrap guard, and JWT/policy enforcementsrc/scheduler: recurring jobs for operational workflowssrc/cluster: optional multi-node replication and discovery
The admin API is exposed under /api/v1. Route registration is centralized in rest/mod.rs.
The REST surface covers:
- authentication and password flows
- teams, users, roles, and system clients
- environments, contexts, clients, and pipelines
- feature CRUD, stage changes, kill switches, rollout metrics, and approvals
- criteria/rule groups/variant allocations
- metrics ingestion and analysis
- canary gate configuration and manual analysis
- notifications and live stream endpoints
OpenAPI is generated directly from code and exposed through:
GET /api/v1/openapi.jsonGET /docs
The backend also serves gRPC on port 50051 by default. It is used primarily by the edge server for:
- feature fetch by key
- client metadata lookup
- streaming feature snapshots and incremental updates
- evaluation event and assignment flushes
- metric tracking
The gRPC implementation lives in grpc/mod.rs.
Flag evaluation logic is implemented in the shared evaluation-engine. The backend maps database entities into engine features and uses the same model as the edge server, which keeps evaluation behavior consistent.
The evaluator supports:
- simple and contextual features
- environment-specific stages
- ordered criteria and rule groups
- weighted variant allocation and specific variant selection
- deterministic bucketing
- dependency graph evaluation
- structured dependency-block reasons in evaluation metadata
Recent backend changes added stronger rollout controls:
- dependency graph validation during feature create/update
- cycle detection for feature dependencies
- stage deployment requests blocked when required dependencies are missing, disabled, or not deployed in the target environment
- explicit dependency-block reason codes returned by the evaluator
The rollout safety logic lives in dependency_graph.rs and is enforced during stage changes in feature.rs.
The backend supports emergency disable/enable flows and scheduled rollback enforcement. The rollback scheduler runs in the background and broadcasts feature updates so connected edges can invalidate stale state.
The backend now supports canary analysis gates stored in the database and evaluated by a scheduler. A gate can compare baseline vs canary variants using a metric, minimum sample size, direction, and regression threshold. Failed gates can automatically trigger the existing emergency disable path.
Relevant files:
The backend has two primary caller types:
- human users authenticated with JWTs
- system clients authenticated for machine-to-machine access
Middleware and policy enforcement live in:
The implementation includes:
- bootstrap admin creation only when no admin exists yet
- JWT token validation against persisted token records
- system client token support
- centralized policy checks for privileged admin and team-scoped mutations
- audit entries for policy allow/deny decisions and operational events
Activity and audit data are persisted through the activity log repository under src/database/activity_log.rs.
The backend stores evaluation and experiment data and exposes analytics APIs for the UI. The metrics subsystem supports:
- raw metric event tracking
- feature evaluation summaries and rates
- experiment result queries
- feature growth and recent activity views
- scheduled metric aggregation
The main implementation is in metrics.rs and rest/metrics.rs.
The backend config model is defined in config.rs. Configuration is loaded in this order:
FEATURE_TOGGLE_CONFIGfeature-toggle-backend/config.tomlconfig.tomlin the current working directory
The backend currently reads:
allowed_originhttp_addrgrpc_addr- optional cluster settings
Database connectivity is not part of the TOML config. It must be provided through DATABASE_URL.
Example backend config: feature-toggle-backend/config.toml
- Rust toolchain
- PostgreSQL
DATABASE_URLpointing to a writable database
From the workspace root:
export DATABASE_URL=postgres://postgres:password@localhost:5432/feature_toggle
cargo run -p feature-toggle-backendThe backend will:
- create the connection pool
- run migrations from
feature-toggle-backend/migrations - start HTTP on
0.0.0.0:8080by default - start gRPC on
0.0.0.0:50051by default
If you want the database populated with the provided seed fixtures after migrations:
sqlx migrate run --database-url "$DATABASE_URL" --source feature-toggle-backend/migrations
psql "$DATABASE_URL" -f init.sqlThe Docker image and compose setup are already wired for the backend. Relevant files:
The container entrypoint copies config, runs SQLx migrations, and then starts the backend binary.
This repository now includes contract export and compatibility tooling for SDK generation.
Use:
./scripts/export-contracts.sh
./scripts/check-contract-compat.shGenerated artifacts include:
- OpenAPI JSON
- protobuf source
- protobuf descriptor set
- a baseline hash manifest for compatibility checks
See contract-driven-sdk.md for TypeScript and Java SDK generation examples.
Useful targeted commands:
cargo test -p feature-toggle-backend
cargo test -p evaluation-engine
cargo test -p feature-edge-serverFocused checks recently added for backend safety work include:
cargo test -p feature-toggle-backend logic::policy::tests
cargo test -p feature-toggle-backend logic::canary::tests
cargo test -p feature-toggle-backend dependency_graph
./scripts/check-contract-compat.shThe backend schema has evolved from the initial feature/pipeline model into a larger platform that now includes:
- users, roles, user-team membership, JWT tokens, and JWT secret rotation
- feature evaluation storage and analytics
- kill switch support
- feature variants and ordered criteria
- compound targeting rules and variant allocations
- approval workflows
- notifications
- system clients
- canary governance
The migrations live in feature-toggle-backend/migrations.
If you are working on the control plane, start in feature-toggle-backend. If you are working on evaluation semantics, start in evaluation-engine. If you are working on low-latency delivery behavior, follow the integration between backend gRPC streaming and feature-edge-server.
This workspace is no longer just a CRUD API for feature definitions. It is the backend implementation of a feature flag platform with policy enforcement, rollout governance, live delivery, metrics, and contract-driven integration support.