GMI · TECHNOLOGY OBSERVATORY // ALL SYSTEMS NOMINAL
ENGINEERED BY LEOPARD DATA

Data Access Layer

Entity Framework Core implementation, repositories, and data access patterns.

DATA ACCESS FLOW
rendering diagram…
flowchart LR
    UI[Blazor Page<br/>MAUI Screen]:::app
    SVC[Service Interface<br/>50 plus implementations]:::svc
    REPO[Repository<br/>46 interfaces]:::svc
    CTX[GmiDbContext<br/>EF Core 9]:::svc
    DB[(MySQL<br/>Flexible Server)]:::data
    BLOB[(Azure Blob<br/>Storage)]:::data
    EXT[External APIs<br/>Stripe - FMP - SendGrid]:::ext

    UI -->|calls| SVC
    SVC -->|reads - writes via| REPO
    REPO -->|queries via| CTX
    CTX -->|SQL| DB
    SVC -->|file operations| BLOB
    SVC -->|integration calls| EXT

    classDef app fill:#1f2630,stroke:#C0894E,color:#F3EFE8;
    classDef svc fill:#241c14,stroke:#E2B583,color:#F3EFE8;
    classDef data fill:#22201a,stroke:#C0894E,color:#EBD3AE;
    classDef ext fill:#1b1f27,stroke:#5A616B,color:#C4C0B8;
    classDef sec fill:#1d2733,stroke:#5cc8e0,color:#eafaff;
Request flow from UI through service and repository layers to MySQL.

Gmi.DataAccess Library

The data access layer is implemented using Entity Framework Core with the following architecture:

  • DbContext: GmiDbContext - Central database context
  • Entities: POCO classes representing database tables
  • Configuration: Fluent API configuration for relationships and constraints
  • Migrations: Database schema versioning and updates

Entity Models

All entity models are defined in the Gmi.ClassLibrary.Models namespace with full Entity Framework Core annotations and navigation properties.

  • Account - User accounts with profile, contact info, and validation status
  • AccountEmailAddress - Multiple email addresses per account
  • AccountEmailValidationToken - Email verification tokens with expiration
  • AccountSmsNumber - SMS phone numbers for notifications
  • CreditCard - Tokenized payment methods

  • Job - Report generation jobs with status tracking
  • JobStatusType - Job status definitions (NewReadyForProcessing, Processing, etc.)
  • JobCharge - Links jobs to their associated charges
  • JobNotificationSetting - Notification preferences for jobs
  • JobNotificationSettingsAccountEmailAddress - Email notification recipients
  • JobNotificationSettingsAccountSmsNumber - SMS notification recipients

  • File - Generated reports with Azure blob storage integration
  • Folder - Hierarchical folder structure with parent/sibling relationships
  • JobFolder - Links jobs to folders
  • AccountFolder - Links accounts to folders
  • FileDownload - Download tracking and analytics

  • SymbolList - Named collections of stock symbols
  • SymbolListItem - Individual symbols within lists
  • JobSymbolList - Links jobs to symbol lists
  • PositionReport - Portfolio position tracking
  • PositionReportListItem - Individual positions with share counts and prices
  • ReportGenerationSchedule - Scheduled report generation

  • Charge - Service usage charges
  • Payment - Payment transaction records
  • ServicePricing - Pricing configuration per service
  • CouponCode - Promotional codes with discounts
  • CouponUsage - Tracks coupon redemptions
  • Invoice - Monthly billing invoices
  • InvoiceCharge - Links charges to invoices
  • BillingRun - Monthly billing process tracking

  • EmailToSend - Email queue with To/Cc/Bcc support
  • SmsToSend - SMS notification queue

  • AdminUser - Admin users with Azure AD integration
  • AdminUserRole - Enum: SuperAdmin, Admin, Support
  • AdminNotificationEmailAddress - Email addresses for admin event notifications

  • StripeWebhookEvent - Captured Stripe webhook events for idempotent processing
  • StripeRefund - Refund records from Stripe charge.refunded events
  • StripeDispute - Dispute records from Stripe dispute webhooks
  • FailedPaymentReconciliation - Failed payment tracking for reconciliation

  • ClaudeAnalysisJob - Claude AI analysis job tracking
  • ClaudeAnalysisRequest - Individual file analysis requests within a job
  • ReportComparisonJob - Period-over-period report comparison jobs
  • ReportComparisonJobSymbolList - Links comparison jobs to symbol lists

  • LoginHistory - User login tracking
  • AuditLog - System audit trail
  • ActivityLogEntry - User activity tracking (page views, clicks, operations)
  • SystemHealthCheck - Periodic system health check results
  • CriticalErrorLog - Critical error tracking across all services

  • SymbolListTemplate - Predefined symbol list templates (system and customer)
  • SymbolListTemplateItem - Individual symbols within templates
  • Download - ZIP download queue for folder downloads

