Clipbook.it Website Architecure 1.0

Client: HTML + CSS + JavaScript + JQuery
Server-Side Web Tier: PHP
Data Tier: Python + MySQL

Client Tier

The client tier is the standard HTML, CSS and JavaScript. JavaScript is supported by JQuery.

Web Tier

The web layer is written in PHP. It roughly follows the principles outlined by Rasmus Leodorf's "No-Framework PHP MVC Framework".

There is no PHP-based Front Controller for request dispatching. Request dispatching is left to Apache and mod_rewrite. Think of this approach as analogous to the use of REST over SOAP. REST came along when people realized that SOAP was reinventing much of what HTTP already offered.

The PHP code does not connect directly to a RDBMS. Instead it places REST calls to the Data Layer. As needs evolve, the PHP tier may connect to other data sources, such as memcached. However, it is envisioned that MySQL will always hold the master copy of the application's data.

Data Tier

The data tier consists of a Python-based front end and a MySQL backend. Data is served by a REST API provided by Python running on a CherryPy HTTP server. The Python code makes one or more requests to the MySQL server, builds a data graph, and returns it encoded as JSON to the web tier. Ideally the REST server would always be located on the same machine as MySQL, communicating over Unix sockets.

Instead of running an application server in the data tier, all the data access and data graph building could have been implemented in PHP directly. This would be a significantly simpler design. However, I am betting that Python (or its peers) provide such an advantage over PHP (but outside the web tier), that it is worth taking on the extra architectural complexity. Example advantages include a decent REPL, less syntax, smaller resulting codebase for most problems, ability to do long-running processes, a more complete, more professional library for doing sophisticated data processing. You may ask, why not implement the web tier in Python? For the same reason, but in reverse. I believe that when approached the right way, PHP is such a superior platform for simplifying the web tier, that it is worth the added architectural complexity of this design. I'm also betting that as the architecture evolves, that the extra complexity will become insignificant.

Near-Term Enhancements

Before serving any significant traffic, the application should be optimized to meet expected traffic. Usually the best place to start is caching whole web pages so that they may be served statically. At first, only pages that a served to anonymous users will be cached. Pages for logged-in users will still be delivered by the whole stack. Then, pages for logged-in users will be cached, and dynamic content will be delivered via JavaScript XHR (Ajax). This will require that registered users have JavaScript.