Skip to content

kernelshard/hcaas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

176 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš‘ HealthCheck as a Service (HCaaS)

Go Version
License: MIT
Build Status

A Golang-based microservice for registering and monitoring the health of HTTP URLs. Built with idiomatic Go and clean architecture, itโ€™s designed for production-ready reliability and maintainability.


โœจ Features

  • Register and track the health of HTTP URLs
  • Manually update URL status (automated cron checks planned)
  • Clean architecture (Handler โ†’ Service โ†’ Storage)
  • PostgreSQL storage via pgxpool
  • Idiomatic, production-grade Go codebase

๐Ÿ“ Project Structure

hcaas/
โ”œโ”€โ”€ cmd/
โ”‚   โ””โ”€โ”€ server/
โ”‚       โ””โ”€โ”€ main.go         # Application entry point
โ”œโ”€โ”€ handler/                # HTTP handlers (Chi-based)
โ”œโ”€โ”€ model/                  # URL struct definitions
โ”œโ”€โ”€ service/                # Business logic
โ”œโ”€โ”€ storage/                # PostgreSQL storage layer
โ”œโ”€โ”€ .env                    # Environment variable config
โ”œโ”€โ”€ .env.example            # Example environment config
โ”œโ”€โ”€ go.mod                  # Go module dependencies
โ”œโ”€โ”€ go.sum                  # Dependency checksums
โ”œโ”€โ”€ README.md               # Project documentation

๐Ÿ› ๏ธ Tech Stack

  • Language: Go 1.22+
  • HTTP Router: Chi
  • Database: PostgreSQL (via pgxpool)
  • Architecture: Clean layered architecture (Handler โ†’ Service โ†’ Storage)

๐Ÿš€ Getting Started

Prerequisites

  • Go: 1.22 or higher
  • PostgreSQL: A running instance (local or remote)
  • Git: For cloning the repository

1. Clone the Repository

git clone https://github.com/kernelshard/hcaas
cd hcaas

2. Configure Environment

Copy the example environment file:

cp .env.example .env

Update .env with your PostgreSQL configuration:

DATABASE_URL=postgres://username:password@localhost:5432/yourdb?sslmode=disable

Replace username, password, and yourdb with your PostgreSQL credentials.

3. Install Dependencies

go mod tidy

4. Run the Service

go run ./cmd/server

The service starts on http://localhost:3000 (default port).


๐Ÿ“ก API Endpoints

Method Endpoint Description
POST /urls Register a new URL for monitoring
GET /urls List all monitored URLs
PATCH /urls/{id} Update health status of a URL

POST /urls

Register a new URL to monitor.

Request Body:

{
  "address": "https://example.com"
}

Note: Health checks currently use GET by default. Support for other HTTP methods is planned.

Response:

{
  "id": "e2c1b7f4-6d04-4fc6-a1de-2cf85801f645",
  "address": "https://example.com",
  "status": "unknown",
  "checked_at": "2025-07-21T12:05:07Z"
}

Status: 201 Created

GET /urls

List all monitored URLs.

Response:

[
  {
    "id": "e2c1b7f4-6d04-4fc6-a1de-2cf85801f645",
    "address": "https://example.com",
    "status": "up",
    "checked_at": "2025-07-21T12:00:00Z"
  }
]

PATCH /urls/{id}

Update the health status of a URL (used internally for now).

Request Body:

{
  "status": "down"
}

Response:

{
  "id": "e2c1b7f4-6d04-4fc6-a1de-2cf85801f645",
  "address": "https://example.com",
  "status": "down",
  "checked_at": "2025-07-21T12:05:30Z"
}

Status: 200 OK


๐Ÿงช Testing with cURL

Test the API using the following cURL commands:

# Add a URL
curl -X POST http://localhost:3000/urls \
  -H "Content-Type: application/json" \
  -d '{"address": "https://example.com"}'

# List URLs
curl http://localhost:3000/urls

# Update status
curl -X PATCH http://localhost:3000/urls/e2c1b7f4-6d04-4fc6-a1de-2cf85801f645 \
  -H "Content-Type: application/json" \
  -d '{"status": "up"}'

๐Ÿ›๏ธ Architecture Overview

HCaaS follows a clean architecture with three layers:

  • Handler: Manages HTTP requests and responses using Chi.
  • Service: Handles business logic for URL registration and health checks.
  • Storage: Persists data to PostgreSQL via pgxpool.

This modular design ensures testability and scalability.


โœ… Design Principles

  • Idiomatic Go: Simple, readable, and maintainable code.
  • Separation of Concerns: Handlers delegate to services, which interact with storage.
  • Interface-Driven: Enables easy mocking for testing.
  • Extensible: Designed for future features like cron-based checks.

๐Ÿงญ Roadmap

  • PostgreSQL integration
  • RESTful API with Chi
  • Automated cron-based health checks
  • Support for additional HTTP methods
  • Alerts (email, webhooks)
  • Authentication and rate limiting
  • Comprehensive test suite with mocks

๐Ÿ‘จโ€๐Ÿ’ป Author

Samiul Sk
Senior Software Engineer
Kolkata, India
Passionate about microservices, Go, and scalable system design.
LinkedIn | GitHub


๐Ÿ“œ License

This project is licensed under the MIT License.


๐Ÿ“Œ Contributing

Contributions are welcome! Please:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/xyz).
  3. Submit a pull request with clear descriptions.

See CONTRIBUTING.md for details. Report issues or suggest features on GitHub.

Want to enhance this project? Let me know if youโ€™d like:

  • A Dockerfile and docker-compose.yml for containerized deployment
  • A Mermaid diagram illustrating the architecture
  • A docs/ folder structure for GitHub Pages
  • Additional badges (e.g., code coverage, last commit)

โญ๏ธ Feel free to fork, improve, or use this as a portfolio project!

About

A Golang-based microservices for registering and monitoring the health of HTTP URLs.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

โšก