Skip to content

feat: add Edamam food provider integrations#1100

Closed
serjsv87 wants to merge 19 commits into
CodeWithCJ:mainfrom
serjsv87:feature/edamam-clean
Closed

feat: add Edamam food provider integrations#1100
serjsv87 wants to merge 19 commits into
CodeWithCJ:mainfrom
serjsv87:feature/edamam-clean

Conversation

@serjsv87

@serjsv87 serjsv87 commented Apr 7, 2026

Copy link
Copy Markdown
  • Add EdamamService for food search and barcode lookup via Edamam API
  • Extend FatSecretService with improved barcode support
  • Add edamam provider type to foodCoreService barcode lookup chain
  • Extend foodIntegrationService and foodRoutes v2 with Edamam/FatSecret support
  • Add migration to add edamam provider type
  • Add Edamam/FatSecret provider fields to settings UI
  • Add English translations for Edamam/FatSecret settings fields

Tip

Help us review and merge your PR faster!
Please ensure you have completed the Checklist below.
For Frontend changes, please run pnpm run validate to check for any errors.
PRs that include tests and clear screenshots are highly preferred!
Note: AI-generated descriptions must be manually edited for conciseness. Do not paste raw AI summaries.

Description

What problem does this PR solve?
Adds Edamam as a food search and barcode lookup provider, and improves FatSecret barcode support, giving users more options for food data sources.

How did you implement the solution?
Added edamamService.ts with food search and barcode lookup via the Edamam Nutrition API. Extended fatsecretService.ts with improved barcode support. Added the edamam provider type to the barcode lookup chain in foodCoreService.ts (between USDA and the OpenFoodFacts fallback). Extended foodIntegrationService.ts and foodRoutes.ts (v2) to route requests to the correct provider. Added a migration to register the edamam provider type. Added Edamam/FatSecret credential fields to the settings UI.

Linked Issue: #1100 (This is just something I decided to do on my own—there’s no specific task for it—so I’m linking to my own page to keep the validator from complaining :))

How to Test

  1. Check out this branch and start the server
  2. Navigate to Settings → External Providers → Add Provider → select Edamam
  3. Enter your Edamam app_id and app_key
  4. Go to Food Log → search for a food item — verify results come from Edamam
  5. Use barcode scan with an Edamam provider set as default — verify lookup works

PR Type

  • Issue (bug fix)
  • New Feature
  • Refactor
  • Documentation

Checklist

All PRs:

  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code, and I agree to the License terms.

New features only:

  • [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers or it was approved on Discord.

Frontend changes (SparkyFitnessFrontend/ or src/):

  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate and it passes.
  • [MANDATORY for Frontend changes] Translations: I have only updated the English (en) translation file.

Backend changes (SparkyFitnessServer/):

  • [MANDATORY for Backend changes] Code Quality: I have run typecheck, lint, and tests. New files use TypeScript, new endpoints have Zod schemas, and new endpoints include tests.
  • [MANDATORY for Backend changes] Database Security: I have updated rls_policies.sql for the new edamam provider type entry.

UI changes (components, screens, pages):

  • [MANDATORY for UI changes] Screenshots: I have attached Before/After screenshots below.

Screenshots

Click to expand

Before

before

After

after

Notes for Reviewers

Optional — use this for anything that doesn't fit above: known tradeoffs, areas you'd like specific feedback on, qustions you have or context that helps reviewers.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request integrates the Edamam Food Database API, adding search and barcode lookup capabilities along with necessary frontend configurations and database migrations. It also updates the FatSecret integration to support localized nutrient parsing and introduces a new database query for daily nutrition summaries. Review feedback focuses on implementing proper pagination for Edamam, adding timeouts to external API requests, and addressing the fragility of the positional parsing logic in the FatSecret service. Additionally, the unused getDailyNutritionByCategory function should be removed or properly integrated.

Comment thread SparkyFitnessServer/integrations/edamam/edamamService.js Outdated
Comment thread SparkyFitnessServer/integrations/edamam/edamamService.js Outdated
Comment thread SparkyFitnessServer/integrations/fatsecret/fatsecretService.js Outdated
Comment thread SparkyFitnessServer/models/foodEntry.js
Comment thread SparkyFitnessServer/services/foodIntegrationService.js Outdated
@apedley

apedley commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

When I try to add Edamam as a food provider there is no text input for app id or key.

@serjsv87

serjsv87 commented Apr 8, 2026

Copy link
Copy Markdown
Author

I think I fixed it—the fields were there when I added them, but not when I edited them, so I added them
but I'm using a beta version, so there might be some bugs

@apedley

apedley commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

When I run pnpm run typecheck for server:

Found 76 errors in 4 files.

Errors Files
9 integrations/telegram/telegramBotService.ts:1
1 integrations/telegram/telegramTranslations.ts:1
1 services/mfpSyncService.ts:94
65 tests/telegramBotService.test.ts:12

You also have a failing server test in tests/chatService.test.js at line 225

It now lets me add the provider fine but when I search for a food through the web it gives me a error box "common.error" "Provider not supported". There's nothing in console log or server log about it.

@serjsv87

serjsv87 commented Apr 8, 2026

Copy link
Copy Markdown
Author
image FIX

serjsv87 and others added 18 commits April 10, 2026 08:22
- edamamService: add page/from/to pagination params to searchEdamamByQuery
- edamamService: add AbortController 10s timeout to both fetch calls
- fatsecretService: parse search nutrients by label with positional fallback
- foodIntegrationService: pass page to searchEdamamByQuery, use data.count and _links.next for real pagination
- foodEntry: remove unused getDailyNutritionByCategory export

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@serjsv87 serjsv87 force-pushed the feature/edamam-clean branch from aea7041 to dd3556b Compare April 10, 2026 13:09
@Sim-sat

Sim-sat commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Due to the latest changes with switching everything to typescript and esm this would need a good amount of work. Edamam seems to be paid, so it's hard to test the integration

@serjsv87

Copy link
Copy Markdown
Author

Edamam is free for up to a few thousand requests, but app tokens are issued with a delay of several hours

I'm not sure how well this works, since the number of changes, my workload, and the fact that I didn't initially split it into a separate PR—plus my lack of experience with PRs—made it difficult to implement the improvements "easily."

Everything is working pretty well in my fork on the main branch right now

@Sim-sat

Sim-sat commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Edamam is free for up to a few thousand requests, but app tokens are issued with a delay of several hours

I'm not sure how well this works, since the number of changes, my workload, and the fact that I didn't initially split it into a separate PR—plus my lack of experience with PRs—made it difficult to implement the improvements "easily."

Everything is working pretty well in my fork on the main branch right now

Oh okay thats great, I didn't see it. Have you rebased the latest changes? There are some conflicts now.

@serjsv87

Copy link
Copy Markdown
Author

Edamam is free for up to a few thousand requests, but app tokens are issued with a delay of several hours
I'm not sure how well this works, since the number of changes, my workload, and the fact that I didn't initially split it into a separate PR—plus my lack of experience with PRs—made it difficult to implement the improvements "easily."
Everything is working pretty well in my fork on the main branch right now

Oh okay thats great, I didn't see it. Have you rebased the latest changes? There are some conflicts now.

I just merged the latest changes from the project and incorporated all my updates.
But I'm not sure how to break it down; if you'd like, we can work on my changes together or you can handle them on your own.

@Sim-sat

Sim-sat commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Edamam is free for up to a few thousand requests, but app tokens are issued with a delay of several hours
I'm not sure how well this works, since the number of changes, my workload, and the fact that I didn't initially split it into a separate PR—plus my lack of experience with PRs—made it difficult to implement the improvements "easily."
Everything is working pretty well in my fork on the main branch right now

Oh okay thats great, I didn't see it. Have you rebased the latest changes? There are some conflicts now.

I just merged the latest changes from the project and incorporated all my updates. But I'm not sure how to break it down; if you'd like, we can work on my changes together or you can handle them on your own.

it still shows conflicts and there are .js file like SparkyFitnessServer/routes/garminRoutes.js in the pr.
The server doesn't have a single javascript file left so I guess git didn't realize that the files were renamed so it doesn't show any conflicts for them

@serjsv87

Copy link
Copy Markdown
Author

it still shows conflicts and there are .js file like SparkyFitnessServer/routes/garminRoutes.js in the pr. The server doesn't have a single javascript file left so I guess git didn't realize that the files were renamed so it doesn't show any conflicts for them

I didn't do this for a separate PR or branch.
Unfortunately or fortunately, I implemented several features at once that seemed important and good to me.

  1. A separate Edamam provider—to be honest, I don't really need it; I thought there would be a product library in Cyrillic, but it still works for me if I need to log a barcode or something similar.

  2. Connection via cookies and a key to MyFitnessPal (by the way, I was afraid the key would drop, but no, it's been working for about a week without issues).

  3. Sending the number of consumed calories to MyFitnessPal (which, in turn, is already integrated with Garmin).

  4. Downloading activities from Garmin to Sparky was already there, but I also added downloading the daily water intake goal.

  5. Sending water intake data to Garmin + MyFitnessPal.

And perhaps most importantly, interacting with the application via Telegram as a simple AI bot. My menu and goals (which I entered via the existing user context functionality) are passed into its context, plus the last 7 days of sports activities and food consumption are dynamically pulled in, along with the current time and date, which allows the AI to respond very intelligently. It accepts incoming data as text, voice, video, and photos, which removes any friction or emotional difficulty of manual data entry that would exist in a classic library-style interface.

I am ready to participate in getting all this functionality into the community, but unfortunately, I am not ready to implement it from scratch in small steps, considering I would have to race against other community changes and the fact that my features overlap, making them not so easy to separate.

You can simply see the working code on main (in my fork). We could also work on the integration personally in a separate branch, a chat, or some other way. Perhaps you could share your CI/CD on your end so I can run it, or something else to make it productive.

If this is too much for you, no worries; we can leave it as is. Your project is wonderful and evolving. I'm glad I found it and grateful that I can use it as a core for my own purposes (keeping a diary via messenger).

@Sim-sat

Sim-sat commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

it still shows conflicts and there are .js file like SparkyFitnessServer/routes/garminRoutes.js in the pr. The server doesn't have a single javascript file left so I guess git didn't realize that the files were renamed so it doesn't show any conflicts for them

I didn't do this for a separate PR or branch.
Unfortunately or fortunately, I implemented several features at once that seemed important and good to me.

  1. A separate Edamam provider—to be honest, I don't really need it; I thought there would be a product library in Cyrillic, but it still works for me if I need to log a barcode or something similar.

  2. Connection via cookies and a key to MyFitnessPal (by the way, I was afraid the key would drop, but no, it's been working for about a week without issues).

  3. Sending the number of consumed calories to MyFitnessPal (which, in turn, is already integrated with Garmin).

  4. Downloading activities from Garmin to Sparky was already there, but I also added downloading the daily water intake goal.

  5. Sending water intake data to Garmin + MyFitnessPal.

And perhaps most importantly, interacting with the application via Telegram as a simple AI bot. My menu and goals (which I entered via the existing user context functionality) are passed into its context, plus the last 7 days of sports activities and food consumption are dynamically pulled in, along with the current time and date, which allows the AI to respond very intelligently. It accepts incoming data as text, voice, video, and photos, which removes any friction or emotional difficulty of manual data entry that would exist in a classic library-style interface.

I am ready to participate in getting all this functionality into the community, but unfortunately, I am not ready to implement it from scratch in small steps, considering I would have to race against other community changes and the fact that my features overlap, making them not so easy to separate.

You can simply see the working code on main (in my fork). We could also work on the integration personally in a separate branch, a chat, or some other way. Perhaps you could share your CI/CD on your end so I can run it, or something else to make it productive.

If this is too much for you, no worries; we can leave it as is. Your project is wonderful and evolving. I'm glad I found it and grateful that I can use it as a core for my own purposes (keeping a diary via messenger).

More providers are always a good idea and we should probably integrate that into the codebase. Regarding MyFitnessPal, I am hesitant.
While it's good that it's working right now, it's not supported by an official public API. Relying on unofficial endpoints or scraping requires continuous maintenance and risks violating their Terms of Service.

I also don't see a clear use case for a continuous sync. We already provide multiple reliable ways to retrieve nutrition data (OpenFoodFacts, USDA, FatSecret, Nutritionix). What is missing in Sparky that pervents you from switching?

@serjsv87

Copy link
Copy Markdown
Author

My goal was to synchronize with Garmin (which also does not have an open API)
And they only synchronize with myfitnespal

@Sim-sat

Sim-sat commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

My goal was to synchronize with Garmin (which also does not have an open API)
And they only synchronize with myfitnespal

We have a garmin sync. The only difference is that we rely on a python package to interact with garmin which reduces the maintainence. In the end @CodeWithCJ should decide If this should get integrated

@serjsv87

Copy link
Copy Markdown
Author

I saw and use it, there were problems with authorization, I got the tokens in a different way and wrote them to the database directly

but the problem is that you only download activities (which is very good, but more could be done)

Through my fitnesspal, Garmin learns about the balance of calories consumed (there is no other way)

And I modified it so that the water balance was loaded into Garmin from Sparky, and the goal from the water balance was taken from Garmin (it is dynamic there, and is adjusted depending on physical activity)

I'm talking about the fact that some PRs have difficulties, but it seems to me that they are very useful functions.

@CodeWithCJ

Copy link
Copy Markdown
Owner

I am afraid people choosing selfhosted version is mainly because they don't want to trust their data with MyFitnessPal or other cloud providers.
But it doesn't mean that I want to stop integration with MyFitnessPal.

The PR is currently not ready to be merged as there are several files having conflict with main branch. And we didn't even start code review yet properly. So not sure what other issues could be there.

This is exactly the reason we want contributors to first raise issue in github, disucss with us about the approach so we can align on the implementation.

Currently I am overseas and don't have bandwidth to troubleshoot this PR and merge. @Sim-sat also busy with other items.

If you are able to cleanup the PR and re-submit again, happy to merge.

@CodeWithCJ

Copy link
Copy Markdown
Owner

While it's good that it's working right now, it's not supported by an official public API. Relying on unofficial endpoints or scraping requires continuous maintenance and risks violating their Terms of Service.

I missed key point from @Sim-sat . If the code within SparkyFitness is scrapping, that could be stopper for SparkyFitness integration. Because we don't want to maintain that code base in future. Thats the exact reason I choosen python-garmin-connect library as it takes care heavy lifting on downloading the data and integrating with Garmin.

If there is existing library for MyFitnessPal, use that. BUt we don't want to directly scrap from them.

@serjsv87

Copy link
Copy Markdown
Author

Garmin partners with myfitnesspal and Garmin does not support a calorie diary internally, only with a combination with my fitness, but you can download activity from Garmin (and it works great for you, the only thing I could improve is better categorization of activities on the sparky side)

@Sim-sat

Sim-sat commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Garmin partners with myfitnesspal and Garmin does not support a calorie diary internally, only with a combination with my fitness, but you can download activity from Garmin (and it works great for you, the only thing I could improve is better categorization of activities on the sparky side)

Any changes are welcome, it can certainly be improved. If you don't have the time, create a feature request and i'll look at it since I use garmin myself and can test it

@serjsv87

Copy link
Copy Markdown
Author

Technically, I have already implemented everything I wanted for myself in the open access, I went through a lot yesterday (more than 200 test errors) after the merge with the main branch updates) I will be glad if some piece of code or approaches or ideas will be interesting, for me the most valuable thing is the ability to interact with Telegram. I just thought at the very beginning to make small faxes for myself personally, and receive quite a large-scale and several, so I did not allocate them in a separate pr and now the difficulties (

If necessary, I can conduct any express demonstration

@CodeWithCJ

Copy link
Copy Markdown
Owner

Hi Looks like only meal planner API is free with Edaman and food database needs $14 subscription. I am afraid I won't be able to try to implement as they doesn't seem to offer free API.

@CodeWithCJ CodeWithCJ closed this Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants