No source code may be written before the spec and plan exist.
## Selected Approach
The system employs a client-server architecture utilizing **Java 21**, **Hibernate 6**, and **SQLite**.
### Key Design Decisions
-**Persistence**: SQLite was selected for its ACID compliance. To prevent write-lock upgrade deadlocks, the server uses `BEGIN IMMEDIATE` transactions.
-**Concurrency**: A combination of per-account Java synchronization (as an optimization) and SQLite's `IMMEDIATE` locking is used to ensure thread-safety.
-**Idempotency**: Enforced via a persistent `TransactionHistory` table and an `IdempotencyMetadata` table that binds sequence keys to idempotency keys, ensuring that failed attempts (e.g., insufficient funds) are also tracked.
-**Consistency**: A `busy_timeout` is configured in the JDBC connection to handle lock contention gracefully.
## Implementation Details
-**Language**: Java 21
-**Build Tool**: Maven
-**AI Coding Agent**: Claude Code
### Setup and Execution
#### Build the Project
```bash
mvn clean install
```
#### Run the Server
Currently, the core logic is implemented in a service layer. To run the system, start the server application:
-**Concurrency Tests**: Verified that $N$ simultaneous identical requests result in exactly one debit.
-**Fault Scenarios**:
-**Completed**: Atomic rollback on failure, historical retry recognition, and idempotency conflict detection.
-**Planned**: Full end-to-end validation of the four fault-injection scenarios (response loss, crashes, delays).
## Engineering Reflection
Applying Spec-Driven Development (SDD) identified critical gaps during the specification phase that would have otherwise emerged as bugs during implementation. For example:
-**Idempotency Conflict**: SDD revealed that simply tracking committed transactions was insufficient; we needed a separate metadata log to prevent different idempotency keys from being used for the same sequence key during failed attempts.
-**SQLite Deadlocks**: The planning phase highlighted that standard Hibernate transactions (`DEFERRED`) would cause `SQLITE_BUSY` deadlocks during lock upgrades, leading to the requirement for `BEGIN IMMEDIATE`.