Every developer accumulates code snippets—Ansible playbooks, Terraform configs, shell scripts, quick Python utilities. Scattered across Gists, notes apps, and random text files, they’re never where you need them. Here’s how to build your own private snippet manager.
Architecture Overview
The solution is simple:
- FastAPI backend with JSON file storage
- Static HTML frontend with vanilla JavaScript
- Prism.js for syntax highlighting
- Hugo for deployment (optional, or serve directly)
The Data Model
| |
Files belong to projects. Each file stores:
filename- e.g., “deploy-webserver.yml”content- the actual codelanguage- for syntax highlighting- Timestamps for sorting
Auto-Detecting Language
Rather than forcing users to select a language, detect it from the file extension:
| |
Frontend Syntax Highlighting
Prism.js makes this trivial. Include the CSS theme and language components:
| |
Then wrap your code:
| |
Call Prism.highlightAll() after rendering.
Dark Theme Styling
| |
Why Not Use Gists?
GitHub Gists are great, but:
- Public by default (secret gists are still discoverable)
- No organization beyond descriptions
- No project grouping
- API rate limits if you build tooling around them
A private snippet manager gives you full control and works offline.
Authentication Considerations
For a personal tool, simple password authentication works:
| |
For production, add token expiration and consider using proper secrets management.
Deployment
Run FastAPI behind a reverse proxy with HTTPS. Store the JSON data file in a persistent location (or upgrade to SQLite if you need querying).
The frontend can be served statically or through the same API. For ultimate simplicity, use a localtunnel or Cloudflare Tunnel for secure remote access.
Conclusion
A private code snippet manager is one of those tools that seems trivial until you have one. Suddenly your playbooks, configs, and scripts are organized, searchable, and syntax-highlighted—without touching a third-party service.
Total build time: about an hour. Value: saves countless “where did I put that script?” moments.