Contributing
PRs welcome! Here's how to get started.
Development Setup
bash
# Clone
git clone https://github.com/Vesper36/snip.git
cd snip
# Build and run
make build
make run
# Run tests
make test
# Run linter
make lint
Project Structure
tree
snip/
cmd/server/ Entry point, route registration
internal/
config/ Environment-based configuration
models/ Data structures
store/ SQLite layer (WAL, pure-Go driver)
auth/ JWT, bcrypt, API tokens
i18n/ Embedded translations (EN/ZH/JA/FR/DE)
middleware/ Rate limit, auth, i18n, security
handlers/ HTTP handlers + embedded templates/static
templates/ Go html/template (per-page instances)
static/ CSS, JS, favicon, manifest
scripts/ CLI tool + install script
.github/ CI/CD workflows, issue/PR templates
Workflow
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Make your changes
- Run tests:
make test - Run linter:
make lint - Commit with a descriptive message
- Push and create a Pull Request
Commit Convention
format
type(scope): description
# Examples:
feat(api): add paste pagination
fix(auth): prevent token timing attack
docs(readme): update deployment guide
test(store): add CRUD operation tests
Types: feat, fix, docs, test, refactor, perf, chore
Code Style
- Follow Go conventions and idioms
- Use
go vetfor static analysis - Keep functions focused and small
- Write tests for new features
- Add i18n keys for all user-facing strings
- Use CSS variables for theming
Adding a New Language
- Create
internal/i18n/XX.jsonwith translations - Update the
//go:embeddirective ini18n.go - Add the language code to the
supportedslice - Add the language label to the
Labelsmap - Add
lang_XXkeys to all existing translation files - Run tests:
go test ./internal/i18n/...
Testing
bash
# Run all tests
make test
# Run with coverage
make cover
# Run benchmarks
make bench
# Run specific package tests
go test ./internal/store/... -v
Architecture
Snip follows a layered architecture:
- Handlers - HTTP request handling, template rendering, response formatting
- Services - Business logic, validation, password checking
- Store - Database operations, SQL queries, migrations
- Models - Data structures shared between layers
- Middleware - Cross-cutting concerns (auth, rate limiting, logging)
diagram
HTTP Request
-> Middleware (auth, rate limit, CORS)
-> Handler (parse request, format response)
-> Service (business logic, validation)
-> Store (database queries)
-> SQLite
Pull Request Guidelines
- Keep PRs focused -- one feature or fix per PR
- Include tests for new functionality
- Update documentation if needed
- Ensure CI passes
- Write a clear PR description
Tip: Check the GitHub Issues for good first issues and feature requests.