/truck_my_food

Primary LanguageJavaScript

Truck My Food!

Objective


**Subject:** Create a service that tells the user what types of food trucks might be found near a specific location on a map. The data is available on [DataSF](http://www.datasf.org/): [Food Trucks](https://data.sfgov.org/Permitting/Mobile-Food-Facility-Permit/rqzj-sfat)

I have a full Time job, appointments at night .. challenge accepted!

Take a look at the result here => My app

How I did it

Originally, I am a Backend developper, my aim is to be a FullStack developper, this is my first try! My app is composed of a Backend API in ruby with an elasticsearch store and an independant Front in BackboneJs.

Architectural choices

Backend

Instead of resolving this problem at the applicative level, we do it around an ElasticSearch store with:

  • A daily task that updates the store
  • A model that is the the transformation layer between the SFData API and the front
  • An API that transmint data to the front

We delegate the searches to elasticsearch in order to have way faster answers. The fact to have a backend permits to have a bigger extension and open possibilities of queries to make more complex researches.

API documentation => here

Technologies and Libraries

Ruby:
2+ years of experience - Language that I master. Very productive and readable language. Perfect for this test.
Grape Framework:
First use - REST-like API micro-framework for Ruby. See their GitHub
We have a read only API, with no authentication, grape is very light the best solution.
Elasticsearch
1,5 years -

The elasticsearch store is a way to have the same data as the SF data but to access it faster and in a structure that is optimized for the request the application needs. Elasticsearch has a known issue of persistence but since this is not the primary store, it perfectly fits our needs. Here, elasticsearch is a store and a cache. The data is updated every night.
Ruby Gems

  • rack: Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby
  • grape-swagger: provides an autogenerated documentation for your Grape API
  • rake: Rake is a Make-like program implemented in Ruby
  • elasticsearch-persistence : Persistence layer for Ruby domain objects in Elasticsearch, using the Repository and ActiveRecord patterns
  • bonsai-elasticsearch-rails : Elasticsearch on production to
  • racksh : console for Rack based ruby web applications.
  • rspec : Test Ruby
  • rack-test : require: 'rack/test'
  • webmock : stubbing and setting expectations on HTTP requests in Ruby

**Heroku**
Hosted on Heroku with basic settings for convinience
**Heroku add-ons**
- Heroku scheduler - to schedule the store update - Bonsai Elasticsearch - Papertail - For logs

Front-End

The view is in full isolation, you can find it in the 'public' folder. Components:

  • Map with place autocomplation, location on right click and marker placements
  • Type of food autocompletion research
  • FoodTruck list Models
  • Current search than contains the latitude, longitude et types of food
  • FoodTruck Collection
  • FoodTypes Collection

The search is the center of the application. The map 'right click', place autocomplete and food types autocomplete will change the search. The collections are watching search change to update themselves and the views are updating when the collection changes.

#####Technologies used Backbone JS
First time using it - 'Highly recommanded', plus I love trying new languages.
Mustache - For easy templating
Bower - Frontend dependency management
BootStrap 3 typeahead - Perfect for simple autocomplete
Google maps and Google Places

###Tradoffs I did not forget the tests on the views, it would be the first thing I do with more time.
Please don't look at it on a mobile phone.. With more time, I would have done a responsive interface and make spend more time on the design implementation.
Minifying the JS. Collect other data to get the foodtrucks depending of their schedule

To launch it in local

  1. Install Ruby (v 2.0+)
  2. Install Bundler
  3. Install Elasticsearch
  4. Launch your elasticsearch server
  5. Install dependencies > bundle install
  6. Prepare the app > rake bootstrap
  7. Load the store > rake update_database

You can then launch your server > rackup and see the result on your localhost:9292

##My resume Check it out here ==> My resume