gwack / core
The gwack framework
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/gwack/core
Requires
- php: >=8.3
- psr/container: 2.0.2
- psr/log: 3.0.2
- symfony/http-foundation: 7.3.0
Requires (Dev)
- monolog/monolog: ^3.0
- phpunit/phpunit: ^12.0
README
Gwack is a modern PHP framework designed for full-stack development with seamless Vue.js integration. Built with developer experience in mind, it offers file-based routing, powerful dependency injection, and fast development workflow.
๐ Features
- File-Based Routing: Zero configuration routing - just create PHP files in your
server/directory - Vue.js Integration: Native Vue.js support with hot module reloading
- High Performance: Optimized router with static route lookup and intelligent regex grouping
- PSR Compliant: Built on Symfony components with PSR standards compliance
- Dependency Injection: Container system with automatic resolution and caching
- Developer Experience: CLI tools for project scaffolding, development server, and production builds
- API-First Design: RESTful API server with built-in serialization and validation
๐ฆ Installation
Using the CLI (Recommended)
# Install the CLI globally npm install -g @gwack/cli # Create a new project gwack create my-app # Navigate to your project cd my-app # Install PHP dependencies composer install # Start development server gwack dev
Manual Installation
# Install via Composer composer require gwack/core # Install frontend tooling npm install @gwack/cli
๐ Example Project Structure
my-app/
โโโ pages/ # Vue.js pages (frontend)
โ โโโ index.vue # Home page
โ โโโ about.vue # About page
โโโ server/ # PHP API routes (backend)
โ โโโ posts/
โ โ โโโ index.php # GET/POST /api/posts
โ โโโ users/
โ โโโ [id].php # GET/POST /api/users/{id}
โโโ assets/ # Static assets
โโโ gwack.config.js # Framework configuration
โโโ composer.json # PHP dependencies
โโโ package.json # Node.js dependencies
โโโ index.html # Entry point
๐ฏ Quick Start
1. Backend API Routes
Create API endpoints by adding PHP files to the server/ directory:
<?php // server/posts/index.php function getPosts() { return [ ['id' => 1, 'title' => 'Hello World'], ['id' => 2, 'title' => 'Getting Started'] ]; } // Return a JSON response return fn() => json(getPosts());
Available at: GET /api/posts
2. Dynamic Routes
Use bracket notation for dynamic parameters:
<?php // server/posts/[id].php return function() { $request = request(); $id = $request->get('id'); return json(['id' => $id, 'title' => "Post #{$id}"]); };
Available at: GET /api/posts/123
3. Frontend Pages
Create Vue.js pages in the pages/ directory:
<!-- pages/index.vue --> <template> <div> <h1>Welcome to Gwack</h1> <div v-for="post in posts" :key="post.id"> <h2>{{ post.title }}</h2> </div> </div> </template> <script setup> import { ref, onMounted } from 'vue' const posts = ref([]) onMounted(async () => { const response = await fetch('/api/posts') posts.value = await response.json() }) </script>
๐ Development Commands
# Start development server with hot reloading gwack dev # Build for production gwack build # Create new project gwack create <project-name> # Development server options gwack dev --port 3000 --php-port 8080 --host localhost
โ๏ธ Configuration
gwack.config.js
export default { php: { port: 8080, }, frontend: { port: 3000, }, build: { target: 'es2020', }, }
Application Bootstrap
<?php // index.php use Gwack\Core\Application; require_once 'vendor/autoload.php'; $app = new Application(__DIR__); $app->configure([ 'env' => 'development', 'debug' => true, 'api_prefix' => '/api' ]); $app->boot()->run();
๐ Architecture
Core Components
- Application: Main application class that bootstraps the framework
- Router: High-performance HTTP router with route compilation and caching
- Container: Dependency injection container with automatic resolution
- ApiServer: RESTful API server with middleware support
- FileBasedRouter: Automatic route discovery from filesystem
Container Functions
The framework provides pre-registered functions available in all route handlers:
// Available functions in route handlers json($data, $status = 200) // Create JSON response request() // Get current request context() // Get application context config($key) // Get configuration value logger() // Get logger instance session() // Get session manager validate($rules) // Validate request data
Middleware Support
// Add middleware to API server $app->getApiServer()->addMiddleware(new CorsMiddleware()); $app->getApiServer()->addMiddleware(new AuthMiddleware());
๐ง Advanced Usage
Manual Route Registration
// Register routes programmatically $app->addRoute('GET', '/custom', function() { return json(['message' => 'Custom route']); });
Container Bindings
// Bind custom services $app->getContainer()->bind('myService', function() { return new MyService(); }); // Access in route handlers return function() { $service = container()->get('myService'); return json($service->getData()); };
๐ Requirements
- PHP: 8.3 or higher
- Node.js: 18.0 or higher
- Composer: For PHP dependency management
- npm/yarn: For frontend dependencies
๐งช Testing
# Run PHP tests composer test # Run with coverage ./vendor/bin/phpunit --coverage-html coverage
๐ License
MIT License. See LICENSE for details.
๐ค Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ Learn More
Built with โค๏ธ by the Gwack Framework Team