Skip to content

self-service order API using the Domain-Driven Design (DDD) architecture.

Notifications You must be signed in to change notification settings

colantuomo/order-self-service-api

Repository files navigation

Self-Service Order API

Static Badge

Static Badge Static Badge Static Badge

Static Badge

Static Badge Static Badge

Static Badge

Static Badge


This repository contains a Node.js TypeScript project that implements a self-service order API using the Domain-Driven Design (DDD) and Hexagonal architecture. The API allows users to place and manage their own orders through a convenient interface.


Table of contents


Docker Prerequisites

To run this project, ensure that you have the following installed:

(Back to Table of contents ⬆️)

Docker Usage

To run in prod mode:

docker compose up -d

To run in dev mode (with hot reload):

docker compose -f docker-compose-dev.yml up -d

In some OS's its necessary to run these commands as sudo

(Back to Table of contents ⬆️)


Tech Challenge

We created a collection in postman to execute all challenges steps easily. You can find inside postman folder at the root of this project

  • Cadastro do cliente
POST
curl --location 'http://localhost:8080/api/customers' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name":"Michael Jackson",
    "cpf": "38267498709",
    "email": "[email protected]"
}'
  • Identificação do cliente via CPF
GET
curl --location 'http://localhost:8080/api/customers/38267498709/cpf'
  • Criar, editar e remover de Produto
POST (Create Product)
curl --location 'http://localhost:8080/api/products' \
--header 'Content-Type: application/json' \
--data '{
    "name": "Nuggets",
    "category": "SIDE_DISH",
    "price": 5
}'
PUT (Update Product)
curl --location --request PUT 'http://localhost:8080/api/products/48a57c23-b50f-4567-b191-0aa17225d1c0' \
--header 'Content-Type: application/json' \
--data '{
    "name": "Big Mac",
    "price": 22.00
}'
GET (All Products)
curl --location 'http://localhost:8080/api/products'
DELETE (Delete Product)
curl --location --request DELETE 'http://localhost:8080/api/products/48a57c23-b50f-4567-b191-0aa17225d1c0'
  • Buscar produtos por categoria
curl --location 'http://localhost:8080/api/product/category/FOOD'
  • Pegar status de pagamento de um pedido
curl --location 'http://localhost:8080/api/payments/order/258da063-caf2-40c3-8c25-ffcbcb554492'
  • Listar todos os pedidos
curl --location 'http://localhost:8080/api/orders'
  • Endpoint para o Webhook do Mercado Pago
curl --location 'http://localhost:8080/api/payments/webhook/mercadopago' \
--header 'Content-Type: application/json' \
--data '{
    "data": {
        "id": 1317578927
    }
}'
  • Atualizar Status de um pedido
curl --location --request PUT 'http://localhost:8080/api/orders/764697de-5c81-437f-8f9b-05394f440bb4/status' \
--header 'Content-Type: application/json' \
--data '{
    "status": "READY"
}'
  • Criar um pedido (e tambem um pedido de pagamento ja integrando com o mercado pago)
curl --location 'http://localhost:8080/api/orders' \
--header 'Content-Type: application/json' \
--data-raw '{
    "customerId": "688dac4f-4781-4ccd-a9cf-74b527eeb91b",
    "products": [
        {
            "id": "4f197bd9-d329-4558-9a39-71f53c0df64e",
            "quantity": 5
        }
    ],
    "description": "Order payment",
    "installments": 1,
    "payer": {
        "email": "[email protected]"
    },
    "paymentMethodId": "pix"
}'

(Back to Table of contents ⬆️)


Node Prerequisites

To run this project, ensure that you have the following installed:

(Back to Table of contents ⬆️)


Node Installation

  1. Clone this repository to your local machine or download the source code.

  2. Open a terminal and navigate to the project's root directory.

  3. Run the following command to install the project dependencies:

    npm install

(Back to Table of contents ⬆️)


Node Usage

To start the development server, run the following command:

npm run dev

This will compile the TypeScript code, start the server, and watch for any file changes, automatically restarting the server when necessary.

(Back to Table of contents ⬆️)


Postman

(Back to Table of contents ⬆️)


Hexagonal Structure

(WIP)

(Back to Table of contents ⬆️)


Database

database

(Back to Table of contents ⬆️)


Folder Structure

The project follows a DDD-inspired folder structure to separate concerns and maintain a clear code organization. Here's an overview of the key directories:

  • src
    • domain: Contains the core business models, services, and repositories.
    • application: Implements the application layer, which orchestrates the domain logic and exposes it through use cases.
    • infrastructure: Provides infrastructure-related implementations, such as database connectors or external service clients.
    • web: Handles API-specific concerns such as route definitions and request validation.

(Back to Table of contents ⬆️)


Domain Storytelling

Order and Payment

domain_storytelling_1

(Back to Table of contents ⬆️)


Preparation And Delivery

domain_storytelling_2

(Back to Table of contents ⬆️)


Event Storming

event_storming_1

event_storming_2

(Back to Table of contents ⬆️)


External Links

(Back to Table of contents ⬆️)


Contributors

  • Denis Wesley Slapelis - rm348515
  • Paulo César Colantuomo Martins - rm349043
  • Willian Yoshiaki Kazahaya - rm348581

(Back to Table of contents ⬆️)

About

self-service order API using the Domain-Driven Design (DDD) architecture.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages