Flipt Documentation

repository·v2·Indexed 26 days ago

https://github.com/flipt-io/flipt

Flipt is a Git-native feature management platform that allows developers to treat feature flags as code by storing them in Git repositories. It supports server-side evaluation via REST and gRPC APIs, client-side local evaluation, and the OpenFeature standard. The platform includes a Go SDK, a CLI with a TUI design system, and enterprise Pro features such as GPG commit signing, integrated secrets management with HashiCorp Vault, and native DevOps integrations for GitHub, GitLab, and BitBucket.

Tokens
16.6K
Snippets
32
Records
130
Agent score
88%

What's inside Flipt

  1. Flipt CLI TUI Design System Overview

    v2

    The Flipt CLI uses a Terminal User Interface (TUI) design system based on the lipgloss and huh libraries. The system is built on five core principles:

    1. Progressive Disclosure: Guide users step-by-step and reveal information only as needed.
    2. Clear Visual Hierarchy: Use badges, colors, and spacing to prioritize important information.
    3. Responsive Design: Adapt to terminal widths, handling a minimum of 48 characters and optimizing for 80 characters.
    4. Consistent Experience: Reuse patterns and components across all commands.
    5. Delightful Interactions: Provide immediate visual feedback and helpful error messages.
  2. Flipt v2 Pro Features and Pricing

    v2

    Flipt v2 Pro provides enterprise-grade features for Git-native feature management.

    Key Features

    • Enterprise DevOps Integration: Native workflows for GitHub, GitLab, BitBucket, Azure DevOps, and Gitea (includes merge proposals and automated PR/MR creation).
    • GPG Commit Signing: Cryptographic signing of changes for security and auditability.
    • Integrated Secrets Management: Secure storage for GPG keys with integration for HashiCorp Vault, AWS Secrets Manager, GCP Secret Manager, and Azure Key Vault.
    • Air-Gapped Support: Annual licenses support offline validation for air-gapped environments.
    • Enterprise Auth & Advanced Analytics: (Coming soon).

    Pricing Models

    • Free 14-day trial: Includes all Pro features (up to 5 instances).
    • Monthly License: $200/month (requires continuous internet connectivity).
    • Annual License: $2,000/year (supports offline validation via license files).
    • Instance Limits: Paid plans include unlimited instances.
  3. Implement a Wizard-driven CLI Command

    v2

    When building interactive CLI commands for Flipt, use a structured wizard pattern to guide users through multiple steps. This involves checking for a TTY (interactive terminal), managing the current step state, and executing a sequence of step functions. Ensure you handle user interruptions (like Ctrl+C) gracefully by checking for interrupt errors.

    type myCommand struct {
        // Configuration
        configFile string
        
        // Wizard state
        currentStep WizardStep
        totalSteps  int
        
        // User inputs
        userInput string
    }
    
    func (c *myCommand) run(cmd *cobra.Command, args []string) error {
        // 1. Check TTY
        if !isatty.IsTerminal(os.Stdout.Fd()) {
            return fmt.Errorf("requires interactive terminal")
        }
        
        // 2. Initialize
        c.currentStep = StepWelcome
        c.totalSteps = 4
        
        // 3. Run wizard steps
        steps := []wizardStep{
            {StepWelcome, c.runWelcomeStep},
            {StepConfig, c.runConfigStep},
            {StepValidate, c.runValidateStep},
        }
        
        for _, step := range steps {
            c.currentStep = step.step
            fmt.Print("\033[H\033[2J")  // Clear screen
            
            if err := step.runFunc(); err != nil {
                if isInterruptError(err) {
                    fmt.Println(HelperTextStyle.Render("Cancelled."))
                    return nil
                }
                return err
            }
        }
        
        // 4. Show success
        c.currentStep = StepComplete
        c.renderSuccessScreen()
        
        return nil
    }
  4. Install and run Flipt locally

    v2

    You can install Flipt using a shell script, use the built-in wizard for setup, or run the server directly.

    Installation

    curl -fsSL https://get.flipt.io/v2 | sh

    Quick Start Wizard

    To perform a guided setup:

    flipt quickstart

    Run Server

    To start the Flipt server:

    flipt server
    # Install Flipt
    curl -fsSL https://get.flipt.io/v2 | sh
    
    # Wizard-driven setup to get you started quickly
    flipt quickstart
    
    # Run Flipt server
    flipt server
  5. Create a new database migration

    v2

    Flipt v2 uses golang-migrate to manage database migrations. Currently, the only supported database for migrations is Clickhouse (used for analytics). To create a new migration, use the migrate create command, specifying the SQL extension and the directory corresponding to the database type.

    migrate create -ext sql -dir ./migrations/clickhouse create_table_X
  6. Develop the Flipt UI with hot reloading

    v2

    The UI is built with NPM and Vite. To develop the UI with hot reloading enabled, follow these steps:

    1. Start the UI development server (runs on port 5173 and proxies to the API on 8080):
      mise run ui:dev
    2. In a separate terminal, start the backend server (runs on port `8080`):
       ```bash
    mise run dev
    1. Visit http://localhost:8080 in your browser.

    Changes made in the ui directory will trigger automatic reloads in the development server.

    mise run ui:dev
    mise run dev
  7. Create interactive forms with the huh library

    v2

    The Flipt CLI uses the huh library for interactive forms.

    Form Setup

    form := huh.NewForm(groups...).WithTheme(huh.ThemeCharm())
    form = form.WithProgramOptions(
        tea.WithOutput(os.Stdout),
        tea.WithAltScreen(),
        tea.WithReportFocus(),
    )

    Common Input Types

    • Text Input: Use huh.NewInput() for text. Use .EchoMode(huh.EchoModePassword) for sensitive data like license keys.
    • Select: Use huh.NewSelect[T]() with .Options() to provide a list of choices.
    • Confirm: Use huh.NewConfirm() for yes/no prompts.

    Validation Attach validation logic using .Validate(func(s string) error { ... }) to ensure input correctness.

    form := huh.NewForm(groups...).WithTheme(huh.ThemeCharm())
    form = form.WithProgramOptions(
        tea.WithOutput(os.Stdout),
        tea.WithAltScreen(),
        tea.WithReportFocus(),
    )
  8. Handle errors and user interrupts in the CLI

    v2

    Follow these patterns to ensure errors are helpful and user interruptions are handled gracefully.

    Error Display Pattern Avoid duplicating error messages. Use ErrorStyle for the main failure message and LabelStyle + ValueStyle for the specific error detail.

    fmt.Println(ErrorStyle.Render("✗ Operation failed"))
    fmt.Println(LabelStyle.Render("Error: ") + ValueStyle.Render(err.Error()))
    fmt.Println()
    fmt.Println(HelperTextStyle.Render("Try this to fix the issue"))
    return nil // Return nil to prevent Cobra from printing error again

    User Interrupts Detect if a user aborted the process (e.g., via Ctrl+C) by checking for tea.ErrInterrupted or huh.ErrUserAborted using errors.Is().

    // Don't duplicate error messages
    fmt.Println(ErrorStyle.Render("✗ Operation failed"))
    fmt.Println(LabelStyle.Render("Error: ") + ValueStyle.Render(err.Error()))
    fmt.Println()
    fmt.Println(HelperTextStyle.Render("Try this to fix the issue"))
    return nil  // Return nil to prevent Cobra from printing error again
  9. Set up a local development environment for Flipt

    v2

    To develop Flipt locally, ensure you have the following requirements installed:

    Follow these steps to initialize the environment:

    1. Clone the repository: git clone https://github.com/flipt-io/flipt.
    2. Install required tool versions: mise install.
    3. Install development tools: mise run bootstrap.
    4. Run the Go test suite: mise run test.
    5. Build the binary with embedded assets: mise run build.
    6. View all available commands: mise tasks.

    Alternatively, you can use devenv by running devenv up from the root of the repository to start a development environment with the server on port 8080 and the UI dev server on port 5173.

    git clone https://github.com/flipt-io/flipt
    mise install
    mise run bootstrap
    mise run test
    mise run build
    mise tasks
  10. Develop Flipt using Docker Compose

    v2

    You can use the provided docker-compose.yml to run the Flipt environment in containers:

    • server: Runs the Flipt server with a bind mount. Note that the server does not support hot reloading; you must restart the container to pick up changes. The SQLite database is persisted between runs.
    • ui: Runs the UI development server with a bind mount. Changes to the ui directory are picked up immediately via Vite hot reloading.

    To start the environment, run:

    docker-compose up

    Access the UI at http://localhost:8080.