This repository contains QuickNews.ai: a small web app and Serverless API that fetches news, summarizes headlines, and returns sentiment analysis results.
This README documents the project structure, the responsibilities of each unit, how to run locally, environment variables, security guidance, testing strategy (unit tests + a search speed benchmark), and next steps.
-
sentiment-news-app/Next.js frontend (React + Tailwind). Key pieces:src/app/page.tsxmain page and search UI that calls the API.src/components/UsageGuardRail.tsxlocal usage tracking helpers:- checkDailyUsageLimit(limit): returns {allowed, currentCount} (resets daily using localStorage).
- incrementUsageCount(): increments today's usage counter in localStorage.
src/utils/ThemeProvider.tsx,ThemeSwitcher.tsxUI theme support.
-
sentiment-news-api/Serverless-backed API (Node/TypeScript). Key files:handler.tsLambda handler that:- Reads query param
keyword(defaults toAI). - Reads
NEWS_API_KEYfrom environment. - Calls NewsAPI (
https://newsapi.org/v2/everything) to fetch top 3 articles. - Calls AWS Comprehend (
detectSentiment) for each headline. - Returns an array of { headline, summary, sentiment }.
- Reads query param
serverless.ymlServerless Framework deployment config (setsNEWS_API_KEY: ${env:NEWS_API_KEY}in provider environment).
-
Other files:
LICENSEproject license.package.jsonfiles inside each service for dependencies and scripts.
-
Frontend (Next.js)
- page.tsx: renders a search input, calls
/api/news?keyword=<term>(proxy to the Serverless API), displays results and sentiment badges. - UsageGuardRail.tsx: enforces a simple client-side daily usage cap to reduce API calls during demos.
- ThemeProvider/ThemeSwitcher: small helpers for theme toggling and persistence.
- page.tsx: renders a search input, calls
-
API (Lambda handler)
- exports.handler(event): main entry point.
- Input: event.queryStringParameters.keyword
- Outputs: JSON array of objects { headline, summary, sentiment }
- Errors: returns 500 with {message, error} if something fails.
- External dependencies: News API (requires NEWS_API_KEY) and AWS Comprehend (requires AWS credentials when running detectSentiment).
- exports.handler(event): main entry point.
NEWS_API_KEYAPI key for the news provider (NewsAPI.org). Example placeholder insentiment-news-api/.env.example.- AWS credentials when you call AWS Comprehend from your local machine or during deployment, the AWS SDK will need credentials (configure via
~/.aws/credentialsor environment varsAWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, andAWS_REGION).
Important: DO NOT commit real keys. Use sentiment-news-api/.env.example as a template and keep .env ignored.
.gitignoreupdated to ignore.envand.serverless/build artifacts..env.exampleadded to document required keys without exposing secrets.- Any literal API key strings in tracked files have been redacted or removed from the working tree.
If you believe a secret was committed at any point, rotate it immediately. If you want the secret fully removed from repo history, see the "History purge" section below.
Frontend:
cd sentiment-news-app
npm install
npm run devAPI (quick local test):
cd sentiment-news-api
npm install
# copy example env
copy .env.example .env
# set NEWS_API_KEY in .env
# If you want to test AWS Comprehend locally, ensure AWS credentials are configured
# Then invoke locally via Serverless (optional)
# npm i -g serverless
# sls offlineAlternative quick test (no serverless): create a tiny Node script that imports handler and calls it with a mocked event (set process.env.NEWS_API_KEY first).
Planned work (I'll implement these next as you requested):
-
Unit tests
- API: test handler's flow using mocked HTTP responses (mock axios) and mocked AWS Comprehend (mock AWS SDK). Focus on:
- happy path (3 articles -> 3 sentiment responses)
- missing API key -> error
- NewsAPI returning empty articles -> empty results
- Frontend utils: test
checkDailyUsageLimitandincrementUsageCountbehavior using jsdom/localStorage mocks.
- API: test handler's flow using mocked HTTP responses (mock axios) and mocked AWS Comprehend (mock AWS SDK). Focus on:
-
Search speed benchmark
- Create a small Node script that repeats the API search endpoint 100x (or configurable), measures average and 95th percentile latency, and outputs results. Use natively-timed HTTP calls (axios) and sample concurrency.
I'll add a testing scaffold (Jest + ts-jest for TypeScript) and a bench/search-speed.js script in the next change.
If you want every trace of a secret removed from repository history, we can run git filter-repo or BFG on a mirror clone and force-push the cleaned history. This rewrites commit SHAs and requires coordination (all collaborators must re-clone or reset their local repos). I will not do this without explicit confirmation.
- Frontend entry:
sentiment-news-app/src/app/page.tsx - API handler:
sentiment-news-api/handler.ts - Example env:
sentiment-news-api/.env.example
Built by Messi Banzusabe