Skip to content

utej8553/DBrift-main

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

38 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DBrift - Database-as-a-Service Platform

Overview

DBrift is a full-stack Database-as-a-Service (DBaaS) platform that empowers developers to dynamically create, manage, and provision isolated database instances through an intuitive web interface. No manual database installation or configuration neededβ€”just sign up, log in, and launch your database in seconds.

This project demonstrates real-world full-stack development by integrating Spring Boot backend orchestration, React frontend UI, Docker containerization, and cloud-ready deployment patterns.


🎯 Key Features

User Management

  • User Registration & Authentication: Secure sign-up and login with credential management
  • User Dashboard: Centralized hub to view and manage all provisioned databases

Database Provisioning

  • One-Click Database Creation: Instantly provision database instances with selected type and version
  • Automatic Container Management: Backend automatically launches isolated Docker containers for each database
  • Unique Port Assignment: Each database is assigned a unique port for secure isolation
  • Credential Generation: Automatic username/password generation with secure storage
  • Database Metadata Storage: All database information persisted and easily accessible

Database Management

  • Database Listing: View all active databases with connection details
  • Connection Information: Display generated credentials (host, port, username, password)
  • Database Deletion: Safe cleanup and container removal to prevent resource conflicts
  • Lifecycle Management: Full control over database instance lifecycle

Infrastructure & DevOps

  • Docker-Based Isolation: Each database runs in an isolated container for maximum security and portability
  • Resource Efficiency: Lightweight containerization enables multiple databases on single host
  • Fast Provisioning: Container-based approach enables near-instant database deployment
  • Clean Lifecycle: Automated cleanup prevents resource leaks and port conflicts

πŸ—οΈ Architecture

System Components

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Frontend (React/Vite)                   β”‚
β”‚  - Authentication UI (Login/Sign-up)                        β”‚
β”‚  - Database Dashboard                                       β”‚
β”‚  - Database Creation Panel                                  β”‚
β”‚  - Connection Details Display                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                   (REST API via HTTP)
                            β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Backend (Spring Boot)                      β”‚
β”‚  - User Service & Repository                                β”‚
β”‚  - Database Service & Repository                            β”‚
β”‚  - Authentication & Authorization                           β”‚
β”‚  - Database Provisioning Logic                              β”‚
β”‚  - Docker Container Orchestration                           β”‚
β”‚  - Port Management & Credential Generation                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
              (Docker API / Container Runtime)
                            β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Infrastructure Layer                      β”‚
β”‚  - Docker Engine                                            β”‚
β”‚  - Containerized Database Instances                         β”‚
β”‚  - Isolated Networks & Port Mappings                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

  1. User Registration: Frontend β†’ Backend β†’ Database Storage
  2. Database Creation: Frontend β†’ Backend β†’ Docker API β†’ Container Launch
  3. Database Retrieval: Frontend β†’ Backend β†’ Database Query β†’ Dashboard Display
  4. Database Deletion: Frontend β†’ Backend β†’ Container Stop/Remove β†’ Metadata Cleanup

πŸ’» Technology Stack

Backend

  • Framework: Spring Boot (Java)
  • Database Persistence: JPA/Hibernate with SQL database
  • Container Orchestration: Docker API integration
  • Build Tool: Maven
  • Port Management: Dynamic port allocation system

Frontend

  • Framework: React 18 with Vite
  • Styling: CSS3 with custom animations
  • State Management: React Context API
  • HTTP Client: Axios for REST API communication
  • UI Components: Custom React components with smooth transitions

Infrastructure

  • Containerization: Docker
  • Supported Database Types: PostgreSQL, MySQL, MongoDB (extensible)
  • Isolation: Container-based network isolation
  • Lifecycle: Automated provisioning and cleanup

πŸš€ Getting Started

Prerequisites

  • Node.js 16+ (for frontend development)
  • Java 11+ (for backend)
  • Maven 3.6+ (for backend builds)
  • Docker Desktop (for container management)
  • Git

Installation & Setup

1. Clone the Repository

git clone <repository-url>
cd DBrift-demo2

2. Backend Setup

cd backend

# Build the backend
mvn clean install

# Run the backend (default port: 8080)
mvn spring-boot:run

The backend API will be available at http://localhost:8080

3. Frontend Setup

cd Frontend

# Install dependencies
npm install

# Run development server (default port: 5173)
npm run dev

The frontend will be available at http://localhost:5173

4. Docker Setup

Ensure Docker Desktop is running. The backend will use Docker API to provision database containers.

Quick Start

  1. Navigate to http://localhost:5173 in your browser
  2. Sign up for a new account
  3. Log in with your credentials
  4. Click "Create Database" to provision a new database
  5. Select database type and configuration
  6. Access your database connection details from the dashboard
  7. Use the provided credentials to connect externally (via DBeaver, psql, mysql client, etc.)

πŸ“ Project Structure

