# aws-samples/aws-appconfig-feature-flags architecture

> Architecture diagram of the GitHub repository aws-samples/aws-appconfig-feature-flags, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aws-samples/aws-appconfig-feature-flags
- Repository: https://github.com/aws-samples/aws-appconfig-feature-flags

## Overview

##### Project type and purpose
- This is a full-stack, serverless web application demonstrating AWS AppConfig Feature Flags.
- The README describes a sample storefront: a React SPA ("frontend" folder) that fetches product data and feature-flag settings from an AWS SAM–backed API ("backend" folder). It uses AWS AppConfig to roll out feature flags, DynamoDB to store sample data, and AWS Lambda + API Gateway to serve endpoints.

##### File structure
- Top level:
- backend/ – AWS SAM service with Lambda functions, a shared Lambda layer, DynamoDB template, and SAM template.yaml
- frontend/ – React application with components, pages, services, context, static assets, and a config template
- repo-wide docs & config: README.md, LICENSE, CONTRIBUTING, .gitignore
- backend/ details:
- template.yaml – defines AWS::Serverless::Function resources, DynamoDB table, API endpoint
- backend/src/ – code for three Lambda functions:
– getAllProducts – returns product list
– getFeatureFlags – returns feature flags
– FeatureFlagLayer – shared layer code that calls AWS AppConfig (getConfig.js, getFeature.js)
- backend/dynamodb.json.template – DynamoDB items template for sample data
- frontend/ details:
- public/ – static HTML entry point and images
- src/ – React entry (index.js), App.js, components (e.g., ProductItem, Feature), pages (Product, Checkout), AppContext (state & API client), services (currency formatter), config.json.template

##### README for additional insights
- Describes deployment steps:
- SAM build & deploy – yields HttpApiUrl and DynamoDBTableName
- Populate DynamoDB via aws cli
- Configure frontend config.json with HttpApiUrl, run npm start
- Emphasizes AWS AppConfig Feature Flags usage and DynamoDB-backed sample data

##### Diagramming the architecture
a. Main components:
- Frontend: React SPA (runs in user's browser)
- API Gateway (HTTP API) – exposes REST endpoints
- AWS Lambda functions – getAllProducts, getFeatureFlags, plus shared FeatureFlagLayer
- DynamoDB table – stores products & flags
- AWS AppConfig – external feature-flag service (Application / Environment / Configuration Profile)
b. Relationships & interactions:
1. User’s browser loads React SPA from localhost:3000 (or hosted static site)
2. SPA reads config.json → HttpApiUrl
3. SPA calls API Gateway endpoints (/products, /feature-flags)
4. API Gateway routes to respective Lambda functions
5. Lambdas use:
– DynamoDB SDK to fetch products & raw flag data
– FeatureFlagLayer to call AWS AppConfig GetConfiguration API and evaluate flags
6. Lambdas return JSON to frontend
7. SPA uses AppContext to store & render based on feature flags
c. Architectural patterns & design principles:
- Serverless microservices: each function has its own package.json and granular permissions
- Shared Lambda Layer (FeatureFlagLayer) centralizes AppConfig logic
- React context for state management and API abstraction
- Infrastructure-as-code via AWS SAM (template.yaml)
d. Key technologies, frameworks & libraries:
- AWS SAM, CloudFormation
- AWS Lambda, API Gateway (HTTP API)
- AWS AppConfig
- DynamoDB
- Node.js & npm (backend & layer)
- React, Create React App, Context API (frontend)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Application
    subgraph "Frontend Application"
        direction TB
        SPA["React SPA"]:::frontend
        Static["Static Assets"]:::frontend
        Config["config.json"]:::frontend
        Entry["index.js"]:::frontend
        App["App.js"]:::frontend
        Context1["AppContext.js"]:::frontend
        Context2["AppProvider.js"]:::frontend
        Pages["Pages"]:::frontend
        Components["Components"]:::frontend
        Services["currency.js"]:::frontend
    end

    %% Backend
    subgraph "AWS Serverless Backend"
        direction TB
        APIGW["API Gateway (HTTP API)"]:::gateway
        subgraph "Lambda Functions"
            direction TB
            getAll["Lambda: getAllProducts"]:::lambda
            getFeat["Lambda: getFeatureFlags"]:::lambda
        end
        subgraph "Shared Lambda Layer"
            direction TB
            LayerCore["FeatureFlagLayer"]:::lambda
            getConfig["getConfig.js"]:::lambda
            getFeature["getFeature.js"]:::lambda
            LayerPkg["package.json"]:::lambda
        end
        Dynamo["DynamoDB Table"]:::db
        AppConfig["AWS AppConfig"]:::db
    end

    %% Frontend connections
    SPA --> Static
    SPA --> Config
    SPA --> Entry
    Entry --> App
    App --> Context1
    App --> Context2
    App --> Pages
    App --> Components
    App --> Services

    %% Frontend to Backend
    SPA -->|"reads config & calls API"| APIGW

    %% API Gateway to Lambdas
    APIGW -->|"GET /products"| getAll
    APIGW -->|"GET /feature-flags"| getFeat

    %% Lambdas to Layer and Datastores
    getAll -->|"uses layer"| LayerCore
    getFeat -->|"uses layer"| LayerCore
    getAll -->|"Query/Scan"| Dynamo
    getFeat -->|"Query/Scan"| Dynamo
    LayerCore -->|"GetConfiguration"| AppConfig

    %% Responses back to SPA
    getAll -->|"returns JSON"| SPA
    getFeat -->|"returns JSON"| SPA

    %% Click Events - Frontend
    click SPA "https://github.com/aws-samples/aws-appconfig-feature-flags/tree/main/frontend/"
    click Static "https://github.com/aws-samples/aws-appconfig-feature-flags/tree/main/frontend/public/"
    click Config "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/frontend/src/config.json.template"
    click Entry "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/frontend/src/index.js"
    click App "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/frontend/src/App.js"
    click Context1 "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/frontend/src/context/AppContext.js"
    click Context2 "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/frontend/src/context/AppProvider.js"
    click Pages "https://github.com/aws-samples/aws-appconfig-feature-flags/tree/main/frontend/src/pages/"
    click Components "https://github.com/aws-samples/aws-appconfig-feature-flags/tree/main/frontend/src/components/"
    click Services "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/frontend/src/services/currency.js"

    %% Click Events - Backend
    click APIGW "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/backend/template.yaml"
    click Dynamo "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/backend/dynamodb.json.template"
    click getAll "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/backend/src/getAllProducts/getAllProducts.js"
    click getAll "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/backend/src/getAllProducts/package.json"
    click getFeat "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/backend/src/getFeatureFlags/getFeatureFlags.js"
    click getFeat "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/backend/src/getFeatureFlags/package.json"
    click LayerCore "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/backend/src/FeatureFlagLayer/getConfig.js"
    click getConfig "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/backend/src/FeatureFlagLayer/getConfig.js"
    click getFeature "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/backend/src/FeatureFlagLayer/getFeature.js"
    click LayerPkg "https://github.com/aws-samples/aws-appconfig-feature-flags/blob/main/backend/src/FeatureFlagLayer/package.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#000
    classDef gateway fill:#E0C0FF,stroke:#5a1ea1,color:#000
    classDef lambda fill:#FFDDC1,stroke:#d2691e,color:#000
    classDef db fill:#C1FFC1,stroke:#228B22,color:#000
```
