Skip to content

Ding-Platform/Ding-Platform-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ding Platform Backend

A social networking platform backend built with NestJS, featuring a hybrid database architecture with PostgreSQL and Neo4j.

πŸ—οΈ Architecture

  • Framework: NestJS (Node.js)
  • Databases:
    • PostgreSQL (User data, posts, profiles)
    • Neo4j (Social graph, relationships)
    • Redis (Caching)
  • Authentication: JWT + OAuth2 (Google)
  • File Storage: Cloudinary
  • API Documentation: Swagger/OpenAPI

πŸ“‹ Features

Sprint 1: Authentication & Security

  • βœ… JWT-based authentication
  • βœ… Google OAuth2 integration
  • βœ… Password reset flow
  • βœ… Rate limiting
  • βœ… Session management

Sprint 2: Post Management

  • βœ… Create, read, update, delete posts
  • βœ… Image uploads via Cloudinary
  • βœ… Post reactions
  • βœ… Comments system

Sprint 3: Social Graph

  • βœ… Follow/unfollow users
  • βœ… Friend requests
  • βœ… Connection management
  • βœ… Neo4j-powered social graph

Sprint 4: Feed & Privacy

  • βœ… Personalized feed
  • βœ… Privacy settings
  • βœ… Content visibility control
  • βœ… Social graph-based filtering

πŸš€ Quick Start

Prerequisites

  • Node.js 20+
  • pnpm
  • Docker & Docker Compose (for local development)
  • PostgreSQL 15+
  • Neo4j 5+
  • Redis 7+

Local Development with Docker (Recommended)

# Clone repository
git clone <repository-url>
cd Ding-Platform-Backend

# Copy environment variables
cp .env.example .env
# Edit .env with your configuration

# Start all services
./docker-dev.sh start

# Or use docker-compose directly
docker-compose up -d

# View logs
./docker-dev.sh logs

# Access services:
# Backend: http://localhost:3000
# API Docs: http://localhost:3000/api/docs
# Prisma Studio: http://localhost:5555
# Neo4j Browser: http://localhost:7474

Manual Setup (Without Docker)

# Install dependencies
pnpm install

# Setup databases (PostgreSQL, Neo4j, Redis must be running)

# Generate Prisma Client
pnpm prisma generate

# Run migrations
pnpm prisma migrate dev

# Seed database (optional)
pnpm run prisma:seed

# Start development server
pnpm run start:dev

πŸ“š Documentation

Deployment Guides

API Documentation

Comments API Quick Reference

  • POST /comments/posts/:postId β€” create a top-level comment (auth required, supports parentCommentId to reply)
  • GET /comments/posts/:postId β€” list top-level comments with pagination and sort=top|recent
  • GET /comments/:commentId/replies β€” list replies for a specific comment
  • PATCH /comments/:commentId β€” update own comment content (auth required)
  • DELETE /comments/:commentId β€” soft-delete own comment and update graph sync (auth required)

Project Documentation

πŸ› οΈ Available Scripts

# Development
pnpm run start:dev          # Start with hot-reload
pnpm run start:debug        # Start in debug mode

# Production
pnpm run build              # Build application
pnpm run start:prod         # Start production server

# Database
pnpm prisma generate        # Generate Prisma Client
pnpm prisma migrate dev     # Run migrations (dev)
pnpm prisma migrate deploy  # Run migrations (prod)
pnpm prisma studio          # Open Prisma Studio
pnpm run prisma:seed        # Seed database

# Testing
pnpm run test               # Unit tests
pnpm run test:e2e           # E2E tests
pnpm run test:cov           # Test coverage

# Code Quality
pnpm run lint               # Lint code
pnpm run format             # Format code

# Docker
./docker-dev.sh start       # Start dev environment
./docker-dev.sh stop        # Stop dev environment
./docker-dev.sh logs        # View logs
./docker-dev.sh migrate     # Run migrations
./docker-dev.sh shell       # Access backend shell

./docker-prod.sh deploy     # Deploy production
./docker-prod.sh health     # Check health
./docker-prod.sh backup     # Backup databases

🌍 Deployment

Render (Recommended)

The easiest way to deploy is using Render with the included blueprint:

  1. Setup Neo4j Aura (free tier available)

  2. Deploy via Blueprint

    # Push to GitHub
    git push origin main
    
    # In Render dashboard:
    # - New + β†’ Blueprint
    # - Connect repository
    # - Configure environment variables
    # - Deploy
  3. Complete guide: See RENDER_DEPLOYMENT.md

Docker Production

# Build and deploy
./docker-prod.sh deploy

# Or manually
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d

Vercel (Serverless)

The application also supports Vercel deployment (see vercel.json).

πŸ”§ Environment Variables

Key environment variables (see .env.example for complete list):

# Server
NODE_ENV=development
PORT=3000

# Database
DATABASE_URL=postgresql://user:password@localhost:5432/ding_db
NEO4J_URI=bolt://localhost:7687
NEO4J_AUTH=neo4j/password
REDIS_URL=redis://localhost:6379

# Authentication
JWT_SECRET=your-secret-key
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret

# Services
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret

SMTP_HOST=smtp.gmail.com
SMTP_USER=[email protected]
SMTP_PASS=your-app-password

πŸ›οΈ Project Structure

src/
β”œβ”€β”€ common/              # Shared utilities, decorators, guards
β”œβ”€β”€ configs/             # Database, Neo4j, Redis configurations
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ auth/           # Authentication & authorization
β”‚   β”œβ”€β”€ user/           # User management
β”‚   β”œβ”€β”€ profile/        # User profiles
β”‚   β”œβ”€β”€ post/           # Post management
β”‚   β”œβ”€β”€ social/         # Social graph (follow/friend)
β”‚   β”œβ”€β”€ feed/           # Personalized feed
β”‚   └── privacy/        # Privacy settings
β”œβ”€β”€ app.module.ts       # Root module
└── main.ts             # Application entry point

prisma/
β”œβ”€β”€ schema.prisma        # Database schema
β”œβ”€β”€ migrations/          # Database migrations
└── seed.ts             # Database seeding

scripts/
β”œβ”€β”€ render-build.sh     # Render build script
└── render-start.sh     # Render start script

πŸ§ͺ Testing

# Run all tests
pnpm run test

# Run e2e tests
pnpm run test:e2e

# Test coverage
pnpm run test:cov

πŸ”’ Security

  • JWT-based authentication
  • Bcrypt password hashing
  • Rate limiting (100 req/min)
  • Helmet.js security headers
  • CORS configuration
  • Input validation with class-validator
  • SQL injection protection via Prisma
  • XSS protection

πŸ“Š Monitoring

Health Check

  • Endpoint: /health
  • Returns: Service status, uptime, environment

Logging

  • Development: Pretty-printed console logs
  • Production: JSON logs with Pino
  • Optional: Sentry integration

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the UNLICENSED License.

πŸ‘₯ Team

Built with ❀️ by the Ding Platform team

πŸ“ž Support

  • Documentation: Check files in project root
  • Issues: Open a GitHub issue
  • Email: [Your support email]

πŸ—ΊοΈ Roadmap

  • Real-time notifications (WebSocket)
  • Direct messaging
  • Advanced search
  • Analytics dashboard
  • Mobile app API optimization
  • GraphQL API
  • Microservices architecture

Ready to deploy? Check out RENDER_QUICK_START.md for a 5-minute deployment guide!

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages