{"id":45157389,"url":"https://github.com/couchbase-examples/couchbase-data_api-appsync-demo","last_synced_at":"2026-02-20T05:02:33.599Z","repository":{"id":319269009,"uuid":"1077454835","full_name":"couchbase-examples/couchbase-data_api-appsync-demo","owner":"couchbase-examples","description":"Demo to search hotels by city using an AWS AppSync GraphQL API backed by Couchbase Data API, with a Streamlit frontend for visualization.","archived":false,"fork":false,"pushed_at":"2025-10-28T06:54:31.000Z","size":11163,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-28T08:29:59.183Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/couchbase-examples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-16T09:17:55.000Z","updated_at":"2025-10-28T06:54:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"8dcbc8a8-5344-4eda-9ba5-8afe688607ae","html_url":"https://github.com/couchbase-examples/couchbase-data_api-appsync-demo","commit_stats":null,"previous_names":["couchbase-examples/couchbase-data_api-appsync-demo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/couchbase-examples/couchbase-data_api-appsync-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fcouchbase-data_api-appsync-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fcouchbase-data_api-appsync-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fcouchbase-data_api-appsync-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fcouchbase-data_api-appsync-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/couchbase-examples","download_url":"https://codeload.github.com/couchbase-examples/couchbase-data_api-appsync-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fcouchbase-data_api-appsync-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29641929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-20T03:21:14.183Z","status":"ssl_error","status_checked_at":"2026-02-20T03:18:24.455Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-02-20T05:02:32.137Z","updated_at":"2026-02-20T05:02:33.594Z","avatar_url":"https://github.com/couchbase-examples.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Travel Sample: AppSync + Couchbase Data API\n\n## Motivation\n\nThis demo showcases how to use **Couchbase Capella Data API** in a serverless architecture. The app connects AWS AppSync with Couchbase Capella using the Data API—ideal for serverless environments because it:\n\n- **Enables driverless mode:** No need to deploy SDKs in FaaS environments (AWS Lambda, Azure Functions)\n- **Is lightweight:** Avoids heavy SDK initialization overhead in stateless functions\n- **Simplifies integration:** Uses standard HTTP—no SDK version management or dependencies\n- **Is language agnostic:** Works with any platform that can make HTTP requests\n\nLearn more: [Data API vs. SDKs](https://docs.couchbase.com/cloud/data-api-guide/data-api-sdks.html)\n\n**Architecture Overview:**\n- **Frontend:** Streamlit (Python) for interactive UI\n- **API Layer:** AWS AppSync (GraphQL) as the API source\n- **Backend:** Couchbase Capella connected via Data API\n- **Use Case:** Search hotels near airports using geospatial queries\n\nThe query uses geospatial calculations to find hotels within a specified distance from an airport and visualizes results on an interactive map.\n\n## Screenshots\n\n- Streamlit frontend\n  - Home Page\n    ![Streamlit home](assets/streamlit-search.jpg)\n  \n  - Map visualization  \n    ![Streamlit map](assets/streamlit-map.jpg)\n\n## What's here\n- `src/backend/`\n  - `schema.graphql`: Defines the GraphQL schema with:\n    - Query: `listHotelsNearAirport(airportName: String!, withinKm: Int!)`\n    - Returns `Output` type with `hotels: [Hotel]` and `airport: Airport`\n    - `Airport` type includes `name: String` and `location: GeoObject` (lat, lon, accuracy)\n    - `Hotel` type includes all hotel details, geo location, and reviews\n  - `listHotelsInCity resolver.js`: JavaScript resolver for AppSync HTTP data source\n    - Calls Couchbase Data API to query `travel-sample.inventory.hotel` and `travel-sample.inventory.airport`\n    - Uses a SQL++ query with Common Table Expression (CTE) for geospatial distance calculation\n    - Extracts airport coordinates from query results and combines with airport name from input\n    - Returns structured response matching the `Output` schema\n    - Credentials read from AppSync environment variables (`cb_username`, `cb_password`)\n  - `query.graphql`: Example GraphQL query for testing in the AppSync console\n- `src/frontend/`\n  - `home.py`: Streamlit main entry point with tab-based navigation and connection settings (GraphQL endpoint, API key)\n  - `search_hotels.py`: Interactive search interface\n    - Calls AppSync GraphQL API with airport name and distance parameters\n    - Displays results on an interactive map using Pydeck\n    - Hotels shown as color-coded markers (red to green by rating)\n    - Airport shown as orange marker with white outline\n    - Hover tooltips show hotel details (name, rating, address, price, etc.) or just airport name\n    - Automatically centers and zooms map to show all markers\n\n## Prerequisites\n\nBefore you get started, make sure you have:\n\n1. **[Couchbase Capella account](https://cloud.couchbase.com/sign-up)** with a [running cluster](https://docs.couchbase.com/cloud/get-started/create-account.html)\n2. **[Travel-sample bucket](https://docs.couchbase.com/cloud/clusters/data-service/import-data-documents.html)** imported into your cluster\n3. **[Data API enabled](https://docs.couchbase.com/cloud/data-api-guide/data-api-start.html)** in Capella (via the cluster's Connect page)\n   - **Important:** Set Allowed IP address to **\"Allow access from anywhere\"** for demo purposes\n   - This configuration is required for this demo to function with AWS AppSync\n   - Not recommended for production—see [documentation](https://docs.couchbase.com/cloud/data-api-guide/data-api-start.html) for secure network configurations\n4. **[AWS account](https://aws.amazon.com/)** with permissions to create AppSync APIs\n\n## Quick Start\n\n\u003e **For a detailed step-by-step tutorial, see:** [Build a Hotel Search App with AppSync, Data API, and Streamlit](https://developer.couchbase.com/tutorial-appsync-data-api-streamlit-travel-sample)\n\n### 1. Set Up AWS AppSync\n\n**a) Create AppSync API:**\n- Navigate to AWS AppSync console\n- Create a new API (choose \"Build from scratch\" option)\n- Name your API (e.g., \"HotelSearchAPI\")\n\n**b) Create HTTP Data Source:**\n- Navigate to Data sources → Create data source\n- Data source type: **HTTP**\n- Name: `CouchbaseDataAPI`\n- HTTP endpoint URL: Your Couchbase Data API base URL\n- **Note:** Do NOT enable \"Authorization\" configuration—credentials will be passed via resolver\n\n![AppSync Data Source](assets/appsync-data-source.jpg)\n\n**c) Configure Environment Variables:**\n- Navigate to Settings → Environment variables\n- Add:\n  - `cb_username`: Your Couchbase Data API username\n  - `cb_password`: Your Couchbase Data API password\n\n![AppSync Env Vars Configuration](assets/appsync-env-vars.jpg)\n\n**d) Import Schema:**\n- Navigate to Schema\n- Copy contents from `src/backend/schema.graphql` and paste into the schema editor\n- Save schema\n\n![AppSync schema](assets/appsync-schema.jpg)\n\n**e) Create Resolver:**\n- Navigate to Schema → Query type → `listHotelsNearAirport` field\n- Click \"Attach Resolver\"\n- Data source: Select `CouchbaseDataAPI`\n- Runtime: **JavaScript**\n- Copy contents from `src/backend/listHotelsInCity resolver.js` and paste into resolver code editor\n- Save resolver\n\n![AppSync Resolver](assets/appsync-resolver.jpg)\n\n**f) Test Your Query:**\n- Navigate to Queries\n- Copy the query from `src/backend/query.graphql`\n- Provide variables: `{\"airportName\": \"London Heathrow\", \"withinKm\": 50}`\n- Run query to verify setup\n\n**g) Get API Credentials:**\n- Navigate to Settings to find your **GraphQL endpoint URL**\n- Navigate to API Keys → Create API key and note the **API Key** (starts with `da2-`)\n\n### 2. Set Up Frontend (Streamlit)\n\nInstall dependencies and run:\n```bash\n# Navigate to the project directory\ncd couchbase-data_api-appsync-demo\n\n# Create a virtual environment\npython3 -m venv .venv\n\n# Activate the virtual environment\nsource ./.venv/bin/activate\n\n# Install required dependencies\npip install -r requirements.txt\n\n# Run the Streamlit app\nstreamlit run src/frontend/home.py\n```\n\nIn the app:\n- Enter **AppSync GraphQL Endpoint** and **API Key** in the sidebar (from AppSync Settings)\n- Click the **\"Search Hotels\"** tab\n- Try example airports: `San Francisco Intl`, `Les Loges`, `Luton`, `London St Pancras`\n- Enter distance in km and click **Search**\n\n## Notes\n\n**Backend (Resolver)**\n- Assumes collections `travel-sample.inventory.hotel` and `travel-sample.inventory.airport` exist\n- Uses SQL++ query with CTE to find airport coordinates: `SELECT a.geo.lat, a.geo.lon, a.geo.accuracy FROM airport WHERE a.airportname = $1`\n- Calculates distance using Pythagorean theorem approximation (accurate for small distances): `POWER(hotel_lat - airport_lat, 2) + POWER(hotel_lon - airport_lon, 2) \u003c= POWER(distance_km / 111, 2)` where 111 ≈ km per degree of latitude\n- Returns airport coordinates from first result row (all rows have same airport location)\n- Combines airport location with airport name from input arguments to create `Airport` object\n- Cleans hotel objects by removing airport coordinate fields (alat, alon, accuracy)\n\n**Frontend (Streamlit)**\n- Extracts airport name and location from the `airport` object in GraphQL response\n- Computes hotel ratings by averaging `Overall` scores from reviews array, scaled to 0-10\n- Colors hotel markers from red (low rating) to green (high rating)\n- Shows airport marker in orange with larger size and white outline for visibility\n- Tooltips display full details for hotels, only name for airport\n- Map auto-centers on all markers with appropriate zoom level based on geographic spread\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcouchbase-examples%2Fcouchbase-data_api-appsync-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcouchbase-examples%2Fcouchbase-data_api-appsync-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcouchbase-examples%2Fcouchbase-data_api-appsync-demo/lists"}