Skip to content

Commit 2d89b99

Browse files
authored
CDPS-1054: Replaced template readme file and added in architectural decision records. (#6)
1 parent f4f5643 commit 2d89b99

7 files changed

+258
-127
lines changed

README.md

+4-127
Original file line numberDiff line numberDiff line change
@@ -4,133 +4,10 @@
44
[![Docker Repository on ghcr](https://img.shields.io/badge/ghcr.io-repository-2496ED.svg?logo=docker)](https://ghcr.io/ministryofjustice/hmpps-person-integration-api)
55
[![API docs](https://img.shields.io/badge/API_docs_-view-85EA2D.svg?logo=swagger)](https://hmpps-person-integration-api-dev.hmpps.service.justice.gov.uk/webjars/swagger-ui/index.html?configUrl=/v3/api-docs)
66

7-
Template github repo used for new Kotlin based projects.
7+
This is a Spring Boot service, written in Kotlin, which acts as an interface to the data in the Core Person Record and Person Protected Characteristics domains.
88

9-
# Instructions
9+
## Contents
1010

11-
If this is a HMPPS project then the project will be created as part of bootstrapping -
12-
see [dps-project-bootstrap](https://github.com/ministryofjustice/dps-project-bootstrap). You are able to specify a
13-
template application using the `github_template_repo` attribute to clone without the need to manually do this yourself
14-
within GitHub.
11+
1. [Building, Testing and Running](readme/build_test_run.md)
12+
2. [Architecture Decision Records](architecture-decision-record/README.md)
1513

16-
This project is community managed by the mojdt `#kotlin-dev` slack channel.
17-
Please raise any questions or queries there. Contributions welcome!
18-
19-
Our security policy is located [here](https://github.com/ministryofjustice/hmpps-person-integration-api/security/policy).
20-
21-
Documentation to create new service is located [here](https://tech-docs.hmpps.service.justice.gov.uk/applicationplatform/newservice-GHA/).
22-
23-
## Creating a Cloud Platform namespace
24-
25-
When deploying to a new namespace, you may wish to use the
26-
[templates project namespace](https://github.com/ministryofjustice/cloud-platform-environments/tree/main/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-templates-dev)
27-
as the basis for your new namespace. This namespace contains both the kotlin and typescript template projects,
28-
which is the usual way that projects are setup.
29-
30-
Copy this folder and update all the existing namespace references to correspond to the environment to which you're deploying.
31-
32-
If you only need the kotlin configuration then remove all typescript references and remove the elasticache configuration.
33-
34-
To ensure the correct github teams can approve releases, you will need to make changes to the configuration in `resources/service-account-github` where the appropriate team names will need to be added (based on [lines 98-100](https://github.com/ministryofjustice/cloud-platform-environments/blob/main/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-templates-dev/resources/serviceaccount-github.tf#L98) and the reference appended to the teams list below [line 112](https://github.com/ministryofjustice/cloud-platform-environments/blob/main/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-templates-dev/resources/serviceaccount-github.tf#L112)). Note: hmpps-sre is in this list to assist with deployment issues.
35-
36-
Submit a PR to the Cloud Platform team in
37-
#ask-cloud-platform. Further instructions from the Cloud Platform team can be found in
38-
the [Cloud Platform User Guide](https://user-guide.cloud-platform.service.justice.gov.uk/#cloud-platform-user-guide)
39-
40-
## Renaming from HMPPS Template Kotlin - github Actions
41-
42-
Once the new repository is deployed. Navigate to the repository in github, and select the `Actions` tab.
43-
Click the link to `Enable Actions on this repository`.
44-
45-
Find the Action workflow named: `rename-project-create-pr` and click `Run workflow`. This workflow will
46-
execute the `rename-project.bash` and create Pull Request for you to review. Review the PR and merge.
47-
48-
Note: ideally this workflow would run automatically however due to a recent change github Actions are not
49-
enabled by default on newly created repos. There is no way to enable Actions other then to click the button in the UI.
50-
If this situation changes we will update this project so that the workflow is triggered during the bootstrap project.
51-
Further reading: <https://github.community/t/workflow-isnt-enabled-in-repos-generated-from-template/136421>
52-
53-
The script takes six arguments:
54-
55-
### New project name
56-
57-
This should start with `hmpps-` e.g. `hmpps-prison-visits` so that it can be easily distinguished in github from
58-
other departments projects. Try to avoid using abbreviations so that others can understand easily what your project is.
59-
60-
### Slack channel for release notifications
61-
62-
By default, release notifications are only enabled for production. The circleci configuration can be amended to send
63-
release notifications for deployments to other environments if required. Note that if the configuration is amended,
64-
the slack channel should then be amended to your own team's channel as `dps-releases` is strictly for production release
65-
notifications. If the slack channel is set to something other than `dps-releases`, production release notifications
66-
will still automatically go to `dps-releases` as well. This is configured by `releases-slack-channel` in
67-
`.circleci/config.yml`.
68-
69-
### Slack channel for pipeline security notifications
70-
71-
Ths channel should be specific to your team and is for daily / weekly security scanning job results. It is your team's
72-
responsibility to keep up-to-date with security issues and update your application so that these jobs pass. You will
73-
only be notified if the jobs fail. The scan results can always be found in circleci for your project. This is
74-
configured by `alerts-slack-channel` in `.circleci/config.yml`.
75-
76-
### Non production kubernetes alerts
77-
78-
By default Prometheus alerts are created in the application namespaces to monitor your application e.g. if your
79-
application is crash looping, there are a significant number of errors from the ingress. Since Prometheus runs in
80-
cloud platform AlertManager needs to be setup first with your channel. Please see
81-
[Create your own custom alerts](https://user-guide.cloud-platform.service.justice.gov.uk/documentation/monitoring-an-app/how-to-create-alarms.html)
82-
in the Cloud Platform user guide. Once that is setup then the `custom severity label` can be used for
83-
`alertSeverity` in the `helm_deploy/values-*.yaml` configuration.
84-
85-
Normally it is worth setting up two separate labels and therefore two separate slack channels - one for your production
86-
alerts and one for your non-production alerts. Using the same channel can mean that production alerts are sometimes
87-
lost within non-production issues.
88-
89-
### Production kubernetes alerts
90-
91-
This is the severity label for production, determined by the `custom severity label`. See the above
92-
#non-production-kubernetes-alerts for more information. This is configured in `helm_deploy/values-prod.yaml`.
93-
94-
### Product ID
95-
96-
This is so that we can link a component to a product and thus provide team and product information in the Developer
97-
Portal. Refer to the developer portal at https://developer-portal.hmpps.service.justice.gov.uk/products to find your
98-
product id. This is configured in `helm_deploy/<project_name>/values.yaml`.
99-
100-
## Manually branding from template app
101-
102-
Run the `rename-project.bash` without any arguments. This will prompt for the six required parameters and create a PR.
103-
The script requires a recent version of `bash` to be installed, as well as GNU `sed` in the path.
104-
105-
## TODOs and Examples
106-
107-
We have tried to provide some examples of best practice in the application - so there are lots of TODOs in the code
108-
where changes are required to meet your requirements. There is an `ExampleResource` that includes best practice and also
109-
serve as spring security examples. The template typescript project has a demonstration that calls this endpoint as well.
110-
111-
For the demonstration, rather than introducing a dependency on a different service, this application calls out to
112-
itself. This is only to show a service calling out to another service and is certainly not recommended!
113-
114-
## Running the application locally
115-
116-
The application comes with a `dev` spring profile that includes default settings for running locally. This is not
117-
necessary when deploying to kubernetes as these values are included in the helm configuration templates -
118-
e.g. `values-dev.yaml`.
119-
120-
There is also a `docker-compose.yml` that can be used to run a local instance of the template in docker and also an
121-
instance of HMPPS Auth (required if your service calls out to other services using a token).
122-
123-
```bash
124-
docker compose pull && docker compose up
125-
```
126-
127-
will build the application and run it and HMPPS Auth within a local docker instance.
128-
129-
### Running the application in Intellij
130-
131-
```bash
132-
docker compose pull && docker compose up --scale hmpps-person-integration-api=0
133-
```
134-
135-
will just start a docker instance of HMPPS Auth. The application should then be started with a `dev` active profile
136-
in Intellij.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[Contents](README.md),
2+
[Next >](0001-structure-packages-by-api-version.md)
3+
4+
# 0. Separate domain specific code by package
5+
6+
Date: 2024-11-21
7+
8+
## Status
9+
10+
✅ Accepted
11+
12+
## Context
13+
14+
The HMPPS Person integration API provides an interface to access data from two different domains.
15+
The `Core Person Record` domain and the `Person Protected Characteristics` domain. These domains are
16+
related but may be separated out into separate services in the future.
17+
18+
## Decision
19+
20+
There will be a top level package for each domain, `corepersonrecord` and `personprotectedcharacteristics` which will keep
21+
any domain specific logic separate. A `common` package will be used for any shared code.
22+
23+
```
24+
project/
25+
├── src/
26+
│ ├── main/
27+
│ │ ├── kotlin/
28+
│ │ │ ├── common/ # Common code shared across domains
29+
│ │ │ ├── corepersonrecord/ # Core person record package
30+
│ │ │ ├── personprotectedcharacteristics/ # Person protected characteristics package
31+
│ │ └── resources/
32+
```
33+
34+
## Consequences
35+
36+
N/A
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[< Previous](0001-structure-packages-by-api-version.md),
2+
[Contents](README.md),
3+
[Next >](0002-include-username-in-client-credential-token.md)
4+
5+
# 1. Structure packages by API version
6+
7+
Date: 2024-11-21
8+
9+
## Status
10+
11+
✅ Accepted
12+
13+
## Context
14+
15+
This API is likely to go through multiple iterations as data models change and expand. To ensure the
16+
API can evolve without causing friction to clients, we will version the API whenever there are breaking changes.
17+
As there may be multiple versions of the API live at a given time we need to code structured and easy to maintain and understand.
18+
19+
## Decision
20+
21+
Code specific to a specific API version will be stored in a separate package.
22+
23+
```
24+
project/
25+
├── src/
26+
│ ├── main/
27+
│ │ ├── kotlin/
28+
│ │ │ ├── common/ # Common code shared across modules or components
29+
│ │ │ ├── corepersonrecord/ # Core person record module
30+
│ │ │ │ ├── shared/ # Code common between versions
31+
│ │ │ │ ├── v1/ # Version 1 specific code
32+
│ │ │ │ ├── v2/ # Version 2 specific code
33+
│ │ └── resources/
34+
```
35+
36+
## Consequences
37+
38+
We will need to refactor the current package structure when we start introducing version 2 functionality.
39+
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[< Previous](0002-include-username-in-client-credential-token.md),
2+
[Contents](README.md),
3+
[Next >](9999-end.md)
4+
5+
6+
7+
# 2. Include username in client credentials token
8+
9+
Date: 2024-11-21
10+
11+
## Status
12+
13+
✅ Accepted
14+
15+
## Context
16+
17+
The HMPPS Person Integration API will make calls to downstream services using the OAuth 2.0 client credentials grant for authorisation.
18+
The API will be authorised to make calls to downstream services however for audit purposes the username of the instigating user is required.
19+
The HMPPS Auth service provides functionality to include a username within an OAuth token obtained using client credentials which can then be
20+
verified and extracted by downstream services.
21+
22+
## Decision
23+
24+
The API will make use of the HMPPS Auth functionality to include a username within the token generated whe using a client credentials grant.
25+
26+
## Consequences
27+
28+
In order to the HMPPS Auth functionality to include the username in token when using the client credentials grant will require a non-standard
29+
OAuth token request query.
30+
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
No more records
2+
3+
[Back to Contents](README.md)
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# HMPPS Person Integration API Architecture Decisions
2+
3+
This is a record of architectural decisions made during the development of the HMPPS Person Integration API project.
4+
5+
## Table of contents
6+
7+
*[Use separate packages for domain specific code](0000-separate-domain-specific-code-by-package.md)
8+
*[Structure packages be API version](0001-structure-packages-by-api-version.md)
9+
*[Include username in client credentials token](0002-include-username-in-client-credential-token.md)
10+
11+
### Statuses:
12+
13+
* Proposed: 🤔
14+
* Accepted: ✅
15+
* Rejected: ❌
16+
* Superseded: ⌛️
17+
* Amended: ♻️

readme/build_test_run.md

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
[< Back](../README.md)
2+
---
3+
4+
## Building
5+
6+
To build the project without tests run:
7+
8+
```
9+
./gradlew clean build -x test
10+
```
11+
12+
## Testing
13+
14+
To run the unit and integration tests:
15+
```
16+
./gradlew test
17+
```
18+
19+
## Running Locally
20+
21+
There are two variation for running the application locally.
22+
23+
- [Running against containerised dependencies](#Running against containerised dependencies)
24+
- [Running against dependencies deployed in dev](#Running against dependencies deployed in dev)
25+
26+
### Running against containerised dependencies
27+
28+
The following command will build and run the application via docker compose along with containers for HMPPS Auth and Prison API.
29+
30+
> NOTE: A client with the required roles will need to be added to the containerised version of HMPPS Auth in order to generate OAuth tokens.
31+
> The client id and secret can then be referenced in a .env file as the `SYSTEM_CLIENT_ID` and `SYSTEM_CLIENT_SECRET`.
32+
33+
```
34+
docker compose pull && docker compose up --build
35+
```
36+
37+
This will run the application on http://localhost:8080 and the swagger docs will be found at http://localhost:8080/swagger-ui/index.html# .
38+
39+
#### Running through Gradle or IntelliJ
40+
41+
If you want to run the application through IntelliJ or command line with gradle using the containerised dependencies then use:
42+
43+
```
44+
docker compose pull && docker compose up --scale hmpps-person-integration-api=0
45+
```
46+
47+
Then start the application using Gradle or IntelliJ.
48+
49+
> NOTE: The required client credentials environment variables (`SYSTEM_CLIENT_ID` and `SYSTEM_CLIENT_SECRET`) will need to set prior to starting the application.
50+
51+
**IntelliJ:**
52+
53+
Run or debug the main class with the spring active profile set to `dev`:
54+
55+
**Gradle:**
56+
57+
```
58+
./gradlew bootRun --args='--spring.profiles.active=dev'
59+
```
60+
61+
### Running against dependencies deployed in dev
62+
63+
In order to run against deployed dependencies in dev the
64+
65+
<details>
66+
<summary>Environment variables required</summary>
67+
<br>
68+
Note, client credentials from the dev namespace (hmpps-person-integration-api-dev) kubernetes secrets.
69+
70+
```
71+
SYSTEM_CLIENT_ID=<Extract from k8s namespace>
72+
SYSTEM_CLIENT_SECRET=<Extract from k8s namespace>
73+
HMPPS_AUTH_URL=https://sign-in-dev.hmpps.service.justice.gov.uk/auth
74+
PRISON_API_BASE_URL=https://prison-api-dev.prison.service.justice.gov.uk
75+
```
76+
</details>
77+
78+
Once the environment variables have been set the application can be run via Gradle or IntelliJ using the commands in [this section](#running-through-gradle-or-intellij)
79+
80+
## Common gradle tasks
81+
82+
To list project dependencies, run:
83+
84+
```
85+
./gradlew dependencies
86+
```
87+
88+
To check for dependency updates, run:
89+
```
90+
./gradlew dependencyUpdates --warning-mode all
91+
```
92+
93+
To run an OWASP dependency check, run:
94+
```
95+
./gradlew clean dependencyCheckAnalyze --info
96+
```
97+
98+
To upgrade the gradle wrapper version, run:
99+
```
100+
./gradlew wrapper --gradle-version=<VERSION>
101+
```
102+
103+
To automatically update project dependencies, run:
104+
```
105+
./gradlew useLatestVersions
106+
```
107+
108+
#### Ktlint Gradle Tasks
109+
110+
To run Ktlint check:
111+
```
112+
./gradlew ktlintCheck
113+
```
114+
115+
To run Ktlint format:
116+
```
117+
./gradlew ktlintFormat
118+
```
119+
120+
To register pre-commit check to run Ktlint format:
121+
```
122+
./gradlew addKtlintFormatGitPreCommitHook
123+
```
124+
125+
...or to register pre-commit check to only run Ktlint check:
126+
```
127+
./gradlew addKtlintCheckGitPreCommitHook
128+
```

0 commit comments

Comments
 (0)