Skip to content

A powerful, enterprise-grade multi-tenancy toolkit for modern SaaS applications, featuring a robust microservices architecture.

Notifications You must be signed in to change notification settings

Adamkaram/tenancyship

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Tenancyship πŸš€

New Project

A powerful, enterprise-grade multi-tenancy toolkit for modern SaaS applications, featuring a robust microservices architecture.

Core Features

πŸ”’ Secure Tenant Isolation

  • Database-per-tenant architecture
  • Robust authentication & authorization
  • Resource quotas and rate limiting

πŸ› οΈ Technology Stack

  • Database Layer: High-performance SurrealDB service powered by Rust/Axum
  • Application Layer: Go-based microservices with clean architecture
  • Infrastructure: Container orchestration with Podman/Kubernetes
  • Gateway: Advanced request routing with NGINX

🌟 Key Benefits

  • Seamless tenant management
  • Horizontal scalability
  • Zero-trust security model
  • Real-time analytics
  • Infrastructure as Code (IaC)

πŸ“ˆ Performance

  • Sub-millisecond tenant routing
  • Automatic failover
  • Load balancing
  • Connection pooling

Quick Links

Tenant Service

This project implements a tenant service using Rust, SurrealDB, and Kubernetes, with Terraform for infrastructure management.

Project Structure

tenancyship/
β”œβ”€β”€ db-service/                   # SurrealDB service with Rust/Axum
β”‚   β”œβ”€β”€ src/                      # Rust source code
β”‚   β”œβ”€β”€ Cargo.toml               # Rust dependencies
β”‚   └── Cargo.lock               # Rust lockfile
β”œβ”€β”€ tenant-service/              # Go tenant management service
β”‚   β”œβ”€β”€ go.mod                   # Go module definition
β”‚   β”œβ”€β”€ go.sum                   # Go dependencies checksum
β”‚   β”œβ”€β”€ cmd/                     # Command line applications
β”‚   β”‚   └── server/             # Main server application
β”‚   β”‚       └── main.go         # Server entrypoint
β”‚   β”œβ”€β”€ internal/               # Private application code
β”‚   β”‚   β”œβ”€β”€ api/               # API handlers and routes
β”‚   β”‚   β”œβ”€β”€ models/            # Data models
β”‚   β”‚   └── services/          # Business logic
β”‚   └── pkg/                    # Public packages
β”‚       └── tenant/            # Tenant management package
β”œβ”€β”€ terraform/                  # Infrastructure as code
β”‚   β”œβ”€β”€ main.tf                # Main Terraform configuration
β”‚   β”œβ”€β”€ variables.tf           # Variable definitions
β”‚   └── secrets/               # Environment-specific variables
β”‚       β”œβ”€β”€ template.tfvars    # Template for environment variables
β”‚       β”œβ”€β”€ dev.tfvars         # Development environment variables
β”‚       └── prod.tfvars        # Production environment variables
β”œβ”€β”€ k8s/                       # Kubernetes manifests
β”‚   β”œβ”€β”€ base/                  # Base configurations
β”‚   β”‚   β”œβ”€β”€ namespace.yaml     # Namespace definition
β”‚   β”‚   └── persistent-volumes.yaml # Persistent volume definitions
β”‚   β”œβ”€β”€ tenant-service/        # Tenant service configurations
β”‚   β”‚   └── base/              # Base tenant service configs
β”‚   β”œβ”€β”€ nginx/                 # Nginx configurations
β”‚   β”‚   └── base/              # Base nginx configs
β”‚   β”œβ”€β”€ redis/                 # Redis configurations
β”‚   β”‚   └── base/              # Base redis configs
β”‚   └── overlays/              # Environment-specific configurations
β”‚       β”œβ”€β”€ dev/               # Development environment
β”‚       └── prod/              # Production environment
└── scripts/                   # Utility scripts
    └── all-in-one.sh          # All-in-one management script

Prerequisites

  • Docker or Podman
  • Kubernetes cluster (or Minikube for local development)
  • Terraform
  • kubectl
  • kustomize (installed automatically by the management script)

