Data Flow

End-to-end data flow diagrams query, mutation, backend pipeline, error handling, and caching strategy.

Understanding how data flows through SCRIPE is essential for debugging and extending the system. This page traces data from a button click in the UI all the way to the database and back.

Query Flow (Read)

When a user views data (e.g., opening the Users page), the flow starts at the View, goes through the ViewModel, TanStack Query, Repository, API Service, and finally the backend API.

Full Query Flow — Frontend to Database
View (UI)
uses hook
ViewModel
useQuery
TanStack Query
queryFn
Repository
GET
API Service
HTTP
Backend API

Mutation Flow (Write)

Full Mutation Flow — User Action to Cache Invalidation
User Action
onClick
ViewModel
mutate()
useMutation
mutationFn
Repository
HTTP
POST/PUT/DELETE
onSuccess
Invalidate Queries

Backend Request Pipeline

Every backend request passes through 10 middleware components and 4 SCRIPE mediator pipeline behaviors before reaching the handler. This ensures consistent logging, authentication, authorization, validation, feature gating, and auditing.

Backend Request Lifecycle
HTTP Request
CORS Middleware
Rate Limiter
Request Logger
JWT Authentication
Authorization
Controller → AstraFlow mediator.Send()
ValidationBehavior
AuditBehavior
Handler → Repository → DbContext
Result<T> → JSON Response

Error Handling

Errors are handled at multiple levels. Each error source has a specific handler, response code, and frontend handling strategy.

Error SourceHandlerResponse CodeFrontend Handling
Validation failureValidationBehavior throws ValidationException400 Bad RequestForm field errors via Result.errors[]
Auth failure (no token)JWT Middleware rejects401 UnauthorizedRedirect to /login
Auth failure (forbidden)Authorization policy rejects403 ForbiddenShow permission error
Entity not foundHandler returns Result.Failure()404 Not FoundShow 404 page
Rate limit exceededRate Limiter middleware429 Too Many RequestsShow retry message
Unhandled exceptionGlobal exception handler500 Internal Server ErrorShow generic error
Concurrency conflictEF Core throws DbUpdateConcurrencyException409 ConflictRetry with refresh

Caching Strategy

The backend uses a two-level caching strategy: L1 (in-process IMemoryCache) and L2 (distributed Redis). The frontend uses TanStack Query's built-in cache with configurable staleTime.

Two-Level Caching Strategy
Query Request
Check L1
L1: IMemoryCache (in-process)
Miss → Check L2
L2: Redis (distributed)
Miss → Query DB
Database Query
Cache result
Store in L1 + L2