Feature Implementation Plan: Hierarchical Processing Methods¶
π Todo Checklist¶
- [ ] Update the
ProcessingMethodentity to support a parent-child relationship. - [ ] Create a database migration to add the parent relationship and seed the top-level processing methods.
- [ ] Update the LLM schema (
coffee-bean.schema.json) to extract both the specific processing method and its parent. - [ ] Update the
CoffeeBeanPersisterto handle the new hierarchical data. - [ ] Update the
ProcessingMethodCrudControllerto manage the parent relationship. - [ ] Update the
/api/processing-methodsendpoint to return the hierarchical structure and remove pagination. - [ ] Write unit and integration tests for all new and updated functionality.
- [ ] Final Review and Testing
π Analysis & Investigation¶
Codebase Structure¶
- Entity:
src/Entity/ProcessingMethod.phpwill be modified to add a self-referencingparentrelationship. - Migration: A new Doctrine migration will be created to apply the schema change and, importantly, to insert the top-level processing methods as defined in the GitHub issue.
- LLM Schema:
config/schemas/coffee-bean.schema.jsonwill be updated to instruct the LLM to identify the parent category for any given processing method. - Persistence:
src/Service/Crawler/Persistance/CoffeeBeanPersister.phpwill be updated to correctly associate the processing method with its parent. - Admin:
src/Controller/Admin/ProcessingMethodCrudController.phpwill be modified to allow administrators to set the parent for a processing method. - API:
src/Controller/Api/ProcessingMethodController.phpandsrc/Repository/ProcessingMethodRepository.phpwill be refactored to return the data in a hierarchical format.
Current Architecture¶
The current system treats processing methods as a flat list. This plan will introduce a hierarchical data model. The most significant change to the architecture will be in the API response for /api/processing-methods. Instead of a paginated flat list, it will return a nested structure. This is a necessary change to properly represent the hierarchical data to the frontend.
Dependencies & Integration Points¶
- Doctrine: Will be used for the self-referencing relationship and the migration.
- LLM: The prompt engineering in the JSON schema is critical to get accurate parent classifications.
- EasyAdminBundle: The admin interface will use an
AssociationFieldto create a dropdown for selecting the parent method.
Considerations & Challenges¶
- Pagination: As you noted, pagination of a hierarchical list is complex and not user-friendly. The plan is to remove pagination from the
/api/processing-methodsendpoint and return the full nested structure. The number of categories is small enough that this will not be a performance issue. - LLM Accuracy: The LLM's ability to correctly identify the parent category will be crucial. The prompt in the schema must be very clear.
- Data Integrity: The migration must correctly create the parent categories. The
CoffeeBeanPersistermust correctly link existing and new methods to these parents.
π Implementation Plan¶
Prerequisites¶
- No new external dependencies are required.
Step-by-Step Implementation¶
-
Update
ProcessingMethodEntity- Files to modify:
src/Entity/ProcessingMethod.php - Changes needed:
- Add a
parentproperty with aManyToOneself-referencing relationship. - Add a
childrenproperty with aOneToManyself-referencing relationship. - Ensure the
parentis nullable for top-level methods.
- Add a
- Files to modify:
-
Create Migration and Seed Data
- Files to create: A new Doctrine migration file.
- Changes needed:
- Generate a migration to add the
parent_idcolumn to theprocessing_methodtable. - In the
up()method of the migration, after adding the column, insert the top-level processing methods from the GitHub issue (WASHED/WET, NATURAL/DRY, etc.).
- Generate a migration to add the
-
Update LLM Schema and Persistence
- Files to modify:
config/schemas/coffee-bean.schema.json,src/Service/Crawler/Persistance/CoffeeBeanPersister.php coffee-bean.schema.jsonChanges:- In the
processingMethodsitem schema, add a new propertyparentProcessingMethodof typestring. - Update the
descriptionto instruct the LLM to determine the parent category from the provided list (WASHED/WET, etc.) for each processing method it finds.
- In the
CoffeeBeanPersister.phpChanges:- In the logic that handles processing methods, first find or create the parent method.
- Then, when finding or creating the specific processing method, set its parent to the one you just retrieved.
- Files to modify:
-
Update Admin UI
- Files to modify:
src/Controller/Admin/ProcessingMethodCrudController.php - Changes needed:
- In the
configureFieldsmethod, add anAssociationFieldfor theparentproperty. - This will render as a dropdown in the admin form, allowing you to assign a parent to any processing method.
- In the
- Files to modify:
-
Update API Endpoint
- Files to modify:
src/Controller/Api/ProcessingMethodController.php,src/Repository/ProcessingMethodRepository.php ProcessingMethodController.phpChanges:- Remove the
pageandlimitparameters from thegetProcessingMethodsmethod. - Call a new repository method
findAllHierarchical(). - The response will be a nested array, so no custom formatting is needed if the serialization groups are set up correctly.
- Update the
#[OA\Get]annotation to reflect the new, non-paginated, hierarchical response structure.
- Remove the
ProcessingMethodRepository.phpChanges:- Create a new method
findAllHierarchical(). - This method will first fetch all processing methods.
- Then, it will manually build the hierarchical array in PHP by grouping children under their parents. It should only return the top-level methods (where
parentisnull), with their children nested inside.
- Create a new method
- Files to modify:
Testing Strategy¶
- Unit Tests:
- Write a unit test for the
ProcessingMethodRepository::findAllHierarchicalmethod to ensure it returns the correct nested structure. - Update tests for the
CoffeeBeanPersisterto verify that it correctly links processing methods to their parents.
- Write a unit test for the
- Integration Tests:
- Update the integration test for
/api/processing-methodsto assert that it returns the new hierarchical structure and no longer supports pagination.
- Update the integration test for
- Manual Testing:
- In the admin panel, verify that you can create a new processing method and assign it a parent.
- Trigger a crawl and check that the LLM correctly identifies a processing method and its parent, and that they are saved correctly in the database.
π― Success Criteria¶
- The
ProcessingMethodentity supports a hierarchical structure. - The database is seeded with the correct top-level processing methods.
- The LLM extraction process correctly identifies and links processing methods to their parents.
- The admin UI allows for managing the parent-child relationships.
- The
/api/processing-methodsendpoint returns a nested, hierarchical list of all processing methods. - The new functionality is fully covered by tests.
GitHub Issue¶
Currently, we have many different types of fermentation, often probably overlapping even though we haven't even crawled that many beans yet. We should come up with a way to group them together comprehensively, without giving the users every single option to filter by.
Current values (August 2nd):
name β description ββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Combined Fermentation β Processing using combined fermentation method. Depulped β Cherries were depulped before fermentation. Dry Processing β Coffee cherries are carefully handpicked based on ripeness and dried on raised bedsβ¦ Kenya Washed β In the Kenya process, coffee cherries are sorted, depulped, fermented in ceramic taβ¦ Lactic Washed β A nuanced limited oxygen pre-fermentation in a sealed tank where bacteria and yeastβ¦ Layered Fermentation β Coffee is fermented in layers added over multiple days without water to control pH β¦ Natural β Coffee cherries are dried and fermented inside the whole cherry, which imparts fruiβ¦ Natural Decaffeination β Natural caffeine extraction using a solvent derived from coffee pulp over three cycβ¦ Parabolic Bed Dried β The coffee is dried on parabolic drying beds, which allow for controlled drying conβ¦ Patio Dried β Coffee cherries are dried on patios with careful temperature control and frequent tβ¦ Raised Bed Dried β Coffee is dried on raised African-style beds allowing controlled drying and airflowβ¦ Sugar-Cane Decaf β Decaffeination is done using a product from sugar-cane fermentation, without chemicβ¦ Aerobic Fermentation β Anaerobic Natural β This coffee undergoes 36 hours of limited oxygen fermentation inside the fruit and β¦ Double Fermentation β Cherries undergo a first anaerobic fermentation for 48 hours at 18Β°C, followed by pβ¦ Anaerobic Washed β Coffee cherries undergo pre-fermentation in cherry for 48 hours, are depulped and kβ¦ Bio-Innovation Natural β Starts with a 100-hour limited oxygen fermentation followed by depulping and washinβ¦ Biochar Raised-Bed Dried β The coffee is dried on raised beds enhanced with biochar to aid fermentation and drβ¦ Bioinnovation Washed β Process starts with 100-hour limited oxygen fermentation in cherry form, followed bβ¦ Cold Brew β Cold brew coffee refers to coffee brewed with cold water over an extended period raβ¦ Red Honey β The coffee cherries are depulped but not fermented in tanks; the mucilage is left oβ¦ Swiss Water Decaffeinated β A decaffeination method where green coffee extract is used to remove caffeine withoβ¦ Thermal-Shock Washed β Double fermentation thermal shock process involving extended fermentations in sealeβ¦ Tyoxidator β Ripe cherries undergo an oxidative pre-fermentation before being pulped and fermentβ¦ Washed β Coffee cherries are depulped and fermented to remove the mucilage, then washed withβ¦ Wet Washed β The coffee cherries are depulped, fermented to remove mucilage, washed and then driβ¦ White-Honey β This coffee is processed using the White-Honey method, including patio drying with β¦ Yellow Diamond Process β A honey-process coffee method involving depulping and placing coffee in large pilesβ¦ Yellow Honey β Coffee is depulped, then laid out on drying patios with mucilage left on the seed, β¦ Dry Washed β Depulped and fermented dry for 24 hours, followed by channel washing, then dried apβ¦ EA Decaf β Sugar cane ethyl acetate decaffeination extracts caffeine at low pressure and tempeβ¦ Honey β Coffee cherries are depulped but not fermented in tanks; the seeds dry with mucilagβ¦ Honey Processed β Coffee cherries are depulped but mucilage is left on the seeds during drying, allowβ¦ Unknown β Anaerobic Fermentation β The coffee cherries are dry-fermented and anaerobically fermented for 90 hours, theβ¦ Bioinnovation Natural β Limited oxygen pre-fermentation in a sealed tank with increased sodium inoculation β¦ Carbonic Maceration β Inmaculada Eugenioides undergoes an 8 day carbonic maceration fermentation limitingβ¦
waytocoffee (Member) β’ 7d β’ Edited β’ Newest comment
In bold you have the first category and underneath the subcategories. In the first instance, users should only be able to choose betweem washed/wet process. natural/dry process, honey/pulped natural process, and experimental/innovative process.
WASHED/WET PROCESS
Washed Wet Washed Kenya Washed Dry Washed Double Fermentation Thermal-Shock Washed Lactic Washed Anaerobic Washed Bioinnovation Washed
NATURAL/DRY PROCESS
Natural Dry Processing Anaerobic Natural Bio-Innovation Natural Bioinnovation Natural
HONEY/PULPED NATURAL
Honey Honey Processed Red Honey Yellow Honey White-Honey Yellow Diamond Process
EXPERIMENTAL/INNOVATIVE
All anaerobic variations, Carbonic maceration, Thermal shock methods, Bio-innovation methods
Other experimental techniques
Anaerobic Fermentation Anaerobic Slow Dry Aerobic Fermentation Carbonic Maceration Tyoxidator Layered Fermentation Combined Fermentation Inoculated Multi-Cultured Yeasts Double Anaerobic Inoculated Yeast
DECAFFEINATION METHODS
Natural Decaffeination Swiss Water Decaffeinated EA Decaf (Ethyl Acetate) Sugar-Cane Decaf
Data Cleanup needed
Depulped
DRYING METHODS (Either as secondary filter or leave it out as its not technically a processing method but just describes the drying aspect)
Raised Bed Dried Patio Dried Parabolic Bed Dried Biochar Raised-Bed Dried
View this issue on GitHub: https://github.com/thewaytocoffee/bean.business/issues/2