Skip to content

[Feature]: Third-party integration standard architecture #3789

Open

Description

@objecttothis

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

  1. jekkos commented on Aug 7, 2023

    @jekkos
    Member

    @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.

    • In non event driven architecture I would expect an external system to keep track of the id's in of the records in the master data domain, as most of the time the 3rd party integration initiates the synchronization flow (polling).
    • With events the logic is bit different: Ospos triggers events that then call 3rd party's, and this then needs to be done by mapping Ospos domain to 3rd party domain. So we might indeed need the ability to track those mappings with the 3rd party domain in a customizable xay.
    • I think the best way is to create a separate table for this that has following columns 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.
    • The upside is that it's easy to scale and cohesive. Each integration has it's own set of records in the table and it will be fast to query. You only keep records for items that were synced with the integration. Perhaps we can also a field to track when the record was last updated or touched. If we add an update_time in the regular tables as well, then we can check if the 3rd party system is in sync or not.
    • The downside of this approach is that you will have columns with 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.
  2. objecttothis commented on Aug 7, 2023

    @objecttothis
    MemberAuthor

    @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.

    * In non event driven architecture I would expect an external system to keep track of the id's in of the records in the master data domain, as most of the time the 3rd party integration initiates the synchronization flow (polling).
    
    * With events the logic is bit different: Ospos triggers events that then call 3rd party's, and this then needs to be done by mapping Ospos domain to 3rd party domain. So we might indeed need the ability to track those mappings with the 3rd party domain in a customizable xay.
    
    * I think the best way is to create a separate table for this that has following columns `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.
    
    * The upside is that it's easy to scale and cohesive. Each integration has it's own set of records in the table and it will be fast to query. You only keep records for items that were synced with the integration. Perhaps we can also a field to track when the record was last updated or touched. If we add an `update_time` in the regular tables as well, then we can check if the 3rd party system is in sync or not.
    
    * The downside of this approach is that you will have columns with `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.
    

    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.

  3. objecttothis commented on Aug 7, 2023

    @objecttothis
    MemberAuthor

    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.

  4. jekkos commented on Aug 7, 2023

    @jekkos
    Member

    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.

  5. objecttothis commented on Aug 8, 2023

    @objecttothis
    MemberAuthor
  6. jekkos commented on Aug 8, 2023

    @jekkos
    Member

    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.

  7. objecttothis commented on Aug 8, 2023

    @objecttothis
    MemberAuthor

    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.

    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.

  8. jekkos commented on Aug 15, 2023

    @jekkos
    Member

    Short summary of what we discussed

    • Code for plugins should ideally live in their own package or namespace.
    • No dependencies from the 'core' code to a plugin's code
    • Add an ospos_integration_config table to store specific settings for integrations. We discussed storing it in ospos_config first, but then chose to separate settings.
    • Item/sales attributes tables can be filled from external plugin logic. As long as the code lives in it's own namespace.
    • Event driven integration: trigger a generic endpoint on an external plugin endpoint to sync with the latest data. Ospos can resolve the external id by querying the generic integration mapping table. Other data linked to the id might also need to be mapped in the plugin's code. Ospos should not know what integrations are enabled for which type of data. We can use a pubsub model to do the decoupling.
    • Polling integration: external plugins that poll Ospos could also be developed against a REST API. The CI event log can be used to figure out what exact data needs to be synced.
  9. jekkos commented on Aug 15, 2023

    @jekkos
    Member

    @opensourcepos/org if anyone feels like something is missing, feel free to react or add any comments.

  10. stale commented on Sep 17, 2023

    @stale

    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.

  11. added this to the 3.5.0 milestone on Dec 12, 2023
  12. objecttothis commented on Mar 31, 2025

    @objecttothis
    MemberAuthor

    @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?

  13. changed the title [-]3rd party integration standard architecture[/-] [+][Feature]: Third-party integration standard architecture[/+] on Apr 1, 2026
  14. objecttothis commented on Nov 6, 2026

    @objecttothis
    MemberAuthor

    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 by integration_id + entity foreign keys, event-driven outbound sync via CI4 Events, a dedicated ospos_integration_config table for plugin settings). On current master, none of this exists yet: there is no app/Plugins/ directory with a PluginInterface/PluginManager, no integration-mapping table, and no ospos_integration_config table 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_requests for 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 on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions