Skip to content

acampinho/guardian-go

Repository files navigation

Guardian Go - Microservices Architecture

A complete Go-based microservices platform for the Guardian security and community management system.

πŸ—οΈ Architecture Overview

Guardian Go is built entirely in Go with a modern microservices architecture. All services are containerized and orchestrated with Docker Compose.

Core Services (6 Microservices)

Service Port Purpose Tech Stack
Guardian.ApiGo 3000 REST API Backend Go, Gin, PostgreSQL
Guardian.WebUserGo 3001 Customer Web Portal Go, HTML/Template, PostgreSQL
Guardian.GuardsGo 3002 Guard Management API Go, Gin, PostgreSQL
Guardian.PartnersGo 3003 Partner Management API Go, Gin, PostgreSQL
Guardian.WebAdminGo 3004 Admin Dashboard Go, HTML/Template, PostgreSQL
Guardian.WebPartnerGo 3005 Partner Portal Go, HTML/Template, PostgreSQL

πŸš€ Quick Start

Prerequisites

  • Go 1.21+
  • Docker & Docker Compose
  • PostgreSQL 16 (for local development)
  • Make (optional)

Local Development

  1. Clone and setup

    cd services
  2. Start PostgreSQL

    docker-compose up -d db
  3. Build all services

    # Using VS Code task
    Run task: build-all-go
    
    # Or manually
    cd Guardian.ApiGo && go build -o guardian-api .
    cd ../Guardian.WebUserGo && go build -o guardian-web-user-go .
    # ... repeat for other services
  4. Run services

    # Individual service in VS Code
    Debug: Guardian.ApiGo
    
    # Or all together
    Run task: docker-up

Docker Deployment

# Build and start all services
docker-compose up --build

# Stop all services
docker-compose down

πŸ“ Project Structure

services/
β”œβ”€β”€ Guardian.ApiGo/              # Core REST API
β”‚   β”œβ”€β”€ main.go
β”‚   β”œβ”€β”€ models.go
β”‚   β”œβ”€β”€ middleware.go
β”‚   β”œβ”€β”€ api_*.go                 # API handlers
β”‚   β”œβ”€β”€ go.mod
β”‚   └── Dockerfile
β”œβ”€β”€ Guardian.WebUserGo/          # Customer portal
β”‚   β”œβ”€β”€ main.go
β”‚   β”œβ”€β”€ middleware.go
β”‚   β”œβ”€β”€ pages_*.go              # Page handlers
β”‚   β”œβ”€β”€ templates/              # HTML templates
β”‚   β”œβ”€β”€ static/                 # CSS, JS, images
β”‚   └── Dockerfile
β”œβ”€β”€ Guardian.GuardsGo/          # Guard management
β”œβ”€β”€ Guardian.PartnersGo/        # Partner management
β”œβ”€β”€ Guardian.WebAdminGo/        # Admin dashboard
└── Guardian.WebPartnerGo/      # Partner portal

πŸ”§ Available Tasks

Build Tasks

  • build-api-go - Build Guardian.ApiGo
  • build-web-user-go - Build Guardian.WebUserGo
  • build-guards-go - Build Guardian.GuardsGo
  • build-partners-go - Build Guardian.PartnersGo
  • build-web-admin-go - Build Guardian.WebAdminGo
  • build-web-partner-go - Build Guardian.WebPartnerGo
  • build-all-go - Build all services

Test Tasks

  • test-api-go - Test Guardian.ApiGo
  • test-all-go - Test all services

Docker Tasks

  • docker-build - Build Docker images
  • docker-up - Start all services
  • docker-down - Stop all services

πŸ” Authentication & Security

All services use JWT (JSON Web Tokens) for authentication:

  • JWT Secret: Set via JWT_SECRET environment variable
  • Token Expiry: 24 hours
  • Protected Routes: Require valid JWT in Authorization header

Environment Variables

# Database
DB_USER=postgres
DB_PASSWORD=password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=guardian_go

# API
JWT_SECRET=your-secret-key-here
PORT=3000

# Optional
DEBUG=true
LOG_LEVEL=info

πŸ“š API Documentation

Each service provides comprehensive API endpoints:

Guardian.ApiGo (Core API)

  • /api/auth/register - User registration
  • /api/auth/login - User authentication
  • /api/users/* - User management
  • /api/services/* - Service management
  • /api/bookings/* - Booking management

Guardian.GuardsGo

  • /api/auth/* - Guard authentication
  • /api/profile/* - Guard profile
  • /api/assignments/* - Job assignments

Guardian.PartnersGo

  • /api/auth/* - Partner authentication
  • /api/profile/* - Partner profile
  • /api/services/* - Service management
  • /api/availability/* - Availability management

Web Services

  • Web portals serve server-rendered HTML with Tailwind CSS
  • RESTful API integration via fetch/AJAX
  • Protected pages require authentication

πŸ—„οΈ Database

PostgreSQL 16 with schema:

Main Tables:

  • users - System users (customers, guards, partners)
  • guards - Guard profiles and certifications
  • partners - Partner businesses and services
  • services - Available services
  • bookings - Service bookings
  • reviews - Service reviews and ratings
  • availability - Guard/Partner availability schedules

πŸ§ͺ Testing

# Test specific service
go test ./... -v -run <test_name>

# Run all service tests
task test-all-go

πŸ“¦ Dependencies

Core

  • gin-gonic/gin v1.11.0 - Web framework
  • jackc/pgx v5.8.0 - PostgreSQL driver
  • golang-jwt/jwt v5.3.1 - JWT authentication

Utilities

  • joho/godotenv v1.5.1 - Environment configuration
  • golang.org/x/crypto v0.41.0 - Password hashing

πŸ”„ Deployment

Production Checklist

  • Update JWT_SECRET environment variable
  • Configure production database credentials
  • Set DEBUG=false
  • Review CORS settings
  • Configure nginx reverse proxy
  • Set up SSL/TLS certificates
  • Enable database backups
  • Configure monitoring and logging

Using Docker in Production

# Update environment in docker-compose.yml
services:
  db:
    environment:
      POSTGRES_PASSWORD: <strong-password>
  
  api:
    environment:
      JWT_SECRET: <production-secret>
      DB_PASSWORD: <strong-password>

πŸ› οΈ Development

Adding a New Endpoint

  1. Create handler function in appropriate api_*.go or pages_*.go
  2. Register route in main.go
  3. Add tests in *_test.go
  4. Build and test: go build and run locally

Adding a New Service

  1. Create new directory: Guardian.NewServiceGo/
  2. Copy structure from existing service
  3. Update docker-compose.yml
  4. Update .vscode/launch.json and tasks.json
  5. Update this README

πŸ“Š Monitoring & Logging

Services log to stdout (visible in docker-compose output):

# View logs
docker-compose logs -f api

# Specific service
docker-compose logs guardian-api

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

For issues, questions, or suggestions:

  1. Check existing documentation in /docs
  2. Open an issue on GitHub
  3. Contact the development team

Last Updated: 2024 Go Version: 1.21+ Status: Production Ready

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published