Skip to content
Evan Parish edited this page Oct 31, 2024 · 17 revisions

VA Enterprise Notification Platform API

Project Overview

This API provides a structured way for the VA to handle notifications. It's designed for scalability and reliability, ensuring that notifications are handled securely and efficiently.

Installation

Prerequisites

  • Python ^3.12
  • Poetry 1.8.3 (for dependency management)
  • Pre-commit (for automatic code quality checks)

Steps

  1. Clone the repository locally using ssh,

    git clone [email protected]:department-of-veterans-affairs/va-enp-api.git

    or https

    git clone https://github.com/department-of-veterans-affairs/va-enp-api.git
  2. Navigate to the project directory:

    cd va-enp-api
  3. Using Poetry 1.8.3, install dependencies:

    poetry install --with static_tools,test

Setting Up Pre-commit Hooks

This project uses pre-commit hooks to enforce coding standards and run automatic checks on your code before committing.

To install the pre-commit hooks, run the following command:

poetry run pre-commit install

This will set up the hooks listed in the .pre-commit-config.yaml file to run automatically whenever you attempt to make a commit.

You can manually run the hooks on all files at any time with:

poetry run pre-commit run --all-files

Usage

Running App without Containers

To run the API locally and reload real-time changes, use the following command:

poetry run uvicorn app.main:app --reload

This will start the API on http://127.0.0.1:8000.

The application can be ran with Gunicorn, using the following command:

gunicorn app.main:app -b 0.0.0.0:8000 -k uvicorn_worker.UvicornWorker -w 4

Running with Docker

There is a docker compose file (ci/docker-compose-local.yml) that can be used to run the app and a local postgresql database together. From the base directory for the project va-enp-api you can use the following command to build and run the two containers together.

docker compose -f ci/docker-compose-local.yml build api && docker compose -f ci/docker-compose-local.yml up

You can edit the entrypoint in the compose file to be either of the commands listed above if you'd like to run with gunicorn or uvicorn.

Note

The --reload option only works when running with uvicorn. It still works when running in a container because it maps a volume back to the local code files to detect changes.

Running the Database Container Separately

If you want to run the database by itself you can run this command and start the app normally.

docker compose -f ci/docker-compose-local.yml up enp-db

Endpoints

The API exposes several endpoints for managing notifications. Check the API documentation by visiting the /docs endpoint when the server is running.

Testing

The project uses pytest for testing. To run the tests:

poetry run pytest

Make sure all tests pass before submitting any changes.

Linter Scripts

Linter script are located in the file scripts/run_checks.py

To run all linters locally, install Poetry packages with the static_tools group.

poetry install --with static_tools

Then, run linter scripts with the following command:

poetry run ./scripts/run_checks.sh

Configuration

The project uses a pyproject.toml file for managing dependencies and configuration settings. Please use poetry commands to add, update, or remove any packages.

Home

Design Principles

Clone this wiki locally