An open API service indexing awesome lists of open source software.

https://github.com/arakakimath/order-logistics-api

Last challenge of Rocketseat Node.js course, in which the student has to develop an api, for a ficticious delivery company called FastFeet, to manage related issues
https://github.com/arakakimath/order-logistics-api

apprunner aws ci-cd clean-architecture ddd docker ecr iac-terraform mongodb mongoose nestjs nodejs semantic-release solid-principles swagger tdd test typescript vitest zod

Last synced: 4 months ago
JSON representation

Last challenge of Rocketseat Node.js course, in which the student has to develop an api, for a ficticious delivery company called FastFeet, to manage related issues

Awesome Lists containing this project

README

          

# Order Logistics API ๐Ÿš›

The **Order Logistics API** is the final challenge of Rocketseat's Node.js course, designed for managing deliveries in a fictional company called **FastFeet**. It provides features for **user authentication**, **order tracking**, **delivery management**, and **recipient notifications**, following best practices like **Clean Architecture, DDD, and TDD**.

The project is built with **NestJS, TypeScript, MongoDB**, and **Docker**, ensuring **scalability and maintainability**. It uses **JWT authentication** with **public/private key encryption**, and the infrastructure is deployed using **AWS AppRunner** with a fully automated **CI/CD pipeline**.

The API supports **role-based access control**, allowing **admins to manage deliveries** while **delivery personnel handle pickups and drop-offs**. It also includes a robust **testing suite** and **Swagger documentation** for easy integration.

## ๐Ÿ“Œ Table of Contents

