There are lots of design patterns however since you are interested in the possibility of making API's later the most appropriate for you would be a form of your option 2.
Use JS/Flex only for UI and keep all the application logic in PHP, which will be consumed as independent services.
Simply make a front end using one of the following technologies for single page application front end UI:
Then make all your business logic into RESTful API
calls written in PHP
or Python
or any other backend language
.
If these services allow for full CRUD
and not just Read
I recommend using OAuth
to secure your services to only allow authorized users to Create, Update, and Delete
. You can just use an OAuth PHP library.
The reason for this is it allows you to create any other applications and just have to rebuild the UI and not have to remake the business logic in every language (C, C++, objective C, C#, Python, PHP, JavaScript, Ruby, etc.)
. Then when you release the API
to the public they will call your OAuth service
with a valid username and password (given by the user) and will be able to make a rich full featured application because you have now eating your own dog food. This is a very important concept, although it might take you longer to develop you won't have to re-architect
and thereby re-develop
or re-factor
a lot of code.