Thanks to visit codestin.com
Credit goes to github.com

Skip to content

srk9/srk9.domains

Repository files navigation

Domain Manager API

A comprehensive domain management API built with Hono and deployed to Cloudflare Workers using Durable Objects for persistent state management. This application manages domain registration data including expiration dates, renewal costs, and registrar information.

🌐 Live API

Base URL: https://srk9-domain-manager-api.srk9.workers.dev

πŸ“‹ Project Summary

This domain management system provides a complete REST API for managing domain portfolios. It tracks essential domain information such as:

  • Domain names and registration details
  • Purchase and expiration dates
  • Renewal costs and auto-renewal settings
  • Privacy registration status
  • Transfer lock status
  • Registrar information

The API is built with modern web technologies and deployed on Cloudflare's edge network for high performance and global availability.

πŸ—οΈ Architecture

Core Components

  • DomainManager: Cloudflare Durable Object class that handles domain data persistence and business logic
  • Hono API: REST API built with Hono framework providing CRUD operations for domains
  • TypeScript Types: Domain interface definition in types.ts

Key Files

  • index.ts: Contains both the DomainManager Durable Object and Hono API routes
  • types.ts: TypeScript interface definitions
  • wrangler.toml: Cloudflare Workers configuration with Durable Object bindings
  • package.json: Dependencies and build scripts

Data Storage

  • Uses Cloudflare SQLite-based Durable Objects for persistence
  • Domains are stored as a Map in memory and persisted to Durable Object storage
  • Includes seed data for initial domain portfolio (srk9.com, srk9.net, etc.)

πŸš€ Quick Start

Prerequisites

  • Node.js 16+
  • Cloudflare account
  • Wrangler CLI installed and authenticated

Installation

npm install

Development

npm run dev     # Start Wrangler development server

Deployment

npm run deploy  # Deploy to Cloudflare Workers

πŸ“š REST API Documentation

Base URL

https://srk9-domain-manager-api.srk9.workers.dev

Authentication

No authentication required for this API.

Endpoints

Health Check

GET /health

Returns API status and timestamp.

Response:

{
  "status": "ok",
  "timestamp": "2025-07-02T21:30:20.566Z"
}

Get All Domains

GET /domains

Retrieves all domains in the portfolio.

Response:

[
  {
    "uid": 1,
    "domain_name": "srk9.com",
    "purchase_date": "20080404",
    "expiration_date": "20250404",
    "private_registration": "true",
    "renewal_cost": 10.44,
    "auto_renew_enabled": "true",
    "transfer_lock_enabled": "true",
    "registrar_id": 1
  }
]

Get Domain by UID

GET /domains/{uid}

Retrieves a specific domain by its unique identifier.

Parameters:

  • uid (integer): Domain unique identifier

Response:

{
  "uid": 1,
  "domain_name": "srk9.com",
  "purchase_date": "20080404",
  "expiration_date": "20250404",
  "private_registration": "true",
  "renewal_cost": 10.44,
  "auto_renew_enabled": "true",
  "transfer_lock_enabled": "true",
  "registrar_id": 1
}

Error Response (404):

{
  "error": "Domain not found"
}

Add New Domain

POST /domains

Adds a new domain to the portfolio.

Request Body:

{
  "domain_name": "example.com",
  "purchase_date": "20250101",
  "expiration_date": "20260101",
  "private_registration": "true",
  "renewal_cost": 15.99,
  "auto_renew_enabled": "true",
  "transfer_lock_enabled": "true",
  "registrar_id": 1
}

Response (201):

{
  "uid": 8,
  "domain_name": "example.com",
  "purchase_date": "20250101",
  "expiration_date": "20260101",
  "private_registration": "true",
  "renewal_cost": 15.99,
  "auto_renew_enabled": "true",
  "transfer_lock_enabled": "true",
  "registrar_id": 1
}

Update Domain

