# WP2-003 – Persistence Foundation

## Status

Implemented.

## Scope

WP2-003 introduces the technical persistence foundation without adding repositories, data mappers, schema migrations, rehydration, or aggregate persistence.

## New components

- `App\Application\Persistence\TransactionManager`
- `App\Infrastructure\Database\DatabaseConnectionFactory`
- `App\Infrastructure\Database\PdoTransactionManager`
- `config/database.php`
- `tests/Persistence/PersistenceFoundationTest.php`

## Changed components

- `Configuration` loads and validates the database configuration.
- `ReconciliationCompositionRoot` owns the connection factory and creates the transaction manager.
- `ConfigurationTest` verifies the database configuration baseline.

## Connection lifetime

`DatabaseConnectionFactory` creates the PDO connection lazily on first persistence access and caches it for the lifetime of the composition-root object graph. Controller assembly and manifest access therefore remain possible while persistence is disabled. There is no global or static connection.

## Configuration

Database access is disabled by default. It can be enabled with environment variables:

- `RECONCILIX_DB_ENABLED`
- `RECONCILIX_DB_DRIVER`
- `RECONCILIX_DB_HOST`
- `RECONCILIX_DB_PORT`
- `RECONCILIX_DB_NAME`
- `RECONCILIX_DB_USER`
- `RECONCILIX_DB_PASSWORD`
- `RECONCILIX_DB_CHARSET`

The supported driver in WP2-003 is `mysql`, covering MySQL 8 and MariaDB 10.4 through PDO MySQL.

## Test

```bash
php tests/Persistence/PersistenceFoundationTest.php
```
