Skip to content

SnippetCove is a code snippet sharing platform built with Next.js and Express.js, featuring GitHub OAuth authentication, real-time search, and a community-driven voting system. The platform enables developers to discover, save, and share reusable code snippets across multiple programming languages with user profiles and activity tracking.

Notifications You must be signed in to change notification settings

drockparashar/snippetCove

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ SnipCove - Developer Code Snippets Platform

Next.js React Node.js MongoDB TypeScript

A community-driven platform for developers to save, share, and discover clean, reusable code snippets

Live Demo GitHub Stars License


πŸ“– Table of Contents


✨ Features

πŸ”₯ Core Features

  • πŸ“ Snippet Management: Create, edit, and organize code snippets with syntax highlighting
  • πŸ” Advanced Search: Search snippets by title, tags, language, or content
  • ⭐ Community Engagement: Upvote/downvote system for quality content curation
  • πŸ’Ύ Personal Collections: Save and organize favorite snippets
  • πŸ‘₯ User Profiles: Comprehensive profiles with activity tracking and statistics

🌟 Advanced Features

  • πŸ“Š Analytics Dashboard: Personal dashboard with detailed statistics and insights
  • 🏷️ Smart Tagging: Organize snippets with custom tags for easy discovery
  • πŸ“± Responsive Design: Fully responsive UI that works on all devices
  • πŸŒ™ Dark/Light Theme: Built-in theme switcher with system preference detection
  • ⚑ Real-time Updates: Live updates for votes and interactions
  • πŸ”’ Secure Authentication: GitHub OAuth integration with JWT tokens

πŸ‘€ Profile Features

  • πŸ“ˆ Activity Tracking: Track snippet creation, upvotes, and community engagement
  • πŸ“Š Language Statistics: Visual breakdown of programming languages used
  • 🌟 Achievement System: Display total upvotes, followers, and contribution metrics
  • πŸ”— Social Links: Integration with GitHub, Twitter, and personal websites
  • πŸ“Έ Custom Avatars: Cloudinary-powered image uploads for profile pictures

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Next.js 15    β”‚    β”‚   Express.js    β”‚    β”‚    MongoDB      β”‚
β”‚   Frontend      │◄──►│   Backend       │◄──►│   Database      β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ React 19      β”‚    β”‚ β€’ JWT Auth      β”‚    β”‚ β€’ User Model    β”‚
β”‚ β€’ TypeScript    β”‚    β”‚ β€’ GitHub OAuth  β”‚    β”‚ β€’ Snippet Model β”‚
β”‚ β€’ Tailwind CSS  β”‚    β”‚ β€’ Rate Limiting β”‚    β”‚ β€’ Relationships β”‚
β”‚ β€’ Shadcn/ui     β”‚    β”‚ β€’ Validation    β”‚    β”‚ β€’ Indexing      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                       β”‚                       β”‚
        β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Cloudinary    β”‚    β”‚   Vercel        β”‚    β”‚   Render        β”‚
β”‚   Image Storage β”‚    β”‚   Frontend      β”‚    β”‚   Backend       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

snippetCove/
β”œβ”€β”€ client/                    # Next.js Frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/              # App Router (Next.js 13+)
β”‚   β”‚   β”‚   β”œβ”€β”€ (auth)/       # Auth route group
β”‚   β”‚   β”‚   β”œβ”€β”€ dashboard/    # User dashboard
β”‚   β”‚   β”‚   β”œβ”€β”€ snippets/     # Snippet pages
β”‚   β”‚   β”‚   β”œβ”€β”€ submit/       # Snippet submission
β”‚   β”‚   β”‚   └── users/        # User profiles
β”‚   β”‚   β”œβ”€β”€ components/       # Reusable components
β”‚   β”‚   β”‚   β”œβ”€β”€ ui/          # Shadcn/ui components
β”‚   β”‚   β”‚   β”œβ”€β”€ profile/     # Profile components
β”‚   β”‚   β”‚   └── public-profile/ # Public profile views
β”‚   β”‚   β”œβ”€β”€ lib/             # Utilities and configurations
β”‚   β”‚   └── types/           # TypeScript type definitions
β”‚   └── public/              # Static assets
└── server/                   # Express.js Backend
    β”œβ”€β”€ controllers/         # Business logic
    β”œβ”€β”€ models/             # MongoDB schemas
    β”œβ”€β”€ routes/             # API endpoints
    β”œβ”€β”€ middlewares/        # Custom middleware
    └── config/             # Database configuration

