# Blazor Design Phase Checklist

> **Scope:** blazor-azure
> **Layer:** 2 (on keyword)
> **Keywords:** blazor, design, checklist, phase, architecture
> **Load When:** design phase for blazor features

Use this checklist during FASE 2 (DESIGN) for features involving Blazor Server

---

## 1. State and Session Management

### State Persistence

- [ ] **How will critical state be persisted?**
  - [ ] Database (recommended for important data)
  - [ ] Distributed cache (Redis, SQL Distributed Cache)
  - [ ] Cookie (only for identification, not data)
  - [ ] LocalStorage via JS Interop (only for non-critical preferences)

- [ ] **SessionState has `LoadFrom(entity)` method?**
  - Allows reloading state from persisted source
  - See [state.md](./state.md)

- [ ] **`IsLoaded` property exists to avoid unnecessary reloads?**

- [ ] **SessionId middleware is configured?**
  - HttpOnly cookie with session identifier
  - Injected into HttpContext.Items for component access

### Page Validation

- [ ] **All pages in flow reload state in `OnInitializedAsync`?**
  ```csharp
  if (!Session.IsLoaded)
  {
      var entity = await Repository.GetBySessionIdAsync(sessionId);
      Session.LoadFrom(entity);
  }
  ```

- [ ] **What happens if user accesses middle page directly?**
  - Redirect to start?
  - Load partial state?
  - Show friendly error?

---

## 2. EF Core Concurrency

### Background Operations

- [ ] **Will any service be called via `Task.Run`?**
  - If YES: Use `IDbContextFactory<T>`
  - See [ef-core.md](../../backend/database/ef-core.md)

- [ ] **Will any service be called in background job (Hangfire, Timer)?**
  - If YES: Use `IDbContextFactory<T>` or Repository Factory pattern

- [ ] **Will multiple operations happen concurrently in same component?**
  - If YES: Each operation needs isolated DbContext

---

## 3. File Upload

- [ ] **Will feature handle file uploads?**
  - [ ] Max file size defined?
  - [ ] Allowed file types/extensions specified?
  - [ ] Files read once and bytes stored?
  - [ ] Upload progress indicator planned?

- [ ] **Where will files be stored?**
  - [ ] Azure Blob Storage (recommended)
  - [ ] Local file system (not scalable)
  - [ ] Database as byte[] (only for small files < 1MB)

---

## 4. JavaScript Interop

- [ ] **Will feature use JavaScript?**
  - [ ] JS calls in `OnAfterRenderAsync`, not `OnInitializedAsync`?
  - [ ] `firstRender` check to prevent duplicate calls?
  - [ ] JS file location planned (wwwroot/js/)?

- [ ] **Will feature need external JS libraries?**
  - [ ] Library loaded via CDN or npm?
  - [ ] Initialization strategy planned?

---

## 5. Navigation and Routing

- [ ] **How many pages in the feature?**
  - Single page?
  - Multi-page flow?
  - Modal/dialog-based?

- [ ] **Will users need to navigate back/forward?**
  - [ ] State persisted before navigation?
  - [ ] Browser back button handled correctly?

- [ ] **Are there deep links?**
  - [ ] Each page can load state from URL/DB?
  - [ ] Invalid state handled gracefully?

---

## 6. Real-time Updates

- [ ] **Will feature need real-time updates?**
  - SignalR circuit is already available
  - Update strategy planned?

- [ ] **Will updates come from background jobs?**
  - [ ] Notification mechanism planned?
  - [ ] UI refresh strategy defined?

---

## 7. Performance

- [ ] **Expected data volume?**
  - Pagination needed for lists > 100 items?
  - Lazy loading for large datasets?

- [ ] **Heavy computations planned?**
  - [ ] Run in background (Task.Run with factory)?
  - [ ] Cache results?

- [ ] **Large components/forms?**
  - [ ] Split into smaller components?
  - [ ] Lazy rendering planned?

---

## 8. Error Handling

- [ ] **What errors might occur?**
  - Database errors?
  - Network errors?
  - Validation errors?
  - Permission errors?

- [ ] **Error display strategy?**
  - [ ] Toast notifications?
  - [ ] Inline validation messages?
  - [ ] Error page redirect?

- [ ] **Retry strategy for transient errors?**

---

## 9. Security

- [ ] **Authentication required?**
  - [ ] `[Authorize]` attribute on pages?
  - [ ] Login redirect configured?

- [ ] **Authorization rules?**
  - Role-based?
  - Policy-based?
  - Resource-based?

- [ ] **Input validation?**
  - [ ] Client-side (Blazor validation)?
  - [ ] Server-side (service layer)?
  - [ ] Both?

- [ ] **Sensitive data?**
  - [ ] Not stored in SessionState?
  - [ ] Not logged?
  - [ ] Encrypted in database?

---

## 10. UI/UX

- [ ] **Loading states?**
  - Spinners for async operations?
  - Skeleton loaders for data?
  - Disabled buttons during saves?

- [ ] **Success feedback?**
  - Toast messages?
  - Inline success indicators?
  - Redirect to confirmation page?

- [ ] **Responsive design?**
  - Mobile layout planned?
  - Breakpoints defined?

---

## Quick Design Decisions

Before implementing, answer these:

| Question | Answer Required |
|----------|----------------|
| **State:** Where is critical state stored? | Database / Cache / Cookie |
| **Files:** Where are uploads stored? | Azure Blob / Database / FileSystem |
| **Navigation:** Single page or multi-page? | Single / Multi / Modal |
| **JS:** Is JavaScript needed? | Yes / No |
| **Auth:** Authentication required? | Yes / No |
| **Background:** Any background operations? | Yes (use factory) / No |
| **Real-time:** Real-time updates needed? | Yes / No |

---

## Related Standards

- [state.md](./state.md) - Session state patterns
- [lifecycle.md](./lifecycle.md) - Component lifecycle
- [pitfalls.md](./pitfalls.md) - Common mistakes
- [ef-core.md](../../backend/database/ef-core.md) - DbContext concurrency

---

*MORPH-SPEC by Polymorphism Tech*
