# casolanki/maitree architecture

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

- Interactive diagram: https://gitdiagram.com/casolanki/maitree
- Repository: https://github.com/casolanki/maitree

## Overview

1. **Overall shape**
   - This repository is a **two-tier full-stack application**: an **ASP.NET Core backend** in `API/` and an **Angular SPA frontend** in `client/`.
   - The app appears centered on **user/member profiles, likes, messaging, admin moderation, and presence**, with the backend exposing HTTP APIs and real-time SignalR channels.

2. **Backend entrypoint and host boundary**
   - `API/Program.cs` is the backend composition root.
   - `API/Controllers/*` expose the REST API surface, while `API/wwwroot/` contains the built frontend assets, indicating the backend can also **serve the SPA in production**.
   - `API/Middleware/ExceptionMiddleware.cs` and `API/Errors/ApiException.cs` provide centralized API error handling.

3. **Domain model and persistence**
   - The core entities live in `API/Entities/`: `AppUser`, `AppRole`, `AppUserRole`, `Photo`, `Message`, `Group`, `Connection`, `UserLike`.
   - This is an **EF Core-backed domain** with a social/messaging model:
     - users can have photos,
     - users can like other users,
     - users can exchange messages,
     - users connect to SignalR groups/connections for presence and chat.

4. **Data access pattern**
   - Persistence is organized around repositories and a unit-of-work layer:
     - `API/Data/UserRepository.cs`
     - `API/Data/LikesRepository.cs`
     - `API/Data/MessageRepository.cs`
     - `API/Data/UnitOfWork.cs`
     - interfaces in `API/Interface/*`
   - `API/Data/DataContext.cs` is the EF Core context, with migrations under `API/Data/Migrations/`.
   - The app uses a **repository abstraction over EF Core** rather than direct context access from controllers.

5. **Authentication and authorization**
   - Authentication is token-based via `API/Services/TokenService.cs` and `API/Interface/ITokenService.cs`.
   - `API/Extensions/IdentityServiceExtensions.cs` and identity-related entities indicate **ASP.NET Core Identity** is used for user/role management.
   - The backend has admin-specific surfaces (`AdminController.cs`) and the client has guards/directives for role-based UI control, so authorization is a first-class boundary.

6. **Photos and external storage**
   - `API/Services/PhotoService.cs`, `API/Interface/IphotoService.cs`, and `API/Helpers/CloudinarySettings.cs` show that photo upload/management is delegated to an **external cloud photo service** (Cloudinary).
   - `Photo` is a core entity, so media handling is part of the main user profile flow, not an auxiliary feature.

7. **Real-time subsystem**
   - `API/SignalR/MessageHub.cs`, `PresenceHub.cs`, and `PresenceTracker.cs` implement the real-time layer.
   - This supports at least two live concerns:
     - **presence/online status tracking**
     - **instant messaging updates**
   - These hubs sit alongside the REST API, meaning the app combines **request/response** and **persistent socket-based** interaction.

8. **Backend API surface**
   - Controllers are split by feature:
     - `AccountController` for login/register/account actions
     - `UsersController` for member browsing/profile editing
     - `Likescontroller` for like relationships
     - `MessagesController` for messaging
     - `AdminController` for moderation/administration
   - DTOs in `API/DTOs/` separate API contracts from entities, so the backend does **mapping between persistence models and transport models**.

9. **Frontend application structure**
   - The Angular client is feature-organized under `client/src/app/`:
     - `members/` for member list/detail/edit/photo editor
     - `messages/` for messaging UI
     - `lists/` for likes/match lists
     - `admin/` for admin dashboards and moderation
     - `register/`, `home/`, `nav/`, and error pages
   - This suggests the SPA is the primary user interface, with feature modules and shared components rather than a monolithic page structure.

10. **Frontend-to-backend data flow**
   - Angular services in `client/src/app/_services/` (`account.service.ts`, `members.service.ts`, `message.service.ts`, `presence.service.ts`) are the main API boundary.
   - HTTP cross-cutting concerns are handled by interceptors:
     - `jwt.interceptor.ts` attaches auth tokens
     - `error.interceptor.ts` normalizes API failures
     - `loading.interceptor.ts` and `busy.service.ts` manage UI loading state
   - Guards (`auth.guard.ts`, `admin.guard.ts`, `prevent-unsaved-changes.guard.ts`) enforce route-level access and editing protection.

