This project is a high-performance, scalable back-end API built with NestJS. It enables CSV file uploads, processes large datasets efficiently, and stores product information with real-time currency exchange rates.
- NestJS - Scalable Node.js framework
- TypeORM - PostgreSQL ORM for database operations
- PostgreSQL - Relational database
- Redis - Caching and async processing tracking
- Fast-CSV - Efficient CSV parsing
- Axios - API requests for currency exchange rates
- Throttler - Rate limiting to prevent abuse
- Class-Validator - DTO validation and sanitization
backend/
├── src/
│ ├── common/ # Shared utilities & validation
│ ├── config/ # Configuration module
│ ├── database/ # Database configuration
│ ├── exchange/ # Currency exchange module
│ ├── file-processor/ # CSV processing logic
│ ├── products/ # Product management
│ ├── redis/ # Redis caching
│ ├── throttler/ # Rate limiting
│ ├── app.module.ts # Main entry point
│ ├── main.ts # App bootstrap
├── .env # Environment variables
├── package.json # Dependencies
- Accepts CSV file uploads via
/file/upload
. - Processes files asynchronously (supports large files ~200K+ rows).
- Sanitizes and validates each product entry.
- Bulk inserts using transactions for atomicity.
- Tracks processing status in Redis.
- Filtering & sorting by name, price, expiration.
- Fetches stored exchange rates alongside products.
- Fetches real-time exchange rates from Exchange API.
- Stores conversion rates for 5 currencies (BRL, EUR, GBP, JPY, CAD).
- Caches rates using Redis for efficiency.
- Redis used to cache exchange rates and processing status.
- Rate limiting to prevent API abuse.
- SQL Injection & XSS protection via data sanitization.
- DTO validation ensures correct product format.
- Rate limiting (Throttler) to prevent excessive requests.
- Centralized error handling for better debugging.
- Graceful duplicate handling (prevents DB conflicts).
- Logs validation errors and invalid rows.
POST /file/upload
- Uploads a CSV file for processing
GET /products
- Fetches all products (supports filtering & sorting)GET /products/:id
- Fetches a specific product
GET /exchange/rates
- Fetches latest exchange rates from cache
git clone https://github.com/flatironsdevelopment/rails_node_test_arthursvpb.git
cd backend
npm install
DB_HOST=db
DB_PORT=5432
DB_USER=user
DB_PASS=password
DB_NAME=csv_db
REDIS_HOST=redis
REDIS_PORT=6379
npm run start
docker-compose up --build
✅ NestJS backend
✅ PostgreSQL (TypeORM) database
✅ Redis integration for caching & tracking
✅ Environment variables configured
✅ CSV file upload endpoint
✅ File processing with fast-csv
✅ Validates & sanitizes data (XSS, SQL Injection)
✅ Stores exchange rates along with products
✅ Create and read operations
✅ Sorting & filtering
✅ Returns stored exchange rates per product
✅ Fetches rates from Exchange API
✅ Caches exchange rates
✅ Supports 5 currencies
✅ Sanitization against XSS & SQL Injection
✅ Validates product format
✅ Handles duplicate products gracefully
✅ Rate limiting with Throttler
✅ Centralized exception handling
- Integrate Swagger for API Documentation 📖
- Optimize bulk inserts for even better performance ⚡
- Enhance logging & monitoring 📊