# dukanx/hearth architecture

> Architecture diagram of the GitHub repository dukanx/hearth, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dukanx/hearth
- Repository: https://github.com/dukanx/hearth

## Overview

1. **Repository shape**
   - This is a full-stack monorepo with two major deployable parts: `Hearth.Api` on the backend and `hearth-web` on the frontend.
   - The backend is a .NET 10 ASP.NET Core service; the frontend is a React 19 + TypeScript PWA built with Vite.

2. **Top-level architecture style**
   - The backend follows **Clean Architecture** with **CQRS** and vertical feature slices.
   - Dependency direction is inward: `Api → Infrastructure → Application → Domain`.
   - The `Application` layer owns use cases and abstractions; `Infrastructure` provides persistence, identity, and push implementations; `Api` is a thin transport layer.

3. **Domain layer**
   - `Hearth.Domain` contains the core business model only: entities such as `Household`, `HouseholdTask`, `ShoppingItem`, `Notification`, and `PushSubscription`.
   - It also defines business enums like task status, shopping status, and task priority.
   - This layer has no framework dependencies, which keeps business rules isolated from persistence and transport concerns.

4. **Application layer as the use-case boundary**
   - `Hearth.Application` is organized by feature folders such as `Auth`, `Households`, `Tasks`, `Shopping`, `Notifications`, and `Push`.
   - Each feature typically has a command/query, handler, and validator, using MediatR and FluentValidation.
   - This layer defines the repository, identity, token, push, realtime, and current-user interfaces that the outer layers must implement.

5. **Backend request flow**
   - HTTP requests enter `Hearth.Api` through controllers like `AuthController`, `TasksController`, `ShoppingController`, and others.
   - Controllers do not contain business logic; they forward work to MediatR handlers through `ISender`.
   - Results are converted into HTTP responses via shared result extensions and exception handling.

6. **Persistence and identity**
   - `Hearth.Infrastructure` contains EF Core `AppDbContext`, repository implementations, migrations, and unit-of-work support.
   - ASP.NET Identity is used for user accounts, roles, and authentication, with JWT generation handled by `TokenService`.
   - Database state is PostgreSQL-backed via Npgsql, and migrations are part of the repository, so schema changes are first-class in the architecture.

7. **Household-centric access model**
   - The app is centered around a household boundary: users belong to one household and collaborate inside it.
   - Join codes are generated and stored through infrastructure services, with separate adult/child codes reflected in the domain and application logic.
   - Role-based behavior is enforced at the use-case level, especially where children have limited permissions.

8. **Tasks and shopping as collaborative workflows**
   - Tasks and shopping items are separate bounded areas but share the same household scope and notification patterns.
   - Task use cases cover CRUD, assignment, and status transitions; shopping use cases cover item lifecycle, quantity, and bought/needed state.
   - The application layer maps domain entities to DTOs for API consumption, keeping the frontend insulated from persistence shapes.

9. **Notifications and realtime**
   - Notifications are generated by application event handlers for important domain actions such as task creation, task assignment, item addition, and item purchase.
   - The system has two delivery channels: **SignalR** for live in-app updates and **Web Push** for background/system notifications.
   - `NotificationHub`, `RealtimeNotifier`, and related services create a realtime boundary between backend events and connected clients.

10. **Frontend architecture**
   - `hearth-web` is a React SPA/PWA with feature-oriented folders mirroring backend domains: auth, household, shopping, tasks, notifications, and lobby.
   - Data access is split into a small API client layer and feature-specific API wrappers.
   - State is mostly client-side and server-synced via TanStack Query, with route guards and auth context controlling access.

11. **Frontend realtime and PWA behavior**
   - The frontend subscribes to SignalR notifications through a dedicated hook, and also manages push subscription lifecycle through a separate hook.
   - A service worker in `public/push-sw.js` supports installed-app behavior and background push delivery.
   - This makes the frontend architecturally more than a standard SPA: it is designed for persistent mobile-style engagement and offline shell support.

12. **Cross-cutting concerns**
   - Authentication is JWT-based end to end; the API issues tokens, the frontend stores them, and requests are authenticated through the client layer.
   - Validation is standardized in the application layer, while API-level exception handling translates failures into consistent responses.
   - Shared DTOs and result types keep the contract between layers explicit and reduce coupling.

13. **Deployment model**
   - The root `Dockerfile` builds the frontend and publishes the backend into a single container, so the app is deployed as one host.
   - In production, the backend also serves the built frontend, which avoids CORS complexity and keeps SignalR same-origin.
   - Railway is the intended deployment target, with PostgreSQL as the external state store and optional VAPID configuration for push notifications.

