Skip to content
pillardashPublic

About

A lite PHP builder meta-framework to get your projects up and running quickly

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

110 Commits

Folders and files

Repository files navigation

Lay Framework

Lay - A Lite PHP Meta-Framework for Rapid Development

PHP Version License Framework Version

Lay is a modern, lightweight PHP meta-framework designed to get your projects up and running quickly. Built with developer experience in mind, it provides a clean architecture with powerful features while maintaining simplicity.

✨ Key Features

  • πŸš€ Rapid Development - Get started in minutes with sensible defaults
  • πŸ—οΈ Domain-Driven Architecture - Organize your application by domains/modules
  • πŸ”Œ Built-in API Support - RESTful APIs with automatic routing and rate limiting
  • πŸ“± Modern Frontend Integration - Built-in JavaScript utilities and asset management
  • πŸ—„οΈ Database Agnostic - Support for MySQL, PostgreSQL, and SQLite
  • πŸ”’ Security First - CORS, CSRF protection, and secure session management
  • ⚑ Performance Optimized - Asset compression, caching, and production optimizations
  • 🎨 Flexible View System - Clean templating with PHP or integrate your favorite frontend

πŸš€ Quick Start

Installation

Create a new Lay project using Composer:

composer create-project pillardash/lay my-awesome-project
cd my-awesome-project

Environment Setup

  1. Copy the environment file and configure your settings:
cp .env.example .env
  1. Edit .env to match your environment:
# Set your environment
APP_ENV=DEVELOPMENT

# Database configuration (optional)
DB_DRIVER=mysql
DB_HOST=127.0.0.1
DB_USERNAME=root
DB_PASSWORD=your_password
DB_NAME=your_database

Start Development Server

# Using PHP built-in server
php -S localhost:8000

# Or using your preferred local server (Apache, Nginx, etc.)

Visit http://localhost:8000 and you'll see your Lay application running! πŸŽ‰

πŸ“ Project Structure

my-project/
β”œβ”€β”€ bricks/                 # Business logic layer
β”‚   └── Business/
β”‚       β”œβ”€β”€ Api/            # API hooks and logic
β”‚       β”œβ”€β”€ Controller/     # Application controllers
β”‚       β”œβ”€β”€ Model/          # Data models
β”‚       β”œβ”€β”€ Request/        # Request validation classes
β”‚       └── Resource/       # API resource transformers
β”œβ”€β”€ utils/                  # Utility classes and helpers
β”œβ”€β”€ web/                    # Web layer
β”‚   β”œβ”€β”€ domains/           # Domain-specific code
β”‚   β”‚   β”œβ”€β”€ Api/           # API domain
β”‚   β”‚   β”‚   β”œβ”€β”€ Plaster.php    # API configuration and hooks
β”‚   β”‚   β”‚   └── index.php      # API entry point
β”‚   β”‚   └── Default/       # Default web domain (template for all regular domains)
β”‚   β”‚       β”œβ”€β”€ Plaster.php    # Domain routes and page configuration
β”‚   β”‚       β”œβ”€β”€ foundation.php # Domain-specific setup
β”‚   β”‚       β”œβ”€β”€ layout/        # HTML layout components
β”‚   β”‚       β”‚   β”œβ”€β”€ head.inc   # <head> section (meta, CSS, etc.)
β”‚   β”‚       β”‚   β”œβ”€β”€ body.inc   # Main body wrapper
β”‚   β”‚       β”‚   └── script.inc # JavaScript includes
β”‚   β”‚       β”œβ”€β”€ plaster/       # View templates
β”‚   β”‚       β”‚   β”œβ”€β”€ homepage.view   # Homepage template
β”‚   β”‚       β”‚   └── another.view    # Example page template
β”‚   β”‚       └── public/        # Domain-specific public assets
β”‚   β”‚           β”œβ”€β”€ index.php      # Domain entry point
β”‚   β”‚           β”œβ”€β”€ favicon.ico    # Domain favicon
β”‚   β”‚           └── static/        # Static assets (CSS, JS, images)
β”‚   β”‚               └── dev/       # Development assets
β”‚   β”‚                   β”œβ”€β”€ css/   # Stylesheets
β”‚   β”‚                   β”œβ”€β”€ js/    # JavaScript files
β”‚   β”‚                   β”œβ”€β”€ images/ # Images
β”‚   β”‚                   └── ui/    # UI components
β”‚   └── shared/            # Shared assets and resources
β”œβ”€β”€ foundation.php         # Application bootstrap
β”œβ”€β”€ index.php             # Application entry point
└── bob.config.json       # Build and deployment configuration

πŸ—οΈ Core Concepts

Domains

Lay organizes applications into domains - self-contained modules that handle specific parts of your application:

Domain::new()->create(
    id: "api-endpoint",
    builder: \Web\Api\Plaster::class,
    pattern: "api",
    type: DomainType::SPECIAL,
);

Domain::new()->create(
    id: "default",
    builder: \Web\Default\Plaster::class,
    pattern: "*",
    type: DomainType::REGULAR,
);

Domain Structure

Each regular domain follows a standard structure (using Default as an example):

web/domains/Default/
β”œβ”€β”€ Plaster.php           # Main domain controller - defines routes and pages
β”œβ”€β”€ foundation.php        # Domain-specific configuration and setup
β”œβ”€β”€ layout/              # HTML layout components
β”‚   β”œβ”€β”€ head.inc         # <head> section - meta tags, CSS includes
β”‚   β”œβ”€β”€ body.inc         # Main body wrapper and footer
β”‚   └── script.inc       # JavaScript includes and initialization
β”œβ”€β”€ plaster/             # View templates (your actual page content)
β”‚   β”œβ”€β”€ homepage.view    # Homepage template
β”‚   └── another.view     # Additional page templates
└── public/              # Domain-specific public assets
    β”œβ”€β”€ index.php        # Domain entry point for direct access
    β”œβ”€β”€ favicon.ico      # Domain-specific favicon
    └── static/          # Static assets organized by environment
        └── dev/         # Development assets
            β”œβ”€β”€ css/     # Domain stylesheets
            β”œβ”€β”€ js/      # Domain JavaScript
            β”œβ”€β”€ images/  # Domain images
            └── ui/      # UI components and assets

Key Files Explained:

  • Plaster.php - Your domain's main controller where you define routes and configure pages
  • layout/*.inc - Reusable HTML components that wrap your content
  • plaster/*.view - Your actual page templates with content
  • public/static/ - All your CSS, JavaScript, images, and other assets

Controllers

Controllers handle your application logic using traits for common functionality:

class NewsletterSubController
{
    use IsSingleton, ControllerHelper;

    public function add(): array
    {
        $request = new SubNewsletterRequest();

        if ($request->error)
            return self::res_warning($request->error);

        // Your logic here...
        return self::res_success("Success message");
    }
}

Models

Models extend BaseModelHelper for database operations:

class NewsletterSub extends BaseModelHelper
{
    public static string $table = "newsletter_subs";

    protected function cast_schema(): void
    {
        $this->cast("options", "array");
    }
}

πŸ”Œ Building APIs

API Hooks

Define your API endpoints using the hook system:

class Hook extends ApiHooks
{
    protected function hooks(): void
    {
        $this
            ->post("subscribe-newsletter")->bind(fn() => NewsletterSubController::new()->add())
            ->get("list-subscribers/{page}")->bind(fn($page) => NewsletterSubController::new()->list((int) $page));
    }
}

Request Validation

Create request classes for automatic validation:

class SubNewsletterRequest extends RequestHelper
{
    protected function rules(): void
    {
        $this->vcm(['field' => 'name', 'required' => false ]);
        $this->vcm(['field' => 'email', 'is_email' => true ]);
    }
}

🎨 Frontend Development

Lay includes a minimal but powerful JavaScript library for frontend interactions:

// Built-in DOM utilities
$id('my-element').innerHTML = 'Hello World';
$sel('.my-class').$class('add', 'active');

// AJAX made simple
$ajax($lay.src.api + 'subscribe-newsletter', {
    method: 'POST',
    data: { email: '[email protected]' },
}).then(response => {
    console.log('Success!', response);
    osNote("Success", "success")
});

πŸ—„οΈ Database Integration

Lay can startup without connecting to the database by default, but if you want that, you can use the ->connect_db() method in your foundation.php:

Startup::new()
    ->name($site_name, "$site_name | Slogan Goes Here")
    ->connect_db()
    ->set_globals([
        "desc" => "Your project description"
    ]);

πŸš€ Deployment

Lay includes production optimizations:

  • Asset Compression - Automatic JS/CSS minification
  • HTML Compression - Reduced payload sizes
  • Caching - Domain and asset caching
  • Security Headers - Production-ready security configuration

Configure in your .env:

APP_ENV=PRODUCTION
COMPRESS_HTML=true
COMPRESS_ASSETS=true
CACHE_DOMAINS=true

πŸ“š Learning Resources

  • Official Documentation: https://lay.pillardash.com (Coming Soon)
  • Example Applications: Check the web/domains/Default folder for examples
  • Community: Join our discussions and get help from the community

🀝 Contributing

We welcome contributions! Please feel free to submit issues, feature requests, or pull requests.

πŸ“„ License

Lay is open-source software licensed under the MIT License.


Ready to build something amazing? πŸš€

composer create-project pillardash/lay my-next-project

About

A lite PHP builder meta-framework to get your projects up and running quickly

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages