Skip to content

A NestJS microservice that aggregates and caches NASA news feeds with scheduled synchronization, Redis caching, and PostgreSQL persistence. Built with a clean hexagonal architecture (ports & adapters), it delivers a resilient, fast, and easily extensible REST API for structured news data.

Notifications You must be signed in to change notification settings

annaescalada/news-aggregator-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 News Aggregator API

A NestJS microservice that aggregates and caches NASA RSS feeds using a clean hexagonal architecture. It automatically synchronizes data, ensures high performance with Redis caching, and exposes a documented REST API.


🎯 Overview

  • Fetches and stores NASA news in PostgreSQL
  • Uses Redis for caching and fast responses
  • Syncs automatically via cron job
  • Provides REST API with Swagger docs
  • Fully testable hexagonal architecture (ports & adapters)

🏗️ Architecture Overview

Scheduler → SyncNewsUseCase → NasaProvider → PostgreSQL
HTTP GET /news → GetNewsUseCase → Redis Cache → PostgreSQL

📊 Data Flow

1️⃣ SYNC Flow (Hourly Cron Job)

Scheduler → SyncNewsUseCase → NasaProviderClient
                                     ↓
                              Fetch XML Feed
                                     ↓
                              Parse with fast-xml-parser
                                     ↓
                              Validate & Create Entities
                                     ↓
                              NewsRepository (Upsert)
                                     ↓
                              PostgreSQL

2️⃣ GET Flow (API Request)

HTTP GET /news?limit=10
         ↓
    NewsController
         ↓
    GetNewsUseCase
         ↓
    Check Redis Cache
         ├─ ✅ HIT: Return cached data (⚡ fast)
         └─ ❌ MISS: Query PostgreSQL → Cache in Redis → Return

🛠️ Tech Stack

Category Technology
Framework NestJS 11 + TypeScript 5
Database PostgreSQL (Prisma ORM)
Cache Redis 7
Infra Docker Compose
Docs Swagger / OpenAPI
Tests Jest

🚀 Getting Started

Prerequisites

  • Node.js ≥ 18
  • pnpm ≥ 8
  • Docker & Docker Compose

Quick Start

git clone https://github.com/annaescalada/news-aggregator-api.git
cd api && pnpm install
make run  # Starts DB, runs migrations, and launches the API

API available at http://localhost:3000 Swagger docs at /docs


🔐 Environment Variables

DATABASE_URL=postgresql://postgres:postgres@localhost:5432/anna_escalada
REDIS_URL=redis://localhost:6379
NASA_RSS_URL=https://www.nasa.gov/rss/dyn/breaking_news.rss
PORT=3000
NODE_ENV=development

✨ Features

  • 🕒 Hourly sync of NASA RSS feeds
  • ⚡ Smart Redis caching for repeated queries
  • 🧩 Modular & maintainable architecture
  • 🧪 Unit & E2E tests with Jest
  • 🐳 Docker-based local setup

🧪 Testing

pnpm test       # Run all tests
pnpm test:e2e   # Run end-to-end tests
pnpm test:cov   # Generate coverage report

🧱 Project Structure

api/
├── src/
│   ├── modules/news/
│   │   ├── domain/          # Entities
│   │   ├── application/     # Use cases & ports
│   │   ├── adapters/        # Controllers, schedulers, repos
│   │   └── news.module.ts
│   ├── common/              # Shared services (Prisma, Redis)
│   └── main.ts
└── prisma/                  # DB schema & migrations

🧰 Development Commands

make up       # Start PostgreSQL & Redis
make migrate  # Run migrations
make dev      # Run NestJS in watch mode
make down     # Stop Docker containers

📝 License

MIT


Built using NestJS and Hexagonal Architecture

About

A NestJS microservice that aggregates and caches NASA news feeds with scheduled synchronization, Redis caching, and PostgreSQL persistence. Built with a clean hexagonal architecture (ports & adapters), it delivers a resilient, fast, and easily extensible REST API for structured news data.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •