# luiyems/news-platform architecture

> Architecture diagram of the GitHub repository luiyems/news-platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/luiyems/news-platform
- Repository: https://github.com/luiyems/news-platform

## Overview

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: [`backend/src/app.js`](https://github.com/luiyems/news-platform/blob/main/backend/src/app.js) (Express app), [`backend/src/models/newsModel.js`](https://github.com/luiyems/news-platform/blob/main/backend/src/models/newsModel.js) (News model), [`tests/setup.js`](https://github.com/luiyems/news-platform/blob/main/tests/setup.js) (Tests), [`frontend/index.html`](https://github.com/luiyems/news-platform/blob/main/frontend/index.html) (Home page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_index["Home page<br/>static page<br/>[index.html]"]
  node_frontend_detail["Detail page<br/>static page<br/>[detail.html]"]
  node_frontend_appjs["Browser app<br/>client script<br/>[app.js]"]
  node_frontend_detailjs["Detail script<br/>client script<br/>[detail.js]"]
  node_frontend_css["Styles<br/>[styles.css]"]
end

subgraph group_backend["Backend"]
  node_server["Server entry<br/>nodejs entrypoint<br/>[server.js]"]
  node_app["Express app<br/>[app.js]"]
  node_routes["News routes<br/>http routes<br/>[newsRoutes.js]"]
  node_controller["News controller<br/>api controller<br/>[newsController.js]"]
  node_model["News model<br/>data model<br/>[newsModel.js]"]
  node_database[("Postgres config<br/>db config<br/>[database.js]")]
  node_schema["Schema SQL<br/>sql schema<br/>[schema.sql]"]
  node_rss["RSS service<br/>ingestion service<br/>[rssService.js]"]
  node_swagger["API docs<br/>swagger config<br/>[swagger.js]"]
  node_logger["Logger<br/>logging config<br/>[logger.js]"]
end

subgraph group_ops["Ops & Quality"]
  node_docker["Dockerfile<br/>container build"]
  node_compose["Compose stack<br/>deployment config<br/>[docker-compose.yml]"]
  node_tests["Tests<br/>test suite<br/>[setup.js]"]
end

node_server -->|"starts"| node_app
node_app -->|"mounts"| node_routes
node_app -->|"serves docs"| node_swagger
node_app -->|"uses"| node_logger
node_app -->|"serves"| node_frontend_index
node_app -->|"serves"| node_frontend_detail
node_routes -->|"dispatches"| node_controller
node_controller -->|"queries"| node_model
node_model -->|"connects"| node_database
node_model -.->|"matches"| node_schema
node_rss -->|"writes"| node_database
node_rss -.->|"reuses"| node_model
node_frontend_index -->|"loads"| node_frontend_appjs
node_frontend_detail -->|"loads"| node_frontend_detailjs
node_frontend_appjs -->|"fetches API"| node_app
node_frontend_detailjs -->|"fetches API"| node_app
node_frontend_index -.->|"styles"| node_frontend_css
node_frontend_detail -.->|"styles"| node_frontend_css
node_compose -->|"provisions"| node_database
node_compose -->|"builds"| node_docker
node_tests -.->|"covers"| node_controller
node_tests -.->|"covers"| node_model
node_tests -.->|"covers"| node_rss

click node_server "https://github.com/luiyems/news-platform/blob/main/server.js"
click node_app "https://github.com/luiyems/news-platform/blob/main/backend/src/app.js"
click node_routes "https://github.com/luiyems/news-platform/blob/main/backend/src/routes/newsRoutes.js"
click node_controller "https://github.com/luiyems/news-platform/blob/main/backend/src/controllers/newsController.js"
click node_model "https://github.com/luiyems/news-platform/blob/main/backend/src/models/newsModel.js"
click node_database "https://github.com/luiyems/news-platform/blob/main/backend/src/config/database.js"
click node_schema "https://github.com/luiyems/news-platform/blob/main/database/schema.sql"
click node_rss "https://github.com/luiyems/news-platform/blob/main/backend/src/services/rssService.js"
click node_swagger "https://github.com/luiyems/news-platform/blob/main/backend/src/config/swagger.js"
click node_logger "https://github.com/luiyems/news-platform/blob/main/backend/src/config/logger.js"
click node_frontend_index "https://github.com/luiyems/news-platform/blob/main/frontend/index.html"
click node_frontend_detail "https://github.com/luiyems/news-platform/blob/main/frontend/detail.html"
click node_frontend_appjs "https://github.com/luiyems/news-platform/blob/main/frontend/js/app.js"
click node_frontend_detailjs "https://github.com/luiyems/news-platform/blob/main/frontend/js/detail.js"
click node_frontend_css "https://github.com/luiyems/news-platform/blob/main/frontend/css/styles.css"
click node_docker "https://github.com/luiyems/news-platform/tree/main/Dockerfile"
click node_compose "https://github.com/luiyems/news-platform/blob/main/docker-compose.yml"
click node_tests "https://github.com/luiyems/news-platform/blob/main/tests/setup.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_index,node_frontend_detail,node_frontend_appjs,node_frontend_detailjs,node_frontend_css toneBlue
class node_server,node_app,node_routes,node_controller,node_model,node_database,node_schema,node_rss,node_swagger,node_logger toneAmber
class node_docker,node_compose,node_tests toneMint
```

## Components

### Frontend

Static browser UI and client-side fetches

- [Home page](https://github.com/luiyems/news-platform/blob/main/frontend/index.html): static page · Main news feed and filters · `frontend/index.html`
- [Detail page](https://github.com/luiyems/news-platform/blob/main/frontend/detail.html): static page · Article detail view · `frontend/detail.html`
- [Browser app](https://github.com/luiyems/news-platform/blob/main/frontend/js/app.js): client script · Fetches and renders the news list · `frontend/js/app.js`
- [Detail script](https://github.com/luiyems/news-platform/blob/main/frontend/js/detail.js): client script · Loads a single article by ID · `frontend/js/detail.js`
- [Styles](https://github.com/luiyems/news-platform/blob/main/frontend/css/styles.css): stylesheet · Shared visual presentation for the static site · `frontend/css/styles.css`

### Backend

Express app, API, and data access

- [Server entry](https://github.com/luiyems/news-platform/blob/main/server.js): nodejs entrypoint · Starts the application process · `server.js`
- [Express app](https://github.com/luiyems/news-platform/blob/main/backend/src/app.js): express app · Wires middleware, routes, docs, and static assets · `backend/src/app.js`
- [News routes](https://github.com/luiyems/news-platform/blob/main/backend/src/routes/newsRoutes.js): http routes · Maps news endpoints to controllers · `backend/src/routes/newsRoutes.js`
- [News controller](https://github.com/luiyems/news-platform/blob/main/backend/src/controllers/newsController.js): api controller · Handles request/response logic for news APIs · `backend/src/controllers/newsController.js`
- [News model](https://github.com/luiyems/news-platform/blob/main/backend/src/models/newsModel.js): data model · Implements SQL-backed news retrieval and persistence logic · `backend/src/models/newsModel.js`
- [Postgres config](https://github.com/luiyems/news-platform/blob/main/backend/src/config/database.js): db config · Creates and shares the PostgreSQL connection · `backend/src/config/database.js`
- [Schema SQL](https://github.com/luiyems/news-platform/blob/main/database/schema.sql): sql schema · Defines the PostgreSQL tables and constraints · `database/schema.sql`
- [RSS service](https://github.com/luiyems/news-platform/blob/main/backend/src/services/rssService.js): ingestion service · Fetches and normalizes external news feeds · `backend/src/services/rssService.js`
- [API docs](https://github.com/luiyems/news-platform/blob/main/backend/src/config/swagger.js): swagger config · Exposes interactive API documentation · `backend/src/config/swagger.js`
- [Logger](https://github.com/luiyems/news-platform/blob/main/backend/src/config/logger.js): logging config · Structured application and HTTP logging · `backend/src/config/logger.js`

### Ops & Quality

Runtime packaging, deployment, and tests

- [Dockerfile](https://github.com/luiyems/news-platform/tree/main/Dockerfile): container build · Builds the application image · `Dockerfile`
- [Compose stack](https://github.com/luiyems/news-platform/blob/main/docker-compose.yml): deployment config · Runs app and PostgreSQL together · `docker-compose.yml`
- [Tests](https://github.com/luiyems/news-platform/blob/main/tests/setup.js): test suite · Backend controller, model, and RSS service tests · `tests/setup.js`

## Connections

- 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
