# cloudproject-khu/myfridger-be architecture

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

- Interactive diagram: https://gitdiagram.com/cloudproject-khu/myfridger-be
- Repository: https://github.com/cloudproject-khu/myfridger-be

## Overview

MyFridger is a FastAPI backend for household ingredients and recipe discovery. Users can manage ingredients manually or from receipt images, request recipe recommendations based on their inventory and expiry priority, submit recommendation feedback, and estimate food expiry. A separate synchronization path imports recipes into the catalog. The graph follows the API, service, persistence, and integration responsibilities. Some API and service files were not excerpted; their relationships are included only where the SOURCE INDEX or README supports them.

Main entry points: [`app/api/materials.py`](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/api/materials.py) (Material routes), [`app/services/recipe_sync_service.py`](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/services/recipe_sync_service.py) (Recipe synchronization), [`app/main.py`](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/main.py) (FastAPI app), [`app/api/recommends.py`](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/api/recommends.py) (Recommendation routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Identity"]
  node_fastapi["FastAPI app<br/>[main.py]"]
  node_material_routes["Material routes<br/>[materials.py]"]
  node_recipe_routes["Recipe routes<br/>[recipes.py]"]
  node_recommend_routes["Recommendation routes<br/>[recommends.py]"]
  node_auth["JWT authentication<br/>[auth.py]"]
end

subgraph group_inventory["Inventory"]
  node_materials_service["Receipt parsing<br/>[materials.py]"]
  node_material_model["Ingredient model<br/>[materials.py]"]
  node_expiry_service["Expiry estimation"]
end

subgraph group_recipes["Recipes"]
  node_recommend_service["Recipe matching"]
  node_recipe_model["Recipe and feedback models<br/>[recipes.py]"]
  node_recipe_sync["Recipe synchronization"]
  node_sync_handler["Scheduled sync handler"]
  node_manual_sync_handler["Manual sync handler"]
end

subgraph group_platform["Runtime and Integrations"]
  node_db_session["Database sessions<br/>[db.py]"]
  node_postgres[("PostgreSQL")]
  node_config["Runtime settings<br/>[config.py]"]
  node_bedrock_dependency["Expiry service dependency"]
  node_s3_helper["Recipe image storage helper<br/>[s3_helper.py]"]
end

node_user(("API user"))
node_cognito["Amazon Cognito"]
node_ocr["OCR.space"]
node_food_api["Food safety API"]
node_bedrock["Amazon Bedrock"]

node_user -->|"sends requests"| node_fastapi
node_fastapi -->|"mounts routes"| node_material_routes
node_fastapi -->|"mounts routes"| node_recipe_routes
node_fastapi -->|"mounts routes"| node_recommend_routes
node_material_routes -->|"checks identity"| node_auth
node_recommend_routes -->|"checks identity"| node_auth
node_auth -->|"loads signing keys"| node_cognito
node_material_routes -->|"parses receipt"| node_materials_service
node_material_routes -->|"submits receipt"| node_ocr
node_material_routes -->|"creates and queries"| node_material_model
node_material_routes -->|"uses session"| node_db_session
node_recipe_routes -->|"uses session"| node_db_session
node_recipe_routes -->|"uses recipe model"| node_recipe_model
node_recommend_routes -->|"requests recommendations"| node_recommend_service
node_recommend_routes -->|"resolves expiry service"| node_bedrock_dependency
node_bedrock_dependency -->|"provides service"| node_expiry_service
node_recommend_service -->|"reads ingredients"| node_material_model
node_recommend_service -->|"matches and records"| node_recipe_model
node_recommend_service -->|"queries and saves"| node_postgres
node_expiry_service -->|"requests estimates"| node_bedrock
node_sync_handler -->|"runs synchronization"| node_recipe_sync
node_manual_sync_handler -->|"runs synchronization"| node_recipe_sync
node_recipe_sync -->|"fetches recipes"| node_food_api
node_recipe_sync -->|"uploads images"| node_s3_helper
node_recipe_sync -->|"creates or updates"| node_recipe_model
node_recipe_sync -->|"syncs catalog"| node_postgres
node_db_session -->|"reads settings"| node_config
node_db_session -->|"connects to"| node_postgres
node_expiry_service -->|"reads settings"| node_config

click node_fastapi "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/main.py"
click node_material_routes "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/api/materials.py"
click node_recipe_routes "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/api/recipes.py"
click node_recommend_routes "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/api/recommends.py"
click node_auth "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/core/auth.py"
click node_materials_service "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/services/materials.py"
click node_material_model "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/models/materials.py"
click node_expiry_service "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/services/expiry_estimation_service.py"
click node_recommend_service "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/services/recipe_recommendation_service.py"
click node_recipe_model "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/models/recipes.py"
click node_recipe_sync "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/services/recipe_sync_service.py"
click node_sync_handler "https://github.com/cloudproject-khu/myfridger-be/blob/main/lambda/recipe_sync_handler.py"
click node_manual_sync_handler "https://github.com/cloudproject-khu/myfridger-be/blob/main/lambda/recipe_manual_sync_handler.py"
click node_db_session "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/core/db.py"
click node_config "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/core/config.py"
click node_bedrock_dependency "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/utils/bedrock_dependencies.py"
click node_s3_helper "https://github.com/cloudproject-khu/myfridger-be/blob/main/app/utils/s3_helper.py"

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_fastapi,node_material_routes,node_recipe_routes,node_recommend_routes,node_auth,node_user toneBlue
class node_materials_service,node_material_model,node_expiry_service toneAmber
class node_recommend_service,node_recipe_model,node_recipe_sync,node_sync_handler,node_manual_sync_handler,node_food_api toneMint
class node_db_session,node_postgres,node_config,node_bedrock_dependency,node_s3_helper toneRose
class node_cognito,node_ocr,node_bedrock toneIndigo
```

## Components

### API and Identity

- [FastAPI app](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/main.py): `app/main.py`
- [Material routes](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/api/materials.py): `app/api/materials.py`
- [Recipe routes](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/api/recipes.py): `app/api/recipes.py`
- [Recommendation routes](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/api/recommends.py): `app/api/recommends.py`
- [JWT authentication](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/core/auth.py): `app/core/auth.py`

### Inventory

- [Receipt parsing](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/services/materials.py): `app/services/materials.py`
- [Ingredient model](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/models/materials.py): `app/models/materials.py`
- [Expiry estimation](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/services/expiry_estimation_service.py): `app/services/expiry_estimation_service.py`

### Recipes

- [Recipe matching](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/services/recipe_recommendation_service.py): `app/services/recipe_recommendation_service.py`
- [Recipe and feedback models](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/models/recipes.py): `app/models/recipes.py`
- [Recipe synchronization](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/services/recipe_sync_service.py): `app/services/recipe_sync_service.py`
- [Scheduled sync handler](https://github.com/cloudproject-khu/myfridger-be/blob/main/lambda/recipe_sync_handler.py): `lambda/recipe_sync_handler.py`
- [Manual sync handler](https://github.com/cloudproject-khu/myfridger-be/blob/main/lambda/recipe_manual_sync_handler.py): `lambda/recipe_manual_sync_handler.py`

### Runtime and Integrations

- [Database sessions](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/core/db.py): `app/core/db.py`
- **PostgreSQL**
- [Runtime settings](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/core/config.py): `app/core/config.py`
- [Expiry service dependency](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/utils/bedrock_dependencies.py): `app/utils/bedrock_dependencies.py`
- [Recipe image storage helper](https://github.com/cloudproject-khu/myfridger-be/blob/main/app/utils/s3_helper.py): `app/utils/s3_helper.py`

### Other components

- **API user**
- **Amazon Cognito**
- **OCR.space**
- **Food safety API**
- **Amazon Bedrock**

## Connections

- API user → FastAPI app: sends requests (evidence: `app/main.py`)
- FastAPI app → Material routes: mounts routes (evidence: `app/main.py`)
- FastAPI app → Recipe routes: mounts routes
- FastAPI app → Recommendation routes: mounts routes
- Material routes → JWT authentication: checks identity (evidence: `app/api/materials.py`)
- Recommendation routes → JWT authentication: checks identity (evidence: `app/api/recommends.py`)
- JWT authentication → Amazon Cognito: loads signing keys (evidence: `app/core/auth.py`)
- Material routes → Receipt parsing: parses receipt (evidence: `app/api/materials.py`)
- Material routes → OCR.space: submits receipt (evidence: `app/api/materials.py`)
- Material routes → Ingredient model: creates and queries (evidence: `app/api/materials.py`)
- Material routes → Database sessions: uses session (evidence: `app/api/materials.py`)
- Recipe routes → Database sessions: uses session (evidence: `app/api/recipes.py`)
- Recipe routes → Recipe and feedback models: uses recipe model (evidence: `app/api/recipes.py`)
- Recommendation routes → Recipe matching: requests recommendations (evidence: `app/api/recommends.py`)
- Recommendation routes → Expiry service dependency: resolves expiry service (evidence: `app/api/recommends.py`)
- Expiry service dependency → Expiry estimation: provides service (evidence: `app/utils/bedrock_dependencies.py`)
- Recipe matching → Ingredient model: reads ingredients (evidence: `app/services/recipe_recommendation_service.py`)
- Recipe matching → Recipe and feedback models: matches and records (evidence: `app/services/recipe_recommendation_service.py`)
- Recipe matching → PostgreSQL: queries and saves (evidence: `app/services/recipe_recommendation_service.py`)
- Expiry estimation → Amazon Bedrock: requests estimates (evidence: `app/services/expiry_estimation_service.py`)
- Scheduled sync handler → Recipe synchronization: runs synchronization (evidence: `lambda/recipe_sync_handler.py`)
- Manual sync handler → Recipe synchronization: runs synchronization (evidence: `lambda/recipe_manual_sync_handler.py`)
- Recipe synchronization → Food safety API: fetches recipes (evidence: `app/services/recipe_sync_service.py`)
- Recipe synchronization → Recipe image storage helper: uploads images (evidence: `app/services/recipe_sync_service.py`)
- Recipe synchronization → Recipe and feedback models: creates or updates (evidence: `app/services/recipe_sync_service.py`)
- Recipe synchronization → PostgreSQL: syncs catalog (evidence: `app/services/recipe_sync_service.py`)
- Database sessions → Runtime settings: reads settings (evidence: `app/core/db.py`)
- Database sessions → PostgreSQL: connects to (evidence: `app/core/db.py`)
- Expiry estimation → Runtime settings: reads settings (evidence: `app/services/expiry_estimation_service.py`)
