A modern web application for developers to store, organize, and search useful code snippets with syntax highlighting and tagging features.
- Create & Manage Snippets: Store code snippets with titles, descriptions, and tags
- Syntax Highlighting: Beautiful code highlighting for 20+ programming languages
- Search & Filter: Full-text search with language and tag filtering
- Responsive Design: Clean, modern UI built with Tailwind CSS
- CRUD Operations: Create, read, update, and delete snippets
- REST API: Well-documented API for snippet management
- React 18 - Modern React with hooks
- Vite - Fast build tool and dev server
- Tailwind CSS - Utility-first CSS framework
- React Router - Client-side routing
- Prism.js - Syntax highlighting
- Axios - HTTP client
- React Hot Toast - Toast notifications
- Lucide React - Beautiful icons
- Node.js - JavaScript runtime
- Express - Web framework
- MongoDB - NoSQL database
- Mongoose - MongoDB ODM
- Joi - Data validation
- Helmet - Security middleware
- CORS - Cross-origin resource sharing
Before running this project, make sure you have:
- Node.js (v16 or higher)
- MongoDB (local installation or MongoDB Atlas)
- npm or yarn package manager
git clone <repository-url>
cd code-snippet-vault
# Navigate to backend directory
cd backend
# Install dependencies
npm install
# Copy environment file
cp .env.example .env
# Edit .env file with your MongoDB connection string
# MONGODB_URI=mongodb://localhost:27017/code-snippet-vault
# Start the development server
npm run dev
The backend will be available at http://localhost:5000
# Navigate to frontend directory (in a new terminal)
cd frontend
# Install dependencies
npm install
# Start the development server
npm run dev
The frontend will be available at http://localhost:3000
If using local MongoDB:
# Start MongoDB service
mongod
# The application will automatically create the database and collections
If using MongoDB Atlas:
- Create a cluster on MongoDB Atlas
- Get your connection string
- Update the
MONGODB_URI
in your.env
file
code-snippet-vault/
โโโ backend/ # Express.js API server
โ โโโ src/
โ โ โโโ models/ # Mongoose models
โ โ โโโ routes/ # API routes
โ โ โโโ middleware/ # Custom middleware
โ โ โโโ server.js # Entry point
โ โโโ package.json
โ โโโ .env.example
โโโ frontend/ # React application
โ โโโ src/
โ โ โโโ components/ # Reusable components
โ โ โโโ pages/ # Page components
โ โ โโโ services/ # API services
โ โ โโโ App.jsx # Main app component
โ โโโ package.json
โ โโโ vite.config.js
โโโ README.md
npm run dev # Start development server with nodemon
npm start # Start production server
npm test # Run tests
npm run dev # Start development server
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLint
Method | Endpoint | Description |
---|---|---|
GET | /api/snippets |
Get all snippets (with filtering) |
GET | /api/snippets/:id |
Get snippet by ID |
POST | /api/snippets |
Create new snippet |
PUT | /api/snippets/:id |
Update snippet |
DELETE | /api/snippets/:id |
Delete snippet |
GET | /api/snippets/stats/summary |
Get statistics |
search
- Search in title and descriptionlanguage
- Filter by programming languagetags
- Filter by tags (comma-separated)page
- Page number (default: 1)limit
- Items per page (default: 20, max: 50)sortBy
- Sort field (createdAt, updatedAt, title, language)sortOrder
- Sort order (asc, desc)
# Get all JavaScript snippets
GET /api/snippets?language=javascript
# Search for "async" snippets
GET /api/snippets?search=async
# Get snippets with "utility" tag
GET /api/snippets?tags=utility
# Combined filtering
GET /api/snippets?language=python&tags=utility,helper&sortBy=title&sortOrder=asc
- Supports 20+ programming languages
- Uses Prism.js with a modern dark theme
- Automatic language detection
- Line numbers for detailed view
- Full-text search across titles and descriptions
- Filter by programming language
- Filter by tags (multiple tags supported)
- Sort by date, title, or language
- Pagination for large collections
- Mobile-first approach
- Clean, modern interface
- Tailwind CSS for consistent styling
- Accessible design patterns
- Input validation with Joi
- Rate limiting
- HELMET security headers
- CORS configuration
- XSS protection
- Data sanitization
- Set up a MongoDB database (Atlas recommended)
- Deploy to your preferred platform (Heroku, Railway, DigitalOcean)
- Set environment variables:
NODE_ENV=production MONGODB_URI=your-mongodb-connection-string PORT=5000
- Build the production version:
npm run build
- Deploy the
dist
folder to your preferred platform (Netlify, Vercel, etc.) - Set environment variables:
VITE_API_URL=your-backend-api-url
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This application is optimized for Vercel deployment with serverless functions.
Quick Deploy:
- Sign up at vercel.com
- Import your GitHub repository
- Set environment variables:
MONGODB_URI
- Your MongoDB Atlas connection stringNODE_ENV
-production
FRONTEND_URL
- Your Vercel app URL
- Deploy!
๐ Detailed instructions: See DEPLOYMENT.md
- Netlify: Use the same Vercel configuration
- Railway: Deploy with Docker using the included docker-compose.yml
- Heroku: Deploy frontend and backend separately
- User authentication and authorization
- Public/private snippet sharing
- GitHub Gist integration
- Dark/light mode toggle
- Export to various formats (Markdown, JSON)
- Code snippet collections/folders
- Collaborative features
- Advanced search with regex support
- Code snippet versioning
- Browser extension
- None at the moment! Please report any issues you find.
If you have any questions or need help, please:
- Check the existing issues
- Create a new issue with a detailed description
- Include steps to reproduce any bugs
Happy Coding! ๐