How luiyems/news-platform works
1. Top-level shape
- This is a full-stack news platform, but the core architecture is a Node.js/Express backend plus a static frontend served from the same app.
- Persistent storage is PostgreSQL, and the project is designed to run either locally or in Docker Compose.
2. Application entry points
- server.js is the main process entry point.
- The Express app lives under backend/src/app.js, which likely wires middleware, routes, docs, and static assets.
- entrypoint.sh and Dockerfile suggest container startup is first-class, with docker-compose.yml orchestrating app + database.
3. Backend layering
- The backend follows a clear controller → model → database flow.
- routes/newsRoutes.js maps HTTP endpoints to controllers/newsController.js.
- The controller delegates data access to models/newsModel.js, which in turn uses the PostgreSQL connection defined in config/database.js.
4. API surface
- The main REST API is centered on news resources:
- GET /api/news
- GET /api/news/:id
- GET /api/news/category/:id
- There is also a GET /health endpoint for operational checks.
- Swagger documentation is exposed at /api-docs, configured from backend/src/config/swagger.js.
5. Data persistence
- The database schema is defined in database/schema.sql.
- News content, categories, and related records are stored in PostgreSQL rather than being hardcoded in the frontend.
- The model layer is the only part that should know SQL details, keeping controllers thin.
6. Content ingestion / refresh path
- backend/src/services/rssService.js is the external-content ingestion layer.
- The README says news are refreshed automatically every 3 hours from BBC News and El País, so RSS is the main upstream data source.
- That service likely normalizes RSS items and persists them into the same news tables used by the API.
7. Frontend structure
- The frontend/ folder contains static pages and browser-side JavaScript:
- index.html for the main news feed
- detail.html for article detail
- legal/accessibility pages
- frontend/js/app.js and frontend/js/detail.js are the client-side consumers of the API.
- The frontend appears to be vanilla HTML/CSS/JS, not a framework app.
8. Client-side data flow
- The browser loads the static pages and then fetches news data from the Express API.
- The main page likely renders a list with search/category filtering in the browser, while the detail page fetches a single article by ID.
- This keeps rendering simple and shifts dynamic data retrieval to API calls.
9. Security and cross-cutting concerns
- The README calls out Helmet, XSS sanitization, and rate limiting.
- backend/src/config/logger.js indicates structured logging is part of the runtime, likely for HTTP and app events.
- These are middleware-level concerns around the core request pipeline rather than standalone subsystems.
10. Testing boundary
- Tests are organized by backend unit/integration concern:
- tests/newsController.test.js
- tests/newsModel.test.js
- tests/rssService.test.js
- tests/setup.js suggests shared test bootstrap/mocks.
- The test suite mirrors the architecture layers, which is useful for validating each boundary independently.
11. Infrastructure and runtime
- The stack is explicitly Node.js 18, Express 5, and PostgreSQL 14.
- Docker is the recommended deployment path, with separate app and DB services in Compose.
- Environment configuration is externalized via .env / .env.example.
12. What to draw in an architecture diagram
- Show three primary zones: browser frontend, Express backend, and PostgreSQL.
- Add the RSS feeds as an external upstream feeding into rssService, then into the database.
- Place Swagger, logging, security middleware, and health checks as supporting backend capabilities.
- Treat tests and Docker/deployment files as quality/operational layers around the main runtime, not as runtime business components.
Main entry points: app.js Express app · newsModel.js News model · setup.js Tests · index.html Home page
Components 18
Frontend
Static browser UI and client-side fetches
- Home page · Main news feed and filters
frontend/index.html - Detail page · Article detail view
frontend/detail.html - Browser app · Fetches and renders the news list
frontend/js/app.js - Detail script · Loads a single article by ID
frontend/js/detail.js - Styles · Shared visual presentation for the static site
frontend/css/styles.css
Backend
Express app, API, and data access
- Server entry · Starts the application process
server.js - Express app · Wires middleware, routes, docs, and static assets
backend/src/app.js - News routes · Maps news endpoints to controllers
backend/src/routes/newsRoutes.js - News controller · Handles request/response logic for news APIs
backend/src/controllers/newsController.js - News model · Implements SQL-backed news retrieval and persistence logic
backend/src/models/newsModel.js - Postgres config · Creates and shares the PostgreSQL connection
backend/src/config/database.js - Schema SQL · Defines the PostgreSQL tables and constraints
database/schema.sql - RSS service · Fetches and normalizes external news feeds
backend/src/services/rssService.js - API docs · Exposes interactive API documentation
backend/src/config/swagger.js - Logger · Structured application and HTTP logging
backend/src/config/logger.js
Ops & Quality
Runtime packaging, deployment, and tests
- Dockerfile · Builds the application image
Dockerfile - Compose stack · Runs app and PostgreSQL together
docker-compose.yml - Tests · Backend controller, model, and RSS service tests
tests/setup.js
Connections 23
- Server entry → Express app: starts · Bootstraps the Express application
- Express app → News routes: mounts · Registers API routes
- Express app → API docs: serves docs · Publishes API documentation
- Express app → Logger: uses · Adds runtime logging
- Express app → Home page: serves · Serves static frontend assets
- Express app → Detail page: serves · Serves static frontend assets
- News routes → News controller: dispatches · Routes HTTP requests to handlers
- News controller → News model: queries · Delegates data access to the model
- News model → Postgres config: connects · Uses the shared PostgreSQL connection
- News model → Schema SQL: matches · Operates on the defined database schema
- RSS service → Postgres config: writes · Persists refreshed news content
- RSS service → News model: reuses · Shares the same persistence boundary
- Home page → Browser app: loads · Main page bootstraps the browser app
- Detail page → Detail script: loads · Detail page bootstraps its client script
- Browser app → Express app: fetches API · Retrieves news data from the backend
- Detail script → Express app: fetches API · Retrieves a single article from the backend
- Home page → Styles: styles · Uses shared styling
- Detail page → Styles: styles · Uses shared styling
- Compose stack → Postgres config: provisions · Starts PostgreSQL in the stack
- Compose stack → Dockerfile: builds · Runs the app container
- Tests → News controller: covers · Validates request handling
- Tests → News model: covers · Validates data access logic
- Tests → RSS service: covers · Validates ingestion behavior