For details on versioning and workflow implementation and their scripting using .NET API, please see chapters Workflow internals and Versioning internals.
Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?managing_workflow_using_api.htm