A modular REST API and WebSocket server built with NestJS. It supports the social features, authentication, and real-time communication for the CF Platform.
View Frontend Repository
Table of Contents
This repository contains the server-side application for the CF Platform. It provides a robust API layer handling user identity, content management, social interactions, and real-time events. The architecture is built around Domain-Driven Design principles, separating concerns into distinct modules (Auth, User, Profile, Post, etc.) to ensure maintainability and scalability.
- Hybrid Authentication: supports both local strategy (email/password) and OAuth integration via JWTs and secure HTTP-only cookies.
- Real-Time Messaging: WebSocket gateway via Socket.io for instant private messaging and live notifications.
- Comprehensive Profile System: Decoupled User/Auth and Profile entities to allow for rich user expression while ensuring security.
- Event & Group Management: Dedicated modules for community building, including creating events and managing group memberships.
- Security & Performance:
- Rate limiting via
@nestjs/throttler. - Redis integration for caching and session management. (In progress)
- Secure cookie handling with
cookie-parser.
- Rate limiting via
- Cloud Storage: AWS S3 integration for handling user avatar and banner uploads.
- NestJS
- TypeScript
- MongoDB & Mongoose
- Socket.io
- Redis - for future In-memory data store
- Passport.js - auth middleware
- AWS SDK
To get the backend server running locally, follow these steps.
- Node.js (v20 or higher)
- MongoDB (Local instance or Atlas URI, but set up for Atlas)
- Redis (Local instance, not currently implemented)
- Clone the repo
git clone https://github.com/sbassong/cf-platform-backend.git
- Navigate into the project directory
cd cf-platform-backend - Install dependencies
npm install
Create a .env file in the root directory. You can use the following template:
# Application Settings
PORT=3001
FRONTEND_ORIGIN="http://localhost:3000"
# Database (Atlas URI or below local)
MONGO_URI="mongodb://localhost:27017/cf-platform"
# Redis
REDIS_HOST="localhost"
REDIS_PORT=6379
# Authentication (running `npx auth` generates secret automatically)
JWT_SECRET="your-super-secure-jwt-secret"
JWT_EXPIRATION="7d"
# Rate Limiting
RATE_LIMIT_TTL=60000
RATE_LIMIT_MAX=10
# AWS S3 (for file uploads)
AWS_REGION="us-east-1"
AWS_ACCESS_KEY_ID="your-access-key"
AWS_SECRET_ACCESS_KEY="your-secret-key"
AWS_BUCKET_NAME="your-bucket-name"Runs the server in watch mode, automatically restarting on file changes.
npm run start:devBuilds the application and runs the optimized production build.
npm run build
npm run start:prodThe API will be available at http://localhost:3001 (or your configured PORT).
This project includes utility scripts to help you populate your local database with test data or clear it entirely.
-
Seed Database: Populates the database with dummy users, posts, and comments.
npm run db:seed
-
Clear Database: WARNING - This will wipe all data from the configured MongoDB instance.
npm run db:clear
We use Jest for testing. The project includes both unit tests and end-to-end (e2E) tests.
-
Unit Tests:
npm run test -
End-to-End Tests:
npm run test:e2e
-
Test Coverage:
npm run test:cov
The backend is organized into Feature Modules. Each module typically contains:
- Controller: Handles incoming HTTP requests.
- Service: Contains the business logic.
- Schema: Defines the MongoDB data structure (Mongoose).
- DTO (Data Transfer Object): Defines the shape of data sent over the network.
src/auth/: Authentication strategies (Local, JWT) and guards.src/user/: Manages User accounts (credentials, settings).src/profile/: Manages public user data (bio, interests, avatar).src/messaging/: Handles WebSocket connections for chat.src/post/: Logic for the news feed, posts, and likes.src/search/: Dedicated endpoint for searching users and groups.
Distributed under the MIT License. See LICENSE.txt for more information.
Samuel Bassong – sam.bassong@gmail.com - linkedin.com/in/sambassong