Skip to content

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

Notifications You must be signed in to change notification settings

arakakimath/order-logistics-api

Repository files navigation

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

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 – 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

πŸ”‘ 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

  • Application must have two roles for users: admin and/or delivery person
  • It should be possible to sign in with CPF (National ID) and password
  • 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
  • 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

  • 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
  • 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:

npm test

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

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 file for details.

πŸ“© Contact

For support or inquiries, contact: