# aau-giraf/foodplanner-api architecture

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

- Interactive diagram: https://gitdiagram.com/aau-giraf/foodplanner-api
- Repository: https://github.com/aau-giraf/foodplanner-api

## Overview

#### Purpose and runtime
Foodplanner is an ASP.NET Core REST backend for the GIRAF Foodplanner Flutter client. It manages role-based users, children/classrooms, meals and ingredient composition, images, one-time passwords, and feedback chat. The executable API starts in `FoodplannerApi/Program.cs`; HTTP endpoints are implemented in `FoodplannerApi/Controller/`.

#### Layered application boundary
The solution is organized into four main projects: API, domain/contracts, services, and SQL persistence. Controllers receive HTTP DTOs and delegate to service interfaces; services apply application rules and call repository interfaces defined with models; PostgreSQL implementations sit in the data-access project. Key paths: `FoodplannerApi/FoodplannerApi.csproj`, `FoodplannerModels/FoodplannerModels.csproj`, `FoodplannerServices/FoodplannerServices.csproj`, `FoodplannerDataAccessSql/FoodplannerDataAccessSql.csproj`.

#### API and authentication
Controllers expose resource-oriented endpoints for users, accounts, meal data, images, OTPs, and chat. A shared controller base likely centralizes API concerns. JWT authentication is provided by the auth service, while password handling is modeled separately. Exact paths: `FoodplannerApi/Controller/BaseController.cs`, `FoodplannerApi/Controller/UsersController.cs`, `FoodplannerServices/Auth/AuthService.cs`, `FoodplannerModels/Auth/IAuthService.cs`, `FoodplannerModels/Account/User/PasswordHandler.cs`.

#### Account and role domain
Account management supports teachers and parents, child associations, and classrooms. The domain uses entities plus create/read/update DTOs and mapping profiles, with services mediating repository access. This is the ownership/access boundary for meal-planning users. Paths: `FoodplannerServices/Account/UserService.cs`, `FoodplannerServices/Account/ChildrenService.cs`, `FoodplannerServices/Account/ClassroomService.cs`, `FoodplannerDataAccessSql/Account/UserRepository.cs`, `FoodplannerModels/Account/User/User.cs`.

#### Lunchbox and meal composition
The primary business domain models meals, ingredients, packed ingredients, subingredients, and relations between subingredients. API controllers route operations through corresponding services and PostgreSQL repositories; DTOs/profiles separate transport shapes from persisted domain entities. Paths: `FoodplannerApi/Controller/MealsController.cs`, `FoodplannerServices/Lunchbox/MealService.cs`, `FoodplannerDataAccessSql/Lunchbox/MealRepository.cs`, `FoodplannerServices/Lunchbox/SubIngredientRelationService.cs`, `FoodplannerDataAccessSql/Lunchbox/SubIngredientRelationRepository.cs`.

#### Persistence and schema evolution
PostgreSQL access is created through a connection factory and repository layer, including a generic repository abstraction. FluentMigrator-style versioned migrations define and evolve tables, foreign keys, indexes, OTPs, messages, meal templates, and subingredients; schema changes must be represented as a new reversible migration. Paths: `FoodplannerDataAccessSql/PostgreSQLConnectionFactory.cs`, `FoodplannerDataAccessSql/GenericRepository.cs`, `FoodplannerDataAccessSql/Migrations/1_InitTables.cs`, `FoodplannerDataAccessSql/Migrations/15_AddSubIngredients.cs`.

#### External services and deployment
Images are managed through dedicated image services/repositories and stored in MinIO; relational state is in PostgreSQL. Secrets, including database/service credentials, are loaded via Infisical. Docker supports deployment, with compose provisioning MinIO and PostgreSQL; GitHub Actions build, test, tag, and generate OpenAPI artifacts. Paths: `FoodplannerServices/Image/ImageService.cs`, `FoodplannerDataAccessSql/Image/FoodImageRepository.cs`, `FoodplannerServices/Secret/SecretsLoader.cs`, `Dockerfile`, `docker-compose-example.yml`, `.github/workflows/buildTest.yaml`.

Main entry points: [`FoodplannerDataAccessSql/GenericRepository.cs`](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/GenericRepository.cs) (Repository base), [`FoodplannerApi/Controller/BaseController.cs`](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerApi/Controller/BaseController.cs) (REST controllers), [`FoodplannerApi/Controller/UsersController.cs`](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerApi/Controller/UsersController.cs) (Users endpoints), [`FoodplannerServices/Lunchbox/MealService.cs`](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Lunchbox/MealService.cs) (Meal service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API"]
  node_api_project["API executable<br/>ASP.NET Core project"]
  node_controllers["REST controllers<br/>HTTP endpoint layer<br/>[BaseController.cs]"]
  node_users_controller["Users endpoints<br/>controller<br/>[UsersController.cs]"]
  node_meals_controller["Meals endpoints<br/>controller<br/>[MealsController.cs]"]
end

subgraph group_application["Application services"]
  node_models["Domain and contracts<br/>models project"]
  node_user_domain["User domain<br/>account entity<br/>[User.cs]"]
  node_password_handler["Password handling<br/>security component<br/>[PasswordHandler.cs]"]
  node_services_project["Service layer<br/>application project"]
  node_auth_service["JWT authentication<br/>auth service<br/>[AuthService.cs]"]
  node_account_services["Account services<br/>user, child, classroom services<br/>[UserService.cs]"]
  node_meal_service["Meal service<br/>lunchbox service<br/>[MealService.cs]"]
  node_subingredient_service["Subingredient relations<br/>lunchbox service"]
  node_image_service["Image service<br/>media service<br/>[ImageService.cs]"]
end

subgraph group_persistence["SQL persistence"]
  node_data_project["Data access layer<br/>SQL project"]
  node_repositories["Repository base<br/>generic repository"]
  node_user_repository["User repository<br/>account repository<br/>[UserRepository.cs]"]
  node_meal_repository["Meal repository<br/>lunchbox repository<br/>[MealRepository.cs]"]
  node_relation_repository["Subingredient repository<br/>lunchbox repository"]
  node_image_repository["Food image repository"]
  node_connection_factory["PostgreSQL connections<br/>connection factory"]
  node_migrations["Schema migrations<br/>versioned migrations<br/>[1_InitTables.cs]"]
end

subgraph group_infrastructure["Infrastructure"]
  node_secrets_loader["Secrets loader<br/>configuration service<br/>[SecretsLoader.cs]"]
  node_postgres[("PostgreSQL<br/>relational database")]
  node_minio[("MinIO<br/>object storage")]
  node_container_deploy["Container deployment<br/>Docker"]
  node_ci["Build and OpenAPI CI<br/>GitHub Actions<br/>[buildTest.yaml]"]
end

node_api_project -->|"hosts"| node_controllers
node_controllers -->|"includes"| node_users_controller
node_controllers -->|"includes"| node_meals_controller
node_users_controller -->|"delegates to"| node_account_services
node_users_controller -->|"authenticates via"| node_auth_service
node_meals_controller -->|"delegates to"| node_meal_service
node_models -->|"defines"| node_user_domain
node_auth_service -->|"uses"| node_password_handler
node_account_services -->|"uses"| node_user_repository
node_meal_service -->|"uses"| node_meal_repository
node_meal_service -->|"coordinates"| node_subingredient_service
node_subingredient_service -->|"uses"| node_relation_repository
node_image_service -->|"uses"| node_image_repository
node_repositories -->|"obtains connections"| node_connection_factory
node_user_repository -->|"extends"| node_repositories
node_meal_repository -->|"extends"| node_repositories
node_relation_repository -->|"extends"| node_repositories
node_image_repository -->|"extends"| node_repositories
node_connection_factory -->|"connects to"| node_postgres
node_migrations -->|"evolves schema"| node_postgres
node_image_repository -->|"stores images"| node_minio
node_secrets_loader -.->|"supplies credentials"| node_connection_factory
node_container_deploy -->|"packages"| node_api_project
node_ci -->|"builds"| node_container_deploy

click node_api_project "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerApi/FoodplannerApi.csproj"
click node_controllers "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerApi/Controller/BaseController.cs"
click node_users_controller "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerApi/Controller/UsersController.cs"
click node_meals_controller "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerApi/Controller/MealsController.cs"
click node_models "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerModels/FoodplannerModels.csproj"
click node_user_domain "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerModels/Account/User/User.cs"
click node_password_handler "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerModels/Account/User/PasswordHandler.cs"
click node_services_project "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/FoodplannerServices.csproj"
click node_auth_service "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Auth/AuthService.cs"
click node_account_services "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Account/UserService.cs"
click node_meal_service "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Lunchbox/MealService.cs"
click node_subingredient_service "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Lunchbox/SubIngredientRelationService.cs"
click node_image_service "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Image/ImageService.cs"
click node_secrets_loader "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Secret/SecretsLoader.cs"
click node_data_project "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/FoodplannerDataAccessSql.csproj"
click node_repositories "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/GenericRepository.cs"
click node_user_repository "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/Account/UserRepository.cs"
click node_meal_repository "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/Lunchbox/MealRepository.cs"
click node_relation_repository "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/Lunchbox/SubIngredientRelationRepository.cs"
click node_image_repository "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/Image/FoodImageRepository.cs"
click node_connection_factory "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/PostgreSQLConnectionFactory.cs"
click node_migrations "https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/Migrations/1_InitTables.cs"
click node_postgres "https://github.com/aau-giraf/foodplanner-api/blob/staging/docker-compose-example.yml"
click node_minio "https://github.com/aau-giraf/foodplanner-api/blob/staging/docker-compose-example.yml"
click node_container_deploy "https://github.com/aau-giraf/foodplanner-api/blob/staging/Dockerfile"
click node_ci "https://github.com/aau-giraf/foodplanner-api/blob/staging/.github/workflows/buildTest.yaml"

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_project,node_controllers,node_users_controller,node_meals_controller toneBlue
class node_models,node_user_domain,node_password_handler,node_services_project,node_auth_service,node_account_services,node_meal_service,node_subingredient_service,node_image_service toneAmber
class node_data_project,node_repositories,node_user_repository,node_meal_repository,node_relation_repository,node_image_repository,node_connection_factory,node_migrations toneMint
class node_secrets_loader,node_postgres,node_minio,node_container_deploy,node_ci toneRose
```

## Components

### API

- [API executable](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerApi/FoodplannerApi.csproj): ASP.NET Core project · Application entry point and HTTP host. · `FoodplannerApi/FoodplannerApi.csproj`
- [REST controllers](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerApi/Controller/BaseController.cs): HTTP endpoint layer · Resource endpoints for accounts, meals, images, OTPs, and chat. · `FoodplannerApi/Controller/BaseController.cs`
- [Users endpoints](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerApi/Controller/UsersController.cs): controller · `FoodplannerApi/Controller/UsersController.cs`
- [Meals endpoints](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerApi/Controller/MealsController.cs): controller · `FoodplannerApi/Controller/MealsController.cs`

### Application services

- [Domain and contracts](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerModels/FoodplannerModels.csproj): models project · Entities, DTOs, service and repository contracts. · `FoodplannerModels/FoodplannerModels.csproj`
- [User domain](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerModels/Account/User/User.cs): account entity · Role-based teacher and parent ownership boundary. · `FoodplannerModels/Account/User/User.cs`
- [Password handling](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerModels/Account/User/PasswordHandler.cs): security component · `FoodplannerModels/Account/User/PasswordHandler.cs`
- [Service layer](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/FoodplannerServices.csproj): application project · Applies application rules behind service interfaces. · `FoodplannerServices/FoodplannerServices.csproj`
- [JWT authentication](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Auth/AuthService.cs): auth service · `FoodplannerServices/Auth/AuthService.cs`
- [Account services](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Account/UserService.cs): user, child, classroom services · Manages users, child associations, and classrooms. · `FoodplannerServices/Account/UserService.cs`
- [Meal service](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Lunchbox/MealService.cs): lunchbox service · Coordinates meal and ingredient composition rules. · `FoodplannerServices/Lunchbox/MealService.cs`
- [Subingredient relations](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Lunchbox/SubIngredientRelationService.cs): lunchbox service · `FoodplannerServices/Lunchbox/SubIngredientRelationService.cs`
- [Image service](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Image/ImageService.cs): media service · `FoodplannerServices/Image/ImageService.cs`

### SQL persistence

- [Data access layer](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/FoodplannerDataAccessSql.csproj): SQL project · PostgreSQL repository implementations. · `FoodplannerDataAccessSql/FoodplannerDataAccessSql.csproj`
- [Repository base](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/GenericRepository.cs): generic repository · Shared persistence abstraction and operations. · `FoodplannerDataAccessSql/GenericRepository.cs`
- [User repository](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/Account/UserRepository.cs): account repository · `FoodplannerDataAccessSql/Account/UserRepository.cs`
- [Meal repository](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/Lunchbox/MealRepository.cs): lunchbox repository · `FoodplannerDataAccessSql/Lunchbox/MealRepository.cs`
- [Subingredient repository](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/Lunchbox/SubIngredientRelationRepository.cs): lunchbox repository · `FoodplannerDataAccessSql/Lunchbox/SubIngredientRelationRepository.cs`
- [Food image repository](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/Image/FoodImageRepository.cs): image repository · `FoodplannerDataAccessSql/Image/FoodImageRepository.cs`
- [PostgreSQL connections](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/PostgreSQLConnectionFactory.cs): connection factory · `FoodplannerDataAccessSql/PostgreSQLConnectionFactory.cs`
- [Schema migrations](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerDataAccessSql/Migrations/1_InitTables.cs): versioned migrations · Reversible schema evolution for relational tables and constraints. · `FoodplannerDataAccessSql/Migrations/1_InitTables.cs`

### Infrastructure

- [Secrets loader](https://github.com/aau-giraf/foodplanner-api/blob/staging/FoodplannerServices/Secret/SecretsLoader.cs): configuration service · Loads service credentials from Infisical. · `FoodplannerServices/Secret/SecretsLoader.cs`
- [PostgreSQL](https://github.com/aau-giraf/foodplanner-api/blob/staging/docker-compose-example.yml): relational database · `docker-compose-example.yml`
- [MinIO](https://github.com/aau-giraf/foodplanner-api/blob/staging/docker-compose-example.yml): object storage · Stores managed food images. · `docker-compose-example.yml`
- [Container deployment](https://github.com/aau-giraf/foodplanner-api/blob/staging/Dockerfile): Docker · `Dockerfile`
- [Build and OpenAPI CI](https://github.com/aau-giraf/foodplanner-api/blob/staging/.github/workflows/buildTest.yaml): GitHub Actions · Builds, tests, tags, and generates OpenAPI artifacts. · `.github/workflows/buildTest.yaml`

## Connections

- API executable → REST controllers: hosts
- REST controllers → Users endpoints: includes
- REST controllers → Meals endpoints: includes
- Users endpoints → Account services: delegates to
- Users endpoints → JWT authentication: authenticates via
- Meals endpoints → Meal service: delegates to
- Domain and contracts → User domain: defines
- JWT authentication → Password handling: uses
- Account services → User repository: uses
- Meal service → Meal repository: uses
- Meal service → Subingredient relations: coordinates
- Subingredient relations → Subingredient repository: uses
- Image service → Food image repository: uses
- Repository base → PostgreSQL connections: obtains connections
- User repository → Repository base: extends
- Meal repository → Repository base: extends
- Subingredient repository → Repository base: extends
- Food image repository → Repository base: extends
- PostgreSQL connections → PostgreSQL: connects to
- Schema migrations → PostgreSQL: evolves schema
- Food image repository → MinIO: stores images
- Secrets loader → PostgreSQL connections: supplies credentials
- Container deployment → API executable: packages
- Build and OpenAPI CI → Container deployment: builds
