Architecture Overview¶
Tusk is built on a modular, layered architecture that separates concerns and promotes clean code.
Core Principles¶
- Dependency Injection First: All components use constructor injection
- Attribute-Based Configuration: Routes, services, and more via PHP 8 attributes
- Repository Pattern: Clean separation between domain and data access
- Process Supervision: Long-running workers with automatic restart
Component Layers¶
┌─────────────────────────────────────┐
│ Application Layer │
│ (Your Controllers, Services) │
├─────────────────────────────────────┤
│ Framework Layer │
│ ┌──────────┐ ┌──────────────────┐ │
│ │ tusk-web │ │ tusk-micro │ │
│ │ (HTTP) │ │ (Health/Metrics) │ │
│ └──────────┘ └──────────────────┘ │
│ ┌──────────┐ ┌──────────────────┐ │
│ │tusk-data │ │ tusk-cli │ │
│ │ (Repos) │ │ (Commands) │ │
│ └──────────┘ └──────────────────┘ │
├─────────────────────────────────────┤
│ Runtime Layer │
│ ┌──────────────────────────────┐ │
│ │ tusk-runtime │ │
│ │ (Kernel, Supervisor, Pool) │ │
│ └──────────────────────────────┘ │
├─────────────────────────────────────┤
│ Core Layer │
│ ┌──────────────────────────────┐ │
│ │ tusk-core │ │
│ │ (Container, Contracts) │ │
│ └──────────────────────────────┘ │
└─────────────────────────────────────┘
Request Lifecycle¶
HTTP Request Flow¶
- Server receives TCP connection (
HttpServer) - Parser converts raw data to
Requestobject - Kernel dispatches to
Router - Router matches route and resolves
Controller - Container injects dependencies into controller
- Controller returns
Response - Server sends response back to client
CLI Command Flow¶
- Dispatcher parses
argvand selects command - Command executes with injected services
- Generator (for
init) scaffolds project files - Exit with status code
Component Details¶
- Core (DI) - Dependency injection container
- Runtime (Supervisor) - Process management
- Web (HTTP) - Server, router, request handling
- Data (Repository) - Database abstraction
- Micro (Services) - Microservice utilities