# respawnsive/starcellar architecture

> Architecture diagram of the GitHub repository respawnsive/starcellar, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/respawnsive/starcellar
- Repository: https://github.com/respawnsive/starcellar

## Overview

##### Project Type and Purpose
- This is a full-stack sample application demonstrating how to use Apizr, a resilient Refit-based HTTP client manager, within a .NET MAUI cross-platform app (“StarCellar.App”), backed by a .NET 6 Web API (“StarCellar.Api”) and an EF Core SQL database.
- The README confirms it’s an end-to-end tutorial repository with two flavors of the client (With.Apizr and Without.Apizr) illustrating progressively advanced Apizr features (retry, caching, auth, logging, etc.).

##### File Structure Analysis
- Top-level folders:
- StarCellar.Api – .NET Web API
- StarCellar.App – .NET MAUI app (two sub-projects: With.Apizr and Without.Apizr)
- Api subfolders:
- Data – EF Core DbContext, entities (User, Wine, Token, RefreshToken)
- Migrations – EF Core migration code
- Handlers – HTTP request handlers or controllers (FilesHandler, UsersHandler, WinesHandler)
- Utils – token generator/validator, email validator, claim converter
- appsettings.json – configuration for DB connections, JWT, etc.
- App (With.Apizr):
- Views (Xamarin/.NET MAUI Pages), ViewModels (MVVM), Services/Apis (interfaces Dtos, Refit APIs), NavigationService
- Platform folders (Android, iOS, Windows, MacCatalyst)
- MauiProgram.cs – dependency injection container, Apizr registration
- The Without.Apizr project mirrors the same structure but uses raw Refit or HttpClient calls instead of Apizr.

##### Key README Insights
- Purpose: step-by-step tutorial of Apizr features in a real-world sample (CRUD on Wine cellar, file transfers, auth flows).
- Two client branches show before/after using Apizr.
- Underlying architecture: MAUI client ⇄ Apizr/ReFit HTTP client ⇄ .NET Web API ⇄ EF Core SQL database.

##### Diagramming the Architecture
a. Main Components
- Mobile Clients (MAUI apps)
– View Layer (XAML Pages)
– ViewModels (MVVM)
– Apizr/ReFit HTTP Client layer (With.Apizr) or direct Refit/HttpClient (Without.Apizr)
– Navigation Service
- StarCellar Web API
– Handlers/Controllers (Users, Wines, Files)
– Business Utilities (TokenGenerator, Validators, Converters)
– Data Access (EF Core DbContext)
- Data Store
– SQL Server (or SQLite) database with tables for Users, Wines, RefreshTokens
- External Services (optional)
– Email provider (for validation), Identity Provider if extended
b. Relationships & Interactions
1. User interacts with the MAUI UI → invokes commands on ViewModel.
2. ViewModel calls Apizr client → issues HTTP requests to API endpoints.
3. API Handlers process requests → use Utils + DbContext to read/write to database.
4. Database returns entities → API serializes DTOs back to client.
5. Apizr layer handles retries, caching, connectivity checks, authentication (JWT + refresh tokens).
c. Architectural Patterns & Principles
– MVVM on the client
– Refit + Apizr as a layer to encapsulate HTTP concerns (resilience, logging, auth)
– Clean separation: API controllers vs Data vs Utils
– Dependency Injection throughout (MauiProgram.cs and Program.cs in API)
d. Key Technologies
– .NET MAUI, XAML (cross-platform UI)
– MVVM pattern (ViewModels, NavigationService)
– Apizr/Refit (client HTTP abstraction)
– .NET 6 Web API, minimal Program.cs
– EF Core Code-First migrations
– JWT Bearer Authentication, Refresh Tokens

##### Detail
- Every layer: UI → MVVM → HTTP client → API layers → data access → persistence.
- This clarity helps guide both tutorial readers and maintainers through the end-to-end flow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Mobile Client - With.Apizr"
        direction TB
        ViewsA["Views (XAML)"]:::frontend
        VM_A["ViewModels"]:::frontend
        ApizrLayer["Apizr/ReFit HTTP Client"]:::library
        CellarAPI["Cellar API definitions"]:::library
        FileAPI["File API definitions"]:::library
        Nav_A["Navigation Service"]:::frontend
        DI_A["MauiProgram.cs\n(DI & Apizr Reg)"]:::config

        ViewsA --> VM_A
        VM_A --> ApizrLayer
        ApizrLayer --> CellarAPI
        ApizrLayer --> FileAPI
        VM_A --> Nav_A
        DI_A --> ApizrLayer
    end

    subgraph "Mobile Client - Without.Apizr"
        direction TB
        ViewsB["Views (XAML)"]:::frontend
        VM_B["ViewModels"]:::frontend
        HTTP_B["Raw Refit/HttpClient"]:::library
        Nav_B["Navigation Service"]:::frontend
        DI_B["MauiProgram.cs\n(DI Setup)"]:::config

        ViewsB --> VM_B
        VM_B --> HTTP_B
        VM_B --> Nav_B
        DI_B --> HTTP_B
    end

    subgraph "Web API + Database"
        direction TB
        APIStart["Program.cs\n(Startup & DI)"]:::config
        Controllers["Controllers/Handlers"]:::backend
        Utils["Business Utilities"]:::library
        DataAccess["DbContext & Entities"]:::library
        Migrations["EF Core Migrations"]:::library
        DB["SQL Database"]:::database

        APIStart --> Controllers
        Controllers --> Utils
        Controllers --> DataAccess
        DataAccess --> DB
        Utils --> DataAccess
        Migrations --> DataAccess
    end

    ApizrLayer -->|"HTTP Calls"| APIStart
    HTTP_B -->|"HTTP Calls"| APIStart

    click ViewsA "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.App/StarCellar.With.Apizr/Views"
    click VM_A "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.App/StarCellar.With.Apizr/ViewModels"
    click ApizrLayer "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.App/StarCellar.With.Apizr/Services/Apis"
    click CellarAPI "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.App/StarCellar.With.Apizr/Services/Apis/Cellar"
    click FileAPI "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.App/StarCellar.With.Apizr/Services/Apis/Files"
    click Nav_A "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.App/StarCellar.With.Apizr/Services/Navigation"
    click DI_A "https://github.com/respawnsive/starcellar/blob/01-Getting_started/StarCellar.App/StarCellar.With.Apizr/MauiProgram.cs"

    click ViewsB "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.App/StarCellar.Without.Apizr/Views"
    click VM_B "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.App/StarCellar.Without.Apizr/ViewModels"
    click HTTP_B "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.App/StarCellar.Without.Apizr/Services/Apis"
    click Nav_B "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.App/StarCellar.Without.Apizr/Services/Navigation"
    click DI_B "https://github.com/respawnsive/starcellar/blob/01-Getting_started/StarCellar.App/StarCellar.Without.Apizr/MauiProgram.cs"

    click APIStart "https://github.com/respawnsive/starcellar/blob/01-Getting_started/StarCellar.Api/Program.cs"
    click Controllers "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.Api/Handlers"
    click DataAccess "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.Api/Data"
    click Migrations "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.Api/Migrations"
    click Utils "https://github.com/respawnsive/starcellar/tree/01-Getting_started/StarCellar.Api/Utils"

    classDef frontend fill:#E0F7FA,stroke:#006064,color:#006064
    classDef backend fill:#E1F5FE,stroke:#0D47A1,color:#0D47A1
    classDef library fill:#FFF3E0,stroke:#E65100,color:#E65100
    classDef database fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32
    classDef config fill:#ECEFF1,stroke:#607D8B,color:#37474F
```
