RESTful API where authors publish news, readers consume it, and analytics are aggregated daily from read logs.
- Runtime: Node.js + TypeScript
- HTTP framework: Express
- Database: PostgreSQL + Prisma
- Auth: JWT + Argon2
- Validation: Zod
- Queue & background processing: BullMQ + Redis (with in-process fallback when Redis is unavailable)
backend/src/module/auth: signup + loginbackend/src/module/articles: article lifecycle + read trackingbackend/src/module/analytics: author dashboardbackend/src/queue: queue producer, scheduler, workers
.
├── backend
│ ├── app.ts
│ ├── index.ts
│ ├── prisma
│ │ ├── migrations
│ │ └── schema.prisma
│ ├── src
│ │ ├── config
│ │ │ └── env.ts
│ │ ├── lib
│ │ │ ├── errors.ts
│ │ │ └── prisma.ts
│ │ ├── middleware
│ │ │ ├── auth.middleware.ts
│ │ │ ├── error.middleware.ts
│ │ │ └── rbac.middleware.ts
│ │ ├── module
│ │ │ ├── auth
│ │ │ ├── articles
│ │ │ └── analytics
│ │ ├── queue
│ │ │ ├── index.ts
│ │ │ ├── scheduler.ts
│ │ │ └── worker.ts
│ │ └── types
│ │ └── index.ts
│ └── tests
│ ├── auth
│ ├── articles
│ └── analytics
├── post-analytics.postman_collection.json
├── package.json
└── README.md
- Install dependencies from repository root:
npm install- Configure environment:
cp .env.example .env- Run migrations:
npx prisma migrate dev- Start development server:
npm run devThe server starts HTTP app + queue workers + scheduler on boot.
| Variable | Description |
|---|---|
DATABASE_URL |
PostgreSQL connection string |
JWT_SECRET |
JWT signing secret |
JWT_EXPIRES_IN |
Token expiry window (e.g. 24h) |
PORT |
App port (default 3000) |
REDIS_URL |
Redis connection string for BullMQ |
POST /auth/registerPOST /auth/loginGET /articlesGET /articles/:idPOST /articles(author only)GET /articles/me(author only)PUT /articles/:id(author only)DELETE /articles/:id(author only, soft delete)GET /author/dashboard(author only)
npm run dev- run API in dev modenpm run build- type-check + compilenpm test- run all unit testsnpm run test:auth- auth module testsnpm run test:article- article module testsnpm run test:analytics- analytics module tests
A ready-to-import Postman collection is available at the root:
post-analytics.postman_collection.json
Import steps:
- Open Postman.
- Click
Import. - Select
post-analytics.postman_collection.json. - Confirm collection import.
Collection variables:
baseUrl(default:http://localhost:3000)jwtToken(auto-set fromPOST /auth/login (author)test script)articleId(auto-set fromPOST /articlestest script)
Recommended run order:
GET /healthPOST /auth/register (author)(run once)POST /auth/login (author)(storesjwtToken)POST /articles(storesarticleId)GET /articles/meGET /articles/:idGET /author/dashboardPUT /articles/:idDELETE /articles/:id