askill
flagsmith

flagsmithSafety 95Repository

Flagsmith feature flag patterns covering flag evaluation, segments, traits, remote config, self-hosted vs cloud, and SDK integration. Use when implementing feature flags with Flagsmith.

4 stars
1.2k downloads
Updated 3/21/2026

Package Files

Loading files...
SKILL.md

Flagsmith

Open-source feature flag and remote config service. Self-hosted or cloud. Supports segments, user traits, A/B testing, and multi-environment management.

When to Use

  • Want an open-source feature flag solution you can self-host
  • Need feature flags + remote configuration in one tool
  • Want segments based on user traits (plan, region, version)
  • Need a free/affordable tier with no per-seat pricing

When NOT to Use

  • Need enterprise audit trails and compliance (use LaunchDarkly)
  • Want flags tightly integrated with analytics (use PostHog)
  • Feature flags are simple on/off (environment variables suffice)

Setup

Installation

npm install flagsmith                 # Client/isomorphic
npm install flagsmith-nodejs          # Server-side (Node.js)

Server SDK

import Flagsmith from 'flagsmith-nodejs';

const flagsmith = new Flagsmith({
  environmentKey: process.env.FLAGSMITH_SERVER_KEY!,
  apiUrl: process.env.FLAGSMITH_API_URL ?? 'https://edge.api.flagsmith.com/api/v1/',
  enableLocalEvaluation: true,       // Cache flags locally for zero-latency
  environmentRefreshIntervalSeconds: 30,
});

Client SDK (React)

import flagsmith from 'flagsmith';
import { FlagsmithProvider } from 'flagsmith/react';

function App() {
  return (
    <FlagsmithProvider
      options={{
        environmentID: process.env.NEXT_PUBLIC_FLAGSMITH_ENV_ID!,
        api: process.env.NEXT_PUBLIC_FLAGSMITH_API_URL,
        identity: user?.id,
        traits: { plan: user?.plan, region: user?.region },
      }}
      flagsmith={flagsmith}
    >
      <AppContent />
    </FlagsmithProvider>
  );
}

Flag Evaluation

Server-Side

// Get flags for an identity
const flags = await flagsmith.getIdentityFlags(userId, {
  plan: 'enterprise',
  region: 'us',
  version: '2.1.0',
});

// Boolean flag
const isEnabled = flags.isFeatureEnabled('new_dashboard');

// Remote config value
const maxUploads = flags.getFeatureValue('max_uploads'); // Returns string
const limit = parseInt(maxUploads ?? '10', 10);

// Environment-level (no identity)
const envFlags = await flagsmith.getEnvironmentFlags();
const maintenanceMode = envFlags.isFeatureEnabled('maintenance_mode');

Client-Side (React)

import { useFlags, useFlagsmith } from 'flagsmith/react';

function Feature() {
  const { new_dashboard, max_uploads } = useFlags(['new_dashboard', 'max_uploads']);
  const flagsmith = useFlagsmith();

  // Update traits (triggers re-evaluation)
  const upgradePlan = () => {
    flagsmith.setTraits({ plan: 'enterprise' });
  };

  if (new_dashboard.enabled) {
    return <NewDashboard maxUploads={parseInt(max_uploads.value ?? '10')} />;
  }
  return <LegacyDashboard />;
}

Segments

Define in Flagsmith dashboard — evaluated based on user traits:

SegmentRulesUse Case
Enterprise Usersplan = enterprisePremium features
US Regionregion = usUS-specific compliance
Beta Testersbeta_opt_in = trueEarly access features
High Volumeapi_calls > 10000Scale-tier features

Traits (User Properties)

// Server: set traits
await flagsmith.getIdentityFlags(userId, {
  plan: 'enterprise',
  region: 'eu',
  signup_date: '2024-01-15',
  api_calls: 15000,
});

// Client: set traits dynamically
flagsmith.setTraits({
  theme: 'dark',
  onboarding_complete: true,
});

Multi-Environment

EnvironmentKeyPurpose
Developmentser.dev_xxxLocal development
Stagingser.staging_xxxPre-production
Productionser.prod_xxxLive traffic

Self-Hosted Deployment

# docker-compose.yml
services:
  flagsmith:
    image: flagsmith/flagsmith:latest
    ports:
      - "8000:8000"
    environment:
      DATABASE_URL: postgresql://user:pass@db:5432/flagsmith
      DJANGO_SECRET_KEY: your-secret-key
      ENABLE_ADMIN_ACCESS_USER_PASS: true
    depends_on:
      - db
  db:
    image: postgres:16
    environment:
      POSTGRES_DB: flagsmith
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass

Anti-Patterns

Don'tDo
Evaluate flags without an identity for personalizationPass user ID and traits for segment targeting
Hardcode flag names as strings everywhereDefine flag name constants in a shared module
Skip local evaluation on the serverEnable enableLocalEvaluation for zero-latency server-side eval
Use flag values as numbers directlygetFeatureValue returns strings — parse to the expected type
Leave stale flags after rolloutArchive completed flags to keep the dashboard clean
Use production environment key in developmentUse environment-specific keys for isolation
Deploy self-hosted without PostgreSQLFlagsmith requires PostgreSQL — SQLite is for development only
Skip traits for segment targetingTraits are the input to segments — set them on identify

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

82/100Analyzed 3/28/2026

Highly comprehensive and well-structured Flagsmith skill with excellent actionability through TypeScript/React code examples, setup instructions, anti-patterns table, and segment definitions. Content is accurate and reusable across projects. Slight penalty for deeply nested path (depth 5) under .agent folder suggesting internal-only context, but the actual skill content is generic and broadly applicable to any Flagsmith implementation.

95
92
88
95
92

Metadata

Licenseunknown
Version1.0.0
Updated3/21/2026
PublisherRepairYourTech

Tags

apici-cddatabasesecurity