Backend — News & Projects Application
Confidential document · Client version
This document describes the backend development plan for a hybrid platform: social network and newspaper focused on news and nearby projects. It includes hexagonal architecture, publication flows with AI verification and administrative approval, and agreed technologies (React Native for the mobile app, REST API backend).
We will handle the backend in full: hexagonal architecture, API, database, authentication, integration with AI services for content verification, file storage, testing, CI/CD and cloud deployment.
The system combines social network and newspaper: users upload nearby projects, can create news according to their role, and content goes through AI verification and/or administrator approval before publication.
Users upload and share nearby projects (initiatives, works, local events). These projects are social content and context for news.
Verified journalists: recognised users who pass verification and can publish news directly. Other users: can create news but require AI token verification and then administrator approval for publication.
AI tokens will be used to check that news submitted by unverified users meets quality and consistency criteria. The verification result feeds the approval flow.
An administrator reviews and approves news that passed AI verification (or rejects it). Only approved content is published in the “newspaper” visible to all.
The mobile app (reading news, uploading nearby projects, users creating news) will be developed with React Native. The choice is justified by widespread industry adoption and the benefits it brings to the project:
The backend will be developed using hexagonal architecture: the domain core (business logic, publication rules, verification) is isolated from technical details; communication with the outside is through ports (interfaces) and adapters (concrete implementations).
Benefits for this project: independence from frameworks and databases, unit testing of the domain without infrastructure, and the ability to change or add adapters (another API, another AI provider, another storage) without rewriting business logic.
High-level view: mobile app (React Native), hexagonal backend, admin panel and differentiated publication flows.
Optimised queries, server cache (Redis), low response times and a fast experience in both the web editor and the app will be maintained.
The main frameworks for building this platform's API were compared. Production deployment will use Dokku (self-hosted Heroku-like PaaS, deploy via git push, support for PostgreSQL, Redis and environment variables).
| Framework | Language | Strengths | Fit for this project |
|---|---|---|---|
| NestJS | Node.js / TypeScript | Module architecture and dependency injection, ideal for hexagonal; TypeScript (typing, safe refactor); ecosystem: TypeORM/Prisma, Bull/BullMQ, class-validator, JWT; same language for API and workers. | Very high: fits hexagonal, complex flows (approval, AI), queues and validation; Dokku supports Node natively. |
| Laravel | PHP | Rapid development, Eloquent, queues and cache with Redis, Sanctum/Passport, mature ecosystem. | High: good CRUD and queues; hexagonal needs more discipline; PHP less common in teams already using React Native/Node. |
| FastAPI | Python | Async, automatic OpenAPI docs, Pydantic; strong for ML/AI integration in the same language. | Medium: excellent for pure APIs; project only consumes an external AI API (HTTP), does not run models; less convention for CRUD + workflows than NestJS/Laravel. |
| Go (Gin / Fiber) | Go | Performance, single binary, native concurrency; very good on Dokku. | Medium: more boilerplate for auth, validation, queues and approval flows; fewer "batteries included" for this type of API. |
NestJS with Node.js and TypeScript will be used for this API because it fits directly with the hexagonal architecture we want to apply: modules and dependency injection allow defining ports (interfaces) in the core and injecting adapters (PostgreSQL repositories, AI client, S3 storage) without coupling business logic to the framework. TypeScript typing reduces errors and eases maintenance for a developer working alone on the backend. NestJS offers native support for queues (Bull/BullMQ con Redis), validation with DTOs and class-validator, guards for JWT and roles, and a clear structure by domain (news, projects, users, approvals), which speeds up implementing flows como “verificación IA → aprobación admin” and the distinction between verified journalists and standard users. Integration with AI providers is trivial (HTTP calls from core services). Finally, deployment with Dokku is straightforward (Node buildpack, Procfile, environment variables for DB and Redis), and the same runtime serves both the API and workers that process verification or notification queues.
git push, containerised app management, add-ons or linking of PostgreSQL and Redis, and domain and SSL configuration. Compatible with the NestJS + Node stack and with CI/CD pipelines (e.g. GitHub Actions) that build and deploy to the Dokku server.
The backend will use PostgreSQL as the main engine. The model supports social network + newspaper: users uploading nearby projects, news with AI verification and administrative approval flow, and roles for verified journalists (direct publish) vs users requiring approval. Below: tables and entity-relationship diagram.
| Table | Description and main columns |
|---|---|
roles |
System roles: admin, editor, verified_journalist (verified journalist, publishes directly), user (requires approval). Columns: id, name, slug, timestamps. |
users |
Users. Columns: id, name, email, password (hash), role_id (FK), email_verified_at, remember_token, timestamps. Role determines whether they can publish directly or must go through approval. |
projects |
Nearby projects uploaded by users. Columns: id, user_id (FK), name, slug, description, location (or lat/lng), status, timestamps. Social network content. |
categories |
Categories/topics to classify news. Columns: id, name, slug, parent_id (optional), timestamps. |
news |
News with publication flow. Columns: id, title, slug, excerpt, body, category_id (FK), user_id (author), project_id (FK optional), status (draft, pending_ai_review, pending_approval, published, rejected), ai_verified_at, ai_verification_result (or JSON), approved_by (FK user, admin), approved_at, published_at, timestamps. |
comments |
Comments on news. Columns: id, news_id (FK), user_id (FK), body, parent_id (replies), timestamps. |
media |
Files/images (polymorphic: news or project). Columns: id, path, url, type, mediaable_id, mediaable_type, order, timestamps. |
refresh_tokens |
JWT refresh tokens. Columns: id, user_id (FK), token (hash), expires_at, revoked_at, timestamps. |
password_reset_tokens |
Password reset tokens (forgot/reset). Columns: id, user_id (FK), token, expires_at, used_at, timestamps. |
Profile |
User profile (1:1). Columns: id, userId (FK UNIQUE), firstName, lastName, address, avatar, lastConnectionAt, lastNewsDownloadedId (FK News), lastCommentId (FK Comment), lastSearch, timestamps. Used by admin panel and app. |
Users with roles (admin, editor, verified_journalist, user); nearby projects uploaded by users; news with state flow (AI + approval); categories, comments and media. The diagram prints correctly to PDF.
An automatic backup system will be maintained to ensure data integrity and recovery:
Backups will be stored in secure storage (e.g. S3 or equivalent) and the restore procedure will be documented.
The API will be developed with NestJS (Node.js + TypeScript) and PostgreSQL, as justified in the previous section. Below: efficiency aspects and capabilities of the chosen stack.
How the NestJS + TypeORM/Prisma + Redis stack translates into efficiency and maintainability for this API:
| Criterion | Efficiency impact / Why this technology |
|---|---|
| TypeORM/Prisma + relaciones | Eager loading and well-defined relations avoid N+1 in news listings (with category, author, project). Fewer DB round-trips and faster API responses. |
| Redis as cache and queues (BullMQ) | Response cache (listings, last-news flag) with TTL; BullMQ queues for AI verification, image processing or background notifications without blocking the HTTP request. |
| Indexes and queries in PostgreSQL | Indexes on published_at, category_id, status and slugs. Optional full-text search. Optimisable execution plans. |
| Serialisation and DTOs | DTOs y class-transformer permiten un formato de respuesta controlado y consistente, reduciendo tamaño de payload y tiempo de parsing en la app React Native. |
| Guards y rate limiting | NestJS guards for JWT and roles; throttling by IP or user to avoid overload and keep response times stable. |
| Last-news flag “última noticia” en el API | Lightweight endpoint (e.g. GET /api/v1/news/last-updated) that returns only timestamp or version. The app compares with its cache and only requests full listing when there is new content. |
refresh_tokens.
main, develop and feature branches. Conventional commits and branch protection with mandatory PRs.
.env and validation on startup (e.g. @nestjs/config or similar). Secrets outside the code.
/api/v1/). Documentation with Swagger/OpenAPI.
refresh_tokens, optional rotation). Login, refresh and logout endpoints.
media table (news, project).
git push to server, Node buildpack, Procfile, PostgreSQL and Redis linked (add-ons or external services). Variables and secrets in Dokku; optional pipeline with GitHub Actions to deploy to the Dokku server.
The project is a hybrid platform: social network and newspaper. Users upload nearby projects and can create news; verified journalists publish directly, and other users go through AI token verification and administrator approval. The mobile app is developed with React Native and the backend with hexagonal architecture (ports & adapters), REST API, PostgreSQL, Redis, S3 and AI provider integration.
Development is organised in the described phases, with efficiency, DB backups (every 12 h and on publish), tests, Git flow, CI/CD and cloud deployment. The data model includes roles (admin, editor, verified_journalist, user), nearby projects, news with flow states (pending_ai_review, pending_approval, published) and AI verification and approval fields.