Setup and Management

This project includes a comprehensive all-in-one management script that handles all aspects of development, deployment, and management.

Quick Start

# Make the script executable
chmod +x scripts/all-in-one.sh

# Create a convenient symlink
ln -sf scripts/all-in-one.sh ./manage

# Run the interactive menu
./manage

Interactive Menu

The management script provides an interactive menu system with the following options:

  1. Development Environment

    • Deploy using Kustomize
    • Deploy using Terraform + K8s
    • Show Kubernetes resources
    • Get pod logs
    • Restart deployments
    • Shell into a pod
    • Check SSL certificates
    • Clean up resources
  2. Production Environment

    • Same options as development (with confirmation prompts for safety)
  3. Local Development

    • Run application with Go or Podman
    • Run Rust tenant service
    • Deploy locally using docker-compose
  4. Tools & Setup

    • Install required tools
    • Set up development environment
    • Set up production environment

Command Line Usage

You can also use the script directly with commands:

# General syntax
./manage <command> [options]

Common commands:

# Install required tools
sudo ./manage install

# Set up development environment
./manage setup dev

# Deploy to development environment
./manage deploy dev

# Deploy to development with Kustomize
./manage kustomize dev

# Run local application (Go or Podman)
./manage run-local

# Run Rust tenant service
./manage run-rust

# Deploy locally with docker-compose
./manage deploy-local

# Check status of deployments
./manage status dev

# View logs from pods
./manage logs dev

# Open shell in a pod
./manage shell dev

# Check SSL certificates
./manage ssl-status dev

# Restart deployments
./manage restart dev

# Clean up resources
./manage cleanup dev

Kubernetes Structure

The Kubernetes configurations follow a Kustomize-based structure:

  • Base: Contains shared resources (namespace, persistent volumes)
  • Component Directories: Component-specific configurations:
    • tenant-service: Main backend service
    • nginx: Frontend proxy with SSL termination
    • redis: Caching layer
  • Overlays: Environment-specific configurations
    • dev: Development environment settings
    • prod: Production environment settings with higher replica counts

Local Development

For local development, you can use:

# Run the Go application directly
./manage run-local
# Select option 1 when prompted

# Run with docker-compose/podman-compose
./manage run-local
# Select option 2 when prompted

# Run the Rust tenant service
./manage run-rust

# Deploy locally with all services
./manage deploy-local

Secret Management

This project uses a multi-layered approach to secret management:

  1. Development: Environment variables or ConfigMaps
  2. Kubernetes: Kubernetes Secrets mounted as files
  3. Terraform: Terraform variables for infrastructure secrets

Customization

Adding New Components

  1. Create a new directory in k8s/ for your component
  2. Add base manifests in a base/ subdirectory
  3. Update overlays to include your component
  4. Deploy using ./manage kustomize dev

Adding New Environments

  1. Create a new directory in k8s/overlays/ for your environment
  2. Copy files from an existing environment as templates
  3. Set up Terraform variables: ./manage setup <new-env>
  4. Deploy to the new environment: ./manage deploy <new-env>

Troubleshooting

The management script includes built-in troubleshooting capabilities:

# Check deployment status
./manage status dev

# View pod logs
./manage logs dev

# Shell into a pod for debugging
./manage shell dev

Common issues and solutions:

  1. Connection to database fails: Check the database credentials in your ConfigMap or environment variables
  2. Kubernetes pods not starting: Check pod status and logs with ./manage status dev and ./manage logs dev
  3. Terraform errors: Ensure your .tfvars file has all required variables

For more detailed troubleshooting, check the README files in each component directory:

  • k8s/README.md: Overview of Kubernetes structure
  • k8s/tenant-service/README.md: Tenant service details
  • k8s/nginx/README.md: Nginx proxy details
  • k8s/redis/README.md: Redis cache details
  • scripts/README-all-in-one.md: Detailed usage of the management script

About

A powerful, enterprise-grade multi-tenancy toolkit for modern SaaS applications, featuring a robust microservices architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published