Skip to content

A comprehensive hotel booking and reservation management system built with Go backend and HTML/CSS/JavaScript frontend, featuring room availability checking, reservation management, and administrative dashboard.

Notifications You must be signed in to change notification settings

karthikbhandary2/bookings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hotel Bookings & Reservations System

A comprehensive hotel booking and reservation management system built with Go backend and HTML/CSS/JavaScript frontend, featuring room availability checking, reservation management, and administrative dashboard.

πŸš€ Features

  • Room Management: Multiple room types (General's Quarters, Major's Suite)
  • Reservation System: Complete booking workflow with availability checking
  • User Authentication: Secure login system for administrators
  • Admin Dashboard: Comprehensive reservation management interface
  • Email Integration: Automated email notifications for bookings
  • Session Management: Secure session handling with SCS
  • Database Integration: PostgreSQL with migration support
  • Form Validation: Client and server-side validation
  • Responsive Design: Mobile-friendly Bootstrap interface
  • Calendar Integration: Visual availability calendar
  • Search Functionality: Advanced availability search

πŸ›  Tech Stack

Backend

  • Language: Go 1.23.4
  • Router: Chi Router (github.com/go-chi/chi/v5)
  • Database: PostgreSQL
  • Session Management: SCS (github.com/alexedwards/scs/v2)
  • CSRF Protection: NoSurf (github.com/justinas/nosurf)
  • Email: Simple Mail (github.com/xhit/go-simple-mail/v2)
  • Database Migrations: Buffalo Pop/Fizz

Frontend

  • Framework: Server-side rendered HTML templates
  • Styling: Bootstrap 5
  • JavaScript: Vanilla JS with SweetAlert2
  • Icons: Font Awesome
  • Date Picker: Vanillajs-datepicker
  • Notifications: Notie.js

Database & Tools

  • Database: PostgreSQL
  • Migration Tool: Buffalo Pop
  • Template Engine: Go HTML templates
  • Build Tool: Go build system

πŸ“ Project Structure

bookings/
β”œβ”€β”€ cmd/                          # Application entry points
β”‚   └── web/                      # Web application
β”‚       β”œβ”€β”€ main.go              # Main application entry
β”‚       β”œβ”€β”€ routes.go            # HTTP routes configuration
β”‚       β”œβ”€β”€ middlewares.go       # HTTP middleware
β”‚       β”œβ”€β”€ send-mail.go         # Email service
β”‚       └── *_test.go            # Web layer tests
β”œβ”€β”€ internal/                    # Private application code
β”‚   β”œβ”€β”€ config/                  # Application configuration
β”‚   β”‚   └── config.go           # Config structures
β”‚   β”œβ”€β”€ drivers/                # Database drivers
β”‚   β”‚   └── drivers.go          # Database connection
β”‚   β”œβ”€β”€ forms/                  # Form handling and validation
β”‚   β”‚   β”œβ”€β”€ forms.go            # Form validation logic
β”‚   β”‚   β”œβ”€β”€ errors.go           # Form error handling
β”‚   β”‚   └── forms_test.go       # Form tests
β”‚   β”œβ”€β”€ handlers/               # HTTP request handlers
β”‚   β”‚   β”œβ”€β”€ handlers.go         # Route handlers
β”‚   β”‚   β”œβ”€β”€ handlers_test.go    # Handler tests
β”‚   β”‚   └── setup_test.go       # Test setup utilities
β”‚   β”œβ”€β”€ helpers/                # Utility functions
β”‚   β”‚   └── helpers.go          # Helper functions
β”‚   β”œβ”€β”€ models/                 # Data models
β”‚   β”‚   β”œβ”€β”€ models.go           # Database models
β”‚   β”‚   └── templatedata.go     # Template data structures
β”‚   β”œβ”€β”€ render/                 # Template rendering
β”‚   β”‚   β”œβ”€β”€ render.go           # Template renderer
β”‚   β”‚   β”œβ”€β”€ render_test.go      # Render tests
β”‚   β”‚   └── setup_test.go       # Render test setup
β”‚   └── repository/             # Data access layer
β”‚       β”œβ”€β”€ repository.go       # Repository interfaces
β”‚       └── dbrepo/             # Database repository implementations
β”œβ”€β”€ templates/                   # HTML templates
β”‚   β”œβ”€β”€ base.layout.tmpl        # Base layout template
β”‚   β”œβ”€β”€ admin.layout.tmpl       # Admin layout template
β”‚   β”œβ”€β”€ home.page.tmpl          # Homepage template
β”‚   β”œβ”€β”€ about.page.tmpl         # About page template
β”‚   β”œβ”€β”€ contact.page.tmpl       # Contact page template
β”‚   β”œβ”€β”€ generals.page.tmpl      # General's Quarters room page
β”‚   β”œβ”€β”€ majors.page.tmpl        # Major's Suite room page
β”‚   β”œβ”€β”€ search-availability.page.tmpl    # Search form
β”‚   β”œβ”€β”€ make-reservations.page.tmpl      # Reservation form
β”‚   β”œβ”€β”€ reservation-summary.page.tmpl    # Booking summary
β”‚   β”œβ”€β”€ choose-room.page.tmpl            # Room selection
β”‚   β”œβ”€β”€ login.page.tmpl                  # Admin login
β”‚   β”œβ”€β”€ admin-dashboard.page.tmpl        # Admin dashboard
β”‚   β”œβ”€β”€ admin-reservations-calender.page.tmpl  # Calendar view
β”‚   β”œβ”€β”€ admin-all-reservations.page.tmpl       # All reservations
β”‚   β”œβ”€β”€ admin-new-reservations.page.tmpl       # New reservations
β”‚   └── admin-reservation-show.page.tmpl       # Reservation details
β”œβ”€β”€ static/                      # Static assets
β”‚   β”œβ”€β”€ css/                    # Stylesheets
β”‚   β”‚   └── styles.css          # Custom styles
β”‚   β”œβ”€β”€ js/                     # JavaScript files
β”‚   β”‚   └── app.js              # Application JavaScript
β”‚   β”œβ”€β”€ images/                 # Image assets
β”‚   β”‚   β”œβ”€β”€ outside.png         # Hotel exterior
β”‚   β”‚   β”œβ”€β”€ tray.png           # Service tray
β”‚   β”‚   β”œβ”€β”€ woman-laptop.png    # Hero image
β”‚   β”‚   β”œβ”€β”€ generals-quarters.png  # Room image
β”‚   β”‚   └── marjors-suite.png      # Room image
β”‚   └── admin/                  # Admin panel assets
β”‚       β”œβ”€β”€ css/               # Admin stylesheets
β”‚       β”œβ”€β”€ js/                # Admin JavaScript
β”‚       β”œβ”€β”€ images/            # Admin images
β”‚       └── vendors/           # Third-party libraries
β”œβ”€β”€ migrations/                  # Database migrations
β”‚   β”œβ”€β”€ schema.sql              # Complete database schema
β”‚   β”œβ”€β”€ *_create_*.up.fizz      # Forward migrations
β”‚   β”œβ”€β”€ *_create_*.down.fizz    # Rollback migrations
β”‚   └── *_seed_*.sql            # Database seeding
β”œβ”€β”€ email-templates/            # Email templates
β”‚   └── basic.html             # Basic email template
β”œβ”€β”€ html-source/               # Static HTML source files
β”‚   β”œβ”€β”€ index.html             # Homepage source
β”‚   β”œβ”€β”€ about.html             # About page source
β”‚   β”œβ”€β”€ contact.html           # Contact page source
β”‚   β”œβ”€β”€ generals.html          # General's room source
β”‚   β”œβ”€β”€ majors.html            # Major's room source
β”‚   β”œβ”€β”€ make-reservation.html  # Reservation form source
β”‚   └── reservation.html       # Reservation page source
β”œβ”€β”€ logs/                      # Application logs
β”œβ”€β”€ go.mod                     # Go module definition
β”œβ”€β”€ go.sum                     # Go module checksums
β”œβ”€β”€ database.yml.example       # Database configuration template
β”œβ”€β”€ run.sh                     # Application startup script
β”œβ”€β”€ update.sh                  # Update script
β”œβ”€β”€ testdbconnection.go        # Database connection test
β”œβ”€β”€ .gitignore                 # Git ignore rules
└── README.md                  # This file

🚦 Prerequisites

  • Go: 1.23.4 or later
  • PostgreSQL: 12.0 or later
  • Buffalo CLI: For database migrations (optional)

⚑ Quick Start

1. Clone the Repository

git clone https://github.com/karthikbhandary2/bookings.git
cd bookings

2. Database Setup

Create PostgreSQL Database

# Create database
createdb bookings

# Create user (optional)
psql -c "CREATE USER bookings_user WITH PASSWORD 'your_password';"
psql -c "GRANT ALL PRIVILEGES ON DATABASE bookings TO bookings_user;"

Configure Database Connection

Update the database connection string in cmd/web/main.go:

db, err := drivers.ConnectSQL("host=localhost port=5432 dbname=bookings user=your_user password=your_password")

Or create a database.yml file from the example:

cp database.yml.example database.yml
# Edit database.yml with your database credentials

Run Database Migrations

# If you have Buffalo CLI installed
buffalo pop migrate

# Or execute the schema directly
psql -d bookings -f migrations/schema.sql

3. Install Dependencies

go mod tidy

4. Configure Application

Update configuration in cmd/web/main.go:

// Set to true for production
app.InProduction = false

// Update port if needed
const portNumber = ":8080"

5. Start the Application

Using the run script:

chmod +x run.sh
./run.sh

Or manually:

