Skip to content

feat: add feature flag module with permissions-like architecture#28

Merged
antosubash merged 2 commits intomainfrom
claude/create-feature-flag-module-0nXc0
Mar 30, 2026
Merged

feat: add feature flag module with permissions-like architecture#28
antosubash merged 2 commits intomainfrom
claude/create-feature-flag-module-0nXc0

Conversation

@antosubash
Copy link
Copy Markdown
Owner

@antosubash antosubash commented Mar 29, 2026

Summary

Adds a complete feature flag system mirroring the permissions pattern:

  • Core framework types: IModuleFeatures marker interface, FeatureFlagDefinition, FeatureFlagRegistryBuilder, FeatureFlagRegistry, IFeatureFlagService, RequireFeature() endpoint extension, ConfigureFeatureFlags() on IModule
  • Source generator: auto-discovers IModuleFeatures classes, generates registration code, adds SM0045-SM0048 diagnostics for sealed/naming/duplicate violations
  • FeatureFlags module: DbContext with flags + overrides tables, FeatureFlagService with resolution logic (user override > role override > DB state > registry default), memory cache with 30s TTL, startup sync from registry to DB
  • API endpoints: CRUD for flags/overrides, check endpoint for current user
  • Admin UI: React page with toggle switches, override management dialog
  • Frontend integration: FeatureFlagMiddleware injects flags into Inertia shared props, useFeatureFlag() React hook in @simplemodule/ui
  • Event integration: FeatureFlagToggledEvent, FeatureFlagOverrideChangedEvent
  • Tests: 14 unit + integration tests, Playwright e2e smoke + flow tests

Test plan

  • dotnet build — no errors or warnings
  • dotnet test — all 14 FeatureFlag tests pass, full suite green
  • npm run build — frontend builds successfully
  • npm run check — biome lint + page validation passes
  • Verify source generator discovers module and registers feature flags
  • Verify entity base class (Entity<int>) with auto timestamps and concurrency

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 29, 2026

Deploying simplemodule-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: f9801f0
Status: ✅  Deploy successful!
Preview URL: https://ade34140.simplemodule-website.pages.dev
Branch Preview URL: https://claude-create-feature-flag-m.simplemodule-website.pages.dev

View logs

Add a complete FeatureFlags module that follows the permissions pattern:
modules declare features via IModuleFeatures marker classes, the source
generator auto-discovers them, and a runtime service resolves flag state
with user/role override support.

## Framework (SimpleModule.Core)
- IModuleFeatures marker interface for compile-time feature discovery
- IFeatureFlagService for cross-module runtime checks
- IFeatureFlagRegistry singleton with all known flag definitions
- FeatureFlagRegistryBuilder merging discovered + configured definitions
- EndpointFeatureFlagExtensions with .RequireFeature() endpoint filter
- ConfigureFeatureFlags() added to IModule interface

## Source Generator
- Feature class discovery mirroring permission class pattern
- Diagnostics SM0045-SM0048 (sealed class, naming, duplicates, fields)
- Auto-registration of feature classes and definitions in AddModules()

## Module Implementation
- Contracts: IFeatureFlagContracts, DTOs, events, OverrideType enum
- Entities using Entity<int> base class (auto timestamps, concurrency)
- FeatureFlagService with cached resolution (user > role > global > default)
- FeatureFlagSyncService for startup DB sync with table auto-creation
- FeatureFlagMiddleware injecting flags into Inertia shared data
- Full API endpoints (CRUD flags, overrides, check)
- Admin UI (React) with toggle switches and override management
- useFeatureFlag() React hook for frontend consumption
- Permissions: FeatureFlags.View, FeatureFlags.Manage

## Tests
- 14 unit + integration tests (service logic, endpoint auth, CRUD)
- Playwright e2e smoke + flow tests
- Test infrastructure integration (WebApplicationFactory)
@antosubash antosubash force-pushed the claude/create-feature-flag-module-0nXc0 branch from d5f5546 to a5e236e Compare March 29, 2026 21:37
@antosubash antosubash changed the title feat(feature-flags): add feature flag module with permissions-like architecture feat: add feature flag module with permissions-like architecture Mar 29, 2026
- Add EF Core migration (AddFeatureFlagsModule) to create the
  FeatureFlags and FeatureFlagOverrides tables
- Catch DbException in FeatureFlagMiddleware so a missing or
  unreachable database does not crash the entire request pipeline
  with a 500 — feature flags degrade gracefully instead
- Update HostDbContext model snapshot to include FeatureFlags entities
@antosubash antosubash force-pushed the claude/create-feature-flag-module-0nXc0 branch from 9371a21 to f9801f0 Compare March 30, 2026 07:47
@antosubash antosubash merged commit 4614ff0 into main Mar 30, 2026
3 checks passed
@antosubash antosubash deleted the claude/create-feature-flag-module-0nXc0 branch April 1, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant