Skip to content

patricks-js/picpay-simplified

Repository files navigation

PicPay Simplified - Back-End challenge

🇧🇷 Versão em português

The goal of this challenge is implement a simplified version of PicPay service. It should be possible to perform transfers between users. This project adheres to RESTful principles and incorporates clean code practices, observability, and SOLID.

📌 Table of Contents

📝 Project Overview

PicPay Simplified is a payment service that allows users to transfer and deposit money. It supports two types of users:

  • Customer: Can send and receive money.
  • Merchants: Can only receive money.

Each user has a wallet for transactions. The system ensures security, validation, and reliability during all financial operations.

🛠️ Technologies Used

  • Programming Language: TypeScript
  • Framework: Fastify
  • Database: PostgreSQL
  • Caching: Redis (Proposed)
  • Containerization: Docker & Docker Compose
  • Documentation: Swagger/OpenAPI
  • CI/CD: GitHub Actions
  • Messaging: RabbitMQ (Proposed)
  • Monitoring: Prometheus, Grafana (Proposed)
  • Testing: Vitest, supertest and Bruno for API testing

📋 Business Rules

  • Email and CPF/CNPJ must be uniques
  • Customers can receive and perform transfers
  • Merchant only receive transfers
  • Balance must be sufficient before transfers
  • Every transfer operation is wrapped in a database transaction to ensure atomicity. In case of an error, the system reverts all operations to maintain consistency.
  • Transfers must be authorized with an external authorization service (GET)
  • Users should receive a notification when a transfer is completed with a external notification service (POST)

✅ Requirements

  • User can create an account as customer or merchant
  • User can authenticate with email & password
  • Transaction history is available for all users
  • Customers can transfer money to other users (customers or merchants)
  • Transfers are restricted to customers with sufficient balance
  • All transfers must be authorized by an external service
  • Merchants are limited to receiving transfers only
  • Users should receive notifications (e.g., email or SMS) upon receiving a transfer
  • Transfers must be reversible in case of any failure

📊 ER Diagram (Entity-Relationship)

The following diagram represents the database structure used in this project:

ER Diagram

✨ Features

  • Secure transfers between users.
  • Wallet balance validation before transactions.
  • Integration with external authorization service for validating transfers.
  • Notifications for payees using a mocked external service.
  • Rollback mechanism for failed transactions.
  • Clean code following SOLID principles.
  • Observability with logging and monitoring.
  • Scalable and decoupled architecture.
  • RESTful API with Swagger documentation.
  • Support for relational and non-relational databases.
  • Dockerized environment for consistent deployment.
  • Automated CI/CD pipelines.

⚙️ Setup Instructions

📌 Prerequisites

  • Docker & Docker Compose
  • Node v20+ with pnpm as package manager

🚀 Installation

  1. Clone the repository:

    git clone https://github.com/patricks-js/picpay-simplified.git
    cd picpay-simplified
  2. Installing dependencies:

    pnpm install
  3. Start the services:

    pnpm services:up
  4. Running database migrations:

    pnpm db:migrate
  5. Seed database with some data:

    pnpm db:seed

💻 Usage

  1. Start the application running:

    pnpm dev
  2. The API will be accessible at http://localhost:3333

  3. The API documentation (swagger) will be accessible at http://localhost:3333/api/docs

🧪 Running Tests

Run the following command

pnpm test

To see the code coverage

pnpm test:coverage

🌟 Proposed Improvements

  • Error Handling: Enhance error messages and use semantic status codes.
  • Monitoring: Add detailed transaction metrics for observability.
  • Rate Limiting: Implement API rate limiting and request throttling for security.
  • Database Optimization: Improve query performance with indexes and partitioning.
  • Caching: Introduce caching strategies for high-volume transactions.

Releases

No releases published

Packages

No packages published