πŸ› οΈ Tech Stack

Frontend

  • Framework: Next.js 15.3.2 with App Router
  • Language: TypeScript 5
  • Styling: Tailwind CSS 4 + Shadcn/ui components
  • State Management: React Context API
  • Icons: Lucide React
  • Animations: Tailwind CSS animations
  • Deployment: Vercel

Backend

  • Runtime: Node.js with Express.js 5
  • Language: JavaScript (ES6+ modules)
  • Database: MongoDB with Mongoose ODM
  • Authentication: JWT + Passport.js (GitHub OAuth)
  • File Upload: Multer + Cloudinary
  • Security: bcryptjs, express-rate-limit, sanitize-html
  • Deployment: Render

Key Libraries & Tools

Frontend Dependencies

{
  "@radix-ui/react-*": "Latest", // Accessible UI primitives
  "@vercel/analytics": "^1.5.0", // Analytics tracking
  "react-syntax-highlighter": "^15.6.1", // Code highlighting
  "react-hot-toast": "^2.5.2", // Toast notifications
  "next-themes": "^0.4.6", // Theme management
  "class-variance-authority": "^0.7.1" // Component variants
}

Backend Dependencies

{
  "mongoose": "^8.15.0", // MongoDB ODM
  "jsonwebtoken": "^9.0.2", // JWT authentication
  "passport-github2": "^0.1.12", // GitHub OAuth
  "cloudinary": "^2.7.0", // Image management
  "express-validator": "^7.2.1", // Input validation
  "express-rate-limit": "^7.5.0" // Rate limiting
}

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm/yarn
  • MongoDB database (local or cloud)
  • GitHub OAuth App credentials
  • Cloudinary account (for image uploads)

1. Clone the Repository

git clone https://github.com/drockparashar/snippetCove.git
cd snippetCove

2. Backend Setup

cd server
npm install

Create .env file in server directory:

# Database
MONGO_URI=mongodb://localhost:27017/snippetcove

# JWT
JWT_SECRET=your_super_secret_jwt_key

# GitHub OAuth
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
GITHUB_CALLBACK_URL=http://localhost:5000/api/auth/github/callback

# Cloudinary
CLOUD_NAME=your_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret

# Frontend URL
FRONTEND_URL=http://localhost:3000

# Server Port
PORT=5000

Start the backend server:

npm start

3. Frontend Setup

cd ../client
npm install

Create .env.local file in client directory:

NEXT_PUBLIC_BACKEND_URL=http://localhost:5000

Start the development server:

npm run dev

4. Access the Application


πŸ“‘ API Documentation

Authentication Endpoints

POST   /api/auth/signup              # User registration
POST   /api/auth/login               # User login
GET    /api/auth/me                  # Get current user
GET    /api/auth/github              # GitHub OAuth login
GET    /api/auth/github/callback     # GitHub OAuth callback
GET    /api/auth/check               # Check auth status
POST   /api/auth/save-snippet        # Save snippet to user
POST   /api/auth/unsave-snippet      # Remove saved snippet
PUT    /api/auth/update-profile      # Update user profile

Snippet Endpoints

GET    /api/snippets                 # Get all snippets (paginated)
POST   /api/snippets                 # Create new snippet (auth required)
GET    /api/snippets/:id             # Get snippet by ID
GET    /api/snippets/search?q=query  # Search snippets
GET    /api/snippets/user/:id/upvotes # Get user's total upvotes
POST   /api/snippets/upvote          # Upvote a snippet
POST   /api/snippets/upvote/remove   # Remove upvote

User Endpoints

GET    /api/users/id/:id             # Get user profile by ID
POST   /api/users/follow             # Follow a user
POST   /api/users/unfollow           # Unfollow a user
POST   /api/users/upload             # Upload avatar

Request/Response Examples

Create Snippet

POST /api/snippets
Authorization: Bearer <jwt_token>
Content-Type: application/json

{
  "title": "React useEffect Hook",
  "code": "useEffect(() => {\n  // Effect logic\n}, [dependencies]);",
  "language": "javascript",
  "tags": ["react", "hooks", "useEffect"]
}

Search Snippets

