# Architecture Baseline

Every number below was produced by the command printed beneath it. Run all
commands from `backend/` unless stated otherwise. **No value in this file may be
estimated, rounded from memory, or copied from an example.** If a metric cannot
be measured yet, it must say `not measured` and name the blocker.

- Measured at commit: `e85f62b` (pre-upgrade tip)
- Measured on: 2026-08-14
- PHP: 8.2.12 — `php -v`
- Composer: 2.10.2 — `composer --version`

## Size

- **Lines of PHP in `src/`: 24,976**
  `find src -name '*.php' | xargs wc -l | tail -1`
- **PHP files in `src/`: 139**
  `find src -name '*.php' | wc -l`
- **Lines of PHP in `tests/`: 5,686**
  `find tests -name '*.php' | xargs wc -l | tail -1`

## Layer inventory

- **Controllers: 41**
  `find src -name '*Controller.php' | wc -l`
- **Services: 34**
  `find src -name '*Service.php' | wc -l`
- **Repositories: 14**
  `find src -name '*Repository.php' | wc -l`
- **Files declaring an interface: 3**
  `grep -rl 'interface ' --include='*.php' src | wc -l`
  (`RateLimiterInterface`, `PriceResolverInterface`, `BatchPriceResolverInterface`)
- **Registered routes: 183**
  `grep -rhoE "(get|post|put|patch|delete)\('" routes | wc -l`

## Coupling debt (targets of Phases 3 and 4)

- **Controllers containing raw SQL: 31 of 41**
  `grep -rlE '(SELECT|INSERT INTO|UPDATE [a-zA-Z_]+ SET|DELETE FROM)' --include='*Controller.php' src | wc -l`
  This is the exact list frozen in `tests/Architecture/LayeringTest.php`.
- **`Application $app` occurrences in `src/`: 150**
  `grep -rn 'Application \$app' --include='*.php' src | wc -l`
- **Service-locator calls (`->make(`): 29**
  `grep -rn -- '->make(' --include='*.php' src | wc -l`
- **`Application::getInstance()` call sites: 3**
  `grep -rn 'Application::getInstance' --include='*.php' src | wc -l`
- **Files outside `src/Core/` touching superglobals: 2**
  `grep -rlE '\$_(GET|POST|REQUEST|SERVER|COOKIE|SESSION|FILES)' --include='*.php' src | grep -v '^src/Core/'`
  → `src/Admin/AdminProductController.php`, `src/Upload/UploadController.php`

## Weak hashing (targets of the security hot-fix and Phase 6)

- **`md5(` occurrences at `e85f62b`: 6**
  `grep -rn 'md5(' --include='*.php' src`
  ```
  src/Accounting/Service/BusinessTransactionService.php:54   (fixed in 66093ea)
  src/Accounting/Service/BusinessTransactionService.php:109  (fixed in 66093ea)
  src/Common/Helper/SecurityHelper.php:39
  src/Common/Helper/SecurityHelper.php:185
  src/Common/Service/FileRateLimiter.php:73
  src/Common/Service/RedisRateLimiter.php:85
  ```
- **`md5(` occurrences remaining: 4.** All four are cache-key derivations, not
  security boundaries. Phase 6 replaces them with `hash('xxh128', ...)`.

## Database

- **Migration files: 66**
  `ls database/migrations | wc -l`
  Known collision at ordinal 58 (`58_add_version_to_partner_checks.sql`,
  `58_create_partner_checks_table.sql`, `59_create_partner_checks_table.sql`) —
  resolved in Phase 5.
- **Objects in the reference dump: 111** (94 InnoDB tables, 7 `v_*` views,
  4 triggers, 106 foreign keys, 109 utf8mb4 objects, 22 decimal columns,
  0 float/double columns)
  `grep -c 'CREATE TABLE' database/schema_dump.sql`
- **Objects in the live `anbt_test` schema: not measured.** Blocker: requires a
  migrated test database. Command once available:
  `mysql -N -B -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='anbt_test';"`

## Tests

- **Test classes: 42**
  `grep -rl 'extends TestCase\|extends IntegrationTestCase' tests | wc -l`
- **`test*` methods: 140**
  `grep -rhoE 'function test[A-Za-z0-9_]*' tests | wc -l`
- **Tests executed by the current suite: 146, assertions 614, warnings 1,
  PHPUnit deprecations 29**
  `vendor/bin/phpunit --fail-on-skipped`
  (146 > 140 because data providers expand some methods into several cases.)

## Quality gates

- **PHPStan level before Phase 1: 5.** `git show e85f62b:backend/phpstan.neon | grep level`
- **PHPStan level after Phase 1: 6, `[OK] No errors`, no baseline file.**
  `vendor/bin/phpstan analyse`
  Error counts observed while raising the bar: 29 at level 5, 55 at level 6, all
  fixed structurally.
- **Line coverage: not measured.** Blocker B1 — neither `pcov` nor `xdebug` is
  enabled in the local PHP CLI, so `--coverage-clover` produces nothing.
  This field MUST be filled before Phase 1 can be marked `Done`:
  `vendor/bin/phpunit --coverage-clover=coverage.xml && php tools/coverage-gate.php coverage.xml 40`
- **Coverage ladder:** 40% (Phase 1) → 55% (Phase 4) → 65% (Phase 8) → 75% (Phase 10).
- **PHPStan ladder:** level 6 (Phase 1) → 7 (Phase 6) → 8 (Phase 10).

## Not installed — do not report metrics for these

PHPMD, Infection, and `ramsey/uuid` are **not** dependencies of this project.
Any metric attributed to them is fabricated.