- [๐Ÿ” About the Project](#about)
- [๐Ÿš€ Technologies](#technologies)
- [โš™๏ธ Getting Started](#getting-started)
- [๐Ÿ”‘ Environment Variables](#env-vars)
- [โœ… Functional Requirements](#functional-requirements)
- [๐Ÿ“œ Business Rules](#business-rules)
- [๐Ÿงช Running Tests](#running-tests)
- [๐Ÿ”— API Endpoints](#api-endpoints)
- [๐Ÿค Contributing](#contributing)
- [๐Ÿ“œ License](#license)
- [๐Ÿ“ฉ Contact](#contact)

---

## ๐Ÿ” About the Project

The Order Logistics API is a system designed to manage deliveries for a fictitious company called FastFeet. It allows administrators to manage orders, delivery personnel, and recipients while providing delivery personnel with tools to track and complete deliveries efficiently.

The API includes authentication, role-based access control, order tracking, and notifications for recipients when an order's status changes.

## ๐Ÿš€ Technologies

### **Tech Stack & Tools**

- **๐ŸŸข NestJS (Express)** โ€“ Modular and structured Node.js framework for building efficient and scalable server-side applications.
- **๐Ÿ“Œ TypeScript** โ€“ Statically typed JavaScript for enhanced code quality and maintainability.
- **๐Ÿƒ MongoDB + Mongoose** โ€“ NoSQL database with a schema-based ORM for flexible and scalable data persistence.
- **๐Ÿณ Docker** โ€“ Containerized infrastructure for consistent development and deployment environments.
- **๐Ÿ“ฆ Clean Architecture** โ€“ Separation of concerns for a modular, testable, and scalable codebase.
- **๐Ÿ” JWT Authentication (ES256)** โ€“ Secure user authentication using private/public key encryption and ECDSA algorithm.
- **๐Ÿ›ก๏ธ Zod** โ€“ Schema-based validation for environment variables, request body, query, and params.
- **๐Ÿงช Vitest + Supertest** โ€“ Unit and integration testing for ensuring API reliability and robustness.
- **๐Ÿ“ ESLint** โ€“ Code formatting and linting for maintaining consistent code quality.
- **๐Ÿ”‘ bcryptjs** โ€“ Password hashing and comparison for secure authentication.
- **๐Ÿ“„ Swagger** โ€“ API documentation for easy testing and integration.
- **๐Ÿš€ Semantic Release** โ€“ Automated versioning and changelog generation for streamlined releases.
- **๐Ÿ”— OAuth 2.0 with GitHub** โ€“ Secure authentication via GitHub using OAuth 2.0 for user login.

### **Infrastructure & Deployment**

- **โ˜๏ธ AWS ECR (Elastic Container Registry)** โ€“ Secure storage for Docker images.
- **๐Ÿšฆ AWS AppRunner** โ€“ Fully managed service for deploying containerized applications.
- **๐Ÿ› ๏ธ Infrastructure as Code (IaC)** โ€“ Automated provisioning and management of AWS resources using IAM roles.
- **๐Ÿ”— CI/CD Pipeline** โ€“ Automated workflow from code push to deployment:
- **Push to Main (PR)** โ†’ **GitHub Actions** โ†’ **Docker Build** โ†’ **AWS ECR** โ†’ **AWS AppRunner**.

### **Development Principles**

- **๐Ÿงฉ Domain-Driven Design (DDD)** โ€“ Focus on core business logic and domain models.
- **๐Ÿงช Test-Driven Development (TDD)** โ€“ Write tests before implementation to ensure reliability.
- **๐Ÿ”ง SOLID Principles** โ€“ Design patterns for maintainable and scalable code.
- **๐Ÿ“‚ Modular Codebase** โ€“ Organized and reusable components for easier maintenance.

## โš™๏ธ Getting Started

### Prerequisites

To run this project, you need:
- ๐Ÿณ **[Docker](https://www.docker.com/)** โ€“ Runs the entire application (MongoDB and the built API image)

### Installation

1๏ธโƒฃ Clone this repository:
`git clone https://github.com/your-username/order-logistics-api.git`

2๏ธโƒฃ Enter the project directory:
`cd order-logistics-api`

3๏ธโƒฃ Install dependencies:
`npm install`

### Running the Project

1๏ธโƒฃ Start the services with Docker:
`docker-compose up -d`

2๏ธโƒฃ Make HTTP requests to the base URL [http://localhost:3333](http://localhost:3333)

## ๐Ÿ”‘ Environment Variables

```
PORT=3333
NODE_ENV="dev"

# Database
DATABASE_URL="mongodb://mongodb:docker@localhost:27017/order-logistics?authSource=admin"

# JWT Secrets => Generate ECDSA private key and then public key
JWT_PRIVATE_KEY="jwt_ec_key"
JWT_PUBLIC_KEY="jwt_ec_public_key"

# Auth with GitHub
GITHUB_CLIENT_ID="someID"
GITHUB_CLIENT_SECRET="someSecret"
```

## โœ… Functional Requirements

- [x] Application must have two roles for users: admin and/or delivery person
- [x] It should be possible to sign in with CPF (National ID) and password
- [x] It should be possible to perform the CRUD of the delivery people
- [ ] It should be possible to perform the CRUD of the orders
- [ ] It should be possible to perform the CRUD of the recipients
- [ ] It should be possible to flag an order as awaiting (Available for pickup)
- [ ] It should be possible to pickup an order
- [ ] It should be possible to flag an order as delivered
- [ ] It should be possible to flag an order as returned
- [ ] It should be possible to list orders whose delivery addresses are close to the delivery person
- [x] It should be possible to change user's password
- [ ] It should be possible to list user's orders
- [ ] It should be possible to notify recipient on every order status change

## ๐Ÿ“œ Business Rules

- [x] Only admin users can perform CRUD of the delivery people
- [ ] Only admin users can perform CRUD of the orders
- [ ] Only admin users can perform CRUD of the recipients
- [ ] A photo is needed to flag an order as delivered
- [ ] Only the delivery person who picked up the order can flag it as delivered
- [x] Only admin users can change an user's password
- [ ] It should not be possible for a delivery person to list another one's orders

## ๐Ÿงช Running Tests

Run unit tests with:

```bash
npm test
```

Run end-to-end (e2e) tests with:

```bash
npm run test:e2e
```

## ๐Ÿ”— API Endpoints

### Register delivery person - [POST] /users

### Authenticate login - [POST] /auth

### Authenticate with GitHub (OAuth 2.0) - [GET] /auth/github
Redirects users to authorization github page and then to /auth/github/callback, which can link github with already created users or login into API

## ๐Ÿค Contributing

Want to contribute? Follow these steps:

1. Fork the repository.
2. Create a new branch: `git checkout -b feature-branch`.
3. Make your changes and commit: `git commit -m "Added new feature"`.
4. Push to your fork: `git push origin feature-branch`.
5. Open a Pull Request.

## ๐Ÿ“œ License
This project is under the **MIT License** โ€“ see the [LICENSE](https://opensource.org/license/MIT) file for details.

## ๐Ÿ“ฉ Contact
For support or inquiries, contact:

- **Email:** arakakimath@gmail.com
- **LinkedIn:** [Matheus Arakaki](https://linkedin.com/in/arakakimath)
- **GitHub:** [@arakakimath](https://github.com/arakakimath)