I was asked to work out a case for VCN. In this project, I say how I went to work and how I have thought it out.
There is an interface that can only be used for authorized (paying) customers to allow currency conversion. A few resources can be used for the conversion, the former being less reliable and possibly slower.
Available resources:
- All services must be able to be used and others should be able to be plugged into it with ease.
- Other requirements received on paper.
- Guzzle: HTTP client that is versatile, well documented and almost a global default.
- PHP Soap: This is to interface with currencyvonverter.kowabunga.net.
- Laravel: This will hold the base endpoints. This because it is easily securable and fast also supports all other functionality that is required.
- BootstrapCSS: This is because I am not that great with CSS and will take some pain away.
- jQuery: This will handle all user input, used because it is cross-platform compatible.
- TypeScript: Because we will work in bigger teams and the type definitions are a blessing in that regard.
- Select2: This is a clean, well-supported dropdown with autocomplete.
- WebPack: To make everything as small as possible and not include more javascript than needed.
- NodeJS + SocketIO: This to allow for real-time communication of the new conversion rates when available.[^1]
- (The Laravel application will send information to Nodejs, so a web server on Nodejs is also required).
-
First I checked out the provided paper & screenshot and started thinking about what we needed.
- By interface, I decided that select2, bootstrap, and jQuery are needed to provide for a clean interface.
- An API is also needed for the AJAX calls that will be sent to the server.
- Based on the requirements I decided that caching for the currencies is in order, this will be stored in the database.
- Because the currencies are current for one day, a cronjob will be added to sync the currencies and cache the new data, historic data will be saved in another database.
- An adapter pattern will be used for the separate resources to receive the currencies.
-
Check out the provided resources, I decided that adapters are in place for this.
- The adapters will receive a static variable to give a priority for ordering.
- Based on this ordering the requests will be done, initiated by the cronjob.
- Add Unit tests for the "interface".
- An abstract adapter will be created and will serve by default a guzzle client, which method can be overwritten to support another client (SOAP for example).
- The following methods will be defined:
- getClient
- getRate
- getHistory
-
Interface information
- AJAX will be used to retrieve all the information from the server, this will provide for smooth user experience.
- As information will become available at some time, sockets will be used to distribute new information to all the users when available.[^1]
- A check for online status will also be given [^1]
- Based on the currency conversion the historic data will be retrieved, this will also be done with AJAX.
-
Cronjobs 1.
-
User registration
- This will be a manual task for how this might be automated by giving an authorization based on Ideal or PayPal.
- Because this is manual a command-line command will be created to create a new account. The account will need an email address. The password will be mailed to the user so he can log in.
-
Endpoints
- /login: Show the login
- /: This will be the currency converter
- /api/rate/{currency}: Get the conversion rates of the initially selected currency.
- /api/history/{currency_from}/{currency_to}: Get the historic data of the currency conversion.
- Although far-fetched when a user is offline the currency converter doesn't work.