Model Features

Data Annotations
  • [Key] - Primary key definitions
  • [Required] - Non-nullable fields
  • [StringLength] - Field size constraints
  • [Column] - Custom column mappings
  • [ForeignKey] - Relationship definitions
Navigation Properties
  • One-to-many relationships
  • Many-to-many via junction tables
  • Self-referencing hierarchies
  • Nullable foreign keys
  • Cascade delete behaviors

Repository Pattern Implementation

Service Layer (Gmi.Services) - 50+ Service Interfaces

The service layer provides abstraction over Entity Framework operations with 46 repository implementations:

Account & User Management
  • IAccountService - Account CRUD, search, and validation
  • IAccountEmailService - Email address management
  • IAccountSmsService - SMS number management
  • IAccountEmailValidationService - Email verification tokens
  • IAdminUserService - Admin user management
  • ICreditCardService - Payment method management
Job & Report Management
  • IJobService - Job lifecycle and queue management
  • IJobNotificationService - Notification preferences
  • IReportGenerationScheduleService - Scheduled reports
  • IScheduleEngineService - Schedule execution
  • ISymbolListService - Symbol list CRUD
  • ISymbolListItemService - Symbol list items
  • ISymbolListTemplateService - System/customer templates
  • IReportDashboardService - Report dashboard data
Billing & Payments
  • IChargeService - Charge recording and credits
  • IBillingService - Monthly billing orchestration
  • IInvoiceService - Invoice management
  • IPaymentService - Payment recording
  • IStripePaymentService - Stripe API integration
  • IStripeWebhookService - Webhook event processing
  • ICouponCodeService - Coupon management
Files, Messaging & AI
  • IFileService / IFolderService - File and folder management
  • IDownloadService - ZIP download queue
  • IMessagingService - Email and SMS queuing
  • IClaudeAnalysisManagementService - AI file analysis
  • IReportComparisonManagementService - Report comparison
  • IDashboardService - System and account dashboards
  • IActivityLogEntryService - Activity tracking
  • ISystemHealthCheckService - Health monitoring
  • IEtfHoldingsService - ETF holdings data

Data Flow Patterns

Read Operations
  1. Controller/Page calls Service
  2. Service queries DbContext
  3. EF Core executes SQL
  4. Results mapped to entities
  5. Data returned to UI
Write Operations
  1. UI sends data to Service
  2. Service validates data
  3. Entity changes tracked
  4. SaveChanges() commits
  5. Database updated
EF Core Features
  • Code First Migrations
  • Lazy Loading
  • Change Tracking
  • Connection Pooling
  • Query Optimization
Configuration

Connection String:

Server=localhost;Database=gmi;
Uid=username;Pwd=password;

Provider: Pomelo MySQL 9.0

Version: EF Core 9.0

Best Practices
  • Async/Await patterns
  • Proper disposal
  • Exception handling
  • Transaction management
  • Performance monitoring