How aau-giraf/foodplanner-api works
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: GenericRepository.cs Repository base · BaseController.cs REST controllers · UsersController.cs Users endpoints · MealService.cs Meal service
Components 26
API
- API executable · Application entry point and HTTP host.
FoodplannerApi/FoodplannerApi.csproj - REST controllers · Resource endpoints for accounts, meals, images, OTPs, and chat.
FoodplannerApi/Controller/BaseController.cs - Users endpoints
FoodplannerApi/Controller/UsersController.cs - Meals endpoints
FoodplannerApi/Controller/MealsController.cs
Application services
- Domain and contracts · Entities, DTOs, service and repository contracts.
FoodplannerModels/FoodplannerModels.csproj - User domain · Role-based teacher and parent ownership boundary.
FoodplannerModels/Account/User/User.cs - Password handling
FoodplannerModels/Account/User/PasswordHandler.cs - Service layer · Applies application rules behind service interfaces.
FoodplannerServices/FoodplannerServices.csproj - JWT authentication
FoodplannerServices/Auth/AuthService.cs - Account services · Manages users, child associations, and classrooms.
FoodplannerServices/Account/UserService.cs - Meal service · Coordinates meal and ingredient composition rules.
FoodplannerServices/Lunchbox/MealService.cs - Subingredient relations
FoodplannerServices/Lunchbox/SubIngredientRelationService.cs - Image service
FoodplannerServices/Image/ImageService.cs
SQL persistence
- Data access layer · PostgreSQL repository implementations.
FoodplannerDataAccessSql/FoodplannerDataAccessSql.csproj - Repository base · Shared persistence abstraction and operations.
FoodplannerDataAccessSql/GenericRepository.cs - User repository
FoodplannerDataAccessSql/Account/UserRepository.cs - Meal repository
FoodplannerDataAccessSql/Lunchbox/MealRepository.cs - Subingredient repository
FoodplannerDataAccessSql/Lunchbox/SubIngredientRelationRepository.cs - Food image repository
FoodplannerDataAccessSql/Image/FoodImageRepository.cs - PostgreSQL connections
FoodplannerDataAccessSql/PostgreSQLConnectionFactory.cs - Schema migrations · Reversible schema evolution for relational tables and constraints.
FoodplannerDataAccessSql/Migrations/1_InitTables.cs
Infrastructure
- Secrets loader · Loads service credentials from Infisical.
FoodplannerServices/Secret/SecretsLoader.cs - PostgreSQL
docker-compose-example.yml - MinIO · Stores managed food images.
docker-compose-example.yml - Container deployment
Dockerfile - Build and OpenAPI CI · Builds, tests, tags, and generates OpenAPI artifacts.
.github/workflows/buildTest.yaml
Connections 24
- 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