A modern, feature-rich platform for sharing and discovering code snippets
Features β’ Getting Started β’ Documentation β’ API Reference β’ Contributing
- Overview
- Features
- Tech Stack
- Getting Started
- Project Structure
- Core Features Explained
- Database Schema
- Deployment
- Contributing
- License
ShareMyCode is a modern, full-stack web application inspired by GitHub Gists, designed to make code sharing simple, beautiful, and accessible. Whether you're a developer looking to share a quick snippet, save code for later, or discover solutions from the community, ShareMyCode provides an intuitive platform with powerful features.
- β¨ Beautiful UI/UX - Modern, responsive design with dark/light theme support
- π Secure Authentication - Powered by Clerk for seamless user management
- π Rich Code Editor - Custom code editor with line numbers, syntax highlighting, and customizable settings
- π Public & Private Gists - Share publicly or keep your code private
- π File Attachments - Attach additional files to your gists
- π€ User Profiles - Showcase your gists with personalized profiles
- π View Tracking - See how many times your gists have been viewed
- π¨ Theme Support - Switch between light and dark modes seamlessly
- Clerk Integration - Secure authentication with social login support
- User Profiles - Personalized profile pages showing all user gists
- Session Management - Automatic session handling and protection
- Create Gists - Rich code editor with syntax highlighting
- Edit Gists - In-place editing with real-time updates
- Delete Gists - Secure deletion with confirmation dialogs
- Public/Private Visibility - Control who can see your code
- View Counter - Track how many times your gists are viewed
- Line Numbers - Easy navigation with numbered lines
- Tab Support - Configurable tab size (2, 4, or 8 spaces)
- Word Wrap - Toggle word wrapping for long lines
- Syntax Highlighting - Beautiful code rendering
- Copy to Clipboard - One-click code copying
- Download Code - Download gists as files
- Raw View - View raw code without formatting
- Single File Upload - Attach one file per gist (max 2KB)
- Cloudinary Storage - Secure cloud storage for attachments
- File Management - Upload, view, and delete attachments
- Download Support - Download attached files directly
- Responsive Design - Works perfectly on all devices
- Dark/Light Theme - System-aware theme switching
- Loading States - Skeleton loaders for better UX
- Error Handling - Comprehensive error messages
- Toast Notifications - User-friendly feedback system
- Public Gists Feed - Browse public code snippets
- Demo Gists - Example gists for non-authenticated users
- User Profiles - Explore gists by specific users
- Search & Filter - Find gists by language, user, or description
- Next.js 15.2.4 - React framework with App Router
- TypeScript 5.0 - Type-safe development
- Tailwind CSS 3.4 - Utility-first CSS framework
- Radix UI - Accessible component primitives
- React Hook Form - Form state management
- Zod - Schema validation
- Lucide React - Beautiful icon library
- next-themes - Theme management
- Next.js API Routes - Serverless API endpoints
- MongoDB - NoSQL database for gist storage
- Clerk - Authentication and user management
- Cloudinary - Cloud storage for file uploads
- ESLint - Code linting
- TypeScript - Static type checking
- PostCSS - CSS processing
Before you begin, ensure you have the following installed:
- Node.js 18+ (recommended: latest LTS version)
- npm, yarn, or pnpm package manager
- MongoDB database (local or cloud instance like MongoDB Atlas)
- Clerk account (for authentication)
- Cloudinary account (for file storage)
-
Clone the repository
git clone https://github.com/yourusername/ShareMyCode.git cd ShareMyCode -
Install dependencies
npm install # or yarn install # or pnpm install
-
Set up environment variables (see below)
-
Run the development server
npm run dev # or yarn dev # or pnpm dev
-
Open your browser Navigate to http://localhost:3000
Create a .env.local file in the root directory with the following variables:
# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...
# MongoDB Database
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/?retryWrites=true&w=majority
# Cloudinary Storage
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
# Optional: Next.js Configuration
NEXT_PUBLIC_APP_URL=http://localhost:3000- Go to clerk.com and create an account
- Create a new application
- Copy your publishable key and secret key
- Add them to your
.env.localfile
- Go to mongodb.com and create a free cluster
- Create a database user
- Get your connection string
- Replace
<password>with your actual password - Add the connection string to your
.env.localfile
- Go to cloudinary.com and create a free account
- Navigate to your dashboard
- Copy your cloud name, API key, and API secret
- Add them to your
.env.localfile
npm run devStarts the development server with hot-reload at http://localhost:3000
npm run build
npm startCreates an optimized production build and starts the server
npm run lintRuns ESLint to check for code quality issues
ShareMyCode/
βββ app/ # Next.js App Router directory
β βββ api/ # API routes
β β βββ gists/ # Gist-related endpoints
β β βββ [id]/ # Individual gist operations
β β β βββ [filename]/ # Raw file endpoint
β β β βββ raw/ # Raw code endpoint
β β β βββ route.ts # GET, PATCH, DELETE
β β βββ demo/ # Demo gists endpoint
β β βββ public/ # Public gists endpoint
β β βββ user/ # User-specific gists
β β β βββ [userId]/ # Get gists by user ID
β β βββ route.ts # POST (create gist)
β βββ create/ # Create gist page
β β βββ page.tsx
β βββ gist/ # Gist detail page
β β βββ [id]/
β β βββ page.tsx
β β βββ not-found.tsx
β βββ profile/ # User profile page
β β βββ [userId]/
β β βββ page.tsx
β βββ sign-in/ # Sign in page
β β βββ [[...sign-in]]/
β β βββ page.tsx
β βββ sign-up/ # Sign up page
β β βββ [[...sign-up]]/
β β βββ page.tsx
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Home page
βββ components/ # React components
β βββ ui/ # Reusable UI components
β β βββ button.tsx
β β βββ card.tsx
β β βββ input.tsx
β β βββ ... # More UI components
β βββ code-editor.tsx # Code editor component
β βββ gist-card.tsx # Gist card component
β βββ navbar.tsx # Navigation bar
β βββ theme-provider.tsx # Theme context provider
β βββ theme-toggle.tsx # Theme switcher
βββ hooks/ # Custom React hooks
β βββ use-mobile.tsx
β βββ use-toast.ts
βββ lib/ # Utility libraries
β βββ models/ # TypeScript models
β β βββ gist.ts # Gist data model
β βββ cloudinary.ts # Cloudinary integration
β βββ mongodb.ts # MongoDB connection
β βββ utils.ts # Utility functions
βββ middleware.ts # Next.js middleware (auth)
βββ public/ # Static assets
β βββ favicon.png
β βββ ...
βββ styles/ # Additional styles
βββ next.config.mjs # Next.js configuration
βββ tailwind.config.ts # Tailwind CSS configuration
βββ tsconfig.json # TypeScript configuration
βββ package.json # Dependencies and scripts
ShareMyCode uses Clerk for authentication, providing:
- Social Login - Sign in with Google, GitHub, etc.
- Email/Password - Traditional authentication
- Session Management - Automatic session handling
- Protected Routes - Middleware-based route protection
Protected Routes:
/create- Requires authentication/profile/[userId]- Requires authentication/api/gists(POST) - Requires authentication
Public Routes:
/- Home page (shows demo gists for non-authenticated users)/gist/[id]- View public gists/api/gists/public- Public gists API/api/gists/demo- Demo gists API
- User clicks "Create New Gist" button
- Redirected to
/createpage (requires authentication) - User fills in:
- Description - Optional description of the gist
- Filename - Filename with extension (e.g.,
example.js) - Code - The actual code content
- Visibility - Public or Private
- Attachments - Optional file upload (max 2KB, one file)
- Form submission sends data to
/api/gists(POST) - Server:
- Validates authentication
- Uploads file to Cloudinary (if provided)
- Saves gist to MongoDB
- Returns gist ID
- User redirected to
/gist/[id]to view the created gist
- User navigates to
/gist/[id] - Client fetches gist from
/api/gists/[id](GET) - Server:
- Checks if gist exists
- Validates visibility (private gists require ownership)
- Increments view counter
- Returns gist data
- Client displays:
- Gist metadata (author, date, views)
- Code with line numbers
- Attachments (if any)
- Edit/Delete buttons (if owner)
- Storage: Cloudinary cloud storage
- Limits:
- Maximum file size: 2KB
- Maximum files per gist: 1
- Supported Types: All file types
- Process:
- User selects file in create/edit form
- File validated (size check)
- Uploaded to Cloudinary
- URL stored in MongoDB
- File accessible via Cloudinary CDN
- Implementation:
next-themeslibrary - Modes: Light, Dark, System
- Persistence: Theme preference saved in localStorage
- Components: All components support both themes via Tailwind CSS classes
{
_id: ObjectId // MongoDB document ID
userId: string // Clerk user ID
user_fullName: string // User's full name
gistViews: number // View counter
gistDescription: string // Gist description
fileNameWithExtension: string // Filename with extension
gistCode: string // The actual code
sharedFile: SharedFile[] // Array of attached files
visibility: "public" | "private" // Visibility setting
createdAt: Date // Creation timestamp
updatedAt: Date // Last update timestamp
userImageUrl?: string // Optional user image URL
}{
fileName: string // Original filename
fileUrl: string // Cloudinary CDN URL
fileSize: number // File size in bytes
uploadedAt: Date // Upload timestamp
}-
Push to GitHub
git push origin main
-
Import to Vercel
- Go to vercel.com
- Click "New Project"
- Import your GitHub repository
-
Configure Environment Variables
- Add all variables from
.env.local - Vercel will automatically detect Next.js
- Add all variables from
-
Deploy
- Click "Deploy"
- Your app will be live in minutes!
ShareMyCode can be deployed to any platform that supports Next.js:
- Netlify - Similar to Vercel
- AWS Amplify - AWS hosting
- Railway - Simple deployment
- DigitalOcean App Platform - Cloud hosting
- Self-hosted - Docker, PM2, etc.
Make sure to set all environment variables in your hosting platform:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYCLERK_SECRET_KEYMONGODB_URICLOUDINARY_CLOUD_NAMECLOUDINARY_API_KEYCLOUDINARY_API_SECRET
Contributions are welcome! Here's how you can help:
-
Fork the repository
-
Create a feature branch
git checkout -b feature/amazing-feature
-
Make your changes
- Follow the existing code style
- Add comments for complex logic
- Update documentation if needed
-
Test your changes
npm run build npm run lint
-
Commit your changes
git commit -m "Add amazing feature" -
Push to your branch
git push origin feature/amazing-feature
-
Open a Pull Request
- Describe your changes
- Link any related issues
- Request review from maintainers
- Use TypeScript for all new files
- Follow the existing component structure
- Use meaningful variable and function names
- Add JSDoc comments for complex functions
- Keep components small and focused
If you find a bug or have a feature request:
- Check if the issue already exists
- Create a new issue with:
- Clear description
- Steps to reproduce (for bugs)
- Expected vs actual behavior
- Screenshots (if applicable)
This project is licensed under the MIT License - see the LICENSE file for details.
- Next.js - The React framework
- Clerk - Authentication made easy
- MongoDB - Database solution
- Cloudinary - Cloud storage
- Radix UI - Accessible components
- Tailwind CSS - Utility-first CSS
- Lucide - Beautiful icons
β Star this repo if you find it helpful!