This project is a backend application for managing a movie database. It is built using NestJS and follows the principles of Hexagonal Architecture (also known as Ports and Adapters Architecture). The application provides REST APIs for managing entities:
- movies
- users
- ratings
Hexagonal Architecture, or Ports and Adapters Architecture, is an architectural style that emphasizes separation of concerns and testability. It divides the application into several layers:
- Domain Layer: Contains the business logic of the application. This layer is independent of any external frameworks or technologies.
- Application Layer: Contains the application logic, orchestrating interactions between the domain layer and external systems.
- Adapters Layer: Contains the implementations of interfaces defined in the domain layer, facilitating communication with external systems like databases, web services, etc.
- Inbound Ports: Interfaces through which the external world interacts with the application (e.g., controllers, services).
- Outbound Ports: Interfaces through which the application interacts with external systems (e.g., repositories, external services).
src/
|
├── config/
│ └── database.config.ts
|
├── movies/
│ ├── adapters/
│ │ ├── Typeorm_driven_output/
│ │ │ └── movie.repository.ts
│ │ ├── driver_input/
│ │ │ └── movie.controller.ts
│ │ └── dto/
│ │ ├── create-movie.dto.ts
│ │ └── update-movie.dto.ts
│ ├── domain/
│ │ ├── inbound-ports/
│ │ │ └── movie.service.interface.ts
│ │ ├── model/
│ │ │ └── movie.ts
│ │ └── outbound-ports/
│ │ └── movie.repository.interface.ts
│ ├── application/
│ │ └── movie.service.ts
│ └── movies.module.ts
|
├── users/
│ ├── adapters/
│ │ ├── Typeorm_driven_output/
│ │ │ └── user.repository.ts
│ │ ├── driver_input/
│ │ │ └── user.controller.ts
│ │ └── dto/
│ │ ├── create-user.dto.ts
│ │ └── update-user.dto.ts
│ ├── domain/
│ │ ├── inbound-ports/
│ │ │ └── user.service.interface.ts
│ │ ├── model/
│ │ │ └── user.ts
│ │ └── outbound-ports/
│ │ └── user.repository.interface.ts
│ ├── application/
│ │ └── user.service.ts
│ └── users.module.ts
|
├── rating/
│ ├── adapters/
│ │ ├── Typeorm_driven_output/
│ │ │ └── rating.repository.ts
│ │ ├── driver_input/
│ │ │ └── rating.controller.ts
│ │ └── dto/
│ │ ├── create-rating.dto.ts
│ │ └── update-rating.dto.ts
│ ├── domain/
│ │ ├── inbound-ports/
│ │ │ └── rating.service.interface.ts
│ │ ├── model/
│ │ │ └── rating.ts
│ │ └── outbound-ports/
│ │ └── rating.repository.interface.ts
│ ├── application/
│ │ └── rating.service.ts
│ └── rating.module.ts
|
├── main.ts
└── app.module.ts
-
Create Movie
POST /movies- Request Body:
{ "title": "string", "description": "string", "releaseDate": "date", "genre": "string" }
-
Get All Movies
GET /movies
-
Get Movie by ID
GET /movies/:id
-
Update Movie
PUT /movies/:id- Request Body:
{ "title": "string", "description": "string", "releaseDate": "date", "genre": "string"}
-
Find Movies by Genre
GET /movies/genre/:genre
-
Sort Movies by Rating
GET /movies/sortByRating
-
Create User
POST /users- Request Body:
{ "username": "string", "email": "string" }
-
Get All Users
GET /users
-
Get User by ID
GET /users/:id
-
Update User
PUT /users/:id- Request Body:
{ "username": "string", "email": "string" }
- Create Rating
POST /ratings- Request Body:
{ "rating": "number", "userId": "number", "movieId": "number" }
- Node.js (>= 14.x)
- NestJS CLI
- TypeORM
- PostgreSQL (or another database supported by TypeORM)
-
Clone the repository:
git clone https://github.com/your-username/movie-database-backend.git cd movie-database-backend -
Install dependencies:
npm install
-
Set up the database:
- Create a database and update the
.envfile with your database configuration.
- Create a database and update the
-
Start the application:
npm run start:dev
- Use a tool like Postman to interact with the REST APIs.
- Refer to the API documentation above for the available endpoints and their expected request bodies.
This project is licensed under the MIT License.
