Inside Codebrag: Angular, Grunt, Scala, Slick and code reviews!
Codebrag is a code review tool written by developers, for developers. Business people may tell you that technology isnât important, but every developer knows that choosing a technology stack is the most important thing in every project ;).Â
We started Codebrag basing on Bootzooka - our open-source web-project template. Since both Codebrag and Bootzooka are our projects, thereâs a strong âfeedback loopâ between the two - improvements from the former are applied to the latter.
So what is inside Codebrag?
First of all, Codebrag consists in fact of two apps: frontend and backend. Whatâs important, is that these are not just layers, but applications. (You can find out more about the subject e.g. from MichaĹ Ostruszkaâs - Codebragâs lead developer - slides from GeeCON 2014. The apps communicate through a JSON API.Â
The frontend app is based on Angular.JSÂ which, basing on its popularity, is almost a standard now. Of course even using Angular you have to pay attention to structure your app properly so that itâs readable and maintainable. We have clearly separated services, resources, directives, controllers and helper methods/classes (in separate files) with well defined (of course single!) responsibilities.Â
As we end up with a lot of javascript files, all of this calls for unit testing and a build! And thatâs what we do - we have a dedicated frontend build, based on Grunt.JS. The same approach is present in Bootzooka; you can read more about having separate (but integrated) frontend&backend builds on our blog. Our build consists of multiple steps/extensions:
karma test runner - thatâs the basis
jasmine testing framework we use
stylus to keep our CSS pretty and human-readable
jshint to make sure our javascript is as good as possible
livereload for making development smooth. Whenever a file changes it gets preprocessed (if required) and browser automatically reloads Codebrag for us
html2js for converting Angular templates to JS
plus optional concatenation (on production), cache boosting (by adding unique prefixes to assets) and so on. We use grunt-usemin to handle that work for us.Â
During development we make heavy use of file watchers that check for file changes and automatically trigger test execution for us. That way we get immediate feedback as soon as we save file changes.Â
The backend is entirely Scala-based. We try to keep the usage of frameworks and libraries to minimum. Too much of them and you get into a bad place.
The API is exposed via Scalatra which is also the API layer in Bootzooka; Scalatra is a âmicro-web-frameworkâ, quite simple to write in and providing most of the things you need: cookie management, simple REST endpoints definitions and resource serving.
 We donât have a DI container; but we *do* use DI - just by expressing dependencies through constructors. The object graph is created âat the end of the worldâ in the main class, or through mixed-in traits. Simple, type-safe and easy to understand.Â
Speaking of the end of the world, when you download Codebrag you will notice that it is a single jar. That jar contains an embedded Jetty container and all the other dependencies. If youâd like to see how easy it is to create a fat-jar deployment, head over to our blog again.
Another thing youâll notice is that you donât need any database - well, Codebrag of course does have a database, but itâs embedded; we are using the excellent all-java SQL H2 database. To access it and actually read and write data we are using Slick - a *functional* (not object)-relational mapper from Typesafe. I really recommend Slick, it keeps you close enough to the database so that you donât forget that you are using an SQL DB, but hides all the nasty and boring details.
Finally, a *very* important part of Codebrag is actually getting data from Git :). For that we are using JGit, which is a very nice Java interface for accessing Git repos. Feels similar to the git command line, just from Java (or Scala).
The whole build is managed by SBT- both the backend (naturally) and frontend parts. SBT makes it quite easy to call external tools like Grunt - you just need to write some Scala code.Â
Intrigued how two applications packaged in a single jar, with an embedded database and servlet container work? How fast does it start up? See for yourself, and take a look at Codebrag. Maybe youâll even review a few commits? Or invite your co-workers, to let them know they did a good job?
 P.S. And if you are wondering if we are using Codebrag when writing Codebrag - of course!