Simple web-based audio player. Work in Progress
The application consists of 2 main parts:
- REST API serving songs and metadata, powered by
express.js[Work in Progress] - Frontend, powered by
react.js[Work in Progress]
Requires Docker & modern node environment with yarn/npm.
Rename .env.example to .env:
mv .env{.example,}
Optionally, change values in .env.
Setup Postgres container:
docker-compose up -d --build
Install packages:
yarn
Run database migrations:
yarn data:migrate
Optionally, seed database with test data (each run will clear old values and generate new ones):
yarn data:seed
Run development version of the API:
yarn dev
By default, the API will be available at: http://localhost:3001/api/v1/.
.env defines API URL prefix, the default one is: /api/v1 (I prefer to introduce API versionning from the beginning). For clarity, the prefix is not included in the documented endpoints below.
GET /songs
Query Params:
page(number, default:1) -- page numberlimit(number, default:10, value range: [10, 100]) -- number of songs to show per pageexpand(bool, default:false) -- whether to expandalbum&artist(by default onlyalbum_idandartist_idare present)
Successful response structure
-
success: true -
meta(object) -- info about the page and request:expandpagelimittotal_songshas_more
-
data(array) -- array of song objects (see Single Song for song object structure)
Error response structure
success: falsemessage- error message
GET /songs/:id
:id -- song id
Query Params:
expand(bool, default:false) -- whether to expandalbum&artist(by default onlyalbum_idandartist_idare present)
Successful response structure
success: truedata(object) -- song object:id- song IDtitlealbum_id(not expanded) ORalbum(objectwhen expanded, withidandnameproperties)artist_id(not expanded) ORartist(objectwhen expanded, withidandnameproperties)
Error response structure
success: falsemessage- error message
- eslint & prettier -- maintain code style and formatting
- PostgreSQL -- preferred database I'm familiar with
- Docker -- easy way for runing Postgres locally
- knex.js -- query builder I'm familiar with & nice migration and seed CLI
Since the application is so simple, there's no need for overengineering, crazy DI frameworks or CQRS. I've tried to split the application into 3 layers:
- application layer -- runs the server, manages the base configuration
- controllers -- handle request/response cycle
- "model" queries -- interaction with the database
so future refactors will be easier and (when needed) contained within specific layer.
- add tests
- better error handling
- extract logic for pagination response structure
For the seed/test data, I've created "random" generators for artists, albums and songs names, based on faker.js. This was just for fun :). Some names I've enjoyed: "Intelligent Practical Metal Hat", "Practical Yellow", "Intelligent Back-end".