This document explains the architectural philosophy and internal structure of the Pair PHP framework.
Read it when a task touches framework internals or requires architectural decisions.
Use GEMINI.md for technical conventions and AGENTS.md for workflow and safety rules.
Pair is designed with these principles:
- Simplicity
- Predictable structure
- Minimal dependencies
- Server-rendered first
- Progressive enhancement
- Clean MVC separation
- Backward compatibility
Pair intentionally avoids heavy abstractions or unnecessary layers.
Agents should extend existing patterns instead of introducing new architectural concepts.
- Pair is pragmatic MVC.
- Applications define modules under
/modules. - Routing resolves a module, then a controller action.
- Pair v4 prefers explicit response objects; the legacy MVC bridge still supports view/layout conventions during migration.
- ORM usage should stay close to ActiveRecord and relation helpers.
- PairUI is progressive enhancement, not a frontend application framework.
Pair follows a pragmatic, server-rendered MVC architecture.
The framework provides:
- application bootstrap
- routing
- controllers
- explicit HTML and JSON responses
- legacy views and layouts for migration paths
- ORM
- utilities
- integrations
- debugging tools
Applications built with Pair define modules under /modules.
Typical Pair v4 lifecycle:
- HTTP request arrives
- Application bootstrap initializes environment
- Router parses URL
- Module controller is resolved
- Controller action executes
- Model operations may run through ORM
- Action returns a
ResponseInterface - Response renders HTML or JSON
- Page responses may be wrapped by the configured template
Legacy Pair\Core\Controller modules still follow the older view/layout bridge while applications migrate to Pair\Web\Controller.
Agents should respect this flow when modifying framework code.
Pair uses an ActiveRecord-style ORM.
Key features:
- automatic type casting
- relationship helpers
- lazy loading
- collections
Agents should prefer ORM helpers instead of raw SQL queries.
Example:
affiliate_id → getAffiliate()
PairUI is a lightweight progressive enhancement library.
Principles:
- no build step
- minimal JavaScript
- server-rendered HTML first
Main directives:
- data-text
- data-html
- data-show
- data-if
- data-model
- data-on
- data-each
Agents should prefer these directives instead of introducing heavy frontend frameworks.