# trycatchlearn/datingapp architecture

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

- Interactive diagram: https://gitdiagram.com/trycatchlearn/datingapp
- Repository: https://github.com/trycatchlearn/datingapp

## Overview

1. This repo is a two-part monorepo: an ASP.NET Core 9 backend in `API/` and an Angular 20 SPA in `client/`. The backend also serves the built frontend from `API/wwwroot`, so the deployed app is a single hosted system with an API and static SPA assets behind the same origin.

2. The backend is the application boundary for all data and security. HTTP entry points are organized by controller: `AccountController` for auth, `MembersController` for profile/member data, `LikesController` for matching/likes, `MessagesController` for chat, `AdminController` for moderation/admin workflows, plus `FallbackController` for SPA routing and `BuggyController`/`WeatherForecastController` for testing and template remnants.

3. The core domain is a dating/social model centered on `AppUser`, `Member`, `Photo`, `Message`, `MemberLike`, and the SignalR connection types `Connection`/`Group`. `AppDbContext` is the EF Core persistence boundary, with migrations under `API/Data/Migrations` defining the relational schema.

4. Data access is deliberately split behind repositories and a unit-of-work layer. `MemberRepository`, `LikesRepository`, `MessageRepository`, and `PhotoRepository` implement the main query/update paths, while `UnitOfWork` coordinates shared transaction-style changes. This keeps controllers thin and makes member browsing, likes, and messaging the main backend workflows.

5. Authentication is token-based. `TokenService` issues JWTs, `ClaimsPrincipalExtensions` and `AppUserExtensions` help read identity/claim data, and the Angular client stores and replays the token through a JWT interceptor. Authorization is enforced both server-side and client-side, including an admin-only path via `AdminController` and `admin-guard`.

6. Realtime behavior is handled with SignalR. `PresenceHub` and `PresenceTracker` manage online/offline state, while `MessageHub` supports live message delivery. This creates a separate realtime channel alongside normal REST calls, especially for chat status and message arrival.

7. Photo handling is an externalized subsystem. `IPhotoService`/`PhotoService` abstract image upload and management, with `CloudinarySettings` indicating cloud-hosted media storage rather than local file persistence. The admin photo review flow is also explicit via `PhotoForApprovalDto` and the admin photo-management UI.

8. The Angular app is structured by feature area rather than by technical layer. `app.routes.ts`, `app.config.ts`, and `app.ts` define the shell and route composition; `layout/nav` provides the top-level navigation; `shared/` contains reusable UI pieces like paginator, confirm dialog, star button, image upload, text input, and error pages.

9. Major frontend features map directly to backend domains: account registration, member list/detail/profile, member photos/messages, likes/lists, admin, and error-testing pages. Each feature has its own component tree, which makes the architecture easy to diagram as route-driven feature islands around a common shell.

10. Cross-cutting frontend behavior is centralized in services, guards, interceptors, and pipes. Services such as `account-service`, `member-service`, `message-service`, `likes-service`, `presence-service`, and `admin-service` encapsulate API access; interceptors handle JWT attachment, HTTP errors, and busy/loading state; guards protect authenticated/admin routes and unsaved edits; pipes handle domain presentation like age and time-ago formatting.

11. The data flow is straightforward: Angular screens call typed services, services hit ASP.NET controllers, controllers use DTOs to avoid exposing entities directly, and repositories/EF Core persist to the database. Realtime message/presence updates bypass the normal request/response flow through SignalR hubs, and photo operations route through the dedicated photo service.

12. Supporting infrastructure includes seeding and deployment helpers. `Seed.cs` and `UserSeedData.json` bootstrap initial users/data, `ExceptionMiddleware` standardizes API error handling, and the repo includes `docker-compose.yml` plus GitHub Actions workflow files for automation and environment setup.

Main entry points: [`client/src/core/services`](https://github.com/trycatchlearn/datingapp/tree/main/client/src/core/services) (Client services), [`API/Program.cs`](https://github.com/trycatchlearn/datingapp/blob/main/API/Program.cs) (Program), [`API/Controllers`](https://github.com/trycatchlearn/datingapp/tree/main/API/Controllers) (Controllers), [`API/Data/AppDbContext.cs`](https://github.com/trycatchlearn/datingapp/blob/main/API/Data/AppDbContext.cs) (AppDbContext)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["ASP.NET Core backend"]
  node_program["Program<br/>host bootstrap<br/>[Program.cs]"]
  node_controllers["Controllers<br/>REST endpoints"]
  node_dtos["DTOs<br/>contracts"]
  node_domain["Domain model<br/>entities"]
  node_dbcontext[("AppDbContext<br/>ef core boundary<br/>[AppDbContext.cs]")]
  node_repositories["Repositories<br/>data access"]
  node_uow["UnitOfWork<br/>transaction coordinator<br/>[UnitOfWork.cs]"]
  node_services["Services"]
  node_signalr{{"SignalR<br/>realtime"}}
  node_middleware["Middleware<br/>error handling"]
end

subgraph group_frontend["Angular SPA"]
  node_clientapp["Angular app<br/>spa shell"]
  node_routes["Routes<br/>routing shell<br/>[app.routes.ts]"]
  node_features["Features"]
  node_sharedui["Shared UI<br/>components"]
  node_clientservices["Client services<br/>api access"]
  node_clientguards["Guards<br/>route protection"]
  node_interceptors["Interceptors<br/>http pipeline"]
  node_pipes["Pipes<br/>presentation helpers"]
end

subgraph group_infra["Infrastructure"]
  node_seed["Seed data<br/>bootstrap data<br/>[Seed.cs]"]
  node_deployment["Deployment<br/>automation<br/>[docker-compose.yml]"]
end

node_program -->|"maps HTTP"| node_controllers
node_program -->|"configures"| node_dbcontext
node_program -->|"registers"| node_services
node_program -->|"hosts"| node_signalr
node_program -->|"uses"| node_middleware
node_controllers -->|"exchanges"| node_dtos
node_controllers -->|"queries"| node_repositories
node_controllers -->|"commits"| node_uow
node_controllers -->|"calls"| node_services
node_services -->|"operates on"| node_domain
node_repositories -->|"persists via"| node_dbcontext
node_dbcontext -->|"maps"| node_domain
node_signalr -->|"tracks"| node_domain
node_clientapp -->|"boots"| node_routes
node_routes -->|"loads"| node_features
node_features -->|"reuses"| node_sharedui
node_features -->|"calls"| node_clientservices
node_clientservices -->|"passes through"| node_interceptors
node_clientservices -->|"protected by"| node_clientguards
node_clientservices -->|"formats with"| node_pipes
node_clientservices -->|"requests"| node_controllers
node_clientservices -->|"subscribes to"| node_signalr
node_seed -->|"seeds"| node_dbcontext
node_deployment -->|"packages"| node_program
node_deployment -->|"builds"| node_clientapp

click node_program "https://github.com/trycatchlearn/datingapp/blob/main/API/Program.cs"
click node_controllers "https://github.com/trycatchlearn/datingapp/tree/main/API/Controllers"
click node_dtos "https://github.com/trycatchlearn/datingapp/tree/main/API/DTOs"
click node_domain "https://github.com/trycatchlearn/datingapp/tree/main/API/Entities"
click node_dbcontext "https://github.com/trycatchlearn/datingapp/blob/main/API/Data/AppDbContext.cs"
click node_repositories "https://github.com/trycatchlearn/datingapp/tree/main/API/Data"
click node_uow "https://github.com/trycatchlearn/datingapp/blob/main/API/Data/UnitOfWork.cs"
click node_services "https://github.com/trycatchlearn/datingapp/tree/main/API/Services"
click node_signalr "https://github.com/trycatchlearn/datingapp/tree/main/API/SignalR"
click node_middleware "https://github.com/trycatchlearn/datingapp/tree/main/API/Middleware"
click node_clientapp "https://github.com/trycatchlearn/datingapp/tree/main/client/src/app"
click node_routes "https://github.com/trycatchlearn/datingapp/blob/main/client/src/app/app.routes.ts"
click node_features "https://github.com/trycatchlearn/datingapp/tree/main/client/src/features"
click node_sharedui "https://github.com/trycatchlearn/datingapp/tree/main/client/src/shared"
click node_clientservices "https://github.com/trycatchlearn/datingapp/tree/main/client/src/core/services"
click node_clientguards "https://github.com/trycatchlearn/datingapp/tree/main/client/src/core/guards"
click node_interceptors "https://github.com/trycatchlearn/datingapp/tree/main/client/src/core/interceptors"
click node_pipes "https://github.com/trycatchlearn/datingapp/tree/main/client/src/core/pipes"
click node_seed "https://github.com/trycatchlearn/datingapp/blob/main/API/Data/Seed.cs"
click node_deployment "https://github.com/trycatchlearn/datingapp/blob/main/docker-compose.yml"

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_program,node_controllers,node_dtos,node_domain,node_dbcontext,node_repositories,node_uow,node_services,node_signalr,node_middleware toneBlue
class node_clientapp,node_routes,node_features,node_sharedui,node_clientservices,node_clientguards,node_interceptors,node_pipes toneAmber
class node_seed,node_deployment toneMint
```

## Components

### ASP.NET Core backend

API, domain, data, realtime, and hosting boundary.

- [Program](https://github.com/trycatchlearn/datingapp/blob/main/API/Program.cs): host bootstrap · Composes middleware, controllers, SignalR, auth, and static SPA hosting. · `API/Program.cs`
- [Controllers](https://github.com/trycatchlearn/datingapp/tree/main/API/Controllers): REST endpoints · Primary HTTP entry points for account, members, likes, messages, admin, fallback, and test routes. · `API/Controllers`
- [DTOs](https://github.com/trycatchlearn/datingapp/tree/main/API/DTOs): contracts · Request/response models that keep entities out of the API surface. · `API/DTOs`
- [Domain model](https://github.com/trycatchlearn/datingapp/tree/main/API/Entities): entities · Users, members, photos, likes, messages, and realtime connection/group state. · `API/Entities`
- [AppDbContext](https://github.com/trycatchlearn/datingapp/blob/main/API/Data/AppDbContext.cs): ef core boundary · Database context and schema mapping for the core dating app model. · `API/Data/AppDbContext.cs`
- [Repositories](https://github.com/trycatchlearn/datingapp/tree/main/API/Data): data access · Member, likes, message, and photo repositories behind shared query/update paths. · `API/Data`
- [UnitOfWork](https://github.com/trycatchlearn/datingapp/blob/main/API/Data/UnitOfWork.cs): transaction coordinator · Coordinates shared persistence changes across repositories. · `API/Data/UnitOfWork.cs`
- [Services](https://github.com/trycatchlearn/datingapp/tree/main/API/Services): app services · Token issuance and photo management implementations. · `API/Services`
- [SignalR](https://github.com/trycatchlearn/datingapp/tree/main/API/SignalR): realtime · Presence and message hubs plus online-user tracking. · `API/SignalR`
- [Middleware](https://github.com/trycatchlearn/datingapp/tree/main/API/Middleware): error handling · Centralized API exception translation and response shaping. · `API/Middleware`

### Angular SPA

Route-driven client shell, features, and shared UI.

- [Angular app](https://github.com/trycatchlearn/datingapp/tree/main/client/src/app): spa shell · Frontend application shell, routing, and build output served by the API. · `client/src/app`
- [Routes](https://github.com/trycatchlearn/datingapp/blob/main/client/src/app/app.routes.ts): routing shell · Top-level route composition and app bootstrap configuration. · `client/src/app/app.routes.ts`
- [Features](https://github.com/trycatchlearn/datingapp/tree/main/client/src/features): route features · Account, members, messages, lists, admin, home, and test-error views. · `client/src/features`
- [Shared UI](https://github.com/trycatchlearn/datingapp/tree/main/client/src/shared): components · Reusable controls, dialogs, uploaders, pagination, errors, and directives. · `client/src/shared`
- [Client services](https://github.com/trycatchlearn/datingapp/tree/main/client/src/core/services): api access · Typed services for accounts, members, likes, messages, presence, admin, busy state, and toast/confirm flows. · `client/src/core/services`
- [Guards](https://github.com/trycatchlearn/datingapp/tree/main/client/src/core/guards): route protection · Auth, admin, and unsaved-change route guards. · `client/src/core/guards`
- [Interceptors](https://github.com/trycatchlearn/datingapp/tree/main/client/src/core/interceptors): http pipeline · JWT attachment, error handling, and loading-state interception. · `client/src/core/interceptors`
- [Pipes](https://github.com/trycatchlearn/datingapp/tree/main/client/src/core/pipes): presentation helpers · Age and time-ago formatting for domain views. · `client/src/core/pipes`

### Infrastructure

Deployment, seeding, and automation support.

- [Seed data](https://github.com/trycatchlearn/datingapp/blob/main/API/Data/Seed.cs): bootstrap data · Initial user/data seeding and bundled seed payload. · `API/Data/Seed.cs`
- [Deployment](https://github.com/trycatchlearn/datingapp/blob/main/docker-compose.yml): automation · Docker compose and CI workflow for build and environment automation. · `docker-compose.yml`

## Connections

- Program → Controllers: maps HTTP · Registers controller endpoints and SPA fallback.
- Program → AppDbContext: configures · Wires EF Core persistence and connection settings.
- Program → Services: registers · Adds token and photo services to DI.
- Program → SignalR: hosts · Mounts realtime hubs alongside REST APIs.
- Program → Middleware: uses · Places exception handling in the request pipeline.
- Controllers → DTOs: exchanges · Uses DTOs for input and output models.
- Controllers → Repositories: queries · Member, likes, and message workflows delegate to repositories.
- Controllers → UnitOfWork: commits · Coordinates multi-step persistence operations.
- Controllers → Services: calls · Auth and photo operations depend on service layer.
- Services → Domain model: operates on · Token and photo services work with app entities and claims.
- Repositories → AppDbContext: persists via · Repository implementations run through the EF Core boundary.
- AppDbContext → Domain model: maps · Defines relational storage for the core entities.
- SignalR → Domain model: tracks · Presence and chat state use connection and group entities.
- Angular app → Routes: boots · The SPA shell starts from app routing and config.
- Routes → Features: loads · Routes resolve into feature areas.
- Features → Shared UI: reuses · Feature screens share common controls and error views.
- Features → Client services: calls · Screens talk to backend through typed services.
- Client services → Interceptors: passes through · HTTP calls are wrapped by JWT, error, and loading interceptors.
- Client services → Guards: protected by · Route access is constrained by auth and admin guards.
- Client services → Pipes: formats with · Presentation helpers support member and message views.
- Client services → Controllers: requests · Client services consume the backend API surface.
- Client services → SignalR: subscribes to · Presence and chat services use realtime hubs.
- Seed data → AppDbContext: seeds · Bootstrap data is loaded through the persistence layer.
- Deployment → Program: packages · Deployment bundles the hosted backend and SPA.
- Deployment → Angular app: builds · Frontend assets are part of the deployable system.
