How kn0ws/diba-php works
Project type and purpose
• This is “DIBA PHP,” a lightweight, intent-driven microframework written in PHP.
• Purpose: let application developers declare “what they want to do” via YAML Intents, then resolve and execute them through a chain of Executors, dispatch events/jobs, generate responses, and optionally handle asynchronous workflows.
File structure
• Top-level directories:
• public/ – HTTP entrypoint (index.php) behind Apache/nginx
• app/ – User application modules (Constraints, Intents, Executors, Models, Services, Views, etc.)
• diba/ – Core framework (Kernel, IntentResolver, ExecutorDispatcher, MiddlewareRunner, EventQueue, JobQueue, etc.)
• cli/ – CLI interface and commands (diba.php, worker, make- commands)
• config/ – Configuration (DB, routes, events, queue, middleware)
• database/ – Connection manager, migrations
• plugins/ – Pluggable extensions (Intents, Executors, Services)
• stubs/ – Boilerplate templates for code generators
• logs/ – Runtime logs
• Key config files: config/env.php, database.php, route_types.php
• CLI commands under cli/commands generate or introspect Intents/Executors/Responses/Constraints/Jobs/Plugins.
README for additional insights
• Confirms the Intent → Executors → Effects → on_effects chain, state-emitted events, async job queue (worker).
• Notes MVC-style Views, custom Responses, flexible middleware/constraints, DB connectivity, plugin architecture, CLI tooling for rapid scaffolding and documentation.
Main components
a. Frontend (HTTP)
• Apache/Nginx → public/index.php
• diba\Kernel: bootstrap, routing to Intents
b. Intent Resolver & Router
• Reads YAML Intents (app/Intents + plugins)
• Matches incoming route/event to an Intent definition
c. Middleware/Constraints
• diba\MiddlewareRunner applies pre/post filters
• app/Constraints + diba/Middlewares
d. Executor Dispatcher
• Chains Executors (app/Executors, services) per Intent
e. Services & Models
• Business logic services (app/Services, plugins)
• DB access via Eloquent models (app/Models) and database/ConnectionManager
f. State & Event System
• diba\State emits effects → diba\EventQueue → jobs
g. Job Queue & Worker
• Configured queue (Redis/DB) → worker.php runs async Executors
h. Response layer
• diba\Responses (Json, Html, View, Redirect) + custom ones (app/Responses)
• HTTP response back to client
i. CLI subsystem
• cli/diba.php → commands for scaffolding, simulation, docs, queue runner
Relationships and interactions
• HTTP Request → Kernel → Router → IntentResolver
• IntentResolver → MiddlewareRunner (constraints) → ExecutorDispatcher
• ExecutorDispatcher → sequential calls to Executors → underlying Services → Models → DB
• Executors may call State::emit() → EventQueue → add Job to JobQueue
• Worker process dequeues jobs → ExecutorDispatcher → follow-on Executors
• Final Response object → sent back via Kernel
• CLI commands invoke Kernel for simulate, validate, graph Intent definitions, generate code, run queue, run tests.
Architectural patterns/design principles
• Intent-Driven Architecture: decouples “what” from “how.”
• Chain of Responsibility (Executor chain).
• Event-driven / Pub-Sub for async effects.
• MVC-style Views for HTML.
• Plugin architecture—Intents/Executors/Services can live outside core code.
• Code generation and config-driven patterns for rapid development.
Technologies & frameworks
• PHP >= 8.0, Composer for dependency management.
• Eloquent ORM for models (Laravel components).
• YAML for Intent definitions.
• PSR-4 autoloading.
• Optional Redis/DB for queue (config/queue.php).