Webapp architecture A:
Build all business / data logic in whatever language (a mix even) and expose as a JSON API, then build the entire UI and site frontend as an API client. Initial output is generated by *some* code using an internal use of the same API (but skipping the HTTP overhead). Then Ajaxification ensues.
Webapp approach B:
Don't, just expose what you need as an API