# Feature Full - Implementation Phases

## Phase 2: Domain

```csharp
// {Entity}.cs - Factory Method + Behaviors
public class {Entity} : BaseEntity, IAuditableEntity
{
    public string Name { get; private set; }
    public {Entity}Status Status { get; private set; }
    private {Entity}() { }
    public static {Entity} Create(string name, Guid createdById) =>
        new { Id = Guid.NewGuid(), Name = name, Status = {Entity}Status.Active, ... };
    public void Update(string name) => Name = name ?? throw new DomainException("Name required");
}

// {Entity}Status.cs
public enum {Entity}Status { Active = 0, Inactive = 1, Archived = 2 }
```

## Phase 3: Application

```csharp
// I{Entity}Service.cs
Task<PaginatedResult<{Entity}Dto>> GetAllAsync(...);
Task<{Entity}Dto> CreateAsync(Create{Entity}Request request, CancellationToken ct);

// DTOs
public record {Entity}Dto(Guid Id, string Name, string Status, DateTime CreatedAt);
public record Create{Entity}Request(string Name, string? Description);

// Permissions.cs + PermissionConfiguration.cs (2 files!)
public const string View = "{area}.{module}.read";
```

## Phase 4: Infrastructure

```csharp
// {Entity}Configuration.cs
builder.ToTable("{Entity}s", "{schema}");
builder.Property(x => x.Name).HasMaxLength(200).IsRequired();

// {Entity}Service.cs with Notifications
public async Task<{Entity}Dto> CreateAsync(...) {
    var entity = {Entity}.Create(request.Name, _currentUser.Id);
    _context.{Entity}s.Add(entity);
    await _context.SaveChangesAsync(ct);
    await _notificationService.SendNotificationAsync(_currentUser.Id,
        NotificationType.{Entity}Created, "Created", $"{entity.Name} created",
        relatedEntityType: nameof({Entity}), relatedEntityId: entity.Id, ct);
    return MapToDto(entity);
}

// DependencyInjection.cs
services.AddScoped<I{Entity}Service, {Entity}Service>();
```

## Phase 5: API

```csharp
[ApiController]
[NavRoute("{area}.{module}")]
[Microsoft.AspNetCore.Authorization.Authorize]
[Produces("application/json")]
[Tags("{EntityPlural}")]
public class {Entity}Controller : ControllerBase
{
    private readonly ISender _mediator;

    [HttpGet]
    [RequirePermission(Permissions.{Area}.{Module}.View)]
    [ProducesResponseType(typeof(PaginatedResult<{Entity}Dto>), StatusCodes.Status200OK)]
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
    [ProducesResponseType(StatusCodes.Status403Forbidden)]
    public async Task<ActionResult<PaginatedResult<{Entity}Dto>>> GetAll(...);

    [HttpPost]
    [RequirePermission(Permissions.{Area}.{Module}.Create)]
    [ProducesResponseType(typeof({Entity}Dto), StatusCodes.Status201Created)]
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
    [ProducesResponseType(StatusCodes.Status401Unauthorized)]
    [ProducesResponseType(StatusCodes.Status403Forbidden)]
    public async Task<ActionResult<{Entity}Dto>> Create([FromBody] request, CancellationToken ct);
}
```

## Phase 6: Frontend

```typescript
// {module}Api.ts
export const {module}Api = {
  getAll: (page, pageSize, search?) => apiClient.get<PaginatedResult<{Entity}Dto>>('/{area}/{module}', { params }),
  create: (data) => apiClient.post<{Entity}Dto>('/{area}/{module}', data),
};

// use{Module}.ts with SignalR
export function use{Module}() {
  const queryClient = useQueryClient();
  useSignalR({ onNotification: (n) => {
    if (n.relatedEntityType === '{Entity}') queryClient.invalidateQueries(['{module}']);
  }});
  const createMutation = useMutation({ mutationFn: {module}Api.create, onSuccess: () => ... });
  return { create: createMutation.mutate, ... };
}

// {Module}Page.tsx with EntityCard
<EntityCard title={item.name} actions={[{ label: 'View', onClick: () => navigate(...) }]} />

// Routes (nested mandatory)
<Route path="{area}"><Route path="{module}"><Route index element={<{Module}Page />} /></Route></Route>
```

## Phase 7: Integrations

### Notifications
```csharp
await _notificationService.SendNotificationAsync(userId, NotificationType.{Entity}Created,
    title, message, relatedEntityType: nameof({Entity}), relatedEntityId: entity.Id, actionUrl);
```

### Workflow Email
```csharp
// 1. WorkflowTriggerConfiguration.cs: new { Code = "{entity}.created", ... }
// 2. WorkflowConfiguration.cs: new { TriggerId = ..., ... }
// 3. Service:
await _workflowService.TriggerAsync("{entity}.created", new Dictionary<string, object>{...});
```

### AI
```csharp
var result = await _aiCompletionService.ExecutePromptByCodeWithValidationAsync<{Entity}AnalysisResult>(
    "{entity}-analyzer", new Dictionary<string, object>{ ["name"] = entity.Name }, ct);
```
