Skip to content

A complete system for license key generation and validation, built with REST API, MongoDB, Discord Bot, and CLI, all orchestrated with Docker Compose

License

Notifications You must be signed in to change notification settings

x-name15/KeyGen-Microservices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KeyGen-Microservices

This project is a complete solution for generating, validating, and managing serial keys (software licenses), composed of a RESTful API, a Discord bot, and a command-line interface (CLI). The entire system is orchestrated with Docker and Docker Compose for easy and fast deployment.

✨ Features

  • Centralized API (Node.js/Express): A robust backend written in TypeScript that handles all business logic.
  • Persistent Database: Uses MongoDB to securely store key information.
  • Flexible Key Generation:
    • Create lifetime keys.
    • Create keys with a specific duration (expiration in days).
  • Advanced Validation:
    • Checks if a key is valid, expired, or inactive.
    • Supports binding keys to a Hardware ID (HWID).
  • Multiple User Interfaces:
    • Discord Bot (Python): Manage keys directly from Discord with simple commands.
    • CLI (Python): An interactive terminal tool for developers.
  • Easy Deployment: Fully containerized with Docker and orchestrated with Docker Compose.
  • Database Management: Includes Mongo Express for easy data visualization and management.

🛠️ Tech Stack

  • Backend (API): Node.js, Express, TypeScript, Mongoose
  • Database: MongoDB
  • Bot & CLI: Python, discord.py, requests
  • Orchestration: Docker, Docker Compose

📂 Project Structure

.
├── API/                # Source code for the RESTful API (Node.js)
├── CLI/                # Source code for the Command-Line Interface (Python)
├── DISCORD_BOT/        # Source code for the Discord Bot (Python)
├── .env                # Configuration file (DO NOT commit to git)
├── docker-compose.yml  # Orchestrates all services
└── README.md           # This file

🚀 Getting Started

Follow these steps to get the entire system up and running.

Prerequisites

1. Environment Setup

First, clone the repository. Then, create a .env file in the project root by copying the content below. This file is crucial for configuring all services.

#---------------------------------------
# API Serial Keys
# Internal port for the API container
APP_PORT_INTERNAL=3000
# Port you will expose on your host machine to access the API
HOST_PORT_API=6700
# MongoDB connection URI (the name 'mongodb' is the service name in docker-compose)
MONGO_URI=mongodb://mongodb:27017/serialkeys

#---------------------------------------
# Discord Bot
# Your Discord bot token
DISCORD_BOT_TOKEN=YOUR_DISCORD_BOT_TOKEN_HERE
# Base URL for the bot to communicate with the API (the name 'app' is the service name in docker-compose)
API_BASE_URL=http://app:3000/api/serialkeys
# Prefix for the bot commands
DISCORD_BOT_PREFIX=+
# Activity the bot will display on Discord
DISCORD_BOT_ACTIVITY=Generating Serial Keys

#---------------------------------------
# Mongo Express (Web interface for the database)
# MongoDB service name
ME_CONFIG_MONGODB_SERVER=mongodb
ME_CONFIG_MONGODB_PORT=27017
# Credentials to access Mongo Express
ME_CONFIG_BASICAUTH_USERNAME=admin
ME_CONFIG_BASICAUTH_PASSWORD=pass
ME_CONFIG_MONGODB_ENABLE_ADMIN=true

Important: Replace YOUR_DISCORD_BOT_TOKEN_HERE with your actual Discord bot token.

2. Start the Services

Open a terminal in the project root and run the following command. This will build the Docker images and start all containers in the background.

docker-compose up --build -d

3. Verify Everything is Running

  • API: Open your browser or an API client and navigate to http://localhost:6700. You should see the message "Serial Key API is running!".
  • Mongo Express: Navigate to http://localhost:8081 and log in with the credentials from your .env file (admin/pass).
  • Discord Bot: The bot should appear online in your Discord server.
  • Logs: To view the logs for all services, use docker-compose logs -f. For a specific service, use docker-compose logs -f <service-name> (e.g., app, discord-bot).

🤖 Discord Bot Usage

Invite your bot to a Discord server and use the following commands (with the prefix defined in your .env file):

  • Generate a lifetime key: +genlifetime <ProductName>

  • Generate a key with an expiration date: +gencad <ProductName> <days> Example: +gencad MySoftware 30

  • Check a key: +checkkey <SerialKey> [HWID] The HWID is optional. If provided on the first validation, the key will be bound to it.

💻 CLI Usage

To use the command-line interface, run the following command from your terminal in the project root. This command starts the cli-app container, runs the Python script, and automatically removes the container when you exit.

docker-compose run --rm cli-app python main.py

You will be presented with an interactive prompt CLI>. The available commands are:

  • genlifetime <productName>
  • gencad <productName> <days>
  • check <serialKey> [hwid]
  • help
  • exit

🛑 Stopping the Services

To stop all running containers, execute:

docker-compose down

If you also want to remove the database data (the Docker volume), use:

docker-compose down -v

About

A complete system for license key generation and validation, built with REST API, MongoDB, Discord Bot, and CLI, all orchestrated with Docker Compose

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published