Skip to content

aryanrangapur/Multi-Tenant-PrestaShop-SaaS-Server

PrestaShop Multi-Tenant SaaS Platform

A scalable infrastructure that dynamically provisions isolated PrestaShop e-commerce instances with automated deployment, containerization, and database management.

Features

  • Multi-tenant Architecture: Each store runs in isolated Docker containers with dedicated databases
  • Automated Deployment: Deploy fully functional PrestaShop instances in under 2 minutes
  • Dynamic Port Allocation: Automatic port discovery starting from 8081
  • Containerized Isolation: Dedicated MySQL database for each tenant
  • Scalable Design: Support for hundreds of isolated stores
  • Simple Management: Clean web interface for store creation

Architecture

Frontend (Next.js) β†’ Backend (Flask) β†’ Docker Engine β†’ PrestaShop + MySQL Containers

Each tenant gets:

  • Dedicated PrestaShop container
  • Isolated MySQL database
  • Unique port assignment
  • Separate Docker network

Tech Stack

  • Backend: Flask, Python
  • Frontend: Next.js, React, TypeScript, Tailwind CSS
  • Containerization: Docker, Docker Compose
  • Database: MySQL 5.7
  • E-commerce: PrestaShop 8.1.6

Prerequisites

  • Docker & Docker Compose
  • Python 3.8+
  • Node.js 18+

Quick Start

Local Development

  1. Clone the repository
git clone https://github.com/aryanrangapur/Multi-Tenant-PrestaShop-SaaS-Server.git
cd Multi-Tenant-PrestaShop-SaaS-Server
  1. Start the Backend
cd backend
python -m venv venv

# On Windows:
venv\Scripts\activate
# On Mac/Linux:
source venv/bin/activate

pip install -r requirements.txt
python app.py
  1. Start the Frontend (in a new terminal)
cd frontend
npm install
npm run dev
  1. Access the Application

Using Docker Compose (Recommended)

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

☁️ AWS Deployment

Simple EC2 Deployment

  1. Launch EC2 Instance

    • AMI: Amazon Linux 2023
    • Instance Type: t3.medium (minimum)
    • Storage: 30GB+
    • Security Group: Open ports 22, 3000, 5000, 8081-8100
  2. Deploy with One Command

# Connect to your EC2 instance
ssh -i your-key.pem ec2-user@YOUR_EC2_IP

# Install Docker and deploy
sudo yum update -y
sudo yum install docker -y
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -a -G docker ec2-user

# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

# Clone and deploy
git clone https://github.com/aryanrangapur/Multi-Tenant-PrestaShop-SaaS-Server.git
cd Multi-Tenant-PrestaShop-SaaS-Server
docker-compose up -d
  1. Access Your Application
  • Frontend: http://YOUR_EC2_IP:3000
  • Backend API: http://YOUR_EC2_IP:5000
  • Stores: http://YOUR_EC2_IP:8081, http://YOUR_EC2_IP:8082, etc.

Usage

  1. Access the frontend at http://localhost:3000

  2. Enter admin credentials (email and password) for your new store

  3. Click "Deploy Store" - the system will:

    • Create isolated Docker containers
    • Setup MySQL database
    • Configure PrestaShop
    • Return store URLs
  4. Access your store using the provided URLs:

    • Store Frontend: http://localhost:8081 (or assigned port)
    • Admin Panel: http://localhost:8081/admin-xxxx

πŸ”§ API Endpoints

Create Store

POST /create-store
Content-Type: application/json

{
  "email": "[email protected]",
  "password": "securepassword"
}

Response:

{
  "url": "http://localhost:8081",
  "admin_url": "http://localhost:8081/admin123",
  "admin_email": "[email protected]",
  "admin_password": "securepassword"
}

Health Check

GET /health

Response:

{
  "status": "healthy"
}

Project Structure

Multi-Tenant-PrestaShop-SaaS-Server/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app.py                 # Flask backend server
β”‚   β”œβ”€β”€ requirements.txt       # Python dependencies
β”‚   β”œβ”€β”€ Dockerfile            # Backend container definition
β”‚   └── .env.example          # Environment variables template
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ layout.tsx        # Root layout
β”‚   β”‚   β”œβ”€β”€ page.tsx          # Main page component
β”‚   β”‚   └── globals.css       # Global styles
β”‚   β”œβ”€β”€ package.json          # Node.js dependencies
β”‚   β”œβ”€β”€ Dockerfile            # Frontend container definition
β”‚   β”œβ”€β”€ tailwind.config.js    # Tailwind CSS configuration
β”‚   └── .env.example          # Environment variables template
β”œβ”€β”€ docker-compose.yml        # Multi-container setup
β”œβ”€β”€ README.md                 # This file
└── .gitignore               # Git ignore rules

Docker Configuration

Backend Service

  • Port: 5000
  • Environment: BASE_PORT, TENANTS_DIR
  • Volumes: Docker socket, tenants directory

Frontend Service

  • Port: 3000
  • Environment: BACKEND_URL
  • Depends on: Backend service

Store Containers (Auto-created)

  • Port Range: 8081-8100+
  • Services: PrestaShop + MySQL per store
  • Networks: Isolated per tenant

Environment Variables

Backend (.env)

BASE_PORT=8081
TENANTS_DIR=./tenants

Frontend (.env)

NEXT_PUBLIC_BACKEND_URL=http://localhost:5000

Maintenance

Stop and Cleanup

# Stop all services (preserves data)
docker-compose down

# Stop and remove all data (⚠️ Destructive)
docker-compose down -v

# Clean up individual tenant
cd backend/tenants/tenantX
docker-compose down -v

View Logs

# Application logs
docker-compose logs -f

# Individual store logs
docker logs tenant1_shop
docker logs tenant1_db

Important Notes

  • Docker must be running before creating stores
  • Ports 8081-8100 should be available for store instances
  • Admin credentials are stored in the database - use strong passwords
  • Data persistence uses Docker volumes - backup regularly
  • For production: Add SSL, authentication, and monitoring

Troubleshooting

Store not accessible?

  • Wait 1-2 minutes for full initialization
  • Check Docker container status: docker ps
  • View container logs: docker logs container_name

Port already in use?

  • The system automatically finds the next available port
  • Ensure ports 8081-8100 are not occupied by other services

Docker compose errors?

  • Ensure Docker and Docker Compose are properly installed
  • Check permissions for Docker socket

License

MIT License - see repository for details.

About

This project sets up a multi-tenant SaaS platform for PrestaShop, dynamically provisioning isolated Docker environments for each store via a Flask backend.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors