Lyrix is a song collection app which helps you keep track of the songs you like to play or sing, along with your own notes, lyrics, or chords. It consists of a Node.js server and a React client:
- In development, the client is accessed via the web. It proxies external URLs to the server.
- In production, the server is accessed via the web. It routes clients to a static build of the React client.
Server technologies:
- The server is a REST API service written in Node.js.
- It's built and run with the Yarn package manager.
- It uses Express to structure its request-response system and for routing.
- Database access is via Ojection.js ORM on top of Knex.js query builder.
- Database implementation is PostgreSQL database
- For sessions, it uses Redis and connect-redis
- For authentication, it uses Passport.
- Colorful, namespaced error logging with debug
- Fetch song and artist information from Genius.com using genius-lyrics
Server testing:
- Good coverage of both system and unit testing with the Mocha test framework and the Chai assertion library
- Fixtures for Knex using simple-knex-fixtures
Client technologies:
- The client is a React app, using React Router for routing.
- It uses Bootstrap (both stand-alone and through React Bootstrap) and FontAwesome for graphical goodness.
- Graceful data subscription/fetching with SWR
- Drag & drop to re-order song-list items with react-beautiful-dnd
- View a list of all artists, or an individual artist together with their songs
- View a song's lyrics
- Create your own songlists, to which you can add/remove any song
- Create your own song item for any song: chords, notes, or even your own lyrics
- Easily navigate from song to song within your songlists or per artist
- Import: search for songs to import into the database
- Full text search by song title, lyrics, or artist name.
- Install requirements by running
yarn
- Setup a PostgreSQL database for development.
$ touch .env
- Provide the following environment variables inside
.env
:- DB_HOST
- DB_NAME
- DB_USERNAME
- DB_PASSWORD
- SESSION_SECRET - to be used for creating sessions with
express-session
- LOGGING - optional value to be used with the morgan logger, eg.
common
,dev
- Optional: specify a port number for serving the React frontend, in
client/.env
:- PORT
Default as per
react-scripts start
:3000
- PORT
Default as per
- Install Redis
- If you have non-default Redis instance variables, add a Redis URL in
.env
asREDIS_URL=redis://...
- If you have non-default Redis instance variables, add a Redis URL in
- Run knex migrations:
$ heroku run knex migrate:latest
- Run knex seeds, if any:
$ heroku run knex seed:run
- Run the app:
yarn dev
- Setup a PostgreSQL database for testing.
- Provide database connection parameters inside
.env
:- DB_TEST_NAME
- DB_TEST_USERNAME
- DB_TEST_PASSWORD
- SESSION_SECRET - to be used for creating sessions with
express-session
- Run all tests:
yarn test
. - You can specify specific test types to run, eg.
yarn test:unit
for only unit tests, oryarn test:behav
for only behavior/integration tests.
- Ensure that the server port is read from
process.env.PORT
- Heroku will set this for your deplyed app. - In your database settings for production, create a single property for database URL, instead of single properties for user name, password, host, etc. In this app, the config URL is read from
config
:// In config/config.js: production: { connectionUrl: process.env.DB_URL, [...] // In knexfile.js: production: { client: 'postgresql', connection: config.connectionUrl, [...]
- Install a PostgreSQL database on Heroku as follows:
- Install the PostgreSQL add-on:
This will generate a database name, also retrievable by running
$ heroku addons:create heroku-postgresql:hobby-dev
heroku pg:info
. - Get the database URL (replace
<database_name>
with the name output by the previous step):The output will contain a few parts; select only the part that starts with$ heroku pg:credentials:url <database_name>
postgres://
- Set the database URL for your app (replace the relevant placeholders):
$ heroku config:set DB_URL='<database_url>' -a <app_name>
- Install the PostgreSQL add-on:
- Provision Redis for your Heroku instance.
There should be no further setup needed: the code will look for Heroku's Redis URL as
process.env.REDIS_URL
, and use it if found. - Push your source code to Heroku:
$ git push heroku master
- Run knex migrations:
$ heroku run knex migrate:latest
- Run knex seeds, if any:
$ heroku run knex seed:run