11. **Client state, models, and UI composition**
   - Client-side models mirror backend contracts: `member`, `message`, `photo`, `pagination`, `user`, `group`, `likeParams`, `userParams`.
   - Resolvers such as `member.detailed.resolver.ts` prefetch data before route activation.
   - Shared UI building blocks live in `_forms/`, `_directives/`, and `_modules/shared.module.ts`, indicating a reusable component architecture.

12. **Administration boundary**
   - The admin experience is separated both in backend and frontend:
     - backend: `AdminController`
     - frontend: `admin-panel`, `user-management`, `photo-management`, `admin.service.ts`, `roles-modal`
   - This creates a distinct privileged subsystem for role assignment and moderation, rather than blending admin features into regular user screens.

13. **Deployment and packaging**
   - There are Docker assets for the backend (`API/Dockerfile`) and CI/CD workflows in `.github/workflows/` plus `cicd-bckup/`.
   - `fly.toml` suggests deployment to **Fly.io** or a similarly configured container platform.
   - The presence of built assets in `API/wwwroot/` implies a production build that packages the SPA with the API container or deployable unit.

14. **What to draw as the key architecture boundaries**
   - At minimum, the diagram should show:
     - **Angular SPA client**
     - **ASP.NET Core API**
     - **EF Core/PostgreSQL persistence**
     - **Identity/token auth**
     - **Cloudinary external media storage**
     - **SignalR real-time channel**
   - The main flows are: user authentication → token-protected API calls, profile/photo management → DB + Cloudinary, and messaging/presence → SignalR plus database-backed message history.

