Is this a reasonable explanation? Is it correct? If so, can we get it added to the docsite? Sorry for being lazy and not doing it myself:
- Writing and building apps that run on both Corda (open source) and Corda Enterprise *
Corda and Corda Enterprise are compatible and interoperable, which means you can write a CorDapp that can run on both. Here is how to make sure this works in practice.
First, ensure your CorDapp is structured per this document: https://docs.corda.net/writing-a-cordapp.html. In particular, it is critical to separate the consensus-critical parts of your application (contracts, states and their dependencies) from the rest of the business logic (flows, APIs, etc).
The former - the CorDapp kernel, if you like - is the Jar that will be attached to transactions creating/consuming your states and is the JAR that any node on the network verifying the transaction must execute.
To ensure this works, you should compile this Jar once, and then depend on it from your workflows Jar (or Jars - see below). Importantly, if you want your app to work on both Corda and Corda Enterprise, you must compile this Jar against Corda, not Corda Enterprise. This is because, in future, we may add additional functionality to Corda Enterprise that is not in Corda and you may inadvertently create a CorDapp kernel that does not work on Corda open source. Compiling against Corda open source as a matter of course prevents this risk, as well as preventing the risk that you inadvertently create two different versions of the Jar, which will have different hashes and hence break compatibility and intro.
Your workflow Jar(s) should depend on the CorDapp kernel (contract, states and dependencies). Importantly, you can create different workflow Jars for Corda and Corda Enterprise, because the workflows Jar is not consensus critical. For example, you may wish to add additional features to your CorDapp for when it is run on Corda Enterprise (perhaps it uses advanced features of one of the supported enterprise databases or includes advanced database migration scripts, or some other Enterprise-only feature).
So, in short, structure your app as kernel (contracts, states, dependencies0 and workflow (the rest) and be sure to compile the kernel against Corda open source. You can compile your workflow (Jars) against the distribution of Corda that they target.