Skip to content

adheizal/kvm-ui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

86 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

KVM-UI - Enterprise Edition

Version TypeScript Node Backward Compatible

Enterprise-grade web-based management tool for QEMU KVM virtual machines.

⚑ Quick Start

# Clone and setup
git clone <repository-url>
cd kvm-ui
cp .env.example .env

# Edit .env with your configuration
nano .env

# Start services
docker compose up -d

# Run migrations
docker compose exec app npm run migrate

# Create admin user
curl -X POST http://localhost:3000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": "your-password"}'

# Access application
open http://localhost:3000

πŸ”„ Backward Compatibility

Good news! Your existing v1.0 frontend works without any changes. v2.0 maintains full backward compatibility while adding a modern API.

  • βœ… Legacy endpoints work as-is
  • βœ… Cookie-based authentication maintained
  • βœ… Same response formats
  • πŸ†• Modern API with /api prefix available
  • πŸ†• JWT token authentication
  • πŸ†• Better error handling and validation

See BACKWARD_COMPATIBILITY.md for details.

πŸš€ Features

  • Modern Architecture: TypeScript + Clean Architecture patterns
  • JWT Authentication: Secure token-based authentication with RBAC ready
  • API-First Design: RESTful API with OpenAPI/Swagger documentation
  • Security: Rate limiting, input validation, helmet security headers
  • Logging: Structured logging with Winston
  • Health Checks: Comprehensive health check endpoints
  • Database Migrations: Automated schema migrations
  • Queue System: Background job processing for long-running operations
  • Testing: Jest-based testing framework
  • Code Quality: ESLint, Prettier, Husky pre-commit hooks

πŸ“‹ Prerequisites

πŸ”§ Installation

Using Docker Compose (Recommended)

  1. Clone the repository

    git clone <repository-url>
    cd kvm-ui
  2. Configure environment variables

    cp .env.example .env
    # Edit .env with your configuration
  3. Build Docker image and get SSH public key

    docker compose build app
    
    # The build will display an SSH public key
    # Copy this key for the next step
  4. Add SSH public key to KVM host

    # On your KVM host:
    mkdir -p ~/.ssh
    echo "ssh-ed25519 <YOUR_PUBLIC_KEY_FROM_BUILD> kvm-ui@buildkitsandbox" >> ~/.ssh/authorized_keys
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
    
    # Or use the helper script to retrieve the key:
    ./scripts/show-ssh-key.sh
  5. Start the services

    docker compose up -d
  6. Run database migrations

    docker compose exec app npm run migrate
  7. Create admin user

    curl -X POST http://localhost:3000/api/auth/register \
      -H "Content-Type: application/json" \
      -d '{"username": "admin", "password": "your-secure-password"}'

Manual Installation

  1. Install dependencies

    npm install
  2. Setup environment

    cp .env.example .env
    # Edit .env with your configuration
  3. Run database migrations

    npm run migrate
  4. Start development server

    npm run dev
  5. Build for production

    npm run build
    npm start

πŸ“š API Documentation

Once the server is running, visit:

  • API Documentation: http://localhost:3000/api/docs
  • Health Check: http://localhost:3000/api/health

API Endpoints

Authentication

  • POST /api/auth/register - Register new user (only first user)
  • POST /api/auth/login - Login user
  • POST /api/auth/logout - Logout user
  • GET /api/auth/me - Get current user info

VM Management

  • POST /api/vm/update-ip - Update VM IP address
  • DELETE /api/vm/delete-ip - Delete VM record
  • POST /api/vm/resize-disk - Resize VM disk
  • POST /api/vm/expose-ssh - Expose SSH to public
  • POST /api/vm/expose-service - Expose service to public
  • POST /api/vm/check-ip - Check IP availability
  • GET /api/vm/list - List all VMs

Health

  • GET /api/health - Basic health check
  • GET /api/health/detailed - Detailed health check

πŸ—οΈ Project Structure

kvm-ui/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/          # Configuration files
β”‚   β”œβ”€β”€ controllers/     # Request handlers
β”‚   β”œβ”€β”€ middlewares/     # Express middlewares
β”‚   β”œβ”€β”€ repositories/    # Data access layer
β”‚   β”œβ”€β”€ routes/          # API routes
β”‚   β”œβ”€β”€ services/        # Business logic layer
β”‚   β”œβ”€β”€ types/           # TypeScript types
β”‚   β”œβ”€β”€ utils/           # Utility functions
β”‚   β”œβ”€β”€ validators/      # Request validators
β”‚   β”œβ”€β”€ queues/          # Job queue definitions
β”‚   β”œβ”€β”€ workers/         # Job workers
β”‚   β”œβ”€β”€ app.ts           # Express app setup
β”‚   └── server.ts        # Server entry point
β”œβ”€β”€ migrations/          # Database migrations
β”œβ”€β”€ tests/               # Test files
β”œβ”€β”€ public/              # Static files
β”œβ”€β”€ script/              # Shell scripts
└── docker-compose.yaml  # Docker setup

πŸ§ͺ Testing

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

πŸ”’ Security Features

  • JWT Authentication: Token-based authentication
  • Rate Limiting: Prevent brute force attacks
  • Input Validation: Joi-based request validation
  • Helmet: Security headers
  • CORS: Cross-origin resource sharing configuration
  • Password Hashing: Bcrypt for secure password storage

πŸ“Š Monitoring

Health Check Endpoints

# Basic health check
curl http://localhost:3000/api/health

# Detailed health check
curl http://localhost:3000/api/health/detailed

Logs

Logs are stored in the logs/ directory:

  • all.log - All logs
  • error.log - Error logs only

πŸ”§ Development

Code Quality

# Lint code
npm run lint

# Fix linting issues
npm run lint:fix

# Format code
npm run format

# Type checking
npm run typecheck

Pre-commit Hooks

Husky is configured to run lint-staged before commits:

# Setup pre-commit hooks
npm run prepare

🐳 Docker

Build Image

docker build -t kvm-ui:latest .

Run with Docker Compose

docker compose up -d

View Logs

docker compose logs -f app

Stop Services

docker compose down

πŸ“ Configuration

See .env.example for all available configuration options:

  • SSH_HOST - Target QEMU KVM host IP
  • SSH_USER - SSH user for KVM host
  • JWT_SECRET - Secret key for JWT tokens
  • DB_HOST, DB_USER, DB_PASSWORD - PostgreSQL configuration
  • REDIS_HOST, REDIS_PASSWORD - Redis configuration

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

ISC

πŸ†˜ Troubleshooting

Database Connection Issues

# Check PostgreSQL is running
docker compose ps postgres

# View PostgreSQL logs
docker compose logs postgres

Redis Connection Issues

# Check Redis is running
docker compose ps redis

# View Redis logs
docker compose logs redis

Migration Issues

# Re-run migrations
docker compose exec app npm run migrate

πŸ“ž Support

For issues and questions, please open an issue on GitHub.

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors