protoframework/proto-project

This is a project that uses the Proto Framework.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Language:JavaScript

Type:project

1.0.3 2025-08-07 06:06 UTC

This package is auto-updated.

Last update: 2025-08-09 00:46:21 UTC


README

This repository is a project skeleton for building applications on top of the Proto Framework. It wires up Composer, your folder structure, and a minimal entrypoint so you can start writing modules and apps right away.

οΏ½ Prerequisites

For Containerized Development (Recommended)

For Traditional Development

  • PHP 8.2+
  • Composer
  • MySQL/MariaDB
  • Node.js (for frontend development)

Framework Requirements

  • Proto Framework: v1.0.15+ (includes enhanced Email/SMTP support)
  • PHPMailer: Included with Proto framework for universal email sending

οΏ½πŸ“¦ Installation

Choose one of the two approaches:

1. Create a brand-new project via Composer

composer create-project protoframework/proto-project my-app
cd my-app
composer install

2. Clone & install

git clone https://github.com/protoframework/proto-project.git my-app
cd my-app
composer install

🐳 Local Development (Hybrid Setup)

This project uses a hybrid development approach that combines the best of both worlds:

  • Backend services run in Docker containers (no local PHP/MySQL needed)
  • Frontend apps run locally with Vite for lightning-fast hot reload

Configuration Sync

First, sync your Proto configuration to Docker:

# Generate Docker .env from Proto configuration
./run.sh sync-config

# Or run directly: node sync-config.js

Quick Start

1. Start Backend Services:

docker-compose up -d

✨ New: Database migrations now run automatically when the container starts! This ensures your database schema is always up-to-date. To disable this behavior, set AUTO_MIGRATE=false in your .env file.

2. Start Frontend Apps (in separate terminals):

# Main App
cd apps/main
npm install  # (first time only)
npm run dev

# CRM App
cd apps/crm
npm install  # (first time only)
npm run dev

# Developer App
cd apps/developer
npm install  # (first time only)
npm run dev

Available Services

Service URL Description
🌐 Main App http://localhost:3000 Main application (Vite dev server)
🌐 CRM App http://localhost:3001 CRM interface (Vite dev server)
🌐 Developer Tools http://localhost:3002 Developer UI with scaffolding tools (Vite dev server)
πŸš€ API Server http://localhost:8080 PHP backend API (containerized)
πŸ—„οΈ PHPMyAdmin http://localhost:8081 Database management interface
πŸ—„οΈ Database localhost:3307 MariaDB 11.7.2 server
πŸ“ Cache localhost:6380 Redis server

Development Workflow

Backend Changes:

# View API logs
docker-compose logs -f web

# Access PHP container
docker-compose exec web bash

# Restart backend if needed
docker-compose restart web

# Manual migration control (if AUTO_MIGRATE=false)
docker-compose exec web php infrastructure/scripts/run-migrations.php

Frontend Changes:

  • Edit any .js, .css, or other frontend files
  • Changes appear instantly in browser (hot module reload)
  • No need to restart anything!

Database Management:

# Access database directly
docker-compose exec mariadb mariadb -uroot -proot proto

# Or use phpMyAdmin at http://localhost:8081

Why This Approach?

βœ… Lightning Fast HMR: Native Vite performance on your host machine βœ… Instant Updates: File changes reflect immediately in browser βœ… Clean Architecture: Backend and frontend properly separated βœ… Easy API Access: Frontend apps automatically proxy /api requests to containerized backend βœ… No Setup Complexity: No need for local PHP/MySQL installation βœ… Auto-Migration: Database schema automatically updates on container start

For detailed setup instructions, see infrastructure/docs/DEVELOPMENT.md.

πŸ€– Automated Features

The Docker setup includes several automation features to streamline development:

Build-Time Automation

When you build the Docker image (docker-compose build), the following happens automatically:

  • βœ… Configuration Sync: Reads common/Config/.env and generates Docker environment variables
  • βœ… PHP Validation: Checks PHP syntax across the codebase
  • βœ… Apache Module Setup: Enables all required modules for .htaccess functionality
  • βœ… Build Verification: Ensures all critical files and directories are present

Runtime Automation

When you start the container (docker-compose up), the following happens automatically:

  • βœ… Service Dependencies: Waits for database and Redis to be ready before starting
  • βœ… Database Migrations: Runs pending migrations automatically (configurable)
  • βœ… Health Checks: Verifies autoloader and critical dependencies
  • βœ… Apache Startup: Starts Apache with optimized configuration

