# aws-samples/avp-petstore-sample architecture

> Architecture diagram of the GitHub repository aws-samples/avp-petstore-sample, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aws-samples/avp-petstore-sample
- Repository: https://github.com/aws-samples/avp-petstore-sample

## Overview

This is an Amplify-hosted Pet Store sample demonstrating Cognito sign-in and role- and attribute-based authorization through Amazon Verified Permissions. A signed-in user selects role-specific pet or order actions in the React app; the app sends an authenticated API request, and the Lambda backend verifies the token, constructs authorization entities and a resource, and asks Verified Permissions for a decision. The README also describes manual setup of Cognito users/groups and Verified Permissions schema and policies. Some backend wiring is documented rather than visible in sampled source.

Main entry points: [`amplify/backend/function/petstoresample78b39c63/src/index.js`](https://github.com/aws-samples/avp-petstore-sample/blob/main/amplify/backend/function/petstoresample78b39c63/src/index.js) (Authorization handler), [`src/App.js`](https://github.com/aws-samples/avp-petstore-sample/blob/main/src/App.js) (Role actions UI), [`amplify/backend/auth/petstoresample483a619c/override.ts`](https://github.com/aws-samples/avp-petstore-sample/blob/main/amplify/backend/auth/petstoresample483a619c/override.ts) (Cognito user pool), [`amplify/backend/api/petstoreapi`](https://github.com/aws-samples/avp-petstore-sample/tree/main/amplify/backend/api/petstoreapi) (REST API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Pet Store app"]
  node_app["Role actions UI<br/>[App.js]"]
end

subgraph group_backend["Backend API"]
  node_api["REST API"]
  node_lambda["Authorization handler<br/>[index.js]"]
  node_route_map["Action mapping<br/>[index.js]"]
  node_entity_context["Entity context<br/>[index.js]"]
end

subgraph group_identity["Identity"]
  node_cognito["Cognito user pool<br/>[override.ts]"]
end

subgraph group_authz["Authorization"]
  node_avp["Verified Permissions"]
end

node_user(("Pet Store user"))
node_admin(("AWS console administrator"))

node_user -->|"uses"| node_app
node_app -->|"signs in; gets token"| node_cognito
node_app -->|"sends requests"| node_api
node_api -->|"routes requests"| node_lambda
node_lambda -->|"verifies token"| node_cognito
node_lambda -->|"maps route"| node_route_map
node_lambda -->|"builds entities"| node_entity_context
node_lambda -->|"asks decision"| node_avp
node_admin -->|"manages users"| node_cognito
node_admin -->|"configures policies"| node_avp

click node_app "https://github.com/aws-samples/avp-petstore-sample/blob/main/src/App.js"
click node_api "https://github.com/aws-samples/avp-petstore-sample/tree/main/amplify/backend/api/petstoreapi"
click node_lambda "https://github.com/aws-samples/avp-petstore-sample/blob/main/amplify/backend/function/petstoresample78b39c63/src/index.js"
click node_route_map "https://github.com/aws-samples/avp-petstore-sample/blob/main/amplify/backend/function/petstoresample78b39c63/src/index.js"
click node_entity_context "https://github.com/aws-samples/avp-petstore-sample/blob/main/amplify/backend/function/petstoresample78b39c63/src/index.js"
click node_cognito "https://github.com/aws-samples/avp-petstore-sample/blob/main/amplify/backend/auth/petstoresample483a619c/override.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_user toneBlue
class node_api,node_lambda,node_route_map,node_entity_context toneAmber
class node_cognito toneMint
class node_avp toneRose
class node_admin toneIndigo
```

## Components

### Pet Store app

- [Role actions UI](https://github.com/aws-samples/avp-petstore-sample/blob/main/src/App.js): `src/App.js`

### Backend API

- [REST API](https://github.com/aws-samples/avp-petstore-sample/tree/main/amplify/backend/api/petstoreapi): `amplify/backend/api/petstoreapi`
- [Authorization handler](https://github.com/aws-samples/avp-petstore-sample/blob/main/amplify/backend/function/petstoresample78b39c63/src/index.js): `amplify/backend/function/petstoresample78b39c63/src/index.js`
- [Action mapping](https://github.com/aws-samples/avp-petstore-sample/blob/main/amplify/backend/function/petstoresample78b39c63/src/index.js): `amplify/backend/function/petstoresample78b39c63/src/index.js`
- [Entity context](https://github.com/aws-samples/avp-petstore-sample/blob/main/amplify/backend/function/petstoresample78b39c63/src/index.js): `amplify/backend/function/petstoresample78b39c63/src/index.js`

### Identity

- [Cognito user pool](https://github.com/aws-samples/avp-petstore-sample/blob/main/amplify/backend/auth/petstoresample483a619c/override.ts): `amplify/backend/auth/petstoresample483a619c/override.ts`

### Authorization

- **Verified Permissions**

### Other components

- **Pet Store user**
- **AWS console administrator**

## Connections

- Pet Store user → Role actions UI: uses (evidence: `README.md`)
- Role actions UI → Cognito user pool: signs in; gets token (evidence: `src/App.js`)
- Role actions UI → REST API: sends requests (evidence: `src/App.js`)
- REST API → Authorization handler: routes requests (evidence: `README.md`)
- Authorization handler → Cognito user pool: verifies token (evidence: `amplify/backend/function/petstoresample78b39c63/src/index.js`)
- Authorization handler → Action mapping: maps route (evidence: `amplify/backend/function/petstoresample78b39c63/src/index.js`)
- Authorization handler → Entity context: builds entities (evidence: `amplify/backend/function/petstoresample78b39c63/src/index.js`)
- Authorization handler → Verified Permissions: asks decision (evidence: `amplify/backend/function/petstoresample78b39c63/src/index.js`)
- AWS console administrator → Cognito user pool: manages users (evidence: `README.md`)
- AWS console administrator → Verified Permissions: configures policies (evidence: `README.md`)
