Skip to content

kraitsura/md-pastebin

Repository files navigation

AI Context Pastebin

A modern, efficient pastebin service specifically designed for sharing AI prompts and context windows. Built with Rust, Next.js, and Redis.

License Rust Next.js

Features

  • 🚀 High-performance Rust backend
  • ⚡ Real-time Next.js frontend
  • 🔄 FIFO/LIFO storage with Redis
  • 🌙 Dark/Light mode support
  • 📱 Responsive design
  • 🔗 Shareable links
  • ⌛ Auto-expiring pastes (2 days)
  • 📋 Copy to clipboard
  • 💾 Download/Upload support

Prerequisites

  • Rust 1.72 or higher
  • Node.js 18 or higher
  • Redis 6.0 or higher
  • Docker (optional)

Project Structure

markdown-pastebin/
├── backend/
│   ├── src/
│   │   ├── main.rs          # Server setup and configuration
│   │   ├── handlers.rs      # Request handlers
│   │   ├── models.rs        # Data structures
│   │   └── storage.rs       # Redis interaction
│   ├── Cargo.toml           # Rust dependencies
│   └── Dockerfile          
├── frontend/
│   ├── src/
│   │   ├── components/
│   │   │   └── MarkdownPastebin.tsx
│   │   │   └── PastebinClientWrapper.tsx
│   │   └── app/
│   │       └── page.tsx
│   │       └── globals.css
│   │       └── p/[id]/page.tsx     # Dynamic Pages for created pastebin links
│   ├── package.json
│   └── Dockerfile
├── nginx/
│   └── conf.d/
│       └── default.conf
├── docker-compose.yml
└── README.md

Quick Start

Development Environment

  1. Clone the repository:
git clone https://github.com/yourusername/markdown-pastebin.git
cd markdown-pastebin
  1. Start Redis:
docker run -d -p 6379:6379 redis:alpine
  1. Set up the backend:
cd backend
cp .env.example .env
cargo run
  1. Set up the frontend:
cd frontend
cp .env.example .env.local
npm install
npm run dev
  1. Visit http://localhost:3000 in your browser

Production Deployment

Using Docker Compose:

docker-compose up --build -d

Environment Variables

Backend (.env)

REDIS_URL=redis://127.0.0.1:6379
HOST=127.0.0.1
PORT=8080
RUST_LOG=info

Frontend (.env.local)

NEXT_PUBLIC_API_URL=http://localhost:8080

API Endpoints

Create Paste

POST /api/pastes
Content-Type: application/json

{
  "content": "Your markdown content here"
}

Response:

{
  "id": "unique-paste-id",
  "url": "/p/unique-paste-id"
}

Get Paste

GET /api/pastes/{id}

Response:

{
  "id": "unique-paste-id",
  "content": "Your markdown content",
  "created_at": "2024-11-25T20:22:16Z",
  "last_accessed": "2024-11-25T20:22:16Z"
}

Development

Backend Development

  1. Run tests:
cd backend
cargo test
  1. Run with logging:
RUST_LOG=debug cargo run
  1. Build for release:
cargo build --release

Frontend Development

  1. Run development server:
npm run dev
  1. Build for production:
npm run build
  1. Start production server:
npm start

Docker Support

Build and run individual services:

# Backend
docker build -t pastebin-backend ./backend
docker run -p 8080:8080 pastebin-backend

# Frontend
docker build -t pastebin-frontend ./frontend
docker run -p 3000:3000 pastebin-frontend

# Redis
docker run -p 6379:6379 redis:alpine

Production Deployment

Using Docker Compose

  1. Configure environment:
cp .env.example .env
  1. Deploy:
docker-compose up -d
  1. Scale services (optional):
docker-compose up -d --scale backend=3

Manual VPS Deployment

  1. Install dependencies:
apt update
apt install -y docker.io docker-compose nginx
  1. Configure Nginx:
cp nginx/conf.d/default.conf /etc/nginx/conf.d/
  1. SSL Setup (optional):
apt install -y certbot python3-certbot-nginx
certbot --nginx -d yourdomain.com
  1. Start services:
docker-compose up -d

Monitoring

Docker Logs

# All services
docker-compose logs -f

# Specific service
docker-compose logs -f backend

Redis Monitoring

docker exec -it redis redis-cli
INFO
MONITOR

Backup

Redis Data

# Create backup
docker run --rm -v markdown-pastebin_redis-data:/data \
  -v $(pwd)/backup:/backup alpine tar czf /backup/redis-backup.tar.gz /data

# Restore backup
docker run --rm -v markdown-pastebin_redis-data:/data \
  -v $(pwd)/backup:/backup alpine tar xzf /backup/redis-backup.tar.gz

Security Considerations

  1. Rate Limiting
  2. Input Validation
  3. CORS Configuration
  4. Redis Security
  5. SSL/TLS Configuration

Troubleshooting

Common Issues

  1. Redis Connection:
docker-compose ps
docker-compose logs redis
  1. Frontend Build:
rm -rf .next
npm install
npm run build
  1. Backend Build:
cargo clean
cargo build

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

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

Acknowledgments

Support

For support, please open an issue in the GitHub repository.

About

Markdown Pastebin to improve your AI workflow

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published