Monday, 14 June 2010

Tweetylicious - a Twitter-like microblogging app in just one file!

So, I've been playing a little with Mojolicious::Lite, and here's what I came up with :-)

Tweetylicious is a small - but rather complete - microblogging web application in a single file! It is meant to demonstrate how easy and fun it is to create your own Web applications using modern Perl 5 and jQuery!

Some features:

  • Multi-user, with homepages, search and list of followers/following
  • Nice, clean, pretty interface (at least I think so :P)
  • User avatar images provided by gravatar
  • Unicode support
  • Well structured, commented code, easy to expand and customize
  • Encrypted online sessions
  • Uses an actual database (SQLite) and stores encrypted user password

If you want it, the full code is in github. Removing just blank lines and comments, the Model has ~80 lines, the Controller ~110 lines, templates ~170 lines, plus ~90 lines of static css and ~60 of static javascript. And that's the whole app :D

How do you run it?

perl daemon

You'll need Mojolicious and ORLite - two very lightweight modules - to run the app, and that's about it! A live Internet connection is also good, since it fetches jQuery on the fly.

Mind you, it's far from perfect (bug reports and patches always welcome!). I wrote it as a demo to show the kind of stuff you can quickly achieve with Perl. It's totally usable and might be a good fit for quick deployment and customization on internal networks, but if you're looking for a business ready microblogging solution, you might want to look at (which powers But it's waaaay bigger ;-P


I tried making the commits linear and modular, so newcomers can take a look at git log for a "tutorial":

  1. initial commit - diff, full file
  2. adding index page (and route) - diff, full file
  3. separating common html into a shareable 'layout' - diff, full file
  4. adding (all) css - sorry, this is not a css tutorial :P - diff, full file
  5. users will need to 'login' and 'join' (register)! - diff, full file
  6. first jQuery contact: turning links into buttons - diff, full file
  7. creating the 'User' model schema in our database - diff, full file
  8. registering users: the template - diff, full file
  9. registering users: the controller - diff, full file
  10. registering users: validating registration data - diff, full file
  11. registering users: prevent usernames that are part of a route - diff, full file
  12. user login: the template (and basic route) - diff, full file
  13. user login: the controller (handling form submission) - diff, full file
  14. user logout: controller, and option in template - diff, full file
  15. the user's homepage (template) - diff, full file
  16. the user's homepage (controller) - diff, full file
  17. adding a 'not found' page - diff, full file
  18. making 'login' and 'join' redirect to user's homepage - diff, full file
  19. updating our model: posts! - diff, full file
  20. making user's homepage show posts (but user can't create them just yet - diff, full file
  21. updating our controller: creating posts - diff, full file
  22. updating our controller: deleting posts - diff, full file
  23. updating our controller: turning common posting auth code into a ladder - diff, full file
  24. more jQuery: styling post submit into a button too - diff, full file
  25. more jQuery: showing how many characters are left in a post - diff, full file
  26. more jQuery: highlighting posts on hover - diff, full file
  27. more jQuery: formatting our content for RTs (@user) - diff, full file
  28. creating posts via Ajax (rather, Ajaj, since we're using JSON ;) - diff, full file
  29. deleting posts via Ajax (rather, Ajaj, since we're using JSON ;) - diff, full file
  30. searching posts: search form template - diff, full file
  31. searching posts: jQuery effects - diff, full file
  32. searching posts: model - diff, full file
  33. searching posts: controller - diff, full file
  34. searching posts: results template - diff, full file
  35. searching posts: jQuery (naive) formatting for topics (#topic) - diff, full file
  36. followers and following: the model - diff, full file
  37. followers and following: the controller - diff, full file
  38. followers and following: template changes - diff, full file
Newer commits will likely be not as organized, and mostly bugfixing, but this should get people going - hopefully :P

Well, that's it. Have fun!