You can do this use case with all of the Alfresco APIs (for example CMIS, JCR, Web Services, REST). You can try to get all the contents that you need for your application and if it doesn't exist you can create the new content (space) as a subcontent.