Files
XC_VM/docs/en/development/architecture.md
T
Divarion-D 76844fef11 docs: restructure, fix PSR-4 drift, and unify en/ru
Overhaul the Docsify documentation (English + Russian) so it matches the current
codebase and follows one consistent pattern.

Content accuracy (post-migration):
- Rewrite development/autoloader.md to PSR-4 / Composer (the old XC_Autoloader
  scanner, igbinary tmp/cache/autoload_map and registerDirectories are gone).
- PascalCase every source path (src/core -> src/Core, domain/Stream, cli/Commands,
  public/Controllers, Infrastructure/Redis, ...) across all docs.
- Replace the removed autoload.php references with vendor/autoload.php
  (build_system, bootstrap-contexts, error-handling, modules).
- ssl-generation: note that the installer now auto-generates a unique self-signed
  certificate before Nginx starts.

Common pattern (Clean & uniform):
- Strip emoji from headings; remove the in-page Navigation blocks (the Docsify
  sidebar already provides navigation).
- One H1 + intro per doc; uniform "Related files" / "Связанные файлы" section,
  added to the code-centric docs that lacked it.

Structure:
- Remove the empty stray docs/api/; move updates_checklist.md into builds/;
  link the previously-orphaned ucs-integration.md.
- Regroup the sidebars (split the oversized guides group into Developer Guides /
  Security & Access / Integrations; fold builds into Build & Release).

Augment:
- dev-workflow: Local Setup (make dev-tools) + Quality Checks (phpstan, cs, gates).
- build_system: Composer Dependencies section (committed prod-only vendor,
  committed lock, dev tools via composer install, no build-time vendor step).

en/ru parity:
- Apply the same structure, fixes and pattern to docs/ru/ (translated), including
  a new Russian ucs-integration.md. The en and ru file sets are now identical.
2026-06-26 15:56:15 +03:00

114 lines
3.6 KiB
Markdown

# Architecture Overview
## Project type
Structured PHP monolith with a modular extension layer.
- 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).
---
## Source tree
| Path | Role |
| ---- | ---- |
| `src/Core/` | Infrastructure primitives: DI container, events, HTTP, config, auth, logging |
| `src/Domain/` | Business contexts: Stream, VOD, Line, User, Server, Security, etc. |
| `src/Modules/` | Optional extension layer — loaded by `ModuleLoader` |
| `src/Public/` | Front controller, router, controllers, views, assets |
| `src/Cli/` | Console commands and cron entry points |
| `src/ministra/` | Stalker Portal — isolated subsystem (`BoundaryInterface`) |
---
## Runtime model
Dependencies flow inward — modules may use core and domain, never the reverse.
```
Public/index.php
└── XC_Bootstrap::boot(BootContext::ADMIN)
└── ServiceContainer (DI)
├── EventDispatcher (PSR-14)
├── ModuleLoader → loadAll() → bootAll()
└── Router → dispatch()
```
Domain classes receive the database via `setDb()` injection (called from
`bootstrap.php::wireDomainDatabase()`). No `global $db` in the web request path.
---
## Module system
Modules are isolated directories under `src/Modules/` with a `module.json` manifest
and a class extending `BaseModule`. See [Module System](modules.md) for the full reference.
```
src/Modules/my-module/
├── 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 |
| ------- | -------- |
| `BootContext::MINIMAL` | Scripts needing only paths/config |
| `BootContext::CLI` | Cron jobs and CLI commands |
| `BootContext::STREAM` | Streaming endpoints |
| `BootContext::ADMIN` | Admin/reseller panel |
---
## Build variants (MAIN vs LB)
| | MAIN | LB |
| --- | ---- | -- |
| Admin panel | ✅ | ❌ |
| Streaming | ✅ | ✅ |
| Module system | ✅ | subset |
Controlled by `ServerEnvironment` enum and `module.json` `environment` field (`main` / `lb` / `any`).
---
## Key extension points
| Mechanism | How to use |
| --------- | ---------- |
| PSR-14 events | `EventDispatcher::listen()` or `#[ListensTo]` attribute |
| Service decoration | `$container->decorate('id', callable, priority)` |
| Stream middleware | Implement `StreamMiddlewareProviderInterface` |
| Cron entries | Override `getCronEntries()` in module class |
| DB migrations | Implement `MigratableInterface::getMigrations()` |
---
## 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.
## Related files
| File | Role |
| --- | --- |
| `src/Core/` | Framework primitives (DI, events, HTTP, config, auth, logging) |
| `src/Domain/` | Business contexts (Stream, VOD, Line, User, Server, Security) |
| `src/Infrastructure/` | External adapters (DatabaseFactory, CacheReader, Redis) |
| `src/Streaming/` | Streaming subsystem |
| `src/Modules/` | Optional modules (loaded by ModuleLoader) |
| `src/Public/` | Front controller, controllers, views |
| `src/Cli/` | Console commands and cron jobs |