PUT /domains/{uid}

Updates an existing domain's information.

Parameters:

  • uid (integer): Domain unique identifier

Request Body:

{
  "renewal_cost": 18.99,
  "auto_renew_enabled": "false"
}

Response:

{
  "uid": 1,
  "domain_name": "srk9.com",
  "purchase_date": "20080404",
  "expiration_date": "20250404",
  "private_registration": "true",
  "renewal_cost": 18.99,
  "auto_renew_enabled": "false",
  "transfer_lock_enabled": "true",
  "registrar_id": 1
}

Delete Domain

DELETE /domains/{uid}

Removes a domain from the portfolio.

Parameters:

  • uid (integer): Domain unique identifier

Response:

{
  "message": "Domain deleted successfully"
}

Get Expiring Domains

GET /domains/expiring/{days}

Retrieves domains expiring within the specified number of days.

Parameters:

  • days (integer, optional): Number of days to look ahead (default: 30)

Examples:

  • /domains/expiring - domains expiring in next 30 days
  • /domains/expiring/90 - domains expiring in next 90 days

Response:

[
  {
    "uid": 1,
    "domain_name": "srk9.com",
    "purchase_date": "20080404",
    "expiration_date": "20250404",
    "private_registration": "true",
    "renewal_cost": 10.44,
    "auto_renew_enabled": "true",
    "transfer_lock_enabled": "true",
    "registrar_id": 1
  }
]

Get Total Renewal Cost

GET /stats/renewal-cost

Calculates the total renewal cost for all domains in the portfolio.

Response:

{
  "total_renewal_cost": 140.19
}

πŸ“Š Data Model

Domain Object

interface Domain {
  uid: number;                    // Unique identifier
  domain_name: string;            // Domain name (e.g., "example.com")
  purchase_date: string;          // Format: YYYYMMDD
  expiration_date: string;        // Format: YYYYMMDD
  private_registration: string;   // "true" or "false"
  renewal_cost: number;           // Cost in dollars
  auto_renew_enabled: string;     // "true" or "false"
  transfer_lock_enabled: string;  // "true" or "false"
  registrar_id: number;           // Registrar identifier
}

πŸ”§ Configuration

Cloudflare Workers Configuration

The project uses SQLite-based Durable Objects for free plan compatibility:

# wrangler.toml
name = "srk9-domain-manager-api"
main = "index.ts"
compatibility_date = "2024-01-01"

[durable_objects]
bindings = [{ name = "DOMAIN_MANAGER", class_name = "DomainManager" }]

[[migrations]]
tag = "v1"
new_sqlite_classes = ["DomainManager"]

Dependencies

  • hono: Web framework for Cloudflare Workers
  • @cloudflare/workers-types: TypeScript types for Workers
  • typescript: TypeScript compiler
  • wrangler: Cloudflare Workers CLI

🌟 Features

  • βœ… Complete CRUD Operations - Create, read, update, and delete domains
  • βœ… Expiration Tracking - Monitor domains expiring within specified timeframes
  • βœ… Cost Management - Track individual and total renewal costs
  • βœ… Persistent Storage - SQLite-based Durable Objects for reliable data persistence
  • βœ… Edge Deployment - Global distribution via Cloudflare's edge network
  • βœ… TypeScript Support - Full type safety and IntelliSense
  • βœ… RESTful API - Standard HTTP methods and status codes
  • βœ… CORS Enabled - Cross-origin resource sharing support

🎯 Current Portfolio

The API includes seed data for the following domains:

  • srk9.com
  • srk9.net
  • srk9.org
  • srk9.dev
  • srk9.io
  • srk9.tech
  • luxtechnologies.com

Total Portfolio Value: $140.19 annual renewal cost

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.

πŸ”— Links

About

Domain Manager using an Cloudflare Worker & Durable Object for state persistance

Resources

Stars

Watchers

Forks

Packages

No packages published