DBrift-demo2/
β”œβ”€β”€ backend/                          # Spring Boot Application
β”‚   β”œβ”€β”€ src/main/java/org/utej/backend/
β”‚   β”‚   β”œβ”€β”€ BackendApplication.java           # Main Spring Boot entry point
β”‚   β”‚   β”œβ”€β”€ User.java                         # User entity model
β”‚   β”‚   β”œβ”€β”€ UserService.java                  # User business logic
β”‚   β”‚   β”œβ”€β”€ UserController.java               # User REST endpoints
β”‚   β”‚   β”œβ”€β”€ UserRepository.java               # User data access layer
β”‚   β”‚   β”œβ”€β”€ Database.java                     # Database entity model
β”‚   β”‚   β”œβ”€β”€ DatabaseService.java              # Database provisioning logic
β”‚   β”‚   β”œβ”€β”€ DatabaseController.java           # Database REST endpoints
β”‚   β”‚   β”œβ”€β”€ DatabaseRepository.java           # Database data access layer
β”‚   β”‚   β”œβ”€β”€ CreateDatabaseRequest.java        # DTO for database creation
β”‚   β”‚   β”œβ”€β”€ LoginRequest.java                 # DTO for authentication
β”‚   β”‚   β”œβ”€β”€ GlobalPorts.java                  # Port management system
β”‚   β”‚   └── GlobalPorts.java                  # Port allocation logic
β”‚   β”œβ”€β”€ src/main/resources/
β”‚   β”‚   β”œβ”€β”€ application.properties            # Spring Boot configuration
β”‚   β”‚   └── infra/scripts/postgres/           # Database setup scripts
β”‚   β”œβ”€β”€ pom.xml                       # Maven dependencies
β”‚   └── mvnw                          # Maven wrapper
β”‚
β”œβ”€β”€ Frontend/                         # React Application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/               # React components
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginForm.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ SignupForm.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ DatabaseGrid.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ CreateDatabasePanel.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ CredentialsDisplay.jsx
β”‚   β”‚   β”‚   └── TopNav.jsx
β”‚   β”‚   β”œβ”€β”€ pages/                    # Page components
β”‚   β”‚   β”‚   β”œβ”€β”€ AuthPage.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ DashboardPage.jsx
β”‚   β”‚   β”‚   └── LandingPage.jsx
β”‚   β”‚   β”œβ”€β”€ context/                  # React Context (state management)
β”‚   β”‚   β”‚   └── AuthContext.jsx
β”‚   β”‚   β”œβ”€β”€ services/                 # API service layer
β”‚   β”‚   β”‚   └── api.js
β”‚   β”‚   β”œβ”€β”€ styles/                   # CSS stylesheets
β”‚   β”‚   β”œβ”€β”€ App.jsx                   # Root component
β”‚   β”‚   └── main.jsx                  # Vite entry point
β”‚   β”œβ”€β”€ package.json                  # Node dependencies
β”‚   β”œβ”€β”€ vite.config.js                # Vite configuration
β”‚   └── index.html                    # HTML entry point
β”‚
β”œβ”€β”€ run.sh                            # Start both backend and frontend
β”œβ”€β”€ close.sh                          # Stop services
└── README.md                         # This file

πŸ”Œ API Documentation

Authentication Endpoints

Register User

POST /api/users/register
Content-Type: application/json

{
  "username": "john_doe",
  "password": "secure_password"
}

Login User

POST /api/users/login
Content-Type: application/json

{
  "username": "john_doe",
  "password": "secure_password"
}

Database Endpoints

Create Database

POST /api/databases/create
Content-Type: application/json
Authorization: Bearer <token>

{
  "databaseType": "postgres",
  "version": "15",
  "userId": "<user_id>"
}

Get User Databases

GET /api/databases/<userId>
Authorization: Bearer <token>

Delete Database

DELETE /api/databases/<databaseId>
Authorization: Bearer <token>

For detailed API documentation, see API_DOCUMENTATION.md


🐳 Docker Integration

How It Works

  1. Database Request: User submits database creation request via frontend
  2. Backend Processing: Spring Boot service receives request
  3. Port Allocation: System assigns available port from pool
  4. Container Launch: Docker API creates new container with:
    • Selected database image (PostgreSQL, MySQL, etc.)
    • Assigned port mapping
    • Auto-generated credentials
    • Persistent volume (if configured)
  5. Metadata Storage: Database connection info stored in application database
  6. Frontend Display: User sees credentials and connection details

Container Lifecycle

  • Create: Automated on database provisioning request
  • Run: Continuous execution until deletion
  • Delete: Safe cleanup with container stop and removal
  • Cleanup: Automatic port deallocation and metadata removal

πŸ› οΈ Development

Optimized Architecture: Database-Based Container Strategy

Current Approach: Each user's database request creates a new isolated Docker container.

Optimal Enhancement Strategy: Instead of creating multiple individual Docker containers per user database, optimize resource utilization by:

  1. Shared Database Containers: Create containerized database instances (one container per database type/version combination)
  2. Per-User Database Provisioning: Within each container, create individual databases for each user
  3. Credential Management: Generate unique usernames and passwords for each user
  4. Permission Assignment: Grant granular permissions to each user's database within the container
  5. Resource Efficiency: Multiple user databases coexist within a single container, reducing:
    • Container overhead
    • Memory footprint
    • Host system resource consumption
    • Port allocation pressure

Benefits of Database-Based Approach:

  • βœ… Reduced Resource Usage: One shared container vs. multiple individual containers
  • βœ… Better Scalability: Serve more users with fewer resources
  • βœ… Simplified Management: Centralized database administration
  • βœ… Cost Efficiency: Lower infrastructure costs for cloud deployments
  • βœ… Improved Performance: Reduced context switching and virtualization overhead
  • βœ… Easier Backups: Single container backup covers multiple user databases
  • βœ… Faster Provisioning: Database/user creation faster than container creation

This strategy maintains full isolation at the database/user level while optimizing at the container infrastructure level, making DBrift more production-ready for scale.


Backend Development

cd backend

# Build without running
mvn clean package

# Run tests
mvn test

# Run with debug mode
mvn spring-boot:run -Dspring-boot.run.arguments="--debug"

Frontend Development

cd Frontend

# Development server with hot reload
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

Useful Docker Commands

# View running containers
docker ps

# View all containers (including stopped)
docker ps -a

# View logs for a database container
docker logs <container_id>

# Stop all containers
docker stop $(docker ps -q)

# Remove all containers
docker rm $(docker ps -aq)

About

A Cloud-Native Database-as-a-Service Platform Using Containerized Infrastructure

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors