# Amazon S3 Backup Export

## Objective

Let customers send their exports and archives to a bucket they control themselves.

A customer-configured S3 destination with scoped credentials, multipart transfer, and verified object integrity.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Let a customer configure their own bucket as an export destination — bucket, region, key prefix, and expected encryption — and validate all of it with a test write at the moment they save the settings.
2. Prefer credentials the customer can scope and rotate, such as a role the app assumes with an external identifier, and store whatever is held encrypted at rest. Do not make a long-lived account-wide key the only supported option.
3. Write large archives as a multipart upload driven by the app's existing background-job system, so a failed part is retried rather than the whole archive resent.
4. Give every export an immutable key built from the prefix, a timestamp, and the export's own identifier, so a new run can never land on top of an old one.
5. Dropbox File Export and OneDrive File Export cover consumer destinations and their interactive folder pickers. This entry owns the customer-operated bucket case: credential scoping, multipart transfer, and integrity verification.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Permanent broad keys become a liability the moment the app is breached. Assume a scoped role where the provider supports it, require an external identifier so the app cannot be used as a confused deputy, and allow rotation without breaking scheduled exports.
- A wrong region, a missing bucket, a prefix the credential cannot write, or a bucket policy demanding a particular encryption setting all fail at upload time. Validate each on save and name the specific setting that is wrong.
- An abandoned multipart upload leaves incomplete parts the customer keeps paying to store. Abort explicitly on failure, and resume or clean up on the next run.
- Two exports must never collide on one key and silently destroy the earlier backup. Keys are unique per run, and an unexpected existing object fails the run loudly instead of overwriting it.
- Confirm the stored object's checksum matches what was sent before marking the export complete. An export reported as successful but truncated is worse than one that plainly failed.
- Bucket policy can change after connection so that working exports start being refused. Treat access denial as a connection-level problem, notify the account owner, and stop the retry schedule.
- The provider throttles per key prefix under sustained load. Back off on throttling responses rather than treating them as fatal.
- Never echo a stored credential back to the browser, even masked in a settings form. Show only enough to identify which credential is in use.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] A customer can point exports at their own bucket with region, prefix, and encryption settings validated on save.
- [ ] Credentials are scoped, encrypted at rest, rotatable, and never returned to the client.
- [ ] Large archives upload in parts and resume rather than restarting after a failure.
- [ ] Each export writes a unique key and cannot overwrite a previous backup.
- [ ] An export is marked complete only after its checksum is verified against the stored object.
- [ ] Access denied, wrong region, and throttling are reported as distinct causes.
- [ ] Failed multipart uploads are aborted rather than left accruing storage cost.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
