Skip to content

pkeffect/dev-server

Repository files navigation

πŸš€ Multi-Server Development Environment v1.2.0

Status Version License

A containerized development environment for testing and developing applications across multiple server technologies simultaneously. This project provides hot-reloading development servers for HTML/CSS/JS, Python (Flask and FastAPI), and Node.js Express, all running in Docker containers with a unified dashboard for monitoring.

Dashboard Preview

πŸ“‹ Table of Contents

✨ Features

  • Beautiful UI: Dark and light theme with modern component library
  • Cross-platform compatibility: All services run in Docker containers
  • Hot reloading: All servers automatically reload when code changes
  • Unified dashboard: Monitor all services in one interface
  • Standardized API endpoints: Common patterns across all server implementations
  • CORS enabled: All services configured for cross-origin requests
  • Health checks: Docker health checks implemented for all services
  • API testing tools: Built-in interface for testing endpoints
  • Theme switching: Toggle between dark and light themes with persistent preferences
  • Loading screen: Smooth page load experience with animated loading indicator
  • Responsive Layout: Mobile-friendly design with adaptive components
  • Git workflow: Complete Git configuration with hooks, templates, and CI/CD

πŸ—οΈ Architecture

The development environment consists of the following components:

Service Technology Port Purpose
Dashboard HTML/JS/CSS (Live Server) 8081 Monitor all services
Flask API Python Flask 8082 Python web framework
FastAPI Python FastAPI 8083 Modern Python API framework
Node.js API Express.js 8084 JavaScript API server
Reverse Proxy Nginx (optional) 8080 Unified routing

πŸš€ Quick Start

Prerequisites

  • Docker and Docker Compose installed
  • Git for version control

Installation

  1. Clone the repository:

    git clone https://github.com/pkeffect/dev-server.git
    cd dev-environment
  2. Create an environment file:

    cp .env.example .env
  3. Set up Git hooks (optional but recommended):

    chmod +x .githooks/pre-commit
    git config core.hooksPath .githooks
  4. Build and start all services:

    docker-compose up --build
  5. Access the dashboard:

πŸ”Œ Service Access Points

Click to expand all service endpoints

🎨 UI Features

  • Dark & Light Themes: Toggle between themes with persistent preferences that respect system settings
  • Modern UI Components: Buttons, cards, alerts, badges, dropdowns, forms and more
  • Loading Screen: Smooth page load experience with animated loading indicator
  • Responsive Layout: Mobile-friendly design with adaptive components
  • Interactive Dashboard: Real-time service status monitoring
  • API Testing Panel: Built-in interface for testing endpoints across all services
  • GitHub-Inspired Design: Familiar, clean interface for developers

πŸ’» Development Workflow

Project Structure

dev-environment/
β”œβ”€β”€ app_flask.py              # Flask application
β”œβ”€β”€ app_fastapi.py            # FastAPI application
β”œβ”€β”€ app_node.js               # Node.js Express application
β”œβ”€β”€ Dockerfile                # Multi-stage Docker build
β”œβ”€β”€ compose.yml               # Docker Compose configuration
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ package.json              # Node.js dependencies
β”œβ”€β”€ .env.example              # Environment variables template
β”œβ”€β”€ .gitignore                # Git ignore patterns
β”œβ”€β”€ .gitattributes            # Git attributes configuration
β”œβ”€β”€ .githooks/                # Git hooks
β”‚   └── pre-commit            # Pre-commit hook
β”œβ”€β”€ .github/                  # GitHub configuration
β”‚   β”œβ”€β”€ workflows/            # GitHub Actions
β”‚   β”‚   └── ci.yml            # CI workflow
β”‚   β”œβ”€β”€ ISSUE_TEMPLATE/       # Issue templates
β”‚   └── PULL_REQUEST_TEMPLATE.md # PR template
β”œβ”€β”€ healthcheck.sh            # Health check script
β”œβ”€β”€ nginx/                    # Nginx configuration
β”‚   └── nginx.conf            # Reverse proxy setup
β”œβ”€β”€ src/                      # Front-end source files
β”‚   β”œβ”€β”€ index.html            # Dashboard HTML
β”‚   β”œβ”€β”€ css/                  # CSS styles
β”‚   β”‚   β”œβ”€β”€ main.css          # Main shared styles
β”‚   β”‚   β”œβ”€β”€ components.css    # UI component styles
β”‚   β”‚   β”œβ”€β”€ dark-theme.css    # Dark theme styles
β”‚   β”‚   β”œβ”€β”€ light-theme.css   # Light theme styles
β”‚   β”‚   β”œβ”€β”€ dashboard.css     # Dashboard-specific styles
β”‚   β”‚   β”œβ”€β”€ utilities.css     # Utility classes
β”‚   β”‚   └── loading.css       # Loading screen styles
β”‚   β”œβ”€β”€ js/                   # JavaScript files
β”‚   β”‚   β”œβ”€β”€ main.js           # Main functionality
β”‚   β”‚   β”œβ”€β”€ theme.js          # Theme switching logic
β”‚   β”‚   β”œβ”€β”€ dashboard.js      # Dashboard functionality
β”‚   β”‚   └── loading.js        # Loading screen manager
β”‚   β”œβ”€β”€ img/                  # Images directory
β”‚   β”‚   └── icons/            # SVG icons
β”‚   └── api.html              # Live Server API endpoint
└── tests/                    # Testing utilities
    β”œβ”€β”€ api_tests.sh          # Bash test suite
    β”œβ”€β”€ test_suite.py         # Python test suite
    β”œβ”€β”€ test_flask.py         # Flask-specific tests
    β”œβ”€β”€ conftest.py           # pytest configuration
    └── node-tests.js         # Node.js tests

Making Changes

All code is mounted as volumes in the Docker containers, so changes to files will automatically trigger server reloads:

  • HTML/CSS/JS: Edit files in the src/ directory
  • Python (Flask/FastAPI): Edit app_flask.py or app_fastapi.py
  • Node.js: Edit app_node.js

Adding Dependencies

  • Python: Add to requirements.txt and restart the containers
  • Node.js: Add to package.json and restart the containers

Environment Variables

Configure your development environment by editing the .env file:

View example environment configuration
# Server Configurations
FLASK_ENV=development
FLASK_DEBUG=1
NODE_ENV=development

# API Keys (for demonstration)
DEMO_API_KEY=your_api_key_here

# Database Configuration (if needed)
DB_HOST=localhost
DB_PORT=5432
DB_NAME=devdb
DB_USER=devuser
DB_PASSWORD=devpassword

πŸ“ API Documentation

All services implement the following standard endpoints:

View API endpoints

Root Endpoint

GET /

Returns basic service information:

{
  "message": "Hello from [Service]!",
  "service": "[Service Name]",
  "environment": "development",
  "version": "1.0.0"
}

Health Check

GET /health

Returns service health status:

{
  "status": "healthy",
  "service": "[Service Name]"
}

Echo Endpoint

POST /echo

Body:

{
  "message": "Hello world",
  "data": { "key": "value" }
}

Response:

{
  "echo": {
    "message": "Hello world",
    "data": { "key": "value" }
  },
  "service": "[Service Name]"
}

FastAPI Documentation

FastAPI automatically generates interactive API documentation:

πŸ§ͺ Testing

Dashboard Testing

The dashboard provides an interactive way to test all services:

  1. Open http://localhost:8081
  2. Use the "Test" buttons for individual services
  3. Click "Test All Services" for a comprehensive check
  4. Use the API Testing panel for custom endpoint tests
View command line testing options

Command Line Testing

Bash Script

# Run the bash test suite
./tests/api_tests.sh

Python Script

# Run the Python test suite
python tests/test_suite.py

Node.js Tests

# Run the Node.js tests
npm test

Flask and FastAPI Tests

# Run the Flask tests
docker-compose exec flask-dev pytest tests/test_flask.py

# Run the FastAPI tests 
docker-compose exec fastapi-dev pytest

🐳 Managing Containers

View Docker management commands

Starting Services

# Start all services
docker-compose up

# Start in detached mode
docker-compose up -d

# Start a specific service
docker-compose up flask-dev

Stopping Services

# Stop all services
docker-compose down

# Stop and remove volumes
docker-compose down -v

Viewing Logs

# View logs from all services
docker-compose logs

# Follow logs
docker-compose logs -f

# View logs for a specific service
docker-compose logs flask-dev

πŸš„ Performance Optimization

This environment includes several performance optimizations:

FastAPI Resource Management

The FastAPI service includes CPU and memory limits to prevent resource contention:

deploy:
  resources:
    limits:
      cpus: '0.5'
      memory: 256M
    reservations:
      cpus: '0.25'
      memory: 128M

Optimized Asset Loading

The dashboard implements:

  • Progressive loading of resources
  • Efficient theme switching without page reloads
  • Preloading of critical JavaScript
  • Optimized SVG icons

Development vs. Production Settings

For development, use the included hot-reload settings. For production, consider:

  1. Disabling hot-reload flags (--reload)
  2. Adjusting worker counts based on available CPU cores
  3. Setting appropriate logging levels

πŸ”’ Security Considerations

Container Security

The Dockerfile includes options for running containers as non-root users:

# --- Create non-root user and group ---
RUN addgroup -S dev-group && adduser -S dev-user -G dev-group

# --- Change ownership of the application directory ---
RUN chown -R dev-user:dev-group /app

# --- Switch to the non-root user ---
USER dev-user

Uncomment these sections for improved container security in production.

Environment Variables

Ensure sensitive information is stored in .env files and never committed to version control. The .gitignore file excludes .env files by default:

# Environment variables
.env
.env.*
!.env.example

πŸ”„ Git Configuration

This project includes a complete Git workflow setup:

  • .gitignore: Comprehensive ignore patterns for development files
  • .gitattributes: Line ending normalization and file handling
  • GitHub Workflows: Automated CI/CD with GitHub Actions
  • Issue & PR Templates: Standardized formats for contributions
  • Git Hooks: Pre-commit validation for code quality
View Git setup instructions

Setting Up Git Hooks

# Make git hooks executable
chmod +x .githooks/pre-commit

# Set hooks path
git config core.hooksPath .githooks

Branch Strategy

Follow the GitHub Flow branching strategy:

  1. Create a feature branch from main
  2. Make changes and commit
  3. Push branch and create a Pull Request
  4. After review, merge to main

For detailed instructions, see GIT_SETUP.md.

πŸ”§ Troubleshooting

View common issues and solutions

Common Issues

Service Not Starting

Check the Docker logs:

docker-compose logs [service-name]

Hot Reloading Not Working

Ensure the correct volume mounts are in place and file permissions are correct:

docker-compose down
docker-compose up --build

Cannot Access Service

Verify the port mappings in compose.yml and check if the container is running:

docker-compose ps

Theme Switching Not Working

Check browser console for errors in theme.js. Local storage might be disabled or full.

Live Server Test Failing

Ensure the src/api.html file exists for the Live Server API endpoint. If the test still fails, check the browser console for CORS errors.

CI Pipeline Failing

Check the GitHub Actions logs for detailed error information. Common issues include:

  • Missing test files or incorrect paths
  • Import errors in Python tests
  • Timing issues with service startup

Health Checks

Each service has built-in health checks that Docker uses to monitor container status:

# View container health
docker ps

πŸ‘₯ Contributing

We welcome contributions to this project! Please follow these steps:

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

Please read our Code of Conduct and Security Policy before contributing.

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❀️ for developers

About

private - proof of concept before release

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published