Migration Control

By default, database migrations run automatically for convenience:

# Default behavior - migrations run automatically
docker-compose up -d

For production or when you want manual control:

# Disable auto-migrations
echo "AUTO_MIGRATE=false" >> .env
docker-compose up -d

# Then run migrations manually when ready
docker-compose exec web php infrastructure/scripts/run-migrations.php

SSL Setup (Manual)

For security reasons, SSL certificate setup remains manual:

# Set up SSL certificates (production only)
./run.sh setup-ssl yourdomain.com your-email@yourdomain.com

This automation makes the development experience much smoother while maintaining production safety controls.

πŸ—οΈ Directory Layout

proto-project/
β”œβ”€ apps/                   # Frontend PWAs (main, crm, developer)
β”œβ”€ common/                 # Shared Proto framework code
β”œβ”€ modules/                # Proto framework feature modules
β”œβ”€ public/                 # HTTP entrypoints & public assets
β”œβ”€ vendor/                 # Composer dependencies
β”œβ”€ infrastructure/         # Development & deployment infrastructure
β”‚  β”œβ”€ config/              # Configuration files
β”‚  β”‚  β”œβ”€ domain.config.js  # Domain configuration system
β”‚  β”‚  β”œβ”€ docker-compose.prod.yaml # Production Docker setup
β”‚  β”‚  └─ docker-compose.traefik.yaml # Traefik reverse proxy
β”‚  β”œβ”€ docker/              # Docker-related files
β”‚  β”‚  β”œβ”€ apache-subdomain.conf # Apache virtual host config
β”‚  β”‚  β”œβ”€ apache-vhost.conf # Standard Apache config
β”‚  β”‚  β”œβ”€ php/              # PHP configuration
β”‚  β”‚  └─ mysql/            # MySQL initialization scripts
β”‚  β”œβ”€ docs/                # Documentation
β”‚  β”‚  β”œβ”€ DEVELOPMENT.md    # Development setup guide
β”‚  β”‚  β”œβ”€ SSL-SETUP.md      # SSL certificate setup
β”‚  β”‚  β”œβ”€ SUBDOMAIN-DEPLOYMENT.md # Production deployment
β”‚  β”‚  └─ ...               # Other documentation
β”‚  └─ scripts/             # Build and setup scripts
β”‚     β”œβ”€ build-production.* # Production build scripts
β”‚     β”œβ”€ setup-ssl.*       # SSL certificate setup
β”‚     β”œβ”€ sync-config.*     # Configuration sync scripts
β”‚     └─ ...               # Other utility scripts
β”œβ”€ docker-compose.yaml     # Development Docker setup
β”œβ”€ sync-config.js          # Configuration sync utility
β”œβ”€ run.sh / run.bat        # Script runner
└─ README.md               # This file

πŸš€ Quick Commands

# Configuration
./run.sh sync-config              # Sync Proto config to Docker
node sync-config.js               # Alternative: direct sync

# Development
docker-compose up -d              # Start backend services (auto-migrates by default)
cd apps/main && npm run dev       # Start main app
cd apps/crm && npm run dev        # Start CRM app
cd apps/developer && npm run dev  # Start developer tools

# Database
AUTO_MIGRATE=false docker-compose up -d  # Start without auto-migration
./run.sh migrations               # Run database migrations manually
docker-compose exec web php infrastructure/scripts/run-migrations.php  # Alternative manual migration

# Production
./run.sh setup-ssl yourdomain.com your-email@domain.com  # Setup SSL
./run.sh build                    # Build all apps for production
docker-compose -f infrastructure/config/docker-compose.prod.yaml up -d  # Deploy production

# Utilities
./run.sh help                     # Show all available scripts
docker-compose logs -f web        # Watch container startup and migration logs

Application Settings

Your application-specific settings live in common/Config/.env. Proto reads JSON-encoded environment variables from there:

{
  "APP_ENV": "dev",
  "siteName": "My Application",
  "domain": {
    "production": "yourdomain.com",
    "development": "localhost",
    "subdomains": {
      "api": "api",
      "main": "app",
      "crm": "crm",
      "developer": "dev"
    },
    "ssl": true,
    "ports": {
      "development": {
        "api": 8080,
        "main": 3000,
        "crm": 3001,
        "developer": 3002
      }
    }
  }
}

Domain Configuration

The project uses a hybrid domain configuration system that automatically adapts URLs based on your environment:

Development Mode:

  • All apps use localhost with specific ports
  • No SSL/HTTPS required for local development

Production Mode:

  • Uses subdomains with your configured domain
  • Automatic SSL/HTTPS based on configuration
  • All frontend apps automatically use correct API endpoints

To change your domain:

  1. Edit the "production" value in common/Config/.env
  2. All apps will automatically use the new domain
  3. No code changes required in individual apps

The domain configuration is handled by domain.config.js, which reads from your Proto configuration and provides fallback defaults if needed.

SSL Certificate Setup (Production)

For production deployment with HTTPS, use the automated SSL setup:

Quick SSL Setup:

# Linux/macOS
./run.sh setup-ssl yourdomain.com your-email@yourdomain.com

# Windows
run.bat setup-ssl yourdomain.com your-email@yourdomain.com

This automatically:

  • βœ… Requests free Let's Encrypt SSL certificates for all subdomains
  • βœ… Sets up certificate renewal scripts
  • βœ… Configures Apache for HTTPS
  • βœ… Creates production-ready deployment files

Manual SSL Setup: See infrastructure/docs/SSL-SETUP.md for detailed SSL configuration options including custom certificates and Traefik reverse proxy setup.---

βš™οΈ Configuration

All you need in your front-controller is:

<?php declare(strict_types=1);

// public/api/index.php
require __DIR__ . '/../../vendor/autoload.php';

// Kick off your API router (or any other Proto component)
Proto\Api\ApiRouter::initialize();

Behind the scenes Composer’s autoloader handles:

  • Proto\… via the core framework in vendor/protoframework/proto
  • Modules\…, Common\…, and Apps\… via your local folders

πŸ“¦ Creating a New Module

  1. Make a directory under modules/YourFeature

  2. Define your namespace in PHP files:

    <?php declare(strict_types=1);
    namespace Modules\YourFeature\Api;
    
    // … your controllers, routers, etc.
  3. In modules/YourFeature/Api/api.php register routes:

    <?php declare(strict_types=1);
    namespace Modules\YourFeature\Api;
    
    use Modules\YourFeature\Controllers\FeatureController;
    
    router()
      ->resource('feature', FeatureController::class);

πŸ› οΈ Developer Tools

A simple admin UI lets you:

  • Scaffold modules, controllers, models, migrations, etc.
  • Run migrations, view error logs, dispatch jobs
  • Manage users, permissions, and system settings

Access Developer Tools:

  1. Start backend: docker-compose up -d
  2. Start developer app: cd apps/developer && npm run dev
  3. Visit: http://localhost:3002

Screenshots

Generator Page Generator Modal Migration Page Error Page Error Modal Documentation Page Users Page IAM Page IAM Modal Email Page

πŸ”§ Troubleshooting

Common Issues

Docker not starting:

  • Ensure Docker Desktop is running
  • Check that virtualization is enabled in BIOS/UEFI
  • On Windows, ensure WSL2 is installed and updated

Port conflicts:

  • Default ports: 3000-3002 (Vite dev servers), 8080 (API), 8081 (PHPMyAdmin), 3307 (DB), 6380 (Redis)
  • Stop conflicting services or modify ports in docker-compose.yaml (backend) or vite.config.js (frontend)

Database connection issues:

# Check if containers are running
docker-compose ps

# Restart database
docker-compose restart mariadb

# Check logs
docker-compose logs mariadb

Frontend issues:

# Clear Vite cache
rm -rf apps/*/node_modules/.vite

# Reinstall dependencies
cd apps/main && npm install
cd ../crm && npm install
cd ../developer && npm install

API connectivity issues:

  • Frontend apps proxy /api requests to http://localhost:8080
  • Check if backend container is running: docker-compose ps
  • Test API directly: visit http://localhost:8080/api/auth/csrf-token

For more detailed troubleshooting, see DEVELOPMENT.md.

🀝 Contributing

  1. Fork this repo
  2. Create a branch (git checkout -b feature/xyz)
  3. Make your changes, commit & push
  4. Open a Pull Request against main
  5. We’ll review & merge!

Please follow our CONTRIBUTING.md for code standards.

πŸ“„ License

This project is licensed under MIT. See LICENSE.

Build fast, stay modular, ship secure. β€” The Proto Framework Team