# Social Feed Embed

## Objective

Show your latest social posts on your own pages without breaking when the network is down.

A server-side fetch of an external social account's recent posts, cached and rendered in the app's own markup.

## 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. Fetch the posts on the server on a schedule and store them, then render from your own store. Do not have every visitor's browser call the social platform directly.
2. Render the posts in the app's own card markup with your own typography and spacing. A dropped-in third-party script fights your styling, tracks your visitors, and disappears when the platform changes its widget.
3. Reuse the app's existing image pipeline for post media so thumbnails are resized and served from your own storage rather than hotlinked from the platform.
4. Give operators a settings screen showing the connected account, the last successful fetch, and the current authorisation state, with a clear reconnect action.
5. Do not fail the page when the feed cannot be refreshed. Serve the last good cached copy, and if there is no cached copy, hide the section entirely rather than rendering an empty box.

## 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

- An upstream outage must not blank the section. Keep serving the last successful fetch and mark it stale internally, so the page looks the same to a visitor who does not care why.
- The platform will rate-limit you. Back off exponentially on rejection, respect any retry hint returned, and never retry a failed fetch on every page request.
- If any third-party markup is embedded at all, sandbox it so it cannot run scripts against your page, read cookies, or navigate the top-level window.
- Posts load after the page does and will push content down. Reserve the section's height from the cached post count and known media dimensions so nothing jumps.
- Account authorisation expires or gets revoked. Surface that to the operator with a visible reconnect prompt instead of quietly serving a feed that stops updating and slowly goes stale.
- Post text and media come from a platform where a caption can be edited or deleted after you cached it. Refresh on a schedule and drop posts that no longer exist upstream.
- Media needs alt text. Use the platform's own description where one exists and fall back to something meaningful rather than an empty attribute.
- If the app has Consent and Cookie Preferences, an embed that would set third-party cookies must not load until consent is given, and must show a placeholder with an explicit load action instead.

## 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

- [ ] Posts render from the app's own cached copy, not from a live browser request to the platform.
- [ ] An upstream outage or rate limit leaves the last good posts visible with no error on the page.
- [ ] Retries use exponential backoff and honour any retry hint the platform returns.
- [ ] The section's height is reserved so late-arriving posts do not shift the layout.
- [ ] Revoked or expired authorisation is visible to the operator with a reconnect action.
- [ ] Any embedded third-party markup is sandboxed and cannot script the host page.
- [ ] Every post image carries meaningful alt text.
- [ ] 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.
