Skip to content

Latest commit

 

History

History
262 lines (227 loc) · 9.67 KB

PHASE_5_ARCHITECTURE.md

File metadata and controls

262 lines (227 loc) · 9.67 KB

Phase 5: Wizard Architecture Documentation

Overview

Phase 5 transforms EntityClassGenerator from a single-page UI into a structured 5-step wizard for guided entity class generation from SQL Server databases.

Architecture Diagram

MainWindow (Title bar + Frame)
    └─ WizardView (Container)
        ├─ LeftPanel
        │   └─ StepIndicator (Steps 1-5 with titles)
        ├─ Separator (Vertical divider)
        ├─ CenterPanel
        │   └─ ContentControl (dynamic step content)
        │       ├─ Step1ConnectionView
        │       ├─ Step2TablesView
        │       ├─ Step3NamingView
        │       ├─ Step4OutputView
        │       └─ Step5PreviewView
        └─ BottomBar
            ├─ Cancel Button
            ├─ Progress Bar + Status
            ├─ Back Button
            ├─ Next Button (steps 1-4)
            └─ Generate Button (step 5)

Data Flow

MainWindow
    └─ DataContext: WizardViewModel
        ├─ Exposes: MainViewModel (for step views)
        ├─ Properties:
        │   ├─ CurrentStep (1-5)
        │   ├─ CanGoBack, CanGoNext, CanGenerate
        │   ├─ IsBusy, StatusMessage
        │   ├─ Step1Valid, Step2Valid, ... Step5Valid
        │   └─ PreviewEntity, PreviewDbContext, PreviewFluentConfig
        │
        ├─ Commands:
        │   ├─ GoBackCommand
        │   ├─ GoNextCommand (loads preview on step 5)
        │   └─ GenerateCommand
        │
        └─ Listeners (auto-validation on MainViewModel changes):
            ├─ ServerName → validates Step1
            ├─ DatabaseName → validates Step1
            ├─ SelectedCount → validates Step2
            ├─ Namespace → validates Step3
            ├─ DbContextName → validates Step3
            └─ OutputDirectory → validates Step4