14. **What an architecture diagram should emphasize**
   - Draw one backend host with three internal concentric layers: API transport, application use cases, and domain core, with infrastructure attached as the persistence/identity/push adapter layer.
   - Show PostgreSQL, JWT/Identity, SignalR, and Web Push as external dependencies of the backend.
   - Show the React PWA as a separate client that talks to the API, opens a SignalR connection, and registers for web push notifications.

Main entry points: [`Hearth.Infrastructure`](https://github.com/dukanx/hearth/blob/main/Hearth.Infrastructure) (Infrastructure), [`hearth-web`](https://github.com/dukanx/hearth/tree/main/hearth-web) (hearth-web), [`Hearth.Api`](https://github.com/dukanx/hearth/blob/main/Hearth.Api) (Hearth.Api), [`Hearth.Application`](https://github.com/dukanx/hearth/blob/main/Hearth.Application) (Application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend host"]
  node_api["Hearth.Api<br/>ASP.NET Core transport<br/>[Hearth.Api]"]
  node_controllers["Controllers<br/>HTTP endpoints<br/>[Controllers]"]
  node_hubs["SignalR Hub<br/>realtime transport<br/>[Hubs]"]
  node_app["Application<br/>use-case layer<br/>[Hearth.Application]"]
  node_features["Feature slices<br/>CQRS handlers<br/>[Features]"]
  node_app_interfaces["Ports<br/>abstractions<br/>[Interfaces]"]
  node_notifications_app["Notifications<br/>event handlers<br/>[Notifications]"]
  node_domain["Domain<br/>core model<br/>[Hearth.Domain]"]
  node_infrastructure["Infrastructure<br/>persistence and services"]
  node_dbcontext["AppDbContext<br/>EF Core context<br/>[AppDbContext.cs]"]
  node_repositories["Repositories<br/>data access<br/>[Repositories]"]
  node_identity["Identity<br/>auth service<br/>[Identity]"]
  node_pushsvc["Push service<br/>web push<br/>[WebPushNotifier.cs]"]
end

subgraph group_frontend["Frontend PWA"]
  node_web["hearth-web<br/>React PWA"]
  node_api_client["API client<br/>HTTP client"]
  node_auth_ui["Auth state<br/>client auth"]
  node_feature_ui["Feature UI<br/>pages and widgets"]
  node_realtime_ui["Realtime hooks<br/>SignalR client"]
  node_push_sw["Service worker<br/>PWA worker<br/>[push-sw.js]"]
end

subgraph group_external["External systems"]
  node_postgres[("PostgreSQL<br/>database")]
  node_signalr(("SignalR<br/>realtime channel"))
  node_jwt(("JWT auth<br/>token boundary"))
  node_webpush(("Web Push<br/>browser push"))
end

node_web -->|"uses"| node_api_client
node_web -->|"controls access"| node_auth_ui
node_web -->|"renders"| node_feature_ui
node_web -->|"subscribes"| node_realtime_ui
node_web -->|"registers"| node_push_sw
node_api_client -->|"HTTP"| node_api
node_api -->|"routes"| node_controllers
node_api -->|"hosts"| node_hubs
node_controllers -->|"delegates"| node_app
node_hubs -->|"connects to"| node_signalr
node_app -->|"organizes"| node_features
node_app -->|"depends on"| node_app_interfaces
node_features -->|"uses"| node_domain
node_notifications_app -->|"publishes via"| node_app_interfaces
node_notifications_app -->|"broadcasts"| node_hubs
node_domain -.->|"raises events"| node_notifications_app
node_infrastructure -->|"contains"| node_dbcontext
node_infrastructure -->|"implements"| node_repositories
node_infrastructure -->|"implements"| node_identity
node_infrastructure -->|"implements"| node_pushsvc
node_infrastructure -->|"satisfies"| node_app_interfaces
node_repositories -->|"persists to"| node_postgres
node_dbcontext -->|"maps to"| node_postgres
node_identity -->|"issues"| node_jwt
node_pushsvc -->|"delivers via"| node_webpush
node_auth_ui -->|"stores"| node_jwt
node_realtime_ui -->|"listens on"| node_signalr
node_realtime_ui -->|"subscribes"| node_webpush

click node_api "https://github.com/dukanx/hearth/blob/main/Hearth.Api"
click node_controllers "https://github.com/dukanx/hearth/blob/main/Hearth.Api/Controllers"
click node_hubs "https://github.com/dukanx/hearth/blob/main/Hearth.Api/Hubs"
click node_app "https://github.com/dukanx/hearth/blob/main/Hearth.Application"
click node_features "https://github.com/dukanx/hearth/blob/main/Hearth.Application/Features"
click node_app_interfaces "https://github.com/dukanx/hearth/blob/main/Hearth.Application/Common/Interfaces"
click node_notifications_app "https://github.com/dukanx/hearth/blob/main/Hearth.Application/Common/Notifications"
click node_domain "https://github.com/dukanx/hearth/blob/main/Hearth.Domain"
click node_infrastructure "https://github.com/dukanx/hearth/blob/main/Hearth.Infrastructure"
click node_dbcontext "https://github.com/dukanx/hearth/blob/main/Hearth.Infrastructure/Persistence/AppDbContext.cs"
click node_repositories "https://github.com/dukanx/hearth/blob/main/Hearth.Infrastructure/Persistence/Repositories"
click node_identity "https://github.com/dukanx/hearth/blob/main/Hearth.Infrastructure/Identity"
click node_pushsvc "https://github.com/dukanx/hearth/blob/main/Hearth.Infrastructure/Services/WebPushNotifier.cs"
click node_web "https://github.com/dukanx/hearth/tree/main/hearth-web"
click node_api_client "https://github.com/dukanx/hearth/tree/main/hearth-web/src/api"
click node_auth_ui "https://github.com/dukanx/hearth/tree/main/hearth-web/src/auth"
click node_feature_ui "https://github.com/dukanx/hearth/tree/main/hearth-web/src/features"
click node_realtime_ui "https://github.com/dukanx/hearth/tree/main/hearth-web/src/features/notifications"
click node_push_sw "https://github.com/dukanx/hearth/blob/main/hearth-web/public/push-sw.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_controllers,node_hubs,node_app,node_features,node_app_interfaces,node_notifications_app,node_domain,node_infrastructure,node_dbcontext,node_repositories,node_identity,node_pushsvc toneBlue
class node_web,node_api_client,node_auth_ui,node_feature_ui,node_realtime_ui,node_push_sw toneAmber
class node_postgres,node_signalr,node_jwt,node_webpush toneMint
```

## Components

### Backend host

ASP.NET Core API, application use cases, domain core, and infrastructure adapters.

- [Hearth.Api](https://github.com/dukanx/hearth/blob/main/Hearth.Api): ASP.NET Core transport · HTTP controllers, hubs, result mapping, and request entrypoint for the backend host. · `Hearth.Api`
- [Controllers](https://github.com/dukanx/hearth/blob/main/Hearth.Api/Controllers): HTTP endpoints · Auth, households, tasks, shopping, notifications, and push endpoints that forward to MediatR. · `Hearth.Api/Controllers`
- [SignalR Hub](https://github.com/dukanx/hearth/blob/main/Hearth.Api/Hubs): realtime transport · Notification hub, connection tracking, and notifier bridge for live client updates. · `Hearth.Api/Hubs`
- [Application](https://github.com/dukanx/hearth/blob/main/Hearth.Application): use-case layer · CQRS features, validation, DTO mapping, and application-facing abstractions. · `Hearth.Application`
- [Feature slices](https://github.com/dukanx/hearth/blob/main/Hearth.Application/Features): CQRS handlers · Auth, households, tasks, shopping, notifications, and push commands and queries. · `Hearth.Application/Features`
- [Ports](https://github.com/dukanx/hearth/blob/main/Hearth.Application/Common/Interfaces): abstractions · Repository, identity, token, join code, push, realtime, and current-user interfaces. · `Hearth.Application/Common/Interfaces`
- [Notifications](https://github.com/dukanx/hearth/blob/main/Hearth.Application/Common/Notifications): event handlers · Domain-action events and handlers that fan out to realtime and push delivery. · `Hearth.Application/Common/Notifications`
- [Domain](https://github.com/dukanx/hearth/blob/main/Hearth.Domain): core model · Entities and enums for households, tasks, shopping, notifications, and subscriptions. · `Hearth.Domain`
- [Infrastructure](https://github.com/dukanx/hearth/blob/main/Hearth.Infrastructure): persistence and services · EF Core, repositories, identity, JWT, join codes, and web push implementations. · `Hearth.Infrastructure`
- [AppDbContext](https://github.com/dukanx/hearth/blob/main/Hearth.Infrastructure/Persistence/AppDbContext.cs): EF Core context · Database model and unit-of-work boundary for PostgreSQL persistence. · `Hearth.Infrastructure/Persistence/AppDbContext.cs`
- [Repositories](https://github.com/dukanx/hearth/blob/main/Hearth.Infrastructure/Persistence/Repositories): data access · Concrete household, task, shopping, notification, and push subscription stores. · `Hearth.Infrastructure/Persistence/Repositories`
- [Identity](https://github.com/dukanx/hearth/blob/main/Hearth.Infrastructure/Identity): auth service · ASP.NET Identity user management and JWT token issuance. · `Hearth.Infrastructure/Identity`
- [Push service](https://github.com/dukanx/hearth/blob/main/Hearth.Infrastructure/Services/WebPushNotifier.cs): web push · VAPID-backed push subscription management and notification delivery. · `Hearth.Infrastructure/Services/WebPushNotifier.cs`

### Frontend PWA

React client with feature modules, API access, realtime hooks, and push support.

- [hearth-web](https://github.com/dukanx/hearth/tree/main/hearth-web): React PWA · Feature-oriented SPA/PWA client with auth, household, shopping, tasks, and notifications flows. · `hearth-web`
- [API client](https://github.com/dukanx/hearth/tree/main/hearth-web/src/api): HTTP client · Shared client and feature wrappers for authenticated server requests. · `hearth-web/src/api`
- [Auth state](https://github.com/dukanx/hearth/tree/main/hearth-web/src/auth): client auth · JWT storage, auth context, and route guards for access control. · `hearth-web/src/auth`
- [Feature UI](https://github.com/dukanx/hearth/tree/main/hearth-web/src/features): pages and widgets · Task, shopping, lobby, household, and notification screens and feature hooks. · `hearth-web/src/features`
- [Realtime hooks](https://github.com/dukanx/hearth/tree/main/hearth-web/src/features/notifications): SignalR client · Client subscription to notification hub updates and push subscription lifecycle. · `hearth-web/src/features/notifications`
- [Service worker](https://github.com/dukanx/hearth/blob/main/hearth-web/public/push-sw.js): PWA worker · Background push and installed-app support for the web client. · `hearth-web/public/push-sw.js`

### External systems

Runtime dependencies outside the repo boundary.

- **PostgreSQL**: database · Primary state store for application data and identity-backed records.
- **SignalR**: realtime channel · Live websocket-style transport used for in-app notification delivery.
- **JWT auth**: token boundary · Bearer token authentication used between client and API.
- **Web Push**: browser push · Background notification delivery through push subscriptions and VAPID.

## Connections

- hearth-web → API client: uses · The PWA sends all backend requests through shared HTTP client wrappers.
- hearth-web → Auth state: controls access · Auth context, storage, and route guards manage logged-in state.
- hearth-web → Feature UI: renders · Pages and feature widgets make up the main user experience.
- hearth-web → Realtime hooks: subscribes · The client listens for live notification updates and manages push registration.
- hearth-web → Service worker: registers · The installed app uses a service worker for background push support.
- API client → Hearth.Api: HTTP · Authenticated requests target the backend transport layer.
- Hearth.Api → Controllers: routes · Controllers are the public HTTP entrypoints.
- Hearth.Api → SignalR Hub: hosts · The API host exposes the notification hub and realtime boundary.
- Controllers → Application: delegates · Controllers forward work to MediatR instead of containing business logic.
- SignalR Hub → SignalR: connects to · Clients attach through SignalR for live updates.
- Application → Feature slices: organizes · Use cases are implemented as feature-based CQRS handlers.
- Application → Ports: depends on · Application code targets abstractions implemented by outer layers.
- Feature slices → Domain: uses · Commands and queries operate on the core entities and enums.
- Notifications → Ports: publishes via · Notification handlers dispatch through realtime and push ports.
- Notifications → SignalR Hub: broadcasts · Realtime notifications are sent to connected clients.
- Domain → Notifications: raises events · Task and shopping actions trigger notification events.
- Infrastructure → AppDbContext: contains · EF Core persistence is centered on the application DbContext.
- Infrastructure → Repositories: implements · Repository adapters fulfill the application persistence ports.
- Infrastructure → Identity: implements · Identity and token services support authentication and authorization.
- Infrastructure → Push service: implements · Push subscriptions and outbound web push delivery are provided here.
- Infrastructure → Ports: satisfies · Outer-layer services implement the application abstractions.
- Repositories → PostgreSQL: persists to · Entity state is stored in PostgreSQL.
- AppDbContext → PostgreSQL: maps to · The EF Core model is backed by PostgreSQL.
- Identity → JWT auth: issues · JWT tokens are generated for authenticated API access.
- Push service → Web Push: delivers via · Background notifications use browser push infrastructure.
- Auth state → JWT auth: stores · The client persists bearer tokens for subsequent requests.
- Realtime hooks → SignalR: listens on · The frontend opens a SignalR connection for live events.
- Realtime hooks → Web Push: subscribes · The client manages push subscription lifecycle with the browser push channel.
