poc-nestjs-ports-and-adapters

🚀 NestJS x Ports and adapters 🚀

Stars
24

Description

This repository serves as a proof of concept for implementing the Ports and Adapters (Hexagonal) architecture pattern using NestJS. The structure emphasizes a clear separation between application logic and external dependencies, promoting maintainability and testability.

Installation

$ npm install

Running the app

Running Locally

  • Using Docker
    To run the NestJS application using Docker, follow these steps:

Build the Docker image:

docker-compose build

Start the application:

docker-compose build

This will start the NestJS application and an SQLite database in separate containers. Access the application at http://localhost:3000

  • Without Docker
    If you prefer not to use Docker, you can run the application locally with the following command:
# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Folder structure

.
├── src
│   ├── user
│   │   ├── domain
│   │   │   ├── UserRepository.ts
│   │   │   └── User.ts
│   │   ├── application
│   │   │   ├── get-all-users/ 
│   │   │   └── user-creator
│   │   │       ├── UserCreator.ts
│   │   │       ├── UserCreatorRequest.ts
│   │   │       └── UserCreator.spec.ts     
│   │   └── infrastructure
│   │       ├── dto
│   │       │   └── create-user.dto.ts
│   │       ├── persistence
│   │       │   └── typeorm
│   │       │       ├── TypeormUser.ts
│   │       │       └── TypeormUserRepository.ts        
│   │       ├── user.controller.ts
│   │       ├── user.module.ts
│   │       └── user.service.ts
│   ├── shared
│   │   ├── domain
│   │   │   ├── exceptions/
│   │   │   └── value-objects/
│   │   │       ├── Uuid.ts
│   │   │       └── MongoId.ts
│   │   └── infrastructure
│   │       └── persistence
│   │           ├── typeorm/          
│   │           ├── mongo/
│   │           └── redis/        
│   └── main.ts
└── test
    └── user
        └── domain
            ├── UserMother.ts
            └── UserEmailMother.ts

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

License

Nest is MIT licensed.