{"id":15056699,"url":"https://github.com/scylladb/shopping-cart","last_synced_at":"2025-04-10T04:34:47.920Z","repository":{"id":221341864,"uuid":"754109193","full_name":"scylladb/shopping-cart","owner":"scylladb","description":"Sample ecommerce shopping cart app with ScyllaDB and Python","archived":false,"fork":false,"pushed_at":"2025-02-17T10:52:18.000Z","size":397,"stargazers_count":4,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T05:51:43.016Z","etag":null,"topics":["api","cassandra","ecommerce","fastapi","nosql","python","scylladb"],"latest_commit_sha":null,"homepage":"https://shopping-cart.scylladb.com/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scylladb.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2024-02-07T12:22:06.000Z","updated_at":"2025-02-17T10:52:23.000Z","dependencies_parsed_at":"2024-07-18T22:31:36.256Z","dependency_job_id":"4ff8a2c2-5b7c-41e2-b173-46bbc5bb9d92","html_url":"https://github.com/scylladb/shopping-cart","commit_stats":null,"previous_names":["zseta/shopping-cart","scylladb/shopping-cart"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scylladb%2Fshopping-cart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scylladb%2Fshopping-cart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scylladb%2Fshopping-cart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scylladb%2Fshopping-cart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scylladb","download_url":"https://codeload.github.com/scylladb/shopping-cart/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248158133,"owners_count":21057117,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["api","cassandra","ecommerce","fastapi","nosql","python","scylladb"],"created_at":"2024-09-24T21:55:15.843Z","updated_at":"2025-04-10T04:34:47.880Z","avatar_url":"https://github.com/scylladb.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ecommerce API - ScyllaDB \u0026 FastAPI sample application\nThis is a sample ecommerce application built with [ScyllaDB](https://www.scylladb.com/) and [FastAPI](https://fastapi.tiangolo.com/).\n\n\n## Prerequisites\n* [CQLSH](https://cassandra.apache.org/doc/stable/cassandra/tools/cqlsh.html)\n* Python 3\n* [ScyllaDB Cloud account](https://cloud.scylladb.com)\n\n## Get started\n\nClone the repository:\n\n```\ngit clone https://github.com/zseta/shopping-cart\ncd shopping-cart\n```\n\n## Create database schema\n\nConnect to your ScyllaDB Cloud cluster using CQLSH and create the schema:\n\n```\ncqlsh -u scylla -p \u003cYOUR_PASSWORD\u003e -f schema.cql xxxx.xxxx.xxxx.clusters.scylla.cloud\n```\n\n## Set up API server\n\nCreate a new virtual environment:\n```\nvirtualenv env\nsource env/bin/activate\n```\n\nInstall Python requirements (FastAPI with Uvicorn server and ScyllaDB driver):\n```\npip install fastapi \"uvicorn[standard]\" scylla-driver requests\n```\n\nModify `config.py` to match your database credentials:\n\n```python\nHOST=\"node-0.aws-us-east-1.xxxx.clusters.scylla.cloud\"\nUSER=\"scylla\"\nPASSWORD=\"xxxxxx\"\nDATACENTER=\"AWS_US_EAST_1\"\nKEYSPACE=\"ecommerce\"\n```\n\nRun the server:\n```\nuvicorn main:app --reload\n```\n\nVisit API docs: http://127.0.0.1:8000/docs\n\n![fast api docs](images/apidocs.png)\n\n## Generate sample data\n\nInsert products to the database:\n```bash\ncqlsh \u003cip_address\u003e\nCOPY ecommerce.product (id, img, name, price) FROM 'product.csv' with HEADER = TRUE;\n```\n\nGenerate user interactions (adding products to cart, checkout):\n1. Run the API server:\n    ```\n    uvicorn main:app\n    ```\n1. Run the python script:\n    ```bash\n    python generate_requests.py\n    ```\n    ```\n    Shopping started - User(6773b120-8499-4196-9df8-2c4a60b6f1ac) \n    (1) Added to cart: abe0e6dc-6ad1-4c3e-8127-80c6176ce99a \n    (2) Added to cart: ee9b125d-c92f-4555-bdb3-35aa260b6f91 \n    (3) Added to cart: 2bf36d87-9b36-4bd3-a44a-8d167e189ce6 \n    (4) Added to cart: 0c38b0c8-a792-4128-bff9-64c527366202 \n    (5) Added to cart: 609ed832-e565-4f46-830b-5fabc120e1d4 \n    Checkout completed (5 items)! \n    -----\n    (1) Added to cart: e8ce5e13-0a7e-4e6e-8858-252f5b1cb1db \n    (2) Added to cart: 3a33f31b-b37c-413e-81a5-1f4b42cedcf6 \n    (3) Added to cart: ffa5f74c-26f2-4342-a6f4-ee2338dd205f \n    (4) Added to cart: ef281712-2169-49e4-880a-8da503b0b6de \n    (5) Added to cart: 1e8abb0c-f558-433c-a8c8-e029f12c0d7d \n    (6) Added to cart: 609ed832-e565-4f46-830b-5fabc120e1d4 \n    Checkout completed (6 items)! \n    -----\n    (1) Added to cart: 0015b10c-0842-4796-840a-2e43a6a719d3 \n    (2) Added to cart: abe0e6dc-6ad1-4c3e-8127-80c6176ce99a \n    (3) Added to cart: 0c38b0c8-a792-4128-bff9-64c527366202 \n    Checkout completed (3 items)! \n    -----\n    ```\n    You can run this script from multiple terminals to generate more data.\n\n## Change Data Capture (CDC)\nChange Data Capture (CDC) is a ScyllaDB feature that records every change (insert, update, delete) that happens in your table. CDC provides real-time and historical insights into user behavior, product performance, and activity. \n\n\nHere are some example CDC queries that can provide insights into user behaviour:\n\n**How many times did users add more than 2 of the same product to the cart?**\n```sql\nSELECT count(*), toTimestamp(min(\"cdc$time\")) AS \"from\", toTimestamp(max(\"cdc$time\")) AS \"to\"\nFROM ecommerce.cart_items_scylla_cdc_log\nWHERE \"cdc$operation\"= 2 AND product_quantity \u003e 2\nALLOW FILTERING;\n```\n\n**How many carts contain a particular product?**\n```sql\nSELECT count(*), toTimestamp(min(\"cdc$time\")) AS \"from\", toTimestamp(max(\"cdc$time\")) AS \"to\"\nFROM ecommerce.cart_items_scylla_cdc_log\nWHERE product_id = \u003cPRODUCT_ID\u003e AND \"cdc$operation\" = 2\nALLOW FILTERING;\n```\n\nNotice how in both cases we put `\"cdc$operation\"= 2` in the where clause. This is because if the operation is `2` that means it was an `INSERT` operation. Learn more about [ScyllaDB CDC](https://opensource.docs.scylladb.com/stable/features/cdc/cdc-intro.html).\n\nNow, running analytical queries on the CDC table requires you to use `ALLOW FILTERING`. This can caouse unpredictable performance at larger scale use cases. In order to query CDC log data in highly scalable way, use our integration with Kafka. Using The [ScyllaDB CDC Kafka source connector](https://github.com/scylladb/scylla-cdc-source-connector), you can easily extract data from ScyllaDB and push it into an external service like ElasticSearch for further analytics.\n\n## Push ScyllaDB CDC data into Kafka\nRun the Kafka Connect container:\n```\ncd kafka\ndocker compose up -d\n```\n\nThis will start up several Docker services needed to run Kafka Connect and the Confluent Control Center.\n\nIn case you have an existing Kafka Connect service running, install the ScyllaDB source connector:\n```\nconfluent-hub install --no-prompt scylladb/scylla-cdc-source-connector:latest\n```\n\nIn the Kafka Control Center, use these parameters to create a new ScyllaDB connection:\n```\nAdd a new ScyllaDB connection with these parameters:\n- Name: ScyllaDBConnector\n- Key converter class, value converter class: `org.apache.kafka.connect.json.JsonConverter`\n- Hosts: ScyllaDB_ADDRESS:9042\n- Namespace: ScyllaDBConnectorNamespace\n- Table names: ecommerce.cart_items\n```\n\nFor `ScyllaDB_ADDRESS`, use either the Docker container's address or the ScyllaDB Cloud address depending on where you host your ScyllaDB.\n\nClick launch and the connection should be created successfully.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscylladb%2Fshopping-cart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscylladb%2Fshopping-cart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscylladb%2Fshopping-cart/lists"}