Skip to content

Commit 51dab82

Browse files
Improve development documentation and scripts
This commit enhances the developer experience by: - Updating the main README.md with a "Getting Started / Local Development Setup" section, providing clear instructions for running your project locally using Docker Compose. - Adding a "Useful Scripts" section to the main README.md, documenting key scripts for building, testing, linting, formatting, and client generation. - Reviewing and updating `development.md` to ensure clarity on Docker Compose usage, local development workflows, and service URLs. - Reviewing and updating `backend/README.md` and `frontend/README.md` to ensure accuracy of setup, development, and testing instructions. - Reviewing and adding comments to various scripts in `scripts/` and `backend/scripts/` for better understanding and maintainability. - Ensuring consistency in commands (e.g., `fastapi dev` vs `fastapi run --reload`). These changes aim to make it easier for new developers to get started with your project and for existing developers to utilize available scripts and documentation effectively.
1 parent 739ef40 commit 51dab82

File tree

10 files changed

+105
-3
lines changed

10 files changed

+105
-3
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ The input variables, with their default values (some auto generated) are:
212212
- `postgres_password`: (default: `"changethis"`) The password for the PostgreSQL database, stored in .env, you can generate one with the method above.
213213
- `sentry_dsn`: (default: "") The DSN for Sentry, if you are using it, you can set it later in .env.
214214

215+
## Getting Started / Local Development Setup
216+
217+
Docker Compose is the recommended way to run the project locally.
218+
Use the command `docker compose watch` to start the services.
219+
220+
For more details on Docker Compose, including how to access services (frontend, backend, docs, etc.), please refer to `development.md`.
221+
222+
For faster development iteration, frontend and backend services can be run directly on the host machine.
223+
Instructions for this can be found in `frontend/README.md` and `backend/README.md`.
224+
215225
## Backend Development
216226

217227
Backend docs: [backend/README.md](./backend/README.md).
@@ -230,6 +240,18 @@ General development docs: [development.md](./development.md).
230240

231241
This includes using Docker Compose, custom local domains, `.env` configurations, etc.
232242

243+
## Useful Scripts
244+
245+
Here's a list of scripts available in the project to help with common development tasks:
246+
247+
- `scripts/build.sh`: Builds the Docker images for the project.
248+
- `scripts/test.sh`: Runs the complete test suite in a Dockerized environment. This typically includes backend tests and can be expanded to include frontend end-to-end tests.
249+
- `scripts/test-local.sh`: Runs backend tests directly on the host. It assumes the backend services (like the database) are already running (e.g., via `docker compose watch` or a similar local setup).
250+
- `scripts/generate-client.sh`: Generates or updates the frontend client based on the backend's OpenAPI schema. This usually involves fetching the schema and running a code generation tool.
251+
- `backend/scripts/format.sh`: Formats the backend Python code using Ruff to ensure consistent code style.
252+
- `backend/scripts/lint.sh`: Lints the backend Python code using MyPy for static type checking and Ruff for identifying potential errors and style issues.
253+
- `backend/scripts/test.sh`: Runs backend tests directly on the host (similar to `scripts/test-local.sh` but often focused only on backend unit/integration tests) and generates a test coverage report.
254+
233255
## Release Notes
234256

235257
Check the file [release-notes.md](./release-notes.md).

backend/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ root@7f2607af31c3:/app#
7171

7272
that means that you are in a `bash` session inside your container, as a `root` user, under the `/app` directory, this directory has another directory called "app" inside, that's where your code lives inside the container: `/app/app`.
7373

74-
There you can use the `fastapi run --reload` command to run the debug live reloading server.
74+
There you can use the `fastapi dev` command to run the debug live reloading server.
7575

7676
```console
77-
$ fastapi run --reload app/main.py
77+
$ fastapi dev app/main.py
7878
```
7979

8080
...it will look like:
8181

8282
```console
83-
root@7f2607af31c3:/app# fastapi run --reload app/main.py
83+
root@7f2607af31c3:/app# fastapi dev app/main.py
8484
```
8585

8686
and then hit enter. That runs the live reloading server that auto reloads when it detects code changes.

backend/scripts/format.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/sh -e
2+
# Print commands and their arguments as they are executed
23
set -x
34

5+
# Run ruff to check for linting issues in 'app' and 'scripts' directories and automatically fix them.
46
ruff check app scripts --fix
7+
# Run ruff to format the code in 'app' and 'scripts' directories.
58
ruff format app scripts

backend/scripts/lint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#!/usr/bin/env bash
22

3+
# Exit in case of error
34
set -e
5+
# Print commands and their arguments as they are executed
46
set -x
57

8+
# Run Mypy for static type checking on the 'app' directory.
69
mypy app
10+
# Run Ruff to check for linting errors in the 'app' directory.
11+
# This command only reports errors, it does not fix them.
712
ruff check app
13+
# Run Ruff formatter in check mode on the 'app' directory.
14+
# This command reports files that need formatting without actually modifying them.
15+
# It's useful for CI to verify that code is correctly formatted.
816
ruff format app --check

backend/scripts/test.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
#!/usr/bin/env bash
22

3+
# Exit in case of error
34
set -e
5+
# Print commands and their arguments as they are executed
46
set -x
57

8+
# Run pytest with coverage measurement.
9+
# --source=app specifies that coverage should be measured for the 'app' directory.
10+
# -m pytest ensures that pytest is run as a module.
611
coverage run --source=app -m pytest
12+
13+
# Generate a text-based coverage report in the terminal.
14+
# --show-missing will also list the line numbers of code that were not executed.
715
coverage report --show-missing
16+
17+
# Generate an HTML coverage report.
18+
# The output will be in a directory named 'htmlcov' by default.
19+
# The --title option sets the title of the HTML report.
20+
# "${@-coverage}" attempts to use any arguments passed to this script in the title.
21+
# For example, if the script is called with `backend/scripts/test.sh -k my_test`,
22+
# the title might become "-k my_test-coverage". If no arguments are passed, it will be "-coverage".
823
coverage html --title "${@-coverage}"

development.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Backend, JSON based web API based on OpenAPI: http://localhost:8000
1616

1717
Automatic interactive documentation with Swagger UI (from the OpenAPI backend): http://localhost:8000/docs
1818

19+
Automatic alternative documentation with ReDoc (from the OpenAPI backend): http://localhost:8000/redoc
20+
1921
Adminer, database web administration: http://localhost:8080
2022

2123
Traefik UI, to see how the routes are being handled by the proxy: http://localhost:8090

scripts/build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
# Exit in case of error
44
set -e
55

6+
# Set the TAG for Docker images, and exit if not provided
7+
# TAG is typically the version or a git commit hash
68
TAG=${TAG?Variable not set} \
9+
# Set the FRONTEND_ENV to 'production' if not already set
10+
# This ensures the frontend is built with production optimizations
711
FRONTEND_ENV=${FRONTEND_ENV-production} \
12+
# Build the Docker images using docker-compose
13+
# The -f flag specifies the docker-compose file to use
814
docker-compose \
915
-f docker-compose.yml \
1016
build

scripts/generate-client.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
#! /usr/bin/env bash
22

3+
# Exit in case of error
34
set -e
5+
# Print commands and their arguments as they are executed
46
set -x
57

8+
# Navigate to the backend directory
69
cd backend
10+
# Generate the OpenAPI schema from the FastAPI application
11+
# This command executes a Python one-liner:
12+
# - Imports the main FastAPI application (app.main)
13+
# - Imports the json library
14+
# - Accesses the app's OpenAPI schema (app.main.app.openapi())
15+
# - Dumps the schema to a JSON string
16+
# - Redirects the output to openapi.json in the parent (project root) directory
17+
# Note: This step assumes that the necessary Python environment is active
18+
# or that the FastAPI application and its dependencies can be imported.
719
python -c "import app.main; import json; print(json.dumps(app.main.app.openapi()))" > ../openapi.json
20+
# Navigate back to the project root directory
821
cd ..
22+
# Move the generated openapi.json to the frontend directory
923
mv openapi.json frontend/
24+
# Navigate to the frontend directory
1025
cd frontend
26+
# Run the npm script to generate the API client code using the openapi.json
1127
npm run generate-client
28+
# Format the generated client code using Biome
1229
npx biome format --write ./src/client

scripts/test-local.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
#! /usr/bin/env bash
22

3+
#! /usr/bin/env bash
4+
35
# Exit in case of error
46
set -e
57

8+
# Stop and remove any existing containers, volumes, and orphaned containers
9+
# This ensures a clean environment before starting the tests
610
docker-compose down -v --remove-orphans # Remove possibly previous broken stacks left hanging after an error
711

12+
# On Linux systems, remove __pycache__ directories.
13+
# Note: Using sudo here might indicate a permissions issue if these files are not owned by the current user.
14+
# __pycache__ directories are created by Python and generally should not require sudo for removal.
815
if [ $(uname -s) = "Linux" ]; then
916
echo "Remove __pycache__ files"
1017
sudo find . -type d -name __pycache__ -exec rm -r {} \+
1118
fi
1219

20+
# Build the Docker images for all services
1321
docker-compose build
22+
# Start all services in detached mode (in the background)
1423
docker-compose up -d
24+
# Execute the backend test script (scripts/tests-start.sh) inside the 'backend' container
25+
# -T disables pseudo-TTY allocation, suitable for non-interactive scripts
26+
# "$@" forwards all arguments passed to this script to the tests-start.sh script
1527
docker-compose exec -T backend bash scripts/tests-start.sh "$@"
28+
29+
# Note: Unlike test.sh, this script does not run `docker-compose down` at the end.
30+
# This means the services will remain running after the tests complete,
31+
# potentially for inspection or further local development.

scripts/test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@
22

33
# Exit in case of error
44
set -e
5+
# Print commands and their arguments as they are executed
56
set -x
67

8+
# Build the Docker images for all services
79
docker compose build
10+
11+
# Stop and remove any existing containers, volumes, and orphaned containers
12+
# This ensures a clean environment before starting the tests
813
docker compose down -v --remove-orphans # Remove possibly previous broken stacks left hanging after an error
14+
15+
# Start all services in detached mode (in the background)
916
docker compose up -d
17+
18+
# Execute the backend test script (scripts/tests-start.sh) inside the 'backend' container
19+
# -T disables pseudo-TTY allocation, suitable for non-interactive scripts
20+
# "$@" forwards all arguments passed to this script to the tests-start.sh script
1021
docker compose exec -T backend bash scripts/tests-start.sh "$@"
22+
23+
# Stop and remove all containers, volumes, and orphaned containers after tests are done
1124
docker compose down -v --remove-orphans

0 commit comments

Comments
 (0)