Rapid prototyping with code templates

Over the last few years I have been using Python quite a lot to build rapid prototypes. By far the best command line tool I’ve found for this is the python ‘cookiecutter’ project below:

https://github.com/audreyr/cookiecutter

There are a large number of sample cookiecutter projects out there but it makes sense to build and maintain your own if you want to get the latest setup.

For ease of use I have a number of linux command line aliases to create new projects from my own code template projects:

In some cases these code template projects have been customised to my own preferences with IDE support etc … but for the most part they tend to be fairly vanilla in case other people might find them useful and also to allow me to customise each new project. So for example with Java applications I tend to prefer IntelliJ with Gradle but beyond that for me it doesn’t make sense to preload all of your favourite java libraries.

In some work places I have noticed a tendency to try and standardise code structure with similar code template tools (e.g. maven archetypes). In many cases this can save project setup time but I tend not to favour this approach. Ideally in agile development teams it is best to reach a group consensus based on the project requirements first and then trying to agree on code standards such as naming, structure etc … A good place to start is often Uncle Bob’s Clean coders book which is widely distributed and possibly combining this with Extreme Programming techniques such as TDD, Pair Programming or Mobbing. This combined approach often gets extremely good results allowing for a wider group consensus and shared ownership.

However in many situations the first place to start on a project is a quick prototype. It can therefore be convenient to use code templates in these situations. This actually helps to reinforce the concept that code implemented as part of the prototype is ‘temporary’ and therefore should be discarded and reimplemented by the team from scratch.

Advertisements

Building a responsive photo gallery

Recently I needed to build a photo gallery for a website built with ReactJS. I came across a convenient react library “react-photo-gallery” which was ideal for this purpose. As a proof of concept I built a small Spring Boot app with ReactJS support:

https://github.com/m-x-k/photo-gallery

The application contains a few sample images which can easily be orientated to fit various devices and screen sizes for responsive behaviour.

I also needed to provide a demo to show off some of the functionality before implementing further. Luckily Heroku provides a great environment for sample demo sites. As usual Heroku can be a little slow on the first load as it builds the app on demand. You can reach the demo site below:

https://responsive-photo-gallery.herokuapp.com/

The code implementation was straight forward to setup with the project split into two separate folders. One for the spring boot ‘src’ code and the other ‘ui’ folder for the ReactJS code. Support for Docker has been included as well as details and scripts on to upload the app and any photos to a Heroku account. The only tricky part was getting the folder permissions just right for the photos to load successfully.

At the minute I tend to favour Gradle for building Java projects it provides a robust DSL with various plugins and support for Maven etc … When it comes to Javascript building I tend to favour NPM/Yarn with Webpack especially for the ease of setup when it comes to ES6 transpiling. The combination allowed me to quickly setup an application which could allow the full stack to be built on demand.

Spring Boot REST External APIs

Recently I’ve been developing a lot of REST styled microservices using Spring Boot. We’ve been looking a lot at technologies to make these new endpoints available externally.

Some nice technologies we’ve come across so far include:

  • Spring Cloud Security
    • https://cloud.spring.io/spring-cloud-security/
    • Greatly simplifies spring security 4 so that all you need are meta annotations and basic spring configuration (i.e. application.yml).
    • This allowed us to setup microservices as Resource Services!
  • JSON Web Tokens (JWT)
    • Supports json data in authentication tokens (i.e. bearer token)
    • The http://jwt.io provides a fantastic introduction and a very useful debugging tool
  • Swagger
    • Rest api documentation generated at source
  • HTTPie