Skip to content

sbassong/cf-platform-backend

Repository files navigation

Child-Free Platform - Backend

NestJS Backend for the Child-Free Community Platform

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
  1. About The Project
  2. Getting Started
  3. Usage
  4. Database Seeding
  5. Running Tests
  6. Architecture Overview
  7. Contact

About The Project

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.

Key Features

  • 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.
  • Cloud Storage: AWS S3 integration for handling user avatar and banner uploads.

Built With

Getting Started

To get the backend server running locally, follow these steps.

Prerequisites

  • Node.js (v20 or higher)
  • MongoDB (Local instance or Atlas URI, but set up for Atlas)
  • Redis (Local instance, not currently implemented)

Installation

  1. Clone the repo
    git clone https://github.com/sbassong/cf-platform-backend.git
  2. Navigate into the project directory
    cd cf-platform-backend
  3. Install dependencies
    npm install

Environment Variables

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"

Usage

Development Mode

Runs the server in watch mode, automatically restarting on file changes.

npm run start:dev

Production Mode

Builds the application and runs the optimized production build.

npm run build
npm run start:prod

The API will be available at http://localhost:3001 (or your configured PORT).

Database Seeding

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

Running Tests

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

Architecture Overview

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.

Core Modules

  • 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.

License

Distributed under the MIT License. See LICENSE.txt for more information.


Contact

Samuel Bassong – sam.bassong@gmail.com - linkedin.com/in/sambassong

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors