Skip to content

Jink API is a powerful RESTful backend built with NestJS, Prisma ORM, and PostgreSQL. Manage users, posts, and bookmarks with ease through robust authentication, clean modular architecture, and fully documented endpoints. Designed for scalability and maintainability, it’s the modern way to power social media-style applications with confidence!

Notifications You must be signed in to change notification settings

mrrmartin01/jink

Repository files navigation

Jink

A modern social media API built with NestJS, featuring Twitter-like functionality including posts, follows, engagement features, and comprehensive user management. Jink provides a robust backend for social networking applications with secure authentication, real-time interactions, and scalable architecture.

Description

Jink is a RESTful API that powers social media applications with core features like user authentication, post creation and management, social interactions (likes, bookmarks, reposts, quotes), and user relationships (follows). Built with enterprise-grade security using JWT tokens, Argon2 password hashing, and comprehensive input validation, it solves the need for a reliable, scalable social media backend that can handle modern social networking requirements.

Features

  • Secure Authentication: JWT-based auth with refresh tokens, email verification, and password reset
  • User Management: Complete user profiles with customizable avatars, cover images, and bio information
  • Post System: Create, edit, delete posts with image support and reply threading
  • Social Interactions: Like, bookmark, repost, and quote posts with real-time engagement tracking
  • Social Network: Follow/unfollow users with follower/following management
  • Media Upload: Cloudinary integration for profile pictures, cover images, and post attachments
  • Post Visibility: Public, followers-only, and private post visibility controls
  • Pin Posts: Ability to pin important posts to user profiles
  • API Documentation: Comprehensive Swagger/OpenAPI documentation
  • Rate Limiting: Built-in throttling for authentication endpoints
  • Testing: Unit and E2E testing with Jest and Pactum
  • Docker Support: Containerized PostgreSQL databases for development and testing

Installation

Prerequisites

  • Node.js (v18 or higher)
  • Yarn package manager
  • Docker and Docker Compose
  • PostgreSQL (via Docker)

Step-by-Step Setup

  1. Clone the repository

    git clone https://github.com/mrrmartin01/jink.git
    cd jink
  2. Install dependencies

    yarn install
  3. Set up environment variables Create a .env file in the root directory:

    # Database
    DATABASE_URL="postgresql://postgres:123@localhost:5434/jink"
    
    # JWT Configuration
    JWT_SECRET="your-super-secret-jwt-key"
    
    # Application
    PORT=9000
    NODE_ENV="development"
    FRONTEND_URL="http://localhost:3000"
    
    # Email Configuration (for verification emails)
    MAIL_HOST="smtp.gmail.com"
    MAIL_PORT=587
    MAIL_USER="[email protected]"
    MAIL_PASS="your-app-password"
    
    # Cloudinary (for image uploads)
    CLOUDINARY_CLOUD_NAME="your-cloud-name"
    CLOUDINARY_API_KEY="your-api-key"
    CLOUDINARY_API_SECRET="your-api-secret"
  4. Start the database

    yarn db:dev:up
  5. Run database migrations

    yarn prisma:dev:deploy
  6. Generate Prisma client

    npx prisma generate
  7. Start the development server

    yarn start:dev

The API will be available at http://localhost:9000/api with Swagger documentation at http://localhost:9000/api/docs.

Usage

Authentication Flow

  1. Register a new user

    curl -X POST http://localhost:9000/api/auth/signup \
      -H "Content-Type: application/json" \
      -d '{
        "email": "[email protected]",
        "userName": "johndoe",
        "password": "securepassword123",
        "firstName": "John",
        "lastName": "Doe"
      }'
  2. Verify account via email

    curl -X POST http://localhost:9000/api/auth/verify \
      -H "Content-Type: application/json" \
      -d '{
        "email": "[email protected]",
        "code": "123456"
      }'
  3. Sign in

    curl -X POST http://localhost:9000/api/auth/signin \
      -H "Content-Type: application/json" \
      -d '{
        "identifier": "[email protected]",
        "password": "securepassword123"
      }'

Creating and Managing Posts

  1. Create a post

    curl -X POST http://localhost:9000/api/posts \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer YOUR_JWT_TOKEN" \
      -d '{
        "content": "Hello, world! This is my first post on Jink.",
        "visibility": "PUBLIC"
      }'
  2. Get user's posts

    curl -X GET http://localhost:9000/api/posts \
      -H "Authorization: Bearer YOUR_JWT_TOKEN"
  3. Like a post

    curl -X POST http://localhost:9000/api/like \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer YOUR_JWT_TOKEN" \
      -d '{
        "postId": "post-uuid-here"
      }'

Social Interactions

  1. Follow a user

    curl -X POST http://localhost:9000/api/follows/user-uuid-here \
      -H "Authorization: Bearer YOUR_JWT_TOKEN"
  2. Bookmark a post

    curl -X POST http://localhost:9000/api/bookmarks/post-uuid-here \
      -H "Authorization: Bearer YOUR_JWT_TOKEN"
  3. Quote a post

    curl -X POST http://localhost:9000/api/quote \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer YOUR_JWT_TOKEN" \
      -d '{
        "postId": "post-uuid-here",
        "content": "This is my comment on the original post!"
      }'

Configuration

Environment Variables

Variable Description Required Default
DATABASE_URL PostgreSQL connection string Yes -
JWT_SECRET Secret key for JWT token signing Yes -
PORT Application port No 9000
NODE_ENV Environment (development/production) No development
FRONTEND_URL Frontend URL for CORS Yes -
MAIL_HOST SMTP server host Yes -
MAIL_PORT SMTP server port Yes -
MAIL_USER SMTP username Yes -
MAIL_PASS SMTP password Yes -
CLOUDINARY_CLOUD_NAME Cloudinary cloud name Yes -
CLOUDINARY_API_KEY Cloudinary API key Yes -
CLOUDINARY_API_SECRET Cloudinary API secret Yes -

Database Configuration

The application uses PostgreSQL with Prisma ORM. Database schemas are defined in prisma/schema.prisma and migrations are managed through Prisma CLI.

Dependencies

Core Dependencies

  • @nestjs/core (^11.0.1) - NestJS framework
  • @nestjs/common (^11.0.1) - Common NestJS utilities
  • @nestjs/platform-express (^11.1.6) - Express platform adapter
  • @nestjs/config (^4.0.2) - Configuration management
  • @nestjs/swagger (^11.2.0) - API documentation
  • @nestjs/throttler (^6.4.0) - Rate limiting
  • @nestjs/jwt (^11.0.0) - JWT authentication
  • @nestjs/passport (^11.0.5) - Passport integration

Database & ORM

  • @prisma/client (^6.9.0) - Prisma database client
  • prisma (^6.9.0) - Prisma CLI and tools

Authentication & Security

  • passport (^0.7.0) - Authentication middleware
  • passport-jwt (^4.0.1) - JWT strategy for Passport
  • argon2 (^0.43.0) - Password hashing
  • cookie-parser (^1.4.7) - Cookie parsing middleware

Validation & Transformation

  • class-validator (^0.14.2) - Validation decorators
  • class-transformer (^0.5.1) - Object transformation

Media & File Handling

  • cloudinary (^2.7.0) - Cloud-based image management
  • multer (^2.0.2) - File upload handling

Email

  • @nestjs-modules/mailer (^2.0.2) - Email service
  • nodemailer (^7.0.6) - Email sending

Getting Started

Quick start for new users:

# Clone and install
git clone https://github.com/mrrmartin01/jink && cd jink && yarn install

# Start database and run migrations
yarn db:dev:restart

# Start development server
yarn start:dev

Visit http://localhost:9000/api/docs for interactive API documentation.

Contributing

We welcome contributions! Please follow these guidelines:

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Run tests: yarn test and yarn test:e2e
  5. Commit your changes: git commit -m 'Add amazing feature'
  6. Push to the branch: git push origin feature/amazing-feature
  7. Open a Pull Request

Code Standards

  • Follow TypeScript best practices
  • Use ESLint and Prettier for code formatting
  • Write comprehensive tests for new features
  • Update documentation for API changes
  • Follow conventional commit messages

Issue Reporting

  • Use GitHub Issues for bug reports and feature requests
  • Provide detailed reproduction steps for bugs
  • Include environment information and error logs

Testing

Running Tests

Unit Tests

yarn test

Unit Tests with Coverage

yarn test:cov

E2E Tests

yarn test:e2e

Watch Mode

yarn test:watch

Test Setup

  • Unit Tests: Jest with ts-jest
  • E2E Tests: Pactum for API testing
  • Test Database: Separate PostgreSQL container (port 5435)
  • Coverage: Istanbul for code coverage reports

Test Environment

Tests use a separate database instance and environment configuration (.env.test).

License

This project is licensed under the UNLICENSED license. All rights reserved.

For usage rights and permissions, please contact the project maintainers.

Contact/Support

Maintainers

  • Project Lead: Mrr. Martin01
  • Core Contributors: Team Members

Badges

Build Status Test Coverage License Node Version NestJS

Project Status

🟢 Active Development - This project is actively maintained and under development. We regularly release updates, fix bugs, and add new features. The API is stable for production use with proper environment configuration.

Table of Contents

Troubleshooting

Common Issues

Database Connection Issues

# If database won't start
yarn db:dev:rm && yarn db:dev:up

# If migrations fail
yarn prisma:dev:deploy

Port Already in Use

# Change PORT in .env file or kill process using port 9000
lsof -ti:9000 | xargs kill -9

JWT Token Issues

  • Ensure JWT_SECRET is set in environment variables
  • Check token expiration and refresh token validity
  • Verify cookie settings for production vs development

Email Verification Not Working

  • Check SMTP credentials in environment variables
  • Verify email service allows less secure apps (Gmail)
  • Check spam folder for verification emails

Image Upload Issues

  • Verify Cloudinary credentials are correct
  • Check file size limits (max 4 images per post)
  • Ensure proper file format (jpg, png, gif)

Roadmap

Upcoming Features

  • Real-time Notifications and Messaging - WebSocket integration for live updates
  • Advanced Search - Full-text search for posts and users
  • Content Moderation - Automated content filtering and reporting
  • Analytics Dashboard - User engagement and post performance metrics
  • Mobile API - Optimized endpoints for mobile applications
  • Push Notifications - Mobile push notification support
  • Advanced Privacy Controls - Granular privacy settings
  • Content Scheduling - Post scheduling and automation

Performance Improvements

  • Caching Layer - Redis integration for improved performance
  • Database Optimization - Query optimization and indexing
  • CDN Integration - Global content delivery for media files
  • Load Balancing - Horizontal scaling support

Credits

Core Technologies

  • NestJS - Progressive Node.js framework
  • Prisma - Next-generation ORM for Node.js and TypeScript
  • PostgreSQL - Powerful, open source object-relational database
  • Cloudinary - Cloud-based image and video management
  • JWT - JSON Web Token for secure authentication

Inspiration

This project draws inspiration from modern social media platforms and aims to provide a robust, scalable foundation for social networking applications.

Contributors

Special thanks to all contributors who have helped shape this project through code contributions, bug reports, and feature suggestions.


Made by The_Dark_Themed_Fella using NestJS and TypeScript

About

Jink API is a powerful RESTful backend built with NestJS, Prisma ORM, and PostgreSQL. Manage users, posts, and bookmarks with ease through robust authentication, clean modular architecture, and fully documented endpoints. Designed for scalability and maintainability, it’s the modern way to power social media-style applications with confidence!

Resources

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published