mikeyglitz/pantry-api
Pantry API is a GraphQL application which is used to aid in managing inventory for a pantry. This application utilizes Postgres and Elasticsearch as its data backend. The application is designed to run in a Docker container.
This application requires the following services to run:
In order to set up connections, check the configurations section below for environment variable configurations.
The docker image is built at https://hub.docker.com/r/mikeyglitz/pantry-api.
docker run -p 8080:8080 -e KEYCLOAK_CLIENT_ID=... mikeyglitz/pantry-api
The configuration for this application is managed through environment variables
Variable | Description |
---|---|
SVC_HOST | The hostname that the service will listen on |
SVC_PORT | The port that the service will listen on |
SVC_PATH | The path that exposes the graphql endpoint |
SVC_PLAYGROUNDPATH | The path that exposes the GraphQL Playground endpoint |
SVC_ISPLAYGROUNDENABLED | Flag to enable GraphQL Playground |
SVC_LOG_LEVEL | The level for which to display the logs |
KEYCLOAK_CLIENT_ID | The Keycloak client ID for authentication |
KEYCLOAK_CLIENT_SECRET | The Keycloak client secret used for authentication |
KEYCLOAK_REALM_NAME | The Keycloak realm name |
KEYCLOAK_ENDPOINT | The address where the Keycloak server is listening on |
ES_USERNAME | The OpenSearch username |
ES_PASSWORD | The OpenSearch password |
ES_CERTIFICATE_PATH | The CA cert used to verify the OpenSearch SSL endpoints |
ES_ADDRESSES | A comma-separate list of OpenSearch server URLs |
DB_PORT | The port that the Postgres database is listening on |
DB_HOST | The host where the Postgres database is listening on |
DB_USERNAME | The username used to login to Postgres |
DB_PASSWORD | The password used to login to Postgres |
DB_NAME | The name of the database to connect to |
This application requires a user account and role to be created in OpenSearch with the following permissions:
Cluster-Level Permissions
cluster:monitor/health
cluster:monitor/main
indices:data/read/scroll/clear
Index-Level Permissions
Indices - ingredients
, users
, and pantries
create_index
indices:data/read/search
indices:data/write/delete/byquery
indices:admin/get
indices:admin/aliases/exists
indices:data/write/update/byquery
indices:data/read/get
indices:admin/create
indices:data/write/index
indices:admin/mapping/put
indices:data/read/scroll/clear
indices:data/write/bulk*
The API provided by this application exposes the following endpoints:
Endpoint | Description |
---|---|
/actuator/* | Exposes the actuator endpoints |
/playground | Exposes the GraphQL Playground UI |
/graphql | Exposes the graphql API |
The /playground
and /graphql
endpoints can be configured by the SVC_PLAYGROUNDPATH
and SVC_PATH
environment variables respectively
This project utilizes the Go standard project layout.
test
- stores integration tests utilizing testcontainerspkg
- contains the root application server bootstrapping codecmd
- contains the main class -- the application entrypointinternal
- majority of the business logic is here
internal/config
- configuration functions and interfacesinternal/database
- database driver, models, and migration logicinternal/index
- OpenSearch driver and interfacesinternal/dataloaders
- dataloader interfacesinternal/handlers
- gin rest handlersinternal/middleware
- middleware used to enhance the request context (i.e. authentication)internal/graph
- GraphQL resolversinternal/graph/services
- database service layer - utilized primarily to supply data to GraphQL resolversinternal/graph/schema
- GraphQL schemas -- written in the GraphQL DSL⚠
internal/graph/model
,internal/graph/generated
, andmocks
all contain generated code
docker pull mikeyglitz/pantry-api