Overview
Introduction to VelvetCMS Core - a modular, high-performance content application framework for PHP 8.4+.
VelvetCMS Core is a modular content application framework built for PHP 8.4+. It provides the foundation for building content-driven applications with a focus on performance, flexibility, and developer experience.
What is VelvetCMS? #
VelvetCMS is not a traditional CMS with a pre-built admin panel. Instead, it's a framework that gives you the building blocks to create exactly the content system you need:
- Headless API backends - Serve content to any frontend
- Static site generators - Build blazing-fast static sites
- Traditional dynamic sites - Server-rendered pages with caching
- Hybrid applications - Mix static and dynamic as needed
Think of it as Laravel's elegance meets content-first architecture, without the overhead.
Why VelvetCMS? #
Performance First #
VelvetCMS is designed to be fast out of the box:
- <1ms response times with warm cache
- Minimal memory footprint (~4MB baseline)
- Lazy loading everywhere - services instantiate only when used
- Multiple cache layers - opcode, content, query caching
Truly Modular #
Everything is a module. The core itself is minimal - functionality is added through composable modules:
VelvetCMS Core (routing, DI, events)
└── Your Modules
├── Blog
├── Shop
├── API
└── Admin Panel
Modules can:
- Register routes, commands, and event listeners
- Provide services and configuration
- Override views and assets
- Depend on other modules
Flexible Content Storage #
Choose how your content is stored:
| Driver | Use Case |
|---|---|
| File | Markdown files with frontmatter - perfect for Git workflows |
| Database | Full database storage - scales to millions of pages |
| Hybrid | Metadata in DB, content in files - best of both worlds |
Switch drivers without changing your code.
Modern PHP #
Built exclusively for PHP 8.4+:
- Constructor property promotion
- Named arguments throughout
- Attributes for routing and DI
- Readonly properties
- Enums for type safety
- First-class callable syntax
No legacy compatibility baggage.
Core Concepts #
The Container #
At the heart of VelvetCMS is a powerful dependency injection container:
// Bind a service
$container->singleton(CacheInterface::class, FileCache::class);
// Resolve with automatic injection
$service = $container->make(MyService::class);
Services are lazy-loaded - they're only instantiated when first requested.
Routing #
Routes map URLs to handlers with a clean, expressive syntax:
$router->get('/posts/{slug}', [PostController::class, 'show']);
$router->post('/api/posts', [ApiController::class, 'store']);
// Route groups with middleware
$router->group(['prefix' => '/admin', 'middleware' => ['auth']], function($router) {
$router->get('/dashboard', [AdminController::class, 'dashboard']);
});
Content & Pages #
The PageService provides a unified API for working with content:
$page = $pageService->find('about');
$page->title; // From frontmatter
$page->content; // Rendered HTML
$page->meta; // All metadata
// Query pages
$posts = $pageService->all(['type' => 'post', 'limit' => 10]);
Events #
Decouple your application with events:
// Dispatch an event
$events->dispatch(new PageSaved($page));
// Listen for events
$events->listen(PageSaved::class, function(PageSaved $event) {
$this->cache->forget("page:{$event->page->slug}");
});
Modules #
Extend VelvetCMS through self-contained modules:
modules/Blog/
├── module.json # Manifest
├── src/
│ └── BlogModule.php # Service provider
├── routes/
│ └── web.php # Routes
├── views/
│ └── post.velvet # Templates
└── config/
└── blog.php # Configuration
Modules are auto-discovered from user/modules/ and loaded based on their dependencies.
Architecture at a Glance #
Request
│
▼
┌─────────────────────────────────────────────────────┐
│ HTTP Kernel │
│ ├─ Middleware Pipeline │
│ │ ├─ Session │
│ │ ├─ CSRF Protection │
│ │ └─ Your Middleware │
│ └─ Router │
│ └─ Controller / Closure │
└─────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ Application Services │
│ ├─ PageService (content management) │
│ ├─ Cache (file, apcu, redis) │
│ ├─ Database (query builder, migrations) │
│ └─ Storage (filesystem abstraction) │
└─────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ Content Drivers │
│ ├─ FileDriver (markdown files) │
│ ├─ DatabaseDriver │
│ └─ HybridDriver │
└─────────────────────────────────────────────────────┘
│
▼
Response
Directory Structure #
A typical VelvetCMS installation:
my-project/
├── config/ # Default configuration
├── database/
│ └── migrations/ # Database migrations
├── public/
│ └── index.php # Web entry point
├── src/ # Core framework code (don't edit)
├── storage/
│ ├── cache/ # Cached data
│ ├── logs/ # Application logs
│ └── database.sqlite # SQLite database (if used)
├── user/
│ ├── config/ # Your configuration overrides
│ ├── content/
│ │ └── pages/ # Your content files
│ ├── modules/ # Your custom modules
│ └── views/ # Your view templates
├── vendor/ # Composer dependencies
├── composer.json
└── velvet # CLI tool
The user/ directory contains everything specific to your project. The rest can be updated independently.
Who Should Use VelvetCMS? #
VelvetCMS is ideal for:
- Developers who want full control over their content architecture
- Agencies building multiple content sites with shared modules
- Teams practicing Git-based content workflows
- Projects that need to scale from simple to complex
VelvetCMS might not be right if you need:
- A ready-to-use admin interface (though modules can add this)
- Visual page builders out of the box
- Non-technical content editors (without building UI for them)
What's Next? #
Ready to dive in?
- Requirements - Check your environment
- Installation - Get up and running
- Configuration - Customize your setup
- Modules - Extend with modules
Or jump straight to the API Reference for detailed documentation on every component.