- Install dependencies with
yarn install - Run docker-compose with
docker-compose up - Create
.envfile in theserverdirectory with the content copied from.env.example. - Switch to the
serverdirectory - Run
yarn prisma migrate devto create the database schema - Run
yarn prisma db seedto seed the database with initial data - Run the server with
yarn start:dev - Server will be running on
http://localhost:3232 - Switch to the
frontenddirectory and runyarn dev - Frontend will be running on
http://localhost:3233
There will be some initial data in the database, including a user with the following credentials:
- email:
test@user.me - password:
password
Frontend has those credentials hardcoded, as I didn't have time to implement proper login form there. DB Schema is deliberately made simple, in real life scenario there would be more tables and relations. Comments are added in the code to explain some decisions and possible improvements.
Default values are in .env.development
Those can be overridden with .env.development.local if needed.
Create .env file in the server directory with the content copied from .env.example.
Most effort has been put into backend code, as it was the main focus of the task. Patterns used:
Repositorypattern for database access. Right now it's a simple wrapper aroundPrisma, but it can be easily extended with more complex queries.Strategypattern in the form of passport strategy. One possible use case could beRecordingStrategywhich specifies how to write log updates to database, for example,ImmediateWriteStrategywhich will write data right away, orBatchWriteStrategywhich will keep update records in a memory buffer and write them all at once to improve performance.Singletonpattern, in particular forPrismaClientinstance. In general NestJS favors singleton services, and all providers are singletons by default.Observerpattern, with help of NestJS's event emitter module. It is used to decouple interceptor from storing logs to database, and also allow to easily extend adding more event types and listeners.Interceptorpattern, leveraging built-in support in NestJS.
Postman collection is included in the root directory, with some basic tests for all endpoints.
Some parts what are crucial to be done, but not implemented:
- handle DB "not found" errors
- handle controller errors in interceptor
- proper authentication handle on frontend, with loading current user and store session.
- error handling on frontend
- better display of updated fields on frontend, to clearly show what was updated
- add pagination to collections endpoints