ums

FeatureFlag — Aggregate Architecture

Bounded Context: Configuration
Aggregate Root: FeatureFlag
Module: Ums.Domain.Configuration.FeatureFlag
Status: Production


1. Aggregate Overview

Purpose

The FeatureFlag aggregate controls runtime feature enablement in a simplified but operationally useful way. It stores a technical flag code, flag type, target definition, optional linked resource targeting, rollout percentage, and state transitions across inactive, active, and archived states.

Business Responsibility

Aggregate Root

FeatureFlag is the aggregate root. State transitions and evaluation behavior are coordinated through the aggregate.

Invariants and Consistency Rules

  1. Percentage flags require RolloutPercentage between 0 and 100.
  2. Archived flags cannot be re-activated or deactivated.
  3. Activating an already active flag is invalid.
  4. Deactivating an already inactive flag is invalid.
  5. New flags start in Inactive.

| Entity / VO | Type | Ownership | |—|—|—| | FeatureFlagId | Value Object | Aggregate identifier | | FlagType | Enumeration | Current rollout category | | FlagStatus | Enumeration | Inactive, Active, Archived | | LinkedResourceType | Enumeration | Optional scoping target | | FlagEvaluationLog | Entity | Aggregate-owned evaluation history |

Domain Events

| Event | Trigger | |—|—| | FeatureFlagCreatedEvent | New flag created | | FeatureFlagActivatedEvent | Flag activated | | FeatureFlagDeactivatedEvent | Flag deactivated | | FeatureFlagArchivedEvent | Flag archived | | FeatureFlagStateChangedEvent | State transition emitted | | FlagEvaluatedEvent | Runtime evaluation executed |


2. Domain Model

FeatureFlag (Aggregate Root)
├── Props: FeatureFlagProps
│   ├── Id: IdValueObject
│   ├── FlagCode: string
│   ├── FlagType: FlagType
│   ├── FlagTargets: string
│   ├── Status: FlagStatus
│   ├── LinkedResourceType?: LinkedResourceType
│   ├── LinkedResourceId?: IdValueObject
│   ├── RolloutPercentage?: int
│   └── Audit: AuditValueObject
└── Children
    └── IReadOnlyCollection<FlagEvaluationLog>

3. Object Model Diagrams

classDiagram
    class FeatureFlag {
        +Guid Id
        +string FlagCode
        +FlagType FlagType
        +string FlagTargets
        +FlagStatus Status
        +LinkedResourceType LinkedResourceType
        +Guid LinkedResourceId
        +int RolloutPercentage
        +List~FlagEvaluationLog~ EvaluationLog
        +Create(flagCode, flagType, flagTargets, linkedResourceType, linkedResourceId, rolloutPercentage, actor)
        +Activate(actor)
        +Deactivate(actor)
        +Archive(actor)
        +Evaluate(evaluatedBy, context)
    }

4. Sequence Diagrams

Evaluate Flag Flow

sequenceDiagram
    participant C as Caller
    participant F as FeatureFlag (AR)

    C->>F: Evaluate(evaluatedBy, context)
    F->>F: Validate not archived
    F->>F: Resolve result from current status
    F->>F: Append FlagEvaluationLog
    F->>F: Raise FlagEvaluatedEvent

5. ER Model

erDiagram
    FEATURE_FLAG ||--o{ FLAG_EVALUATION_LOG : "records"

    FEATURE_FLAG {
        uniqueidentifier Id PK
        nvarchar FlagCode
        int FlagTypeId
        nvarchar FlagTargets
        int StatusId
        int LinkedResourceTypeId
        uniqueidentifier LinkedResourceId
        int RolloutPercentage
        nvarchar CreatedBy
        datetime2 CreatedAtUtc
        nvarchar UpdatedBy
        datetime2 UpdatedAtUtc
        nvarchar AuditTimeSpan
    }

Tenant Isolation Rules


6. Bounded Context Integration


7. Application Layer


8. Infrastructure/Persistence


9. Security & Compliance


10. Technical Decisions


Back to Configuration Index