2026-04-17 16:13:31 +03:00
# Architecture Overview
2026-06-15 18:58:07 +03:00
## Project type
2026-04-17 15:58:55 +03:00
2026-06-15 18:58:07 +03:00
Structured PHP monolith with a modular extension layer.
2026-04-17 15:58:55 +03:00
2026-06-15 18:58:07 +03:00
- No DDD, no Hexagonal, no Clean Architecture — intentional.
- Split by context with minimal abstractions: `Controller → Service → Repository` .
- Two build artifacts from one codebase: **MAIN** (full panel) and **LB** (load balancer subset).
2026-04-17 15:58:55 +03:00
2026-06-15 18:58:07 +03:00
---
2026-04-17 15:58:55 +03:00
2026-06-15 18:58:07 +03:00
## Source tree
2026-04-17 15:58:55 +03:00
2026-06-15 18:58:07 +03:00
| Path | Role |
| ---- | ---- |
2026-08-26 22:42:43 +03:00
| `src/Core/` | Framework primitives: DI container, events, HTTP/router, config, auth, logging |
2026-06-26 15:56:15 +03:00
| `src/Domain/` | Business contexts: Stream, VOD, Line, User, Server, Security, etc. |
2026-08-26 22:42:43 +03:00
| `src/Infrastructure/` | External adapters: `DatabaseFactory` , cache readers, Redis, TMDb |
| `src/Streaming/` | Streaming subsystem: bootstrap, auth, delivery, balancer, protection |
2026-06-26 15:56:15 +03:00
| `src/Modules/` | Optional extension layer — loaded by `ModuleLoader` |
| `src/Public/` | Front controller, router, controllers, views, assets |
| `src/Cli/` | Console commands and cron entry points |
2026-08-11 21:41:11 +03:00
| `src/Ministra/` | Stalker Portal — in core; served at `/home/xc_vm/Ministra` |
2026-04-17 15:58:55 +03:00
2026-06-15 18:58:07 +03:00
---
2026-04-17 15:58:55 +03:00
2026-06-15 18:58:07 +03:00
## Runtime model
2026-04-17 15:58:55 +03:00
2026-06-15 18:58:07 +03:00
Dependencies flow inward — modules may use core and domain, never the reverse.
2026-04-17 15:58:55 +03:00
2026-06-15 18:58:07 +03:00
```
2026-06-26 15:56:15 +03:00
Public/index.php
2026-08-26 22:42:43 +03:00
└── XC_Bootstrap::boot(BootContext::Admin)
2026-06-15 18:58:07 +03:00
└── ServiceContainer (DI)
├── EventDispatcher (PSR-14)
├── ModuleLoader → loadAll() → bootAll()
└── Router → dispatch()
```
2026-04-17 15:58:55 +03:00
2026-08-26 22:42:43 +03:00
Domain and module classes do **not** take `$db` in their constructor. They
`use \XcVm\Infrastructure\Database\DatabaseAware` and call `self::db()` , which lazily
resolves the shared connection. `bootstrap.php::wireDomainDatabase()` sets that connection
**once** per boot (via `DatabaseAware::setDb()` ) — there is no per-class wiring and no
`global $db` in the web request path.
2026-04-17 15:58:55 +03:00
2026-06-15 18:58:07 +03:00
---
2026-04-17 15:58:55 +03:00
2026-06-15 18:58:07 +03:00
## Module system
2026-04-17 15:58:55 +03:00
2026-06-26 15:56:15 +03:00
Modules are isolated directories under `src/Modules/` with a `module.json` manifest
2026-08-26 22:42:43 +03:00
and a class extending `BaseModule` . See [Module Authoring ](module-authoring.md ) for the full reference (and the linked Lifecycle / Extension Points pages).
2026-06-15 18:58:07 +03:00
```
2026-06-26 15:56:15 +03:00
src/Modules/my-module/
2026-06-15 18:58:07 +03:00
├── module.json # metadata
├── MyModuleModule.php # extends BaseModule, namespace XcVm\Module\MyModule
└── ...
```
---
## Bootstrap contexts
Four contexts control which subsystems initialize. See [Bootstrap Contexts ](bootstrap-contexts.md ).
| Context | Used for |
| ------- | -------- |
2026-08-26 22:42:43 +03:00
| `BootContext::Minimal` | Scripts needing only paths/config |
| `BootContext::Cli` | Cron jobs and CLI commands |
| `BootContext::Stream` | Streaming endpoints |
| `BootContext::Admin` | Admin/reseller panel |
2026-06-15 18:58:07 +03:00
---
## Build variants (MAIN vs LB)
| | MAIN | LB |
| --- | ---- | -- |
| Admin panel | ✅ | ❌ |
| Streaming | ✅ | ✅ |
| Module system | ✅ | subset |
2026-08-26 22:42:43 +03:00
Controlled by the `ServerEnvironment` enum and each `module.json` 's `environment` field
(`main` / `lb` / `any` ). At boot, `ModuleLoader::getCurrentEnvironment()` resolves the node's
environment from the `SERVER_TYPE` constant (`'lb'` → `ServerEnvironment::LoadBalancer` , else
`ServerEnvironment::Main` ); a module whose `environment` doesn't match the node is skipped, so
the LB gets a **subset** of modules.
2026-06-15 18:58:07 +03:00
---
## Key extension points
| Mechanism | How to use |
| --------- | ---------- |
2026-08-26 22:42:43 +03:00
| PSR-14 events | `EventDispatcher::listen()` / `#[ListensTo]` — see [Event System ](event-system.md ) |
| Service decoration | `$container->decorate('id', callable, priority)` — see [Module Extension Points ](module-extension-points.md#di-container-and-service-decoration ) |
| Stream middleware | Implement `StreamMiddlewareProviderInterface` — see [Module Extension Points ](module-extension-points.md#stream-middleware ) |
| Cron entries | `getCronEntries()` in the module class — see [Module Extension Points ](module-extension-points.md#cron-task ) |
| DB migrations | `MigratableInterface::getMigrations()` — see [Module Extension Points ](module-extension-points.md#versioned-migrations-migratableinterface ) |
2026-06-15 18:58:07 +03:00
---
## Contributor rules
1. Modules must not modify core files.
2. No `eval` , monkey patching, or runtime file replacement.
3. Any module can be disabled via `config/modules.php` without touching core.
4. Protected services (`db` , `settings` , `config` , `auth` ) cannot be decorated.
5. Keep EN and RU docs in sync in the same commit.