|
1 |
| -# :postbox: Rails API for URL Shortening :outbox_tray: |
| 1 | +# :zap: React URL Shortener :cyclone: |
2 | 2 |
|
3 | 3 | What I'm gonna use:
|
4 | 4 |
|
5 |
| -* [Rails](https://github.com/rails/rails) API 5.2.1 |
| 5 | +* [React](https://github.com/facebook/react) |
6 | 6 |
|
7 |
| -* [MySQL2](https://github.com/brianmario/mysql2) |
| 7 | +* [Webpack](https://github.com/webpack/webpack) for bundling & developing |
8 | 8 |
|
9 |
| -* [RSpec](https://github.com/rspec/rspec-rails) for testing |
| 9 | +* [CoffeeScript2](https://github.com/jashkenas/coffeescript) |
10 | 10 |
|
11 |
| -* [Shoulda Matchers](https://github.com/thoughtbot/shoulda-matchers) for simplier `RSpec` testing |
| 11 | +* [Stylus](https://github.com/stylus/stylus) CSS Preprocessor with [Rupture](https://github.com/jescalan/rupture) media queries |
12 | 12 |
|
13 |
| -* [Faker](https://github.com/stympy/faker) |
| 13 | +* [PostCSS](https://github.com/postcss/postcss) for `lint`ing and `autoprefix`ing mostly |
14 | 14 |
|
15 |
| -* [Heroku](https://heroku.com/) for deployment & development |
| 15 | +* [SugarSS](https://github.com/postcss/sugarss) to `lint` `Stylus` |
16 | 16 |
|
17 |
| -* [Husky](https://github.com/typicode/husky) to manage GIT hooks & to run `RSpec` test on `pre-commit` & `pre-push` |
| 17 | +* [Babel](https://github.com/babel/babel) along with it's ***delightful*** breaking changes in `v7` |
18 | 18 |
|
19 |
| -* [Rack::Attack](https://github.com/kickstarter/rack-attack) to prevent DOS |
20 |
| -* [Memcached/Dalli](https://github.com/petergoldstein/dalli) for requests throttling |
| 19 | +* [Jest](https://github.com/facebook/jest), [Enzyme](https://github.com/airbnb/enzyme) for testing (I would not call it testing, I'm new to `Jest` & `Enzyme` and to the whole `React` ecosystem) |
21 | 20 |
|
22 |
| -* [Geocoder](https://github.com/alexreisner/geocoder) to track locations |
| 21 | +* [Husky](https://github.com/typicode/husky) to manage GIT hooks & to run `Jest` test on `pre-commit` & `pre-push` |
| 22 | + |
| 23 | +* [Heroku](https://heroku.com) for delpoyment & for local development using `Rake` + `./Procfile.dev` in order to run my `Rails API` server along with `webpack-dev-server`. I belive it's okay to do like this. |
23 | 24 |
|
24 | 25 | ----
|
25 | 26 |
|
26 | 27 | ## Development
|
27 | 28 |
|
28 |
| -Use `rails s` and [curl](https://github.com/curl/curl) for HTTP requests. |
| 29 | +Use `rake start` to boot `bundle exec rails -s` and `webpack-dev-server` simultaneously. |
29 | 30 |
|
30 | 31 | ---
|
31 | 32 |
|
32 | 33 | ## Project Structure
|
33 | 34 |
|
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. |
| 35 | +### `client/public` |
| 36 | +Static files. |
37 | 37 |
|
38 |
| -#### Controllers |
| 38 | +### `client/src/api` |
| 39 | +API module for `count`ing, `store`ing and `get`ing `Links`. |
39 | 40 |
|
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); |
| 41 | +### `client/src/components` |
| 42 | +This one serves as the React `components'` storage. Usually `client/src/components/`.sample contains `.coffee` for the logic written in `CoffeeScript2`, `.sss` for the styles written in `Stylus/SugarSS` and the `.test.coffee` for testing with `Jest`. |
44 | 43 |
|
45 |
| -#### Models |
| 44 | +***Sometimes*** it contains another folder `inline` which serves for inline styles for ***some*** components needed to be overwritten. |
46 | 45 |
|
47 |
| -* `Link` to store `:url` and `:shortened`; |
48 |
| -* `Redirect` to store `:location` and `:time`; |
49 | 46 |
|
50 |
| -A single `Link` has many `Redirects`. A single `Redirect` belongs to one `Link`. |
| 47 | +### `client/utils/*.js` |
| 48 | +`Jest` configuration. |
51 | 49 |
|
52 |
| -#### Validators |
| 50 | +### `client/utils/encode` |
| 51 | +`base62` number encoder and the `.test.coffee` for it. |
53 | 52 |
|
54 |
| -* `Base62Validator` to `validate :base62` shortening; |
55 |
| -* `UrlValidator` to `validate :url` formatting; |
| 53 | +### `client/utils/url` |
| 54 | +`process.env.APP_URL` passed using the `Webpack` bundler. |
56 | 55 |
|
57 |
| -### `config/` |
| 56 | +### `client/utils/variables` |
| 57 | +`Stylus/SugarSS` variables. |
58 | 58 |
|
59 |
| -* `initializers/rack_attack.rb` to configure [Rack::Attack](https://github.com/kickstarter/rack-attack); |
| 59 | +### `client/App.coffee` |
| 60 | +Entry point. We call it `instance` in `VueJS`. Has it's own `App.sss` with styles. |
60 | 61 |
|
61 |
| -* `environments/*.rb` to manage heroku `production` and local environments (`development` and `testing`); |
| 62 | +### `client/index.(dev|prod).js` |
| 63 | +That's how `Webpack` knows what he should do in different `environments`. I need the `hot-loading` during the development. |
62 | 64 |
|
63 |
| -### `spec/` |
| 65 | +### `client/jest.config.js` |
| 66 | +`Jest` configuration. |
64 | 67 |
|
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. |
| 68 | +### `client/postcss.config.js` |
| 69 | +`PostCSS` plugins. |
66 | 70 |
|
67 |
| -I belive that everything is backed by tests by now. |
| 71 | +### `webpack.(common|dev|prod).js` |
| 72 | +`.common` to be shared between `.dev` & `.prod` for different `env` |
68 | 73 |
|
69 |
| -### Specific files |
70 |
| - |
71 |
| -`.branch-ignore` is used by me to manage branch-specific `.gitignore` using [Husky](https://github.com/typicode/husky) and `.gitignore.<branch-name>` files. |
| 74 | +--- |
72 | 75 |
|
73 |
| -### `/.*|(other)/` folders & files are pretty default |
| 76 | +:tada: |
0 commit comments