What I'm gonna use:
Rails API 5.2.1
RSpec for testing
Shoulda Matchers for simplier RSpec
testing
Heroku for deployment & development
Husky to manage GIT hooks & to run RSpec
test on pre-commit
& pre-push
Rack::Attack to prevent DOS
Rack CORS for Cross-Origin Resource Sharing
Memcached/Dalli for requests throttling
Geocoder to track locations
Use rails s
and curl for HTTP requests.
This might be deployed as an isolated API as it is shown here (this exactly route returns the current number of links for base62
encoding). Along with a frontend like this (git for it) served with some http server. Just don't forget to respect the CORS
as it is shown here.
On the other hand it could be deployed as a part of monolithic system as it is shown here (react branch of this repo) with a Puma
for http serving.
app/
You may know the app/
structure since it's pretty default. It's the home to models
, controllers
, validators
, exception handlers
etc.
There are three controllers which are interesting for us:
application_controller
with module dependencies;links_controller
handles store
-ing, get
-ing, count
-ing for the Link
model;redirect_controller
with a single method to redirect
and store the Redirect
itself (i.e. it's location) using the Geocoder;Link
to store :url
and :shortened
;Redirect
to store :location
and :time
;A single Link
has many Redirects
. A single Redirect
belongs to one Link
.
Base62Validator
to validate :base62
shortening;UrlValidator
to validate :url
formatting;config/
initializers/rack_attack.rb
to configure Rack::Attack;
environments/*.rb
to manage heroku production
and local environments (development
and testing
);
spec/
This is for RSpec with Shoulda Matchers & Faker testing.
I belive that everything is backed by tests by now.
.branch-ignore
is used by me to manage branch-specific .gitignore
using Husky and .gitignore.<branch-name>
files.
/.*|(other)/
folders & files are pretty default