Skip to content

Commit ea4cb25

Browse files
authored
Improve repository setup (#16)
- Rationalise env variable usage Docker startup in `db/run.sh` now uses `backend/.env` as an env file, so env var naming follows the [container's usage](https://hub.docker.com/_/postgres/) - Add appropriate VS Code configuration - Use created virtualenv - Host frontend on correct root path - Add missing dependencies - Install `requests` and `psycopg2` for Python - Sync the `package-lock.json` file
1 parent b985867 commit ea4cb25

File tree

10 files changed

+64
-20
lines changed

10 files changed

+64
-20
lines changed

.gitignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
node_modules
2-
.env
3-
.specstory/
41
.DS_Store
5-
playwright-report/
6-
.vscode/
7-
test-results/

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"ms-playwright.playwright",
4+
"ms-python.python",
5+
"ritwickdey.liveserver"
6+
]
7+
}

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"liveServer.settings.root": "front-end/",
3+
"python.defaultInterpreterPath": "backend/.venv/bin/python"
4+
}

backend/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ To run:
66

77
1. In the `backend` directory, create a file named `.env` with values for the following environment variables:
88
* `JWT_SECRET_KEY`: Any random string.
9-
* `PGPASSWORD`: Any random string.
10-
* `PGUSER`: `postgres`, assuming you're using the bundled docker-based database, or whatever user you need if you have a custom postgres set up.
11-
* Optionally, `PGDATABASE`, `PGHOST`, and `PGPORT` if you're not using default postgres values.
9+
* `POSTGRES_PASSWORD`: Any random string.
10+
* `POSTGRES_USER`: `postgres`, assuming you're using the bundled docker-based database, or whatever user you need if you have a custom postgres set up.
11+
* Optionally, `POSTGRES_DB`, `POSTGRES_HOST`, and `POSTGRES_PORT` if you're not using default postgres values.
1212
2. Make a virtual environment: `python3 -m venv .venv`
1313
3. Activate the virtual environment: `. .venv/bin/activate`
1414
4. Install dependencies: `pip install -r requirements.txt`

backend/data/connection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
@contextmanager
77
def db_cursor():
88
with psycopg2.connect(
9-
dbname=os.getenv("PGDATABASE"),
10-
user=os.getenv("PGUSER"),
11-
password=os.environ["PGPASSWORD"],
12-
host=os.getenv("PGHOST", "127.0.0.1"),
13-
port=os.getenv("PGPORT"),
9+
dbname=os.getenv("POSTGRES_DB"),
10+
user=os.getenv("POSTGRES_USER"),
11+
password=os.environ["POSTGRES_PASSWORD"],
12+
host=os.getenv("POSTGRES_HOST", "127.0.0.1"),
13+
port=os.getenv("POSTGRES_PORT"),
1414
) as conn:
1515
with conn.cursor() as cur:
1616
yield cur

backend/requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
blinker==1.9.0
2+
certifi==2025.4.26
23
cffi==1.17.1
4+
charset-normalizer==3.4.2
35
click==8.1.8
46
cryptography==44.0.1
57
Flask==3.1.0
68
flask-cors==5.0.1
79
Flask-JWT-Extended==4.7.1
10+
idna==3.10
811
itsdangerous==2.2.0
912
Jinja2==3.1.5
1013
MarkupSafe==3.0.2
14+
psycopg2==2.9.10
1115
pycparser==2.22
1216
PyJWT==2.10.1
1317
python-dotenv==1.0.1
18+
requests==2.32.3
19+
urllib3==2.4.0
1420
Werkzeug==3.1.3

db/create-schema.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ set -euo pipefail
44

55
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
66

7-
export PGPASSWORD="$(cat "${SCRIPT_DIR}/../backend/.env" | grep ^PGPASSWORD= | cut -d= -f2-)"
8-
9-
psql -h 127.0.0.1 -U postgres -f "${SCRIPT_DIR}/schema.sql"
7+
source "$SCRIPT_DIR/../backend/.env"
8+
9+
PGPASSWORD="$POSTGRES_PASSWORD" psql \
10+
--dbname "${POSTGRES_DB:-postgres}" \
11+
--file "${SCRIPT_DIR}/schema.sql" \
12+
--host "${POSTGRES_HOST:-127.0.0.1}" \
13+
--port "${POSTGRES_PORT:-5432}" \
14+
--username "${POSTGRES_USER:-postgres}"

db/run.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
77
BACKING_STORE_DIR="${SCRIPT_DIR}/pg_data"
88
mkdir -p "${BACKING_STORE_DIR}"
99

10-
POSTGRES_PASSWORD="$(cat "${SCRIPT_DIR}/../backend/.env" | grep ^PGPASSWORD= | cut -d= -f2-)"
10+
source "$SCRIPT_DIR/../backend/.env"
1111

12-
docker run -it --rm -e POSTGRES_PASSWORD="${POSTGRES_PASSWORD}" -p 5432:5432 -v "${BACKING_STORE_DIR}:/var/lib/postgresql/data" postgres:17.4
12+
docker run \
13+
--env-file "$SCRIPT_DIR/../backend/.env" \
14+
--interactive \
15+
--publish "${POSTGRES_PORT:-5432}:5432" \
16+
--rm \
17+
--tty \
18+
--volume "${BACKING_STORE_DIR}:/var/lib/postgresql/data" \
19+
postgres:17.4

front-end/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules/
2+
/playwright-report/
3+
/test-results/

front-end/package-lock.json

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)