Simple todo is a very minimalistic webapp. It has been built to demonstrate the process of building an webapp using `Object Oriented PHP`. Though, this app is very minimalistic in nature, it contains all the basic properties of a good web application. It has been built totally object oriented way using pure PHP(no framework has been used other than PHPUnit, which is only a testing framework), HTML, CSS and JavaScript. At present this app support several good features. I'm going to describe them below.
I've hosted the app on heroku and I'm using continous integration to ship changes automatically and instantly(more on this later). You may visit the app using the following link:
http://simple-todo-rs.herokuapp.com/
On the backend I've built the following things:
- A custom Routing Engine
- Pretty URL support
- Middleware support(both generic and route specific)
- Controller's to handle request
- Named Routes
- CSRF protection through middleware
- A small but extensible and efficient templating engine
- A convenient oop way to access global variables(note: the way I've implemented it, it is extensble, but not complete yet).
The app is built using totally object oriented way and have strong type support that may detect breaks during development phase and thus increase speed.
- A very responsive, fast and consistent UI.
- Caching mechanism to cache data on client side.
- Optimized network(i.e. db) calls.
For unit testing I'm using PHPUnit. Though, I've already started writing tests and continuing, but still it would take sometime to cover the whole codebase.
About comments, as the app covers a lot of features, I've tried to write the code verbosely, so that one may not need comments to understand the code(to manage my dev time). But still commenting is the de facto for doc. I'll try to take the whole codebase under comments with time.
- Automated testing support using Github Actions and PHPUnit.
- Continous Deployment support using Github Actions and Heroku Git based deployment system.
[Note: the app runs automated testing on each push, but only deploys to heroku if the test is successful].
For database I've used postgresql. And to handle database operations I've used PHP PDO to perfom insert, delete, update etc. operations.
As a side note, for managing dependency Composer
has been used.
If you want to run this app locally for your own usage or development, you can easily do so. Make sure you've installed PHP, composer and postgresql installed in your pc and an internet connection.
At first run composer to install the dependencies:
$ php composer.phar install
Now, create a .env
in the project root directory and put your db info there as follows:
DATABASE_URL=postgres://<username>:<password>@<hostname>:<port>/<dbname>
You may also want to put other info in your .env file(do as per your need)
And then run:
$ php database/migrate.php
After creating db table you may run the tests:
$ ./vendor/bin/phpunit
If tests are successful then, you can run the app using php's development web server as follows:
$ php -c <path-to-php.ini> -t public/ -S 127.0.0.1:8000
Now visit 127.0.0.1:8000
on your browser to use the webapp.
I've used PHPUnit for unit testing and a slightly edited(according to my need) script from devcoder-xyz/php-dotenv to parse .env
file.
This repository is published under MIT License
. To know more about license please visit this link.
I am thinking of explaining the whole architecture of this project to everyone who are interested in webapp development. I am thinking of planning a book(or tutorial kind of resource) about how to build an web application from scratch. If you have anything to contribute or advise, I'm all ears. Just give me a knock.