Step Views (Each binds to MainViewModel)
    ├─ Step1ConnectionView
    │   ├─ Inputs: ServerName, DatabaseName, UseWindowsAuth, Username, Password
    │   ├─ Commands: TestConnectionCommand, LoadTablesCommand
    │   └─ Validation: Non-empty server & database
    │
    ├─ Step2TablesView
    │   ├─ Inputs: SelectedSchema, TableFilter, DataGrid checkboxes
    │   ├─ Commands: SelectAllVisibleCommand, DeselectAllCommand, InvertSelectionCommand
    │   ├─ Display: SelectedCount (# of tables selected)
    │   └─ Validation: At least 1 table selected
    │
    ├─ Step3NamingView
    │   ├─ Inputs: Namespace, DbContextName, ClassStyle, PropertyStyle, 
    │   │           PrefixToRemove, SuffixToRemove, ClassSuffix, SingularizeClassNames
    │   └─ Validation: Non-empty Namespace & DbContextName
    │
    ├─ Step4OutputView
    │   ├─ Inputs: OutputDirectory, UseNullableReferenceTypes, UseDataAnnotations, UseFluentApi
    │   ├─ Placeholder: Browse button (not wired in Phase 5)
    │   └─ Validation: Valid directory path format
    │
    └─ Step5PreviewView
        ├─ Display: AvalonEdit tabs (Entity, DbContext, FluentConfig)
        ├─ DataContext: WizardViewModel (accesses preview properties)
        └─ Always valid (preview always available)

Validation Rules

Step Valid When Invalid Message
1 Server ≠ "" AND Database ≠ "" Missing server or database
2 SelectedCount > 0 No tables selected
3 Namespace ≠ "" AND DbContextName ≠ "" Missing namespace or DbContext name
4 OutputDirectory matches valid path pattern Invalid directory path
5 Always (preview generated on step 5 entry) N/A

Navigation Flow

Step 1: Connection
    ↓ (Next enabled if Step1Valid)
Step 2: Tables
    ↓ (Next enabled if Step2Valid)
Step 3: Naming
    ↓ (Next enabled if Step3Valid)
Step 4: Output
    ↓ (Next enabled if Step4Valid, trigger preview load)
Step 5: Preview
    ↓ (Generate enabled if Step5Valid)
    └─ Generate() → MainViewModel.GenerateAsync() → Output files

Back button at every step returns to previous step.
Cancel button exits wizard (placeholder for step check).

Component Responsibilities

WizardViewModel

  • Purpose: Orchestrate wizard navigation and validation
  • Responsibilities:
    • Track current step
    • Validate each step's requirements
    • Load preview on step 5
    • Delegate generation to MainViewModel.GenerateAsync()
  • Dependencies: MainViewModel (composition)

WizardView (Container)

  • Purpose: Host wizard UI and step switching
  • Responsibilities:
    • Render step indicator sidebar
    • Switch step content dynamically
    • Render navigation buttons
    • Display progress bar and status
  • Dependencies: WizardViewModel, Step1-5 Views

Step Views (1-5)

  • Purpose: Individual step UI and input
  • Responsibilities:
    • Bind to MainViewModel properties
    • Execute MainViewModel commands
    • Display step-specific UI
  • Dependencies: MainViewModel (for bindings)

Converters

  • Purpose: XAML binding helpers
  • Types:
    • StepIndicatorConverter: Step → Brush color
    • BoolToVisibilityConverter: bool → Visibility
    • ShowNextButtonConverter: step == 5 → hide/show Next
    • ShowGenerateButtonConverter: step != 5 → hide/show Generate
    • NextButtonTextConverter: step → button text
    • StepContentConverter: step → view content
    • InverseBoolConverter: (existing) bool → !bool

State Management

WizardViewModel State

CurrentStep: 1-5                                    // Current wizard step
Step1Valid: bool                                    // Connection valid
Step2Valid: bool                                    // Tables selected
Step3Valid: bool                                    // Naming configured
Step4Valid: bool                                    // Output configured
Step5Valid: bool                                    // Always true
CanGoBack: bool = CurrentStep > 1
CanGoNext: bool = CurrentStep < 5 && CurrentStepValid
CanGenerate: bool = CurrentStep == 5 && Step5Valid
IsBusy: bool                                        // Generation in progress
StatusMessage: string                               // Current status
PreviewEntity: string                               // Entity code snippet
PreviewDbContext: string                            // DbContext code snippet
PreviewFluentConfig: string                         // Fluent config snippet
HasExistingFiles: bool                              // Placeholder for Phase 6

MainViewModel State (unchanged)

ServerName, DatabaseName, UseWindowsAuth, Username, Password
TableFilter, SelectedSchema
Namespace, DbContextName, OutputDirectory
ClassStyle, PropertyStyle, NamespaceStyle, FileStyle
ClassSuffix, PrefixToRemove, SuffixToRemove, SingularizeClassNames
UseNullableReferenceTypes, UseDataAnnotations, UseFluentApi
AllTables, TablesView, Schemas
StatusMessage, IsBusy, ProgressValue

Integration Points

With MainViewModel

  • Read: All properties for binding
  • Write: Checkbox selection (IsSelected), text inputs
  • Call: GenerateAsync() on step 5 completion
  • Listen: Property changes for validation

With App.xaml.cs

  • DI: WizardViewModel registered as singleton
  • Start: Main window DataContext set to WizardViewModel
  • Theme: MainViewModel.AppThemeChanged still fires for app theming

With Core Services

  • Generation: Delegates to EntityGenerator, DbContextGenerator, FluentConfigurationGenerator (unchanged)
  • File I/O: Delegates to CreateOnlyFileWriter (unchanged)
  • Database: Delegates to SqlServerMetadataReader (unchanged)

Future Enhancements (Phase 6+)

  1. Diff View: Show existing vs generated code side-by-side
  2. File Browser: Browse button for output directory
  3. Keyboard Navigation: Enter = Next, Escape = Cancel
  4. Error Messages: Display validation errors per step
  5. Progress Resumption: Save/load wizard state
  6. Preview Comparison: Show existing file contents in preview
  7. Themes in Wizard: Allow theme switching mid-wizard
  8. Batch Generation: Generate multiple namespaces
  9. History: Recent connections/settings
  10. Undo/Redo: Within wizard navigation

Testing Strategy

Unit Tests (MainViewModel + WizardViewModel)

  • Connection validation logic
  • Table selection state
  • Naming configuration
  • Output path validation
  • Step validation transitions
  • Preview generation

Integration Tests

  • Wizard navigation flow (1→5 and back)
  • Button enable/disable state
  • DataGrid selection sync
  • Preview code generation

Manual Tests

  • Click through all 5 steps
  • Verify navigation buttons enable/disable
  • Verify validation blocks Next button
  • Generate entities end-to-end
  • Test Cancel at each step
  • Test Back navigation

Performance Considerations

  • Preview Loading: Async on step 5 entry (LoadPreviewAsync)
  • Code Generation: Uses existing EntityGenerator (optimized)
  • AvalonEdit: Read-only, no syntax highlighting (lighter weight)
  • Binding: MVVM Community Toolkit (compiled bindings in release)

Accessibility (WCAG 2.1 AA)

  • All interactive controls have AutomationProperties.AutomationId
  • Button labels clearly indicate action
  • Step indicator numbered and titled
  • Status messages announced via TextBlock
  • Tab order follows visual flow
  • Color contrast meets AA standard (WPF-UI theme)
  • Keyboard navigation supported (Tab, Enter, Escape)

Security Considerations

  • Password field uses PasswordBox (not bound to ViewModel)
  • Connection string built via SqlServerConnectionStringBuilder
  • No credentials logged
  • Output files checked for overwrite protection
  • Database metadata read-only operation