Skip to content

About

A NestJS REST API backend service with user management, social features, and background job processing.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

Backend API

A NestJS REST API backend service with user management, social features, and background job processing.

Tech Stack

  • NestJS 11 / TypeScript 5.7
  • MySQL with TypeORM
  • RabbitMQ for background jobs
  • JWT authentication with Passport.js
  • Docker for containerization

Quick Start

Prerequisites

  • Node.js 22+
  • Docker & Docker Compose

Development

# Start MySQL and RabbitMQ
docker compose up -d mysql rabbitmq

# Install dependencies
npm install

# Copy environment file
cp .env.example .env

# Run migrations
npm run migration:run

# Start development server
npm run start:dev

# Start worker (separate terminal)
npm run start:worker:dev

API available at http://localhost:3000/api/v1 Swagger docs at http://localhost:3000/docs

Using Docker (Full Stack)

docker compose up

Project Structure

src/
├── main.ts              # API entry point
├── worker.ts            # Worker entry point
├── app.module.ts        # Root module
├── common/              # Shared utilities, filters, interceptors
├── database/
│   ├── entities/        # TypeORM entities
│   └── migrations/      # Database migrations
└── modules/             # Feature modules
    ├── auth/
    ├── users/
    ├── posts/
    ├── comments/
    ├── likes/
    ├── follows/
    ├── feed/
    ├── notifications/
    └── ...

Scripts

# Development
npm run start:dev         # API with hot reload
npm run start:worker:dev  # Worker with hot reload

# Production
npm run build
npm run start:prod        # API
npm run start:worker      # Worker

# Testing
npm run test              # Unit tests
npm run test:e2e          # E2E tests
npm run test:cov          # Coverage report

# Code Quality
npm run lint              # ESLint
npm run format            # Prettier

# Database
npm run migration:generate src/database/migrations/MigrationName
npm run migration:run
npm run migration:revert

Environment Variables

See .env.example for all available options. Required:

DATABASE_URL=mysql://user:pass@localhost:3306/db
RABBITMQ_URL=amqp://guest:guest@localhost:5672
JWT_SECRET=your-secret-key
CORS_ORIGIN=http://localhost:3000
NODE_ENV=development

API Features

  • URI-based versioning (/api/v1/...)
  • Rate limiting (100 req/min per IP)
  • Standard response format: { success, data, timestamp }
  • Pagination via ?page=1&limit=10
  • JWT Bearer authentication

Push Notifications (FCM)

Firebase Cloud Messaging is used for sending push notifications to mobile devices.

Setup

  1. Go to Firebase Console
  2. Create a project or select existing one
  3. Go to Project Settings > Service Accounts
  4. Click "Generate new private key"
  5. Add credentials to .env:
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_CLIENT_EMAIL=[email protected]
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"

Features

  • Auto-initializes on startup (gracefully skips if not configured)
  • Sends to all registered devices for a user
  • Automatically removes invalid/expired tokens
  • Supports custom data payloads

Usage

// Inject FCMService
constructor(private readonly fcmService: FCMService) {}

// Send notification to user
await fcmService.sendToUser(userId, {
  title: 'New Comment',
  body: 'Someone commented on your post',
  data: { postId: '123', type: 'comment' }
})

// Send to specific device token
await fcmService.sendToToken(deviceToken, {
  title: 'Hello',
  body: 'Test notification'
})

Device Token Registration

Users register their device tokens via the Devices module (/api/v1/devices). Tokens are stored per-user and automatically cleaned up when they become invalid.

Deployment

Production Docker

# Build production images
docker build -f Dockerfile.prod -t app:latest .
docker build -f Dockerfile.worker -t worker:latest .

# Run with production compose
docker compose -f docker-compose.prod.yml up -d

CI/CD

  • GitHub Actions: .github/workflows/
  • GitLab CI: .gitlab-ci.yml

Pipelines include:

  • Lint and test on PRs
  • Build Docker images
  • Deploy to staging (main branch)
  • Deploy to production (version tags)

License

MIT

About

A NestJS REST API backend service with user management, social features, and background job processing.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages