Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

305 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

KoalaSnippets Logo

KoalaSnippets

The cure for Notepad++ tab hell β€” a self-hosted snippet manager for all those unnamed code files.

Version Docker Image Build Status Next.js TypeScript SQLite License

KoalaSnippets is a self-hosted web application for storing, organizing, and sharing code snippets. Make them taggable, searchable, filterable β€” and finally get rid of those thousands of unnamed files in Notepad++. Features a two-pane interface, server-side syntax highlighting, and a self-contained build with no external CDN calls. Your code, your server, your rules.

Table of Contents

✨ Core Features

πŸ›‘οΈ Privacy & Security

Feature Description
Argon2id Password Hashing Passwords secured with Argon2id, per-user salt, and an application-level pepper via AUTH_PEPPER.
Timing-Attack-Resistant Comparisons Share tokens and API keys compared using crypto.timingSafeEqual with SHA-256 normalization.
Content Security Policy Strict CSP headers configured in Next.js and optionally enforced via Caddy reverse proxy.
Visibility Controls Public Explorer for anyone, secure shared links with unguessable tokens, or keep snippets strictly private.

🎨 User Interface

Feature Description
Command Palette Ctrl+K / ⌘K opens a search and command palette with shortcuts like /new, /settings, /admin, and /theme.
Keyboard Shortcuts 14+ shortcuts including vim-style navigation (j/k), Cmd+S to save, Cmd+Shift+N for new snippets, and ? for help.
Themes & Backgrounds 7 app themes (Dark, Midnight, Nordic, Dracula, Terracotta, Hacker, Light) and 12 CSS background patterns.
Statistics Page Public metrics tracking total snippets, lines of code, unique tags, languages, and more.
2-Pane Layout Responsive card grid with dark mode by default, JetBrains Mono for code, and a collapsible sidebar.
Internationalization Full English and German localization with a language toggle. Extensible via locale files.

⚑ Developer Workflow

Feature Description
Multi-File Snippets & Collections Group related code files within a single snippet. Organize with tags, collections, and favorites.
Custom Code Editor A lightweight editor with Tab indentation, bracket auto-closing, overtype skipping, and pair-matching deletions.
Server-Side Syntax Highlighting Shiki-based highlighting for 30+ languages, with languages and themes lazy-loaded on demand.
Search & Filters Server-side search with an "include code in search" toggle, filterable by tags and languages, with OR/AND logic.

πŸ“¦ Reliability

Feature Description
WAL-Mode SQLite Write-Ahead Logging with tuned busy timeouts for concurrent read/write access.
Automated Backups Built-in VACUUM INTO backup scheduler with Grandfather-Father-Son retention (7 daily, 4 weekly, 12 monthly).
Admin Panel Role-based admin dashboard for managing users, triggering backups, and monitoring system health.

🧱 Tech Stack

Layer Technology
Framework Next.js 16 (App Router, React Server Components)
Language TypeScript (strict mode)
Styling Tailwind CSS v4 + shadcn/ui-inspired components
Database SQLite via better-sqlite3
ORM Drizzle ORM
Syntax Highlighting Shiki (server-side with lazy-loaded language modules)
Authentication Session cookies + Argon2id + Pepper + RBAC
Fonts next/font/google (Inter, JetBrains Mono)
Icons lucide-react (bundled)
i18n Custom React Context + typed locale files (EN, DE)

πŸš€ Quick Start

Prerequisites

  • Node.js 20+ (Node.js 22 used in Docker)
  • npm (or pnpm/yarn)

1. Clone & Install

git clone https://github.com/Shik3i/KoalaSnippets.git
cd KoalaSnippets
npm install

2. Set Up Environment

cp .env.example .env

Edit .env with your values:

# Required: Application-level pepper for password hashing
AUTH_PEPPER=your-long-random-string-here

# Required: Session encryption secret
SESSION_SECRET=another-long-random-string

# Optional: Admin user seeded on first boot
# CRITICAL: These default credentials ('admin' / 'admin') are for local testing only
# and MUST be changed to secure values before deploying to production!
ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin

# Optional: Enable/disable user registration (default: false)
ALLOW_REGISTRATION=true

# Optional: SQLite database path
DATABASE_URL=file:./data/koalasnippets.db

# Optional: Backup directory (default: ./backups)
BACKUP_DIR=./backups

# Optional: Shared secret for programmatic API access (bypasses CSRF checks)
# API_KEY=your-api-key-here

Warning

The default seeded administrator credentials (ADMIN_USERNAME=admin / ADMIN_PASSWORD=admin) are strictly for local development and verification. You MUST change them to secure random values before pushing to staging or running in production!

Generate secure random strings:

node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

3. Initialize Database

mkdir -p data
npm run db:generate
npm run db:migrate

4. Start Development Server

npm run dev

Open http://localhost:3000. The server uses Turbopack for fast hot-reloading. The SQLite database initializes automatically on first access.

Available Scripts

Command Description
npm run dev Start development server with Turbopack
npm run build Build for production
npm run start Start production server
npm run lint Run ESLint
npm run db:generate Generate Drizzle migrations
npm run db:migrate Apply database migrations
npm run db:studio Open Drizzle Studio (web-based DB browser)

🐳 Docker Deployment

Docker Compose (Recommended)

# Set environment variables
export AUTH_PEPPER="your-pepper"
export SESSION_SECRET="your-secret"
export ALLOW_REGISTRATION="true"
export ADMIN_USERNAME="admin"
export ADMIN_PASSWORD="your-secure-password"

# Build and run
docker compose up --build -d

Open http://localhost:3000. The SQLite database and backups persist across container restarts via Docker volumes.

Manual Docker

docker build -t koalasnippets .
docker run -d -p 3000:3000 \
  -v koalasnippets-data:/app/data \
  -v koalasnippets-backups:/app/backups \
  -e AUTH_PEPPER=your-pepper \
  -e SESSION_SECRET=your-secret \
  -e ALLOW_REGISTRATION=true \
  -e ADMIN_USERNAME=admin \
  -e ADMIN_PASSWORD=your-secure-password \
  koalasnippets

Reverse Proxy (Caddy)

See Caddyfile.example for a production-ready Caddy configuration with security headers (CSP, HSTS, X-Content-Type-Options).

πŸ“ Project Structure

KoalaSnippets/
β”œβ”€β”€ docs/                   # Architecture, security, and AI documentation
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                # Next.js App Router (pages, API routes)
β”‚   β”‚   β”œβ”€β”€ api/            # API routes
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/       # Login, logout, register
β”‚   β”‚   β”‚   β”œβ”€β”€ snippets/   # CRUD operations
β”‚   β”‚   β”‚   β”œβ”€β”€ settings/   # Password change & appearance update
β”‚   β”‚   β”‚   β”œβ”€β”€ admin/      # Admin-only: users, backups, stats
β”‚   β”‚   β”‚   β”œβ”€β”€ health/     # Health check endpoint
β”‚   β”‚   β”‚   └── public/     # Public API (stats)
β”‚   β”‚   β”œβ”€β”€ admin/          # Admin dashboard (RBAC protected)
β”‚   β”‚   β”œβ”€β”€ dashboard/      # User snippet management
β”‚   β”‚   β”œβ”€β”€ snippets/[id]/  # Snippet detail view
β”‚   β”‚   β”œβ”€β”€ settings/       # User settings & Appearance settings
β”‚   β”‚   β”œβ”€β”€ stats/          # Public statistics page
β”‚   β”‚   β”œβ”€β”€ impressum/      # German imprint
β”‚   β”‚   └── privacy/        # Privacy policy
β”‚   β”œβ”€β”€ features/           # Domain-driven feature folders
β”‚   β”‚   β”œβ”€β”€ admin/          # Backup UI lists, metrics, scheduling logic & admin guards
β”‚   β”‚   β”œβ”€β”€ auth/           # Login/register forms, session handlers & crypt auth utils
β”‚   β”‚   β”œβ”€β”€ snippets/       # Snippet cards, search header, custom CodeEditor, sort/view toggles & lazy Shiki highlighting
β”‚   β”‚   β”‚   └── utils/      #   Keyboard shortcuts, filter logic (OR/AND), shared constants
β”‚   β”‚   └── core/           # Common layouts, confirm modals, rate limiters, CommandPalette & i18n
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   └── ui/             # shadcn/ui-inspired base primitives (buttons, inputs, cards, toasts, confirm-modal)
β”‚   β”œβ”€β”€ db/                 # Drizzle schema, migrations, connection (WAL enabled)
β”‚   β”œβ”€β”€ proxy.ts            # Next.js Middleware
β”‚   β”œβ”€β”€ instrumentation.ts  # Server lifecycle hooks (backup, seeding)
β”œβ”€β”€ Dockerfile              # Multi-stage production build
β”œβ”€β”€ docker-compose.yml      # Docker orchestration
└── Caddyfile.example       # Reverse proxy with security headers

🌐 Translations & Localization (i18n)

KoalaSnippets is fully localized in both English and German.

Want to contribute a translation? See the i18n Translation & Contribution Guide for details on adding a new language.

πŸ” Security

  • Passwords hashed with Argon2id + Salt + Pepper
  • Session tokens stored as HMAC-SHA-256 hashes, never plaintext
  • Strict CSP and security headers via Next.js config + Caddy
  • No external CDN calls β€” all assets bundled locally
  • SQL injection prevented via Drizzle parameterized queries
  • Timing-attack-resistant token comparison (crypto.timingSafeEqual)
  • Rate limiting on login (5/15min) and registration (3/60min)
  • Role-based access control (RBAC) β€” admin routes return 403 for non-admins

See docs/SECURITY.md for the full security specification.

πŸ—ΊοΈ Roadmap

Check the Roadmap to see planned features like CLI integration and API keys.

πŸ“„ License

MIT

About

Web based code snippet host.Self-hosted, secure, and lightning-fast web-based code snippet manager built with Next.js, SQLite, and Drizzle.

Resources

Security policy

Stars

Watchers

Forks

Packages

Used by

Contributors

Languages