This is a comprehensive (real-world) e-commerce application that was originially developed by the Hasura team. The original version of the app that uses PostgreSQL as a database and supports only the on-prem deployment option of Hasura. This repository adds instructions explaining how to start the app with YugabyteDB, with no code changes!
- Hasura CLI installed. Instructions here.
- (Optional) Stripe Secret and Publishable keys. The account doesn't need to be verified as no transactions will be happening. Instructions here.
- Local Deployments:
- Docker and Docker Compose installed. Install instructions.
- Cloud Deploymets:
- Hasura Cloud Instance/Project. Insturctions here
- Yugabyte Cloud Instance. Instructions here
- Clone the project:
git clone /~https://github.com/dmagda/hasura-ecommerce
Follow these steps to start the application in a local environment.
Follow these steps to start the application in the cloud.
- An architecure of the on-prem/local deployment.
- An architecture of the cloud native deployment.
The Authentication leverages Hasura Actions and NextJs serverless routes to handle JWT based authentication. The client sends a login mutation, the mutation is forwarded via action to a serverless function where a unique JWT is created, the token is passed back to Hasura where it is stored with client credentials, and the JWT along with helpful client information is forwarded back to the client and set as a sever-set cookie.
The login flow is similar but instead of creating a user in the action, the user is verified.
graph TD
website[Website]
hasura[(Postgres)]
server[Server]
action[[Hasura Action]]
website -->|Signup| action
action -.->|Handler| server
server -.-> |Save User| hasura
server -.-> |return token| action
action -.-> website
- User visits the Checkout page, presses payment button
- GraphQL request is sent to Hasura to invoke custom Hasura Action
- Hasura forwards the request parameters to the Action REST API handler on the Next.js Server
- The API handler calls the Stripe API and invokes
stripe.paymentIntents.create()
, then returns theclient_secret
for the tokenized PaymentIntent - Hasura forwards the response from the Action REST API handler to the client, as GraphQL
graph TD
website[Website]
server[Server - REST API]
hasura[Hasura]
stripe[Stripe]
website -->|Checkout| hasura
hasura --> |Hasura Action| server
server --> |REST API Call| stripe
stripe .-> |PaymentIntent Client Secret| server
server .-> |Forward| hasura
hasura .-> |Forward| website
Product management occurs through the /admin
paths of the client application. New product images are uploaded to the Minio instance and the resource url is saved along with the product details. Again, as a client wrapper to a single GraphQL endpoint, it becomes very easy to expose additional functionality like PIM management without the need for incorporating excessive additional tooling.
This project uses an innovative, generated, GraphQl Client SDK. For more information, see the SDK documentation.
Hasura is a powerful backend provider that has offline development primitives baked in. You can define, iterate on, and deploy your migrations through the helpful CLI. For more information see the migration guide.
This application follows the 3 Factor App principles which are composed of robust client-side state management and a centralized API layer that manages the business logic, architecture and service routing. For more information on 3 factor apps, visit the website.
Use the script below to clear the demo resources such as created containers and volumes:
./clear-demo-resources.sh