feat: add feature flag module with permissions-like architecture#28
Merged
antosubash merged 2 commits intomainfrom Mar 30, 2026
Merged
feat: add feature flag module with permissions-like architecture#28antosubash merged 2 commits intomainfrom
antosubash merged 2 commits intomainfrom
Conversation
Deploying simplemodule-website with
|
| 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 |
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)
d5f5546 to
a5e236e
Compare
- 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
9371a21 to
f9801f0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a complete feature flag system mirroring the permissions pattern:
IModuleFeaturesmarker interface,FeatureFlagDefinition,FeatureFlagRegistryBuilder,FeatureFlagRegistry,IFeatureFlagService,RequireFeature()endpoint extension,ConfigureFeatureFlags()onIModuleIModuleFeaturesclasses, generates registration code, adds SM0045-SM0048 diagnostics for sealed/naming/duplicate violationsFeatureFlagServicewith resolution logic (user override > role override > DB state > registry default), memory cache with 30s TTL, startup sync from registry to DBFeatureFlagMiddlewareinjects flags into Inertia shared props,useFeatureFlag()React hook in@simplemodule/uiFeatureFlagToggledEvent,FeatureFlagOverrideChangedEventTest plan
dotnet build— no errors or warningsdotnet test— all 14 FeatureFlag tests pass, full suite greennpm run build— frontend builds successfullynpm run check— biome lint + page validation passes