GET /api/snippets/search?q=react

Response:
[
  {
    "_id": "64f...",
    "title": "React useState Hook",
    "code": "const [state, setState] = useState(initialValue);",
    "language": "javascript",
    "tags": ["react", "hooks"],
    "author": {
      "_id": "64e...",
      "name": "John Doe"
    },
    "upvotes": 15,
    "createdAt": "2024-01-15T10:30:00Z"
  }
]

🎨 UI Components

Design System

Built with Shadcn/ui components and Tailwind CSS for consistent, accessible design:

  • 🎨 Theme System: Automatic dark/light mode switching
  • πŸ“± Responsive Design: Mobile-first approach with breakpoint utilities
  • β™Ώ Accessibility: ARIA labels, keyboard navigation, screen reader support
  • 🎭 Component Library: Pre-built, customizable components

Key UI Components

  • CodeBlock: Syntax-highlighted code display with copy functionality
  • SnippetCard: Reusable snippet preview cards
  • ProfileSection: User profile information and statistics
  • DashboardHeader: Navigation and user controls
  • SearchBar: Advanced search with filters
  • ThemeToggle: Dark/light theme switcher

Custom Animations

/* Custom animations in globals.css */
.animate-float {
  animation: float 6s ease-in-out infinite;
}

.glow {
  box-shadow: 0 0 20px rgba(0, 123, 255, 0.3);
}

πŸ” Authentication

GitHub OAuth Flow

  1. User clicks "Login with GitHub"
  2. Redirect to GitHub OAuth
  3. GitHub redirects to callback
  4. Server generates JWT token
  5. Frontend receives token
  6. Token stored in localStorage
  7. User authenticated for API calls

JWT Token Structure

{
  "id": "user_mongodb_id",
  "email": "[email protected]",
  "iat": 1640995200,
  "exp": 1641600000
}

Protected Routes

  • Frontend: /dashboard, /submit, /settings
  • Backend: All POST/PUT/DELETE operations

Security Features

  • Rate Limiting: 10 snippets per hour per IP
  • Input Sanitization: HTML sanitization for all user inputs
  • JWT Expiration: 7-day token expiry
  • CORS Configuration: Restricted to allowed origins

🌐 Deployment

Frontend (Vercel)

# Automatic deployment from GitHub
# Environment variables required:
NEXT_PUBLIC_BACKEND_URL=https://your-backend-url.com

Backend (Render)

# Build command: npm install
# Start command: npm start
# Environment variables: (see .env example above)

MongoDB (Atlas)

  • Database: MongoDB Atlas cloud database
  • Connection: Secure connection string with authentication
  • Indexing: Optimized indexes for search and queries

Cloudinary Setup

  1. Create Cloudinary account
  2. Get cloud name, API key, and secret
  3. Configure environment variables
  4. Images automatically optimized and delivered via CDN

🀝 Contributing

We welcome contributions! Here's how to get started:

Development Workflow

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open Pull Request

Coding Standards

  • Frontend: ESLint + TypeScript strict mode
  • Backend: ES6+ modules with consistent formatting
  • Commits: Conventional commit messages
  • Testing: Write tests for new features

Areas for Contribution

  • πŸ› Bug fixes and performance improvements
  • ✨ New features (snippet sharing, code execution, etc.)
  • πŸ“š Documentation improvements
  • 🎨 UI/UX enhancements
  • πŸ§ͺ Test coverage expansion

πŸ“Š Project Statistics

  • πŸ—οΈ Architecture: Full-stack TypeScript application
  • πŸ“¦ Components: 25+ reusable UI components
  • πŸ›‘οΈ Security: JWT authentication with OAuth integration
  • πŸ“± Responsive: Mobile-first design approach
  • ⚑ Performance: Optimized with Next.js 15 and modern React
  • 🌍 Global: CDN-delivered assets via Vercel and Cloudinary

πŸ™ Acknowledgments


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Developer

Pranshu Parashar - @drockparashar


⭐ Star this repository if you found it helpful!

Made with ❀️ by developers, for developers

GitHub Stars GitHub Forks

About

SnippetCove is a code snippet sharing platform built with Next.js and Express.js, featuring GitHub OAuth authentication, real-time search, and a community-driven voting system. The platform enables developers to discover, save, and share reusable code snippets across multiple programming languages with user profiles and activity tracking.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published