Main entry points: [`client/src/app/app.module.ts`](https://github.com/casolanki/maitree/blob/main/client/src/app/app.module.ts) (SPA shell), [`API/Program.cs`](https://github.com/casolanki/maitree/blob/main/API/Program.cs) (API host), [`API/Controllers`](https://github.com/casolanki/maitree/tree/main/API/Controllers) (REST controllers), [`client/src/app/_services`](https://github.com/casolanki/maitree/tree/main/client/src/app/_services) (Client services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Angular SPA"]
  node_client_app["SPA shell<br/>Angular app<br/>[app.module.ts]"]
  node_client_members["Members<br/>feature module"]
  node_client_messages["Messages<br/>feature module"]
  node_client_lists["Likes lists<br/>feature module"]
  node_client_admin["Admin UI<br/>privileged feature"]
  node_client_services["Client services<br/>API adapters"]
  node_client_security["Guards/interceptors<br/>cross-cutting UI"]
  node_client_shared["Shared UI<br/>components/directives"]
end

subgraph group_api["ASP.NET Core API"]
  node_api_host["API host<br/>ASP.NET Core app<br/>[Program.cs]"]
  node_api_auth["Identity/auth<br/>security subsystem"]
  node_api_controllers["REST controllers<br/>api surface"]
  node_api_dtos["DTO mapping<br/>contracts"]
  node_api_domain[("Domain entities<br/>EF Core model")]
  node_api_data["Repositories<br/>data access"]
  node_api_context[("Db context<br/>EF Core context<br/>[DataContext.cs]")]
  node_api_real_time["SignalR hubs<br/>real-time layer"]
  node_api_media["Photo service<br/>external integration<br/>[PhotoService.cs]"]
  node_api_errors["Error handling<br/>middleware"]
end

subgraph group_infra["External / deploy"]
  node_deploy_assets["SPA assets<br/>static build<br/>[index.html]"]
  node_deploy_ci["CI/CD<br/>build/deploy<br/>[fly.toml]"]
end

node_client_app -->|"routes to"| node_client_members
node_client_app -->|"routes to"| node_client_messages
node_client_app -->|"routes to"| node_client_lists
node_client_app -->|"routes to"| node_client_admin
node_client_app -->|"uses"| node_client_services
node_client_app -->|"protected by"| node_client_security
node_client_app -->|"composes"| node_client_shared
node_client_services -->|"calls"| node_api_controllers
node_client_services -->|"connects to"| node_api_real_time
node_api_host -->|"exposes"| node_api_controllers
node_api_host -->|"uses"| node_api_errors
node_api_host -->|"configures"| node_api_auth
node_api_host -->|"wires"| node_api_data
node_api_host -->|"hosts"| node_api_real_time
node_api_host -->|"serves"| node_deploy_assets
node_api_controllers -->|"uses"| node_api_dtos
node_api_controllers -->|"depends on"| node_api_data
node_api_data -->|"wraps"| node_api_context
node_api_context -->|"maps"| node_api_domain
node_api_controllers -->|"secures"| node_api_auth
node_api_controllers -->|"uploads photos"| node_api_media
node_api_real_time -->|"persists state"| node_api_context
node_deploy_ci -->|"builds/deploys"| node_api_host
node_deploy_ci -->|"packages"| node_client_app

click node_client_app "https://github.com/casolanki/maitree/blob/main/client/src/app/app.module.ts"
click node_client_members "https://github.com/casolanki/maitree/tree/main/client/src/app/members"
click node_client_messages "https://github.com/casolanki/maitree/tree/main/client/src/app/messages"
click node_client_lists "https://github.com/casolanki/maitree/tree/main/client/src/app/lists"
click node_client_admin "https://github.com/casolanki/maitree/tree/main/client/src/app/admin"
click node_client_services "https://github.com/casolanki/maitree/tree/main/client/src/app/_services"
click node_client_security "https://github.com/casolanki/maitree/tree/main/client/src/app/_guards"
click node_client_shared "https://github.com/casolanki/maitree/tree/main/client/src/app/_forms"
click node_api_host "https://github.com/casolanki/maitree/blob/main/API/Program.cs"
click node_api_auth "https://github.com/casolanki/maitree/blob/main/API/Extensions/IdentityServiceExtensions.cs"
click node_api_controllers "https://github.com/casolanki/maitree/tree/main/API/Controllers"
click node_api_dtos "https://github.com/casolanki/maitree/tree/main/API/DTOs"
click node_api_domain "https://github.com/casolanki/maitree/tree/main/API/Entities"
click node_api_data "https://github.com/casolanki/maitree/tree/main/API/Data"
click node_api_context "https://github.com/casolanki/maitree/blob/main/API/Data/DataContext.cs"
click node_api_real_time "https://github.com/casolanki/maitree/tree/main/API/SignalR"
click node_api_media "https://github.com/casolanki/maitree/blob/main/API/Services/PhotoService.cs"
click node_api_errors "https://github.com/casolanki/maitree/blob/main/API/Middleware/ExceptionMiddleware.cs"
click node_deploy_assets "https://github.com/casolanki/maitree/blob/main/API/wwwroot/index.html"
click node_deploy_ci "https://github.com/casolanki/maitree/blob/main/fly.toml"

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_client_app,node_client_members,node_client_messages,node_client_lists,node_client_admin,node_client_services,node_client_security,node_client_shared toneBlue
class node_api_host,node_api_auth,node_api_controllers,node_api_dtos,node_api_domain,node_api_data,node_api_context,node_api_real_time,node_api_media,node_api_errors toneAmber
class node_deploy_assets,node_deploy_ci toneMint
```

## Components

### Angular SPA

Browser application with feature modules, shared UI, and API services.

- [SPA shell](https://github.com/casolanki/maitree/blob/main/client/src/app/app.module.ts): Angular app · Root Angular application, routing, and top-level layout. · `client/src/app/app.module.ts`
- [Members](https://github.com/casolanki/maitree/tree/main/client/src/app/members): feature module · Browse, view, edit, and manage member profiles and photos. · `client/src/app/members`
- [Messages](https://github.com/casolanki/maitree/tree/main/client/src/app/messages): feature module · Messaging UI for conversations and live updates. · `client/src/app/messages`
- [Likes lists](https://github.com/casolanki/maitree/tree/main/client/src/app/lists): feature module · Screens for likes and match-oriented member lists. · `client/src/app/lists`
- [Admin UI](https://github.com/casolanki/maitree/tree/main/client/src/app/admin): privileged feature · Admin dashboard, user moderation, photo review, and role management. · `client/src/app/admin`
- [Client services](https://github.com/casolanki/maitree/tree/main/client/src/app/_services): API adapters · HTTP and signal services for account, members, messages, presence, busy state, and pagination. · `client/src/app/_services`
- [Guards/interceptors](https://github.com/casolanki/maitree/tree/main/client/src/app/_guards): cross-cutting UI · Route guards and HTTP interceptors for auth, errors, loading, and unsaved changes. · `client/src/app/_guards`
- [Shared UI](https://github.com/casolanki/maitree/tree/main/client/src/app/_forms): components/directives · Reusable forms, directives, modal dialogs, and shared module. · `client/src/app/_forms`

### ASP.NET Core API

Backend host exposing REST endpoints, identity, persistence, and real-time hubs.

- [API host](https://github.com/casolanki/maitree/blob/main/API/Program.cs): ASP.NET Core app · Composition root, middleware, controllers, SPA fallback, and static hosting. · `API/Program.cs`
- [Identity/auth](https://github.com/casolanki/maitree/blob/main/API/Extensions/IdentityServiceExtensions.cs): security subsystem · ASP.NET Core Identity and token-based authentication/authorization. · `API/Extensions/IdentityServiceExtensions.cs`
- [REST controllers](https://github.com/casolanki/maitree/tree/main/API/Controllers): api surface · Account, users, likes, messages, and admin endpoints. · `API/Controllers`
- [DTO mapping](https://github.com/casolanki/maitree/tree/main/API/DTOs): contracts · Request and response models separating transport from entities. · `API/DTOs`
- [Domain entities](https://github.com/casolanki/maitree/tree/main/API/Entities): EF Core model · Users, roles, photos, likes, messages, connections, and groups. · `API/Entities`
- [Repositories](https://github.com/casolanki/maitree/tree/main/API/Data): data access · Repository and unit-of-work layer over EF Core persistence. · `API/Data`
- [Db context](https://github.com/casolanki/maitree/blob/main/API/Data/DataContext.cs): EF Core context · Database context and migrations for the application schema. · `API/Data/DataContext.cs`
- [SignalR hubs](https://github.com/casolanki/maitree/tree/main/API/SignalR): real-time layer · Presence and messaging hubs plus presence tracking. · `API/SignalR`
- [Photo service](https://github.com/casolanki/maitree/blob/main/API/Services/PhotoService.cs): external integration · Photo upload and management through Cloudinary. · `API/Services/PhotoService.cs`
- [Error handling](https://github.com/casolanki/maitree/blob/main/API/Middleware/ExceptionMiddleware.cs): middleware · Centralized API exception middleware and error model. · `API/Middleware/ExceptionMiddleware.cs`

### External / deploy

Non-application services and packaging boundaries.

- [SPA assets](https://github.com/casolanki/maitree/blob/main/API/wwwroot/index.html): static build · Built frontend files served from the backend wwwroot in production. · `API/wwwroot/index.html`
- [CI/CD](https://github.com/casolanki/maitree/blob/main/fly.toml): build/deploy · Docker build and push workflows plus Fly deployment config. · `fly.toml`

## Connections

- SPA shell → Members: routes to · Primary member browsing and editing area.
- SPA shell → Messages: routes to · Messaging feature entry point.
- SPA shell → Likes lists: routes to · Likes and match list screens.
- SPA shell → Admin UI: routes to · Privileged admin area.
- SPA shell → Client services: uses · All feature modules call backend through services.
- SPA shell → Guards/interceptors: protected by · Route and request cross-cutting controls.
- SPA shell → Shared UI: composes · Reusable UI building blocks.
- Client services → REST controllers: calls · HTTP boundary from Angular to REST endpoints.
- Client services → SignalR hubs: connects to · Presence and message live updates.
- API host → REST controllers: exposes · REST API surface.
- API host → Error handling: uses · Centralized exception handling.
- API host → Identity/auth: configures · Authentication and authorization setup.
- API host → Repositories: wires · Repository and unit-of-work dependencies.
- API host → SignalR hubs: hosts · SignalR hubs alongside HTTP endpoints.
- API host → SPA assets: serves · Production SPA static files.
- REST controllers → DTO mapping: uses · Transport contracts for requests and responses.
- REST controllers → Repositories: depends on · Feature data access through repositories.
- Repositories → Db context: wraps · EF Core persistence implementation.
- Db context → Domain entities: maps · Entity model and relationships.
- REST controllers → Identity/auth: secures · User, role, and token-based access control.
- REST controllers → Photo service: uploads photos · Profile photo management flow.
- SignalR hubs → Db context: persists state · Message history, groups, and presence-related data.
- CI/CD → API host: builds/deploys · Container and release pipeline for the backend.
- CI/CD → SPA shell: packages · Frontend build artifacts included in deployment.
