Repository navigation
Description
With CI4 comes events and with events come the capability to have 3rd party integrations. For example in my implementation I need two 3rd party integrations that communicate with external applications via RESTful API calls. I know others have requested WooCommerce integrations, etc. We need to come up with a standard home and structure for such integrations so that they are easy to distinguish from the base code and do not make the file structure too unruly.
I think we should stick to the MVC structure as much as possible here. Many integrations will not have their own view, unless we gave them a partial view in the config tabs, but some will require their own views. In terms of Models, we could just create app\Models\Integrations\ a la \app\Models\Reports and require 3rd party integration models to live there. I don't see that we are doing something similar in \app\Controllers\ but I imagine we could. Perhaps the same thing in \app\Libraries?
The other question is whether the code for API integrations should be done in a Model or Controller. I posted the question here (https://softwareengineering.stackexchange.com/questions/446878/do-i-use-a-model-or-controller-in-an-existing-mvc-application-for-implementing-a) and got good input but somewhat conflicting. One guy was adamant that IO communication with the external API should go in the model. What about functions preparing the data to be sent to the API? Do those belong in a controller class? For example, the government cash register/receipt printer integration will be called up during a sale triggered event and, given the sale_id, look up relevant data about the products and the sale, prepare the JSON, send the API request, process the response then store relevant data.
This brings in another subject about architecture of 3rd party integrations. These integrations are going to need to store data in the database. At minimum, configuration about the integration. That has traditionally been stored in the ospos_config table. Information needing to be stored about items can be stored in item attributes, so that isn't an issue. However, integrations that need to store data regarding a particular sale that aren't needed outside of that integrations is a question mark. For example this government cash register API will send back a response with information such as a receipt number and UUID to reference that sale in the future. Creating more columns in the ospos_sales table feels like it's going to clutter up the table when other integrations want to do the same thing. So that either means we implement attributes tables for customers and sales a la items attributes or we give each integration needing to store data a table than they can use to link data. For example a table for this government cash register would use the OSPOS sale_id as its index and then store other data it needed in columns of that table.
@jekkos et. al., can you weigh in on these architecture questions?
Activity
jekkos commentedon Aug 7, 2023
@objecttothis I have been thinking about this, indeed the two proposed solutions don't feel like they are very scalable. Question is also who will be the 'master' of the data in the case of integrations? Is data typically created in Ospos and then synced to other integrations? I guess for your case it's probably like that as you started out with OSPOS first, and probably have all your processes linked to it (item entry, sales, ..). Then it would make sense to sync a webshop with what is in the inventory.
sale_id, receiving_id, item_id, person_id, integration_id, insert_time, update_time. This way all mappings are focused in one place and we can maintain foreign keys to Ospos internal tables. The combination of one foreign key and integration_id is unique. I'm not sure if we can add a unique key on this in MySQL.update_timein the regular tables as well, then we can check if the 3rd party system is in sync or not.null's for each entry, but comparing it with the other approaches (clobbering the OSPOS tables with external ids or adding a metadata table for each entiity) I think it's still acceptable.objecttothis commentedon Aug 7, 2023
Thanks for your help in thinking this through. Not being incredibly experienced in software architecture, I tend to rely on what we are already doing and on what the needs of the integrations are that I have. In both my cases, they are one-way "outbound" integrations with identifying data coming back. In the example of the CMS that we send item data to, the only data specific to that CMS is a UUID that I generate and store as an attribute in the item table. This acts as a mapping, so that the next time this item is pushed to the CMS, it overwrites rather than creates a duplicate.
In the case of the cash register API, it responds back with a handful of ID's that I need to store for future reference. For that, we either add attributes to "sales" a la items attributes, or give my integration and each other integration (that needs one) it's own table to store these ID's along with the sale_id to act as a foreign key.
I'm having a difficult time fully understanding what the mapping table would accomplish other than a history of when an integration ran and against what item/sale/receiving/person. Not that a history wouldn't be needed, but I'm thinking I might be missing something about the direction you'd like to go in.
I do think for integrations, we should consider as much separation as possible between OSPOS data and integration data. This means detailed code scrutiny for 3rd party integrations to make sure that the integration is A) off by default and B) doesn't touch data that it isn't supposed to. This becomes more of a pain for integrations that are not just sending data (like mine), but receiving data. The latter I thing should be managed through OSPOS APIs where possible, but in cases where an integration sends an API call that expects data back, that becomes two way.
This is all a little fuzzy for me. Perhaps we can setup a design meeting via Zoom or Skype... that could speed it up a little.
objecttothis commentedon Aug 7, 2023
Sorry, I wrote "the only data specific to that CMS is a UUID that I generate and store as an attribute in the item table." but what I meant was that I store the UUID as an attribute of the item. Not in the items table.
jekkos commentedon Aug 7, 2023
The main reason to keep all this mapping in one table is to decouple OSPOS with the integrations as much as possible. Using the attributes for this does not feel like a right solution, It was meant as a feature that allows you to store extra properties in a denormalized way but I'd say for the OSPOS domain.
Maybe a meeting is better to discuss this, that is fine by me. I currently have neither zoom or skype installed. If you have signal then -we can try that one, I already have it on my laptop.
objecttothis commentedon Aug 8, 2023
jekkos commentedon Aug 8, 2023
I would suggest to use one table for the integration mapping inside the OSPOS database. All integration specific data can live within it's own schema.
I think you're five hours ahead of me at GMT+6? Maybe let's share signal number through opensourcepos DM? Enjoy your holidays, I might be available on saturday during the day.
objecttothis commentedon Aug 8, 2023
I'm GMT+4. I sent you a DM on gitter (I think it's now called element) with my signal number. I wasn't aware GitHub had interface to dm other users.
Having the mapping table sounds good.
jekkos commentedon Aug 15, 2023
Short summary of what we discussed
ospos_integration_configtable to store specific settings for integrations. We discussed storing it in ospos_config first, but then chose to separate settings.jekkos commentedon Aug 15, 2023
@opensourcepos/org if anyone feels like something is missing, feel free to react or add any comments.
stale commentedon Sep 17, 2023
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
objecttothis commentedon Mar 31, 2025
@jekkos I'm just reviewing this to start to put together a development plan. I think the last point regarding REST API endpoints we put in there to add separation between 3rd party code and internal code which would add some protection against plugins causing problems by incorrect data operations. For security, we need to implement some sort of authentication to prevent bad actors from using the endpoints as well as logging which plugins are making which calls to endpoints. Probably the simplest would be a UI view to generate an API key/plugin combination then in the view for the plugin settings to enter that API key. Do you have thoughts on this?
feat: Add REST API implementation with API key authentication
[-]3rd party integration standard architecture[/-][+][Feature]: Third-party integration standard architecture[/+]feat: Add payment provider plugin system for external gateway integra…
feat: Add payment provider plugin system integrated with plugin infra…
feat: Add payment provider plugin system integrated with plugin infra…
objecttothis commentedon Nov 6, 2026
Claude Issue Checker Agent (cc @objecttothis)
Investigated against current
master.Status: Still present (not merged) — design settled in discussion, implementation in progress via an open PR.
The thread converges on a design (plugin code in its own namespace, an
ospos_integration_mapping-style table keyed byintegration_id+ entity foreign keys, event-driven outbound sync via CI4 Events, a dedicatedospos_integration_configtable for plugin settings). On currentmaster, none of this exists yet: there is noapp/Plugins/directory with aPluginInterface/PluginManager, no integration-mapping table, and noospos_integration_configtable in the migrations.There is an open, unmerged PR directly targeting this issue: #4407 "Modular Plugin System with Self-registering Events" (listed under
closed_by_pull_requestsfor this issue, state: open), which appears to implement the self-registering-events plugin architecture discussed here. Since #4407 hasn't merged, the standard architecture this issue calls for is not yet available onmaster.