**Input**: User description: "I want to add a new feature to the existing **Fault-Tolerant Distributed Banking Transaction** project: a web-based user interface (Web UI) for the banking system. ... [ full description provided in prompt ]"
## User Scenarios & Testing *(mandatory)*
### User Story 1 - Account Overview Dashboard (Priority: P1)
A user opens the banking application and sees a high-level overview of the system status, a list of all available bank accounts with their current balances, and a summary of recent activity.
**Why this priority**: Essential for user orientation. Users must be able to see their current financial state before performing operations.
**Independent Test**: Can be fully tested by launching the web interface and verifying that it fetches and displays the current list of accounts and balances from the server.
**Acceptance Scenarios**:
1.**Given** the server is running and contains accounts, **When** the dashboard is loaded, **Then** the user sees a "System Online" status and a table of accounts with correct balances.
2.**Given** the server is unreachable, **When** the dashboard is loaded, **Then** the user sees a "System Offline" or connectivity error message.
3.**Given** a transaction was just completed, **When** the user returns to the dashboard or clicks a "Refresh" button, **Then** the UI triggers a new `GET /accounts` call to update the displayed balances.
---
### User Story 2 - Perform Withdrawal Operation (Priority: P1)
A user submits a withdrawal request through a web form. The system processes the request and provides immediate visual feedback on the outcome.
**Whythis priority**:The core business value of the system is the ability to withdraw funds.
**IndependentTest**:Can be fully tested by filling out the withdrawal form for a valid account and verifying that the success/failure message and updated balance are displayed.
**AcceptanceScenarios**:
1. **Given** an account with $100, **When** the user submits a withdrawal for $20 with a valid sequence key, **Then** the UI displays a success message and the updated balance of $80.
2. **Given** an account with $100, **When** the user submits a withdrawal for $120, **Then** the UI displays an "Insufficient Funds" error and the balance remains $100.
3. **Given** a withdrawal request, **When** the user submits an invalid account ID, **Then** the UI displays an "Invalid Account" error.
---
### User Story 3 - Idempotency and Retry Testing (Priority: P2)
A user retries a transaction that had an unknown outcome (e.g., due to a timeout) to ensure no duplicate funds are withdrawn.
**Why this priority**: Validates the "effectively-once" core principle of the project through the UI.
**Independent Test**: Can be fully tested by arming a response-loss fault and then submitting a withdrawal.
**Acceptance Scenarios**:
1.**Given** the system is in a test environment, **When** the tester calls `POST /__test/faults/response-loss`, **Then** the server arms a one-time response-loss simulation for the next withdrawal request.
2.**Given** a response-loss fault is armed, **When** the user submits a withdrawal, **Then** the server commits the transaction to the database but closes the connection without responding, causing the UI to display an "Unknown Outcome" state.
3.**Given** a previously submitted transaction with an "Unknown Outcome", **When** the user clicks "Retry", **Then** the UI submits the request using the original `accountId`, `amount`, and `sequenceKey` (preserved in client state), setting `isRetry` to `true`.
4.**Given** a successfully committed transaction (from a previous response loss), **When** the user retries it, **Then** the UI displays the original "Success" message and the balance does not decrease a second time.
5.**Given** a failed transaction (e.g., insufficient funds), **When** the user retries it, **Then** the UI displays the original rejection message.
---
### User Story 4 - Transaction History Review (Priority: P2)
A user views a comprehensive list of all processed transactions to audit their banking activity.
**Whythis priority**:Critical for transparency and verification of the "Effectively-Once" guarantee.
**IndependentTest**:Can be fully tested by performing several transactions (success, insufficient funds) and verifying they all appear in the history list with correct metadata.
**AcceptanceScenarios**:
1. **Given** multiple processed transactions, **When** the user navigates to the History page, **Then** they see a table containing transaction IDs, account IDs, amounts, sequence keys, outcomes, and timestamps.
2. **Given** a mix of outcomes, **When** viewing the history, **Then** only transactions persisted in the `TransactionLedger` (SUCCESS, INSUFFICIENT_FUNDS) are displayed. Validation errors (e.g., `STALE_KEY`) are not shown in the persisted history.
3. **Given** the history page is loaded, **When** the user clicks a "Refresh" button, **Then** the UI triggers a new `GET /transactions` call to update the log.
---
### User Story 5 - Account Creation (Priority: P3)
A user creates a new bank account to start performing transactions.
**Why this priority**: Facilitates system setup and testing without manual database manipulation.
**Independent Test**: Can be fully tested by using the "Create Account" form and then verifying the new account appears on the Dashboard.
**Acceptance Scenarios**:
1.**Given** a request to create an account with ID "ACC-NEW" and initial balance $500, **When** submitted via `POST /accounts`, **Then** the server creates the account and the UI confirms success (HTTP 201 Created).
2.**Given** an account with ID "ACC-EXISTING" already exists, **When** the user attempts to create it again, **Then** the server returns an error (HTTP 409 Conflict) and the UI displays "Account already exists".
3.**Given** a request to create an account with a negative initial balance, **When** submitted, **Then** the server returns a validation error (HTTP 400 Bad Request) and the UI displays "Initial balance must be non-negative".
---
### Edge Cases
-**Unknown Outcome/Timeout**: How does the UI handle a request that never returns? The UI MUST display an `UNKNOWN_OUTCOME` state and provide a clear "Retry" button that preserves the transaction identity.
-**Concurrent Tab Updates**: What happens if a user has multiple tabs open? The UI should ideally refresh balance data on page load or provide a refresh button.
-**Invalid Sequence Keys**: When a user enters a sequence key that is too low, the UI must explicitly display the `STALE_KEY` error returned by the server.
-**Zero/Negative Amount**: The UI should prevent submission of non-positive amounts via HTML5 validation, but must also handle `INVALID_AMOUNT` responses from the server.
## Requirements *(mandatory)*
### Functional Requirements
-**FR-001**: The system MUST provide a web-based dashboard displaying server connectivity and account balances.
-**FR-002**: The system MUST provide a withdrawal form that accepts `accountId`, `amount`, and `sequenceKey`.
-**FR-003**: The system MUST visually distinguish between different transaction outcomes (`SUCCESS`, `INSUFFICIENT_FUNDS`, `STALE_KEY`, `CONFLICTING_TRANSACTION`, `INVALID_ACCOUNT`).
-**FR-004**: The system MUST implement a "Retry" mechanism that re-submits a transaction using the exact original `accountId`, `amount`, and `sequenceKey` preserved in client state, while setting `isRetry` to `true`.
-**FR-005**: The system MUST display a transaction history log containing only transactions persisted in the `TransactionLedger` (i.e., outcomes `SUCCESS` and `INSUFFICIENT_FUNDS`).
-**FR-006**: The system MUST provide a mechanism to create new bank accounts via the UI.
-**FR-007**: The system MUST handle network timeouts or lost connections by transitioning the transaction state to `UNKNOWN_OUTCOME` on the client side.
-**FR-008**: The backend MUST expose new API endpoints to support:
-`GET /accounts`: Retrieve all accounts and balances.
-**FR-009**: The system MUST serve frontend assets (HTML, CSS, and JS) directly from the existing Java `HttpServer`.
-**FR-010**: Fault injection and failure simulation MUST be governed by the following strict constraints:
-**Availability**: MUST be disabled by default and available ONLY in development/test environments.
-**Security**: MUST NOT add any debugging, fault-injection, or control fields to the `POST /withdraw` JSON request contract.
-**Production**: MUST be impossible to enable in production environments.
-**Behavior**: Response-loss simulation MUST occur AFTER the database transaction has successfully committed.
-**Activation Mechanism**: For test environments, a dedicated endpoint `POST /__test/faults/response-loss` MUST be provided. Calling this endpoint arms a one-time response-loss simulation for the next applicable withdrawal request. This endpoint MUST NOT be registered or accessible in production.
### Key Entities *(include if feature involves data)*
-**WebSession**: (Client-side) Tracks the current state of the UI and any pending transactions with "Unknown" outcomes.
-**TransactionRecordView**: (UI) A representation of a server-side transaction, including its identity, amount, and outcome.
-**AccountView**: (UI) A representation of a bank account showing its ID and current balance.
## Success Criteria *(mandatory)*
### Measurable Outcomes
-**SC-001**: Users can successfully submit a withdrawal and see the updated balance in under 2 seconds (excluding simulated faults).
-**SC-002**: 100% of "Retry" attempts for "Unknown Outcome" transactions reuse the original transaction identity.
-**SC-003**: All server-side transaction outcomes (including errors) are accurately mapped to specific visual indicators in the UI.
-**SC-004**: The time to create a new account and see it appear on the dashboard is under 3 seconds.
## Assumptions
-**Frontend Technology**: It is assumed that vanilla JavaScript, HTML, and CSS will be used to avoid adding external framework dependencies (React/Vue/etc.).
-**Backend Extension**: It is assumed that the existing `HttpServerApp` and `RequestHandler` can be extended to serve static files and new JSON endpoints without changing the core transaction logic.
-**Authentication**: For the scope of this simulation, no user authentication is required; any user with access to the URL can manage accounts.
-**State Management**: It is assumed that the client-side state is sufficient for handling retries within a single session.