|
1 |
| -# Rails API + React Template |
| 1 | +# :postbox: Rails API for URL Shortening :outbox_tray: |
2 | 2 |
|
3 |
| -Includes: |
| 3 | +What I'm gonna use: |
4 | 4 |
|
5 |
| -* Rails 5.2.1 API |
| 5 | +* [Rails](https://github.com/rails/rails) API 5.2.1 |
6 | 6 |
|
7 |
| -* MySQL2 |
| 7 | +* [MySQL2](https://github.com/brianmario/mysql2) |
8 | 8 |
|
9 |
| -* CoffeeScript2 |
| 9 | +* [RSpec](https://github.com/rspec/rspec-rails) for testing |
10 | 10 |
|
11 |
| -* Stylus + PostCSS (SugarSS) + Rupture |
| 11 | +* [Shoulda Matchers](https://github.com/thoughtbot/shoulda-matchers) for simplier RSpec testing |
12 | 12 |
|
13 |
| -* Husky |
| 13 | +* [Faker](https://github.com/stympy/faker) |
14 | 14 |
|
15 |
| -* Jest |
| 15 | +* [Heroku](https://heroku.com/) for deployment & development |
16 | 16 |
|
17 |
| -* Webpack for dev & prod |
| 17 | +* [Husky](https://github.com/typicode/husky) to manage GIT hooks |
18 | 18 |
|
19 |
| -* And more |
| 19 | +* [Rack::Attack](https://github.com/kickstarter/rack-attack) to prevent DOS |
| 20 | +* [Memcached/Dalli](https://github.com/petergoldstein/dalli) for requests throttling |
20 | 21 |
|
| 22 | +* [Geocoder](https://github.com/alexreisner/geocoder) to track locations |
| 23 | + |
| 24 | +---- |
21 | 25 |
|
22 | 26 | ## Development
|
23 | 27 |
|
24 |
| -```bash |
25 |
| -rake start |
26 |
| -``` |
| 28 | +Use `rails s` and [curl](https://github.com/curl/curl) for HTTP requests. |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Project Structure |
| 33 | + |
| 34 | +### `app/` |
| 35 | + |
| 36 | +You may know the `app/` structure since it's pretty default. It's the home to `models`, `controllers`, `validators`, `exception handlers` etc. |
| 37 | + |
| 38 | +#### Controllers |
| 39 | + |
| 40 | +There are three controllers which are interesting for us: |
| 41 | +* `application_controller` with module dependencies; |
| 42 | +* `links_controller` handles `store`-ing, `get`-ing, `count`-ing for the `Link` model; |
| 43 | +* `redirect_controller` with a single method to `redirect` and store the `Redirect` itself (i.e. it's location) using the [Geocoder](https://github.com/alexreisner/geocoder); |
| 44 | + |
| 45 | +#### Models |
| 46 | + |
| 47 | +* `Link` to store `:url` and `:shortened`; |
| 48 | +* `Redirect` to store `:location` and `:time`; |
| 49 | + |
| 50 | +A single `Link` has many `Redirects`. A single `Redirect` belongs to one `Link`. |
| 51 | + |
| 52 | +#### Validators |
| 53 | + |
| 54 | +* `Base62Validator` to `validate :base62` shortening; |
| 55 | +* `UrlValidator` to `validate :url` formatting; |
| 56 | + |
| 57 | +### `config/` |
| 58 | + |
| 59 | +* `initializers/rack_attack.rb` to configure [Rack::Attack](https://github.com/kickstarter/rack-attack); |
| 60 | + |
| 61 | +* `environments/*.rb` to manage heroku `production` and local environments (`development` and `testing`); |
| 62 | + |
| 63 | +### `spec/` |
| 64 | + |
| 65 | +This is for [RSpec](https://github.com/rspec/rspec-rails) with [Shoulda Matchers](https://github.com/thoughtbot/shoulda-matchers) & [Faker](https://github.com/stympy/faker) testing. |
| 66 | + |
| 67 | +I belive that everything is backed by tests by now. |
27 | 68 |
|
| 69 | +### Specific files |
28 | 70 |
|
29 |
| -## Deployment |
| 71 | +`.branch-ignore` is used by me to manage branch-specific `.gitignore` using [Husky](https://github.com/typicode/husky) and `.gitignore.<branch-name>` files. |
30 | 72 |
|
31 |
| -```bash |
32 |
| -npm run build |
33 |
| -``` |
| 73 | +### `/.*|(other)/` folders & files are pretty default |
0 commit comments