go build -o bookings cmd/web/*.go
./bookings

6. Access the Application

πŸ”§ Development

Available Scripts

# Build and run application
./run.sh

# Update dependencies
./update.sh

# Test database connection
go run testdbconnection.go

# Run tests
go test ./...

# Build for production
go build -o bookings cmd/web/*.go

Database Operations

Create New Migration

# Using Buffalo CLI
buffalo pop generate migration create_new_table

# Manual migration files in migrations/ directory

Seed Database

# Run seed files
psql -d bookings -f migrations/seed_rooms_table.postgres.up.sql
psql -d bookings -f migrations/seed_restrictions_table.postgres.up.sql

Application Routes

Public Routes

  • GET / - Homepage with hero carousel
  • GET /about - About page
  • GET /contact - Contact page
  • GET /generals-quarters - General's Quarters room details
  • GET /majors-suite - Major's Suite room details
  • GET /search-availability - Room availability search
  • POST /search-availability - Process availability search
  • POST /search-availability-json - AJAX availability search
  • GET /choose-room/:id - Room selection
  • GET /make-reservation - Reservation form
  • POST /make-reservation - Process reservation
  • GET /reservation-summary - Booking confirmation

Admin Routes (Protected)

  • GET /admin/dashboard - Admin dashboard
  • GET /admin/reservations-new - New reservations
  • GET /admin/reservations-all - All reservations
  • GET /admin/reservations-calendar - Calendar view
  • GET /admin/reservations/:src/:id/show - Reservation details
  • POST /admin/reservations/:src/:id - Update reservation
  • POST /admin/process-reservation/:src/:id/:action - Process reservation actions

Authentication Routes

  • GET /user/login - Login page
  • POST /user/login - Process login
  • POST /user/logout - Logout

Data Models

Core Models

// User represents system users (admins)
type User struct {
    ID          int
    FirstName   string
    LastName    string
    Email       string
    Password    string
    AccessLevel int
    CreatedAt   time.Time
    UpdatedAt   time.Time
}

// Room represents hotel rooms
type Room struct {
    ID        int
    RoomName  string
    CreatedAt time.Time
    UpdatedAt time.Time
}

// Reservation represents guest bookings
type Reservation struct {
    ID        int
    FirstName string
    LastName  string
    Email     string
    Phone     string
    StartDate time.Time
    EndDate   time.Time
    RoomID    int
    CreatedAt time.Time
    UpdatedAt time.Time
    Room      Room
    Processed int
}

// RoomRestriction represents room availability restrictions
type RoomRestriction struct {
    ID            int
    StartDate     time.Time
    EndDate       time.Time
    RoomID        int
    ReservationID int
    RestrictionID int
    CreatedAt     time.Time
    UpdatedAt     time.Time
    Room          Room
    Reservation   Reservation
    Restriction   Restriction
}

Testing

# Run all tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run specific package tests
go test ./internal/handlers -v
go test ./internal/forms -v
go test ./internal/render -v

# Run tests with race detection
go test -race ./...

Email Configuration

Configure email settings in cmd/web/send-mail.go:

// Update SMTP settings
m := mail.NewMSG()
m.SetServer("your-smtp-server.com")
m.SetAuthentication("username", "password")
m.SetPort(587)
m.SetEncryption(mail.EncryptionSTARTTLS)

🎨 Frontend Features

User Interface

  • Responsive Design: Bootstrap 5 responsive grid system
  • Interactive Calendar: Date picker for reservation dates
  • Form Validation: Real-time client-side validation
  • Notifications: Toast notifications for user feedback
  • Modal Dialogs: SweetAlert2 for confirmations
  • Image Carousel: Hero image slideshow on homepage

JavaScript Libraries

  • SweetAlert2: Beautiful alert dialogs
  • Notie: Lightweight notifications
  • Vanillajs-datepicker: Date selection widget
  • Bootstrap 5: UI framework and components

Admin Panel Features

  • Dashboard: Overview of reservations and statistics
  • Calendar View: Visual representation of bookings
  • Reservation Management: CRUD operations for bookings
  • User Authentication: Secure admin login system
  • Responsive Tables: Mobile-friendly data tables

πŸ”’ Security Features

  • CSRF Protection: NoSurf middleware for CSRF token validation
  • Session Security: Secure session configuration with SCS
  • Input Validation: Server-side form validation
  • SQL Injection Protection: Parameterized database queries
  • Authentication: Admin-only access to management features
  • Secure Cookies: HTTPOnly and Secure cookie flags in production

πŸš€ Deployment

Environment Configuration

For production deployment:

// In cmd/web/main.go
app.InProduction = true

// Update database connection for production
db, err := drivers.ConnectSQL("host=prod-db port=5432 dbname=bookings user=prod_user password=prod_pass sslmode=require")

Production Checklist

  1. Database: Set up production PostgreSQL instance
  2. Environment: Set app.InProduction = true
  3. SSL: Configure HTTPS and secure cookies
  4. Email: Configure production SMTP settings
  5. Logging: Set up proper log rotation
  6. Monitoring: Implement health checks and monitoring
  7. Backup: Set up database backup strategy

Docker Deployment (Optional)

Create a Dockerfile:

FROM golang:1.23.4-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o bookings cmd/web/*.go

FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/bookings .
COPY --from=builder /app/templates ./templates
COPY --from=builder /app/static ./static
COPY --from=builder /app/email-templates ./email-templates
EXPOSE 8080
CMD ["./bookings"]

πŸ“Š Database Schema

Tables

  • users: System administrators
  • rooms: Available room types
  • reservations: Guest bookings
  • restrictions: Restriction types (reservation, owner block)
  • room_restrictions: Room availability restrictions

Key Relationships

  • Reservations belong to Rooms
  • Room Restrictions link Rooms, Reservations, and Restrictions
  • Users manage the system through admin interface

πŸ†˜ Troubleshooting

Common Issues

  1. Database Connection Failed

    # Check PostgreSQL status
    sudo systemctl status postgresql
    
    # Verify connection parameters in main.go
    # Check database exists: psql -l
  2. Template Not Found

    # Ensure templates directory exists and contains .tmpl files
    # Check template cache configuration in main.go
  3. Static Files Not Loading

    # Verify static directory structure
    # Check file permissions: chmod -R 644 static/
  4. Port Already in Use

    # Change port in main.go
    const portNumber = ":8081"
    
    # Or kill existing process
    sudo lsof -ti:8080 | xargs kill -9
  5. Migration Errors

    # Check database connection
    # Verify migration files syntax
    # Run migrations manually: psql -d bookings -f migrations/schema.sql

πŸ“ž Support

For support and questions:

  • Check the existing documentation
  • Review the code comments in handlers and models
  • Test database connection with testdbconnection.go
  • Examine log files in the logs/ directory

πŸ“ License

This project is part of a learning exercise for Go web development with hotel booking system implementation.


Happy Booking! 🏨

About

A comprehensive hotel booking and reservation management system built with Go backend and HTML/CSS/JavaScript frontend, featuring room availability checking, reservation management, and administrative dashboard.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published