Skip to content

Development guide

Ruslan edited this page Jun 15, 2019 · 13 revisions

10Books is built on top of Phoenix, some parts of the app are using react and redux.

In order to launch the dev version, you need to have Elixir, Node.js and PostgresSQL installed on your OS. Then, run following:

  1. mix deps.get to install Elixir dependencies
  2. cd assets && yarn && cd .. to install JavaScript dependencies
  3. mix ecto.create to create database
  4. psql -U postgres -d lib_ten_dev < priv/repo/postgres_dump.sql to load seed data
  5. mix ecto.migrate to apply latest db migrations
  6. mix phx.server to start local server

High level architecture overview

Routing and layout

Done with phoenix router. Because of this, we have a mix of back-end and react rendered html. Therefore, CSS is written using SCSS and BEM naming convention (instead of CSS-in-JS commonly used with React apps).

Authentication

We use ueberauth package with phoenix html views. User can sign in only with a valid google account (domain must match one of allowed_google_auth_domains)

There are 2 types of users:

  • default - can do everything in "Library" section and suggest/vote for books in "Orders" section.
  • Admin - default + can edit books, manage categories or assign new admins.

“Orders”, “Library” and “All” pages

React components rendered inside phoenix layout. When component is initialised, it will join related phoenix channel and start receiving information in real time.

Each time there's INSERT, UPDATE or DELETE on related tables, PostgreSQL will trigger NOTIFYcommand with category_updated, category_id or product_updated, product_id. postgres_listener.ex is listening for those events and forwards information to related channels. Channel then will fetch required data and push new message to the client.

Admin Pages (/admin)

Only user with is_admin: true flag can access. Fully done with phoenix controllers and views.

Local demo with docker

  1. Run docker-compose up to boot the app. It will spawn on http://localhost:4000
  2. Run cat priv/repo/postgres_dump.sql | docker exec -i YOUR_CONTAINER_ID psql -U postgres to upload seed data. Where YOUR_CONTAINER_ID is a container id from docker ps