Backend for shopping list app with Lauren, for personal use. Pairs with frontend found here.
This project is a live app I use personally, and I use it as a sandbox for practices like CI/CD, testing, security. For more, see project goals.
Check out API docs with /api-docs
endpoint.
Create a PostgreSQL database called 'quickshopper' on your local machine (see db starter scripts). It includes four tables:
-
items: stores the added grocery items. It includes four columns:
- name (varchar)
- id (varchar - primary key)
- note (varchar)
- count (smallint)
-
completeditems: stores the completed items. It includes four columns, same as above.
-
groceriestemplate: is used to fetch top 10 favorites on app load and to populate the autocomplete search input. It includes two columns:
- name (varchar - primary key)
- count (integer - not null)
-
grocerystoremodel: is used to fetch and update store layouts. It includes three columns:
- id (integer - primary key)
- name (varchar)
- categories (jsonb)
- In
config/knexFile.js
, edit the server credentials
NODE_ENV
: set to 'development' or 'production'DATABASE_URL
: connection string
RAINFOREST_API_TOKEN
: for visual regression testingSNYK_TOKEN
: for security testingHEROKU_API_KEY
: for deploymentHEROKU_APP_NAME
: for deploymentHEROKU_EMAIL
: for deploymentPOSTMAN_API_KEY
: for functional testing
.github
: contains CI/CD workflowsconfig
: contains configuration files for knex, swagger, and winstondata
: contains seed data for the databasedocker
: contains Dockerfilespostman
: contains postman collection and schemas for functional testingsrc
: contains app codetest
: contains unit tests
npm run start:dev
starts the server on port 3000
npm run test:dev
for verbose output and watch mode
npm run test
for CI
npm run lint
Port is exposed through the Procfile. To forward the port, run:
heroku ps:forward 9090 -a {{app_name}}
The CD pipeline consists of development, staging, and production environments. Each push to master will trigger a GitHub action that will run the following:
- Security vulnerability checks
- Build stage a. Lint checks b. Unit tests, including mock DB and integration-like tests with mock-knex tracker c. Build the app
- Deploy to staging environment
- Functional tests
- Visual regression tests
Email reports are sent for all CI runs, regardless of the status of the run. Once all checks pass, the app is deployed automatically to production.
Note: In addition to the pipeline above, the following security checks are run on a weekly basis: Snyk static scan monitoring and Github Dependabot for dependency security alerts and updates.
Note: There is a Dockerfile to containerize the app, if desired.
Functional tests are run with Postman CLI. Schemas and collections are in the postman
folder.
BASE_URL
: for testing in different environmentsENVIRONMENT
: use 'development', 'staging', and 'production' to test in different environments
schema
: for schema validation. To generate a schema, runnpm run schema
and copy the output./postman/schemas/schema.json
content to the collection variable. Note that some of theanyOf
definitions and array schemas don't translate properly in Postman, so don't override these. Ex: see groceryStoreModel and updateStoreCategoriesResponseSchema. Also manualy change openapi version to 3.1.0 in the schema file.itemName
: random string to use for item name
Import the collection into Postman in order to run the tests either manually or with the Postman CLI.
- body-parser: Node.js body parsing middleware
- cors: to provide a Connect/Express middleware that can be used to enable CORS
- express: To set up server
- knex: A SQL query builder in JavaScript
- pg: PostgreSQL client for Node.js. Uses pure JavaScript
- nodemon: A development utility that monitors for any changes in the code and automatically restarts the server
- mock-knex: to unit test controllers
- eslint: to lint code
- joi for schema validation
- swagger for API documentation
- postman for functional testing
- Rainforest QA for visual regression testing
All rights reserved.
- Granular error responses
- Add authentication to protect the API
- Health check endpoint
- Secure endpoints with input validation (protect against malicious requests)
- Automate DB migrations (ex: Liquibase)
Note: The CI/CD pipeline adopts an automated zero downtime deployment approach. I realize some enterprises require manual intervention when deploying to higher environments, for example when needing approvals at different stages of the pipeline.