Organizing and structuring feature flags for better management and maintainability
Flag hierarchy in FlagFlow allows you to organize feature flags in a nested, tree-like structure using forward slashes as separators. This organizational system helps manage large numbers of flags by grouping related functionality and creating logical namespaces.
Key Concept: Hierarchical flags use path-like naming (e.g., ui/dashboard/new_layout
) to create organized, searchable, and maintainable flag
structures.
Here are practical examples of how flag hierarchy can organize your feature flags:
// Feature-based hierarchy ui/dashboard/new_layout: boolean ui/dashboard/dark_mode: boolean ui/sidebar/collapsible: boolean ui/sidebar/quick_actions: boolean // Service-based hierarchy api/auth/oauth2_enabled: boolean api/auth/session_timeout: number api/payment/stripe_enabled: boolean api/payment/max_retry_attempts: number // Environment-specific hierarchy experiments/checkout/ab_test_flow: "A" | "B" experiments/pricing/discount_banner: boolean experiments/search/ai_suggestions: boolean // Team-based hierarchy marketing/campaigns/holiday_banner: boolean marketing/analytics/conversion_tracking: boolean devops/monitoring/detailed_logging: boolean devops/performance/cache_enabled: boolean
ui/
)One of the key advantages of flag hierarchy is the ability to access specific portions of your flag tree without loading the entire configuration:
// Access only UI-related flags const uiFlags = await flagClient.getFlags('ui'); // Returns: ui/dashboard/*, ui/sidebar/*, etc. // Access only dashboard-specific flags const dashboardFlags = await flagClient.getFlags('ui/dashboard'); // Returns: ui/dashboard/new_layout, ui/dashboard/dark_mode // Access a specific flag directly (constant from generated TS code) const newLayout = await flagClient.getFlag('ui/dashboard/new_layout'); // Access multiple related flags efficiently const experimentFlags = await flagClient.getFlags('experiments'); // Returns all experiment flags without loading API or UI flags
ui/header/search_enabled ui/footer/social_links api/auth/rate_limiting api/database/connection_pool notifications/email/enabled notifications/push/badge_count
frontend/dashboard/widgets frontend/mobile/responsive backend/payments/processor backend/analytics/tracking devops/monitoring/alerts devops/deployment/canary
Obsolete approach: Organizing by lifecycle stages is not the proper way as it creates artificial boundaries that don't reflect actual feature relationships.
# Avoid this pattern stable/core/authentication stable/billing/invoices experimental/ai/suggestions experimental/social/sharing deprecated/legacy/old_ui deprecated/v1/api_endpoints
Wrong approach: You should install one FlagFlow instance per environment rather than organizing flags by environment within a single instance.
# Avoid this pattern - use separate FlagFlow instances instead production/performance/caching production/security/encryption development/debug/logging development/testing/mock_data staging/integration/external_apis staging/qa/feature_testing
FlagFlow's TypeScript integration provides full IntelliSense support for hierarchical flags. All flag path constants are automatically generated from your TypeScript interface:
// Generated TypeScript interface maintains hierarchy export interface FLAGS { 'ui/dashboard/new_layout': boolean; 'ui/dashboard/dark_mode': boolean; 'ui/sidebar/collapsible': boolean; 'api/auth/oauth2_enabled': boolean; 'api/auth/session_timeout': number; 'experiments/checkout/ab_test_flow': "A" | "B"; } // Type-safe flag access with autocompletion (constants from generated TS code) const dashboardLayout = getFlagValue('ui/dashboard/new_layout'); // ↑ Full IntelliSense support from FLAGS interface // Bulk access with type safety (path prefixes from generated constants) const uiFlags = getFlags('ui'); // Returns UI flags with correct types const authFlags = getFlags('api/auth'); // Returns auth flags
Generated Constants: All flag path strings like 'ui/dashboard/new_layout'
, 'api/auth/oauth2_enabled'
, etc. are
automatically generated from your TypeScript FLAGS interface, ensuring type safety and
preventing typos.
When introducing hierarchy to existing flat flag structures or reorganizing existing hierarchies:
// Example migration from flat to hierarchical structure // Before: Flat structure enable_dashboard_v2: boolean enable_dark_mode: boolean enable_sidebar_collapse: boolean auth_oauth_enabled: boolean // After: Hierarchical structure ui/dashboard/v2_enabled: boolean ui/theme/dark_mode: boolean ui/sidebar/collapsible: boolean api/auth/oauth_enabled: boolean // During migration: Support both (with aliases) enable_dashboard_v2 → ui/dashboard/v2_enabled enable_dark_mode → ui/theme/dark_mode