Base project and tooling for authoring data API backends with subZero.
✓ Out of the box GraphQL/REST endpoints created by reflection over a PostgreSQL schema
✓ Cross-platform development on macOS, Windows or Linux inside Docker
✓ PostgreSQL database schema boilerplate with authentication and authorization flow
✓ OpenResty configuration files for the reverse proxy
✓ RabbitMQ integration through pg-amqp-bridge
✓ Lua functions to hook into each stage of the HTTP request and add custom logic (integrate 3rd party systems)
✓ Debugging and live code reloading (sql/configs/lua) functionality using subzero-cli
✓ Full migration management (migration files are automatically created) through subzero-cli/sqitch/apgdiff
✓ SQL unit test using pgTAP
✓ Integration tests with SuperTest / Mocha
✓ Docker files for building production images
✓ Community support on Slack
.
├── db # Database schema source files and tests
│ └── src # Schema definition
│ ├── api # Api entities avaiable as REST endpoints
│ ├── data # Definition of source tables that hold the data
│ ├── libs # A collection modules of used throughout the code
│ ├── authorization # Application level roles and their privileges
│ ├── sample_data # A few sample rows
│ └── init.sql # Schema definition entry point
├── openresty # Reverse proxy configurations and Lua code
│ ├── lualib
│ │ └── user_code # Application Lua code
│ ├── nginx # Nginx files
│ │ ├── conf # Configuration files
│ │ └── html # Static frontend files
│ ├── Dockerfile # Dockerfile definition for production
│ └── entrypoint.sh # Custom entrypoint
├── tests # Tests for all the components
│ ├── db # pgTap tests for the db
│ ├── graphql # GraphQL interface tests
│ └── rest # REST interface tests
├── docker-compose.yml # Defines Docker services, networks and volumes
└── .env # Project configurations
Make sure that you have Docker v17 or newer installed.
Setup your git repo with a reference to the upstream
mkdir example-api && cd example-api
git clone https://github.com/subzerocloud/subzero-starter-kit.git .
git remote rename origin upstream && git branch --unset-upstream
Launch the app with Docker Compose:
docker-compose up -d # Launch Docker containers
The API server must become available at http://localhost:8080/rest and http://localhost:8080/graphql endpoints for REST and GraphQL respectively.
Try a simple REST request.
curl http://localhost:8080/rest/todos?select=id,todo
Try a GraphQL query in the integrated GraphiQL IDE at http://localhost:8080/graphiql
{
todos{
id
todo
}
}
Install subzero-cli using with
npm install -g subzero-cli
Execute subzero dashboard
in the root of your project.
After this step you can view the logs of all the stack components (SQL queries will also be logged) and
if you edit a sql/conf/lua file in your project, the changes will immediately be applied.
The starter kit comes with a testing infrastructure setup. You can write pgTAP tests that run directly in your database, useful for testing the logic that resides in your database (user privileges, Row Level Security, stored procedures). Integration tests are written in JavaScript.
Here is how you run them
npm install # Install test dependencies
npm test # Run all tests (db, rest, graphql)
npm run test_db # Run pgTAP tests
npm run test_rest # Run rest integration tests
npm run test_graphql # Run graphql integration tests
You can always fetch and merge the recent updates back into your project by running:
git fetch upstream
git merge upstream/master
More information in Production Infrastructure (AWS ECS+RDS) and Pushing to Production
Comming soon Request Invite
Anyone and everyone is welcome to contribute.
- Wiki — comprehensive documentation
- PostgREST API Referrance
- PostgreSQL Manual
- Slack — Watch announcements, share ideas and feedback
- GitHub Issues — Check open issues, send feature requests
Copyright © 2017-present subZero Cloud, LLC.
This source code is licensed under MIT license
The documentation to the project is licensed under the CC BY-SA 4.0 license.