How dhruv-sachdev1313/5minpastebin works
Project type and purpose
• This is a lightweight full-stack web application (“5minpastebin.com”) that provides ephemeral pastebin functionality: users paste text/code into a web UI, receive a link, and the paste self-destructs after five minutes.
• It consists of two Go binaries (an API service and a web service), a Redis data store, and a minimal frontend using Go HTML templates, HTMX for dynamic behaviors, and Tailwind CSS for styling.
File structure
• Top-level binaries in cmd/
• cmd/api/main.go – entry point for the pastebin API service
• cmd/web/… – entry point for the web UI server plus embedded assets (templates, JS, CSS)
• internal/
• internal/server/ – HTTP route definitions and server setup
• internal/database/ – Redis client, TTL logic, persistence abstraction
• internal/pkg/ – shared utility code
• Configuration and orchestration
• docker-compose.yml – defines Redis container
• Dockerfile – containerizes the Go application
• Makefile – common build, test, run scripts
README for additional insights
• Tech stack: Go backend, Redis storage, HTMX, Templ, and Tailwind CSS
• Deployment: uses Docker for local Redis; no external dependencies or third-party services
• No user accounts or configuration—stateless HTTP endpoints, ephemeral data
Components
a. Frontend (Browser)
• HTML templates (base.templ, home.templ, viewpaste.templ, notfound.templ)
• Static assets (Tailwind‐generated CSS, HTMX JavaScript)
• HTMX interactions triggering AJAX calls to the API
b. Web UI service (cmd/web)
• Serves initial HTML pages and static assets
• Renders templates using the Go “Templ” engine
• Embeds or proxies HTMX scripts
c. API service (cmd/api)
• Exposes RESTful or JSON endpoints for paste creation, retrieval
• Routes defined in internal/server/routes.go
• HTTP server logic in internal/server/server.go
d. Data store (Redis)
• Hosted in Docker container (docker-compose.yml)
• Provides TTL functionality for automatic paste expiration
• Accessed via internal/database/database.go
e. Shared code (internal/pkg)
• Reusable utilities, constants, helpers
f. Developer tools & environments
• Makefile targets (build, test, run, watch, docker-run)
• Docker + Docker Compose
Relationships and interactions
• User’s browser ⟶ Web UI service (HTTP GET home page)
• Browser + HTMX ⟶ API service (HTTP POST create or GET retrieve paste)
• API service ⟶ Redis (SET with TTL, GET)
• API service returns JSON or HTTP status, HTMX updates the browser dynamically
• Separate processes for web UI and API (could be behind the same domain or proxied via NGINX in production)
Architectural patterns and design principles
• Separation of concerns: distinct API and UI services
• Layered architecture: HTTP layer (internal/server), business logic (internal/pkg), data access (internal/database)
• Ephemeral data pattern: Redis TTL for auto-cleanup
• Minimal external dependencies for performance and privacy
Relevant technologies and frameworks
• Go 1.24+ for both services
• HTMX for client-side interactivity
• Templ engine for server-side HTML rendering
• Tailwind CSS for utility-first styling
• Redis for in-memory persistence with TTL
• Docker + Docker Compose for local development