move into movie-api folder cd movie-api
and docker compose up
and wait (it will take some time to run the db migrations)
-
npm run start:dev
to start the project with hot reload -
npm run typeorm:run-migrations
to run needed migrations -
npm run typeorm:generate-migration
to create a migration after a change in the entities
- Better Error Handling
- More granular e2es
- Customised authentication guards
- NestJS
- Docker
- Postgres
- TyperORM
- Architecture Design: SOLID, DDD, Hexagonal
- Everything is Dockerised
- Authentication: JWT, generated through ('auth/login')
- APIs
- GET ('/movies'): returns list of the authenticates user's movies
- POST('/movies'): using a provided title fetches a movie from omdAPI and saves it's data
- Security: Authentication guards, password hashing using bcrypt
- Seperate .env files for docker and local
- ...
The process tried to adhere as much as possible to: - SOLID (especially Seperation of concerns and IoC), - hexagonal architecture (dependencies are outwards) - DDD maintaining a clean domain layer where the business rules are inforced and an in the application layer used use cases instead of services and seperated the persistance logic from the business logic
The source code contains:
- main files containing docker files, cofigurations and .env
- under src
- external providers: implementation of wrapper around omdAPI (since we have IoC the module will use the interface and not the actual implementation)
- healthcheck: the hello world APIs generated by nest
- modules:
- userauths: (the authentication stuff, does not strictly follow DDD as there is no need)
- application: the local and JWT strategies (the implementations needed to validate credentials, generate tokens andvalidate them; followed nestjs official documentation)
- domain: contains the entities used by the module
- infra:
- http: the auth controller containing the ('auth/login') api
- data-access: the user database entity the repository used to retrieve users
- mocks: the classes used by ject
- the module.ts which is linking it all together
- movies: (this is the core module of the application and does adhere to tactical patterns of DDD)
- application: the orchetrator layer, is not persistance ignorant (as it connects with the
repository but do so using IoC)
- providers: the interfaces of the external providers that the module's application needs to function, the implementation of which will be offered by the module.ts
- the use cases of the application, tahese are the main functionalities of the module, each complete of its own accord
- the use cases' spec files to run unit tests
- domain: the core entities of the movies module, responsible for ensuring business rules
- infra: everything not part of the core business of the module is sent to the edge of the
hexagone!
- http: the movies controller containing the APIs
- dtos: cotaining the objects that will be shared with teh outside world
- data-access:
- repositories: responsible for the data logic and returning the aggregate root
- entities: the database entities (ORMs) that will be used to generate the database and access it
- http: the movies controller containing the APIs
- mocks: the classes used by jest
- the module.ts which is linking it all together
- application: the orchetrator layer, is not persistance ignorant (as it connects with the
repository but do so using IoC)
- tests: contains the e2e tests used to validate this application
- Create project: nest new movie-api with npm
- Build modular project structure
- application containing the use cases
- domain containing the domain objects and logic
- infra: containing both http (controllers) and data-access (entities, repositories implementation)
- Added online movies provider, used explicit injection instead of injection by interface to respect hexagonal architecture
- Implemented movies domain functionality
- Added repository (no DB access yet)
- Link the above together orchastrated in the use case
- Implement authentication module (following nestjs official documentation)
- Add local and jwt guards
- Guard create movie APi by JWT token
- Create entities and install typeORM packages
- Create docker files for postgres
- Create database from TypeORM to postgres docker
- Save created movie in DB
- Get authenticated user from context
- Implement business logic (only 5 movies for basic users)
- Implement get movies API fully
- Implement unit tests for movies use cases
- dockerise nestjs