Skip to content

Gitznik/robswebhub

Repository files navigation

RobsWebHub

My personal website built with Go, featuring personal projects and an introduction about myself.

πŸš€ Quick Start

# Clone the repository
git clone https://github.com/gitznik/robswebhub.git
cd robswebhub

# Run the setup script (installs everything and starts the database)
just setup

# Start the development server
just dev

# Visit http://localhost:8000

Tech Stack

  • Backend: Go with Gin web framework
  • Database: PostgreSQL with sqlc for type-safe queries
  • Migrations: golang-migrate
  • Templates: templ for type-safe HTML templates
  • Frontend: HTMX for dynamic interactions, Pico CSS for styling
  • Charts: go-echarts for data visualization
  • Build Tool: just for task automation

Why just?

This project uses just instead of make for task automation because:

  • Better syntax: Cleaner, more readable command definitions
  • Built-in help: Automatic help text generation
  • Cross-platform: Works consistently across Linux, macOS, and Windows
  • Shell flexibility: Choose your shell per recipe
  • Better error messages: More helpful when things go wrong
  • Parameters: Easy command parameters without make's complexity

Features

  • Personal portfolio and about page
  • Scorekeeper: A game score tracking application
    • Single and batch score entry
    • Visual charts showing win progression
    • Historical score tracking

Prerequisites

  • Go 1.22 or later
  • PostgreSQL
  • Docker (optional, for containerized development)
  • just (command runner, install with cargo install just or brew install just)

Installation

  1. Clone the repository:
git clone https://github.com/gitznik/robswebhub.git
cd robswebhub
  1. Install just (if not already installed):
# macOS
brew install just

# Linux/WSL
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin

# Or with Cargo
cargo install just
  1. Install dependencies and tools:
just install

Or manually:

go mod download
go install github.com/a-h/templ/cmd/templ@latest
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your configuration

Development

Quick Start with Docker Compose

# Start PostgreSQL and the application
docker-compose up -d

# Stop everything
docker-compose down

Manual Setup

  1. Start PostgreSQL:
just setup-env
# Or use your existing PostgreSQL instance
  1. Run migrations:
just migrate-up
  1. Generate code (templ templates and sqlc queries):
just generate
  1. Run the application:
just run

For hot reload during development (requires air):

go install github.com/cosmtrek/air@latest
just dev

Available Commands

just --list          # Show all available commands
just setup           # Complete initial setup
just start           # Start everything (DB, migrations, seed, dev server)
just stop            # Stop all services
just dev             # Run with hot reload
just test            # Run tests
just check           # Run all checks (fmt, lint, test)
just db-reset        # Reset database completely
just compose-up      # Start with docker-compose
just backup-db       # Backup database
just help            # Show detailed help

Advanced Commands

The justfile includes many advanced commands for development:

# Database Management
just db-console              # Connect to database with psql
just migrate-status          # Check migration status
just migrate-goto <version>  # Go to specific migration
just backup-db               # Create timestamped backup
just restore-db <file>       # Restore from backup

# Development Tools
just watch                   # Watch files and auto-rebuild
just profile-cpu            # Profile CPU usage
just profile-mem            # Profile memory usage
just outdated               # Check for outdated dependencies
just audit                  # Run security audit

# Docker & Deployment
just docker                 # Build and run Docker container
just compose-logs          # View docker-compose logs
just deploy                # Deploy to Fly.io
just fly-ssh               # SSH into Fly.io app

For a complete list of commands with descriptions:

just help

Project Structure

robswebhub/
β”œβ”€β”€ cmd/server/           # Application entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ config/          # Configuration management
β”‚   β”œβ”€β”€ database/        # Database connection and generated sqlc code
β”‚   β”œβ”€β”€ handlers/        # HTTP request handlers
β”‚   └── templates/       # Templ templates
β”‚       β”œβ”€β”€ layouts/     # Base layouts
β”‚       β”œβ”€β”€ pages/       # Page templates
β”‚       └── components/  # Reusable components
β”œβ”€β”€ migrations/          # Database migrations
β”œβ”€β”€ static/              # Static assets (CSS, JS, images)
β”œβ”€β”€ config/              # Configuration files
└── scripts/             # Utility scripts

Configuration

The application uses a hierarchical configuration system:

  1. Base configuration from config/dev.yaml or config/production.yaml
  2. Environment variables (prefixed with APP_)
  3. .env file (for local development)

Environment Variables

  • APP_ENVIRONMENT: dev or production
  • APP_APPLICATION__HOST: Server host
  • APP_APPLICATION__PORT: Server port
  • DATABASE_URL: PostgreSQL connection string

Database Schema

Matches Table

  • id: UUID (Primary Key)
  • player_1: Text
  • player_2: Text
  • created_at: Timestamp

Scores Table

  • match_id: UUID (Foreign Key)
  • game_id: UUID
  • winner: Text
  • winner_score: SmallInt
  • loser_score: SmallInt
  • played_at: Date
  • created_at: Timestamp

Deployment

Using Docker

# Build the image
just docker-build

# Run the container
just docker-run

# Or do both
just docker

Fly.io Deployment

# Install flyctl
curl -L https://fly.io/install.sh | sh

# Deploy
fly deploy

API Routes

  • GET / - Home page
  • GET /about - About page
  • GET /scores - Scorekeeper index
  • POST /scores/single - Submit single score
  • POST /scores/batch - Submit batch scores
  • GET /scores/single-form - Get single score form (HTMX)
  • GET /scores/batch-form - Get batch score form (HTMX)
  • GET /scores/chart/:id - Get match chart

Development Tips

  1. Code Generation: Always run just generate after modifying .templ files or queries.sql

  2. Database Changes: Create new migrations with:

    just migrate-create your_migration_name
  3. Testing: The example match ID b13a16d8-c46e-4921-83f2-eec9675fce74 is seeded for testing

  4. Hot Reload: Use just dev for automatic reloading during development

  5. Quick Commands:

    • just start - Start everything (DB, migrations, seed, dev server)
    • just quick - Quickly rebuild and run after changes
    • just check - Run all pre-commit checks (fmt, lint, test)

Contributing

Feel free to open issues or submit pull requests if you find any bugs or have suggestions for improvements.

Author

Robert Offner

License

This project is open source. Feel free to use it as a template for your own projects.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published