Skip to content

Commit ee64013

Browse files
General refactor and code cleanup (#75)
1 parent b57d448 commit ee64013

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+744
-498
lines changed

.envs/dev/frontend.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
# Backend configuration
66
# -------------------------------------------------------------------
7-
VITE_API_BASE_URL=https://127.0.0.1:8000/api
7+
VITE_API_BASE_URL=https://127.0.0.1:8000/api

.envs/prod/frontend.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
# Backend configuration
66
# -------------------------------------------------------------------
7-
VITE_API_BASE_URL=https://127.0.0.1:8000/api
7+
VITE_API_BASE_URL=https://127.0.0.1:8000/api

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ body:
6060
description: |
6161
Any other information?
6262
validations:
63-
required: false
63+
required: false

.github/ISSUE_TEMPLATE/devops.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: DevOps Task
22
description: Template for tracking DevOps-related tasks and improvements.
3-
title: "[DevOps] "
3+
title: "[DevOps]: "
44
labels: ["type: devops"]
55
assignees: []
66

@@ -33,20 +33,11 @@ body:
3333
validations:
3434
required: false
3535

36-
- type: input
37-
id: deadline
38-
attributes:
39-
label: Deadline
40-
description: When should this task be completed by? (optional)
41-
placeholder: YYYY-MM-DD
42-
validations:
43-
required: false
44-
4536
- type: textarea
4637
id: additional
4738
attributes:
4839
label: Additional Notes
4940
description: Any other information or resources.
5041
placeholder: Links, references, or related issues.
5142
validations:
52-
required: false
43+
required: false

.github/ISSUE_TEMPLATE/planning_task.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ body:
5555
description: When should this task be completed?
5656
placeholder: YYYY-MM-DD
5757
validations:
58-
required: false
58+
required: false

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
## Deployment Notes (if any)
1919
<!--
2020
Add any special deployment or migration steps here.
21-
-->
21+
-->

.pre-commit-config.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
repos:
2+
# ------------------------
3+
# General sanity checks
4+
# ------------------------
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.6.0
7+
hooks:
8+
- id: trailing-whitespace
9+
- id: end-of-file-fixer
10+
- id: check-yaml
11+
- id: check-added-large-files
12+
13+
# ------------------------
14+
# Backend (Python / FastAPI)
15+
# ------------------------
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
rev: v0.14.10
18+
hooks:
19+
- id: ruff-check
20+
args: [--fix]
21+
files: ^backend/
22+
- id: ruff-format
23+
files: ^backend/
24+
25+
# ------------------------
26+
# Frontend (Node / TS)
27+
# NOTE: Git hooks run in a non-interactive shell. Node tooling (pnpm) must be available on PATH.
28+
# ------------------------
29+
- repo: local
30+
hooks:
31+
- id: frontend-eslint
32+
name: Frontend ESLint (staged files)
33+
entry: >
34+
bash -c '
35+
command -v pnpm >/dev/null 2>&1 ||
36+
{ echo "❌ pnpm not found on PATH (git hooks run non-interactively)"; exit 1; };
37+
export PATH="$HOME/.local/bin:$HOME/.pnpm:$PATH";
38+
pnpm --dir frontend run lint:fix:staged
39+
'
40+
language: system
41+
files: ^frontend/.*\.(ts|tsx|js|jsx)$
42+
43+
- id: frontend-prettier
44+
name: Frontend Prettier (staged files)
45+
entry: >
46+
bash -c '
47+
command -v pnpm >/dev/null 2>&1 ||
48+
{ echo "❌ pnpm not found on PATH (git hooks run non-interactively)"; exit 1; };
49+
export PATH="$HOME/.local/bin:$HOME/.pnpm:$PATH";
50+
pnpm --dir frontend run format:staged
51+
'
52+
language: system
53+
files: ^frontend/.*\.(ts|tsx|js|jsx|css|json|md)$

.vite/deps/_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"browserHash": "deca6459",
66
"optimized": {},
77
"chunks": {}
8-
}
8+
}

Makefile

Lines changed: 72 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,43 +40,75 @@ help:
4040
@echo ""
4141
@echo "$(BLUE)Environment:$(NC) APP_ENV=$(env)"
4242
@echo ""
43+
4344
@echo " $(YELLOW)Project Setup$(NC)"
44-
@echo " make setup-dev env=dev # Bare-metal dev setup"
45-
@echo " make setup-dev-docker env=dev_docker # Docker dev setup"
46-
@echo " make setup-dev-assets env=<env> # Ensure .env + certs exist"
47-
@echo " make copy-env env=<env> # Copy .env.example → .env"
48-
@echo " make gen-certs # Generate dev SSL certs"
45+
@echo " make install # Install backend + frontend deps + pre-commit"
46+
@echo " make setup-dev env=dev # Bare-metal dev setup"
47+
@echo " make setup-dev-docker env=dev_docker # Docker dev setup"
48+
@echo " make setup-dev-assets env=<env> # Ensure .env files + certs exist"
49+
@echo " make copy-env env=<env> # Copy .env.example → .env"
50+
@echo " make gen-certs # Generate dev SSL certs"
51+
@echo ""
52+
53+
@echo " $(YELLOW)Pre-commit$(NC)"
54+
@echo " make pre-commit-install # Install git pre-commit hooks"
55+
@echo " make pre-commit-run # Run all pre-commit hooks"
4956
@echo ""
57+
5058
@echo " $(YELLOW)Backend Commands$(NC)"
51-
@echo " make backend-install # Create venv + install deps"
52-
@echo " make backend-clean # Clean caches"
53-
@echo " make backend-run # Start FastAPI"
54-
@echo " make backend-reload # Start with auto-reload"
55-
@echo " make backend-migrate m='msg' # Create Alembic migration"
56-
@echo " make backend-upgrade # Apply migrations"
57-
@echo " make backend-downgrade rev=<rev> # Downgrade DB"
58-
@echo " make backend-test # Run pytest"
59+
@echo " make backend-install # Create venv (if missing) + install deps"
60+
@echo " make backend-reset # Recreate venv + reinstall deps"
61+
@echo " make backend-clean # Clean Python caches"
62+
@echo " make backend-run # Start FastAPI server"
63+
@echo " make backend-reload # Start FastAPI with auto-reload"
64+
@echo " make backend-migrate m='msg' # Create Alembic migration"
65+
@echo " make backend-upgrade # Apply DB migrations"
66+
@echo " make backend-downgrade rev=<rev> # Downgrade DB"
67+
@echo " make backend-test # Run pytest"
5968
@echo ""
69+
6070
@echo " $(YELLOW)Frontend Commands$(NC)"
61-
@echo " make frontend-install # Install dependencies"
62-
@echo " make frontend-dev # Start Vite dev server"
63-
@echo " make frontend-build # Build site"
64-
@echo " make frontend-preview # Preview built site"
65-
@echo " make frontend-lint # ESLint"
71+
@echo " make frontend-install # Install frontend dependencies"
72+
@echo " make frontend-clean # Remove node_modules + build artifacts"
73+
@echo " make frontend-dev # Start Vite dev server"
74+
@echo " make frontend-build # Build frontend"
75+
@echo " make frontend-preview # Preview production build"
76+
@echo " make frontend-lint # Run ESLint"
77+
@echo " make frontend-fix # Run ESLint with --fix"
6678
@echo ""
67-
@echo " $(YELLOW)Docker$(NC)"
68-
@echo " make docker-up env=<env> svc=<svc> # Start service(s)"
69-
@echo " make docker-build env=<env> svc=<svc> # Build service images"
79+
80+
@echo " $(YELLOW)Docker Commands$(NC)"
81+
@echo " make docker-build env=<env> svc=<svc> # Build Docker image(s)"
82+
@echo " make docker-rebuild env=<env> svc=<svc> # Build Docker image(s) without cache"
83+
@echo " make docker-up env=<env> svc=<svc> # Start service(s)"
84+
@echo " make docker-up-detached env=<env> svc=<svc> # Start service(s) in background"
85+
@echo " make docker-down env=<env> # Stop all services"
86+
@echo " make docker-restart env=<env> svc=<svc> # Restart service(s)"
87+
@echo " make docker-logs env=<env> svc=<svc> # Follow service logs"
88+
@echo " make docker-shell env=<env> svc=<svc> # Shell into running container"
89+
@echo " make docker-ps env=<env> # List running containers"
90+
@echo " make docker-config env=<env> # Show resolved docker-compose config"
7091
@echo ""
92+
7193
@echo " $(YELLOW)Database (via Docker)$(NC)"
72-
@echo " make db-init env=<env> # Migrate + seed dev DB"
94+
@echo " make db-migrate m='msg' env=<env> # Create migration"
95+
@echo " make db-upgrade env=<env> # Apply migrations"
96+
@echo " make db-rollback env=<env> # Roll back last migration"
97+
@echo " make db-seed env=<env> # Seed database (non-prod only)"
98+
@echo " make db-init env=<env> # Migrate + seed database"
99+
@echo ""
100+
101+
@echo " $(YELLOW)Build & Cleanup$(NC)"
102+
@echo " make build # Build frontend"
103+
@echo " make preview # Preview frontend build"
104+
@echo " make clean # Clean backend + frontend artifacts"
73105

74106

75107
# ============================================================
76108
# ⚙️ CORE SETUP
77109
# ============================================================
78110

79-
.PHONY: setup-dev setup-dev-docker setup-dev-assets copy-env gen-certs
111+
.PHONY: setup-dev setup-dev-docker setup-dev-assets copy-env gen-certs install
80112

81113
# ------------------------------------------------------------
82114
# Bare-metal dev
@@ -153,14 +185,29 @@ gen-certs:
153185
cd certs && ./generate-dev-certs.sh
154186

155187

188+
# ------------------------------------------------------------
189+
# Pre-commit
190+
# ------------------------------------------------------------
191+
192+
.PHONY: pre-commit-install pre-commit-run
193+
194+
pre-commit-install:
195+
cd $(BACKEND_DIR) && uv run pre-commit install --install-hooks
196+
197+
pre-commit-run:
198+
cd $(BACKEND_DIR) && uv run pre-commit run --all-files
199+
156200
# ============================================================
157201
# 🧑‍💻 BACKEND COMMANDS
158202
# ============================================================
159203

160204
.PHONY: backend-install backend-clean backend-run backend-reload backend-migrate backend-upgrade backend-downgrade backend-test
161205

162206
backend-install:
163-
cd $(BACKEND_DIR) && uv venv .venv && uv sync --all-groups
207+
cd $(BACKEND_DIR) && if [ ! -d .venv ]; then uv venv .venv; fi && uv sync --all-groups
208+
209+
backend-reset:
210+
cd $(BACKEND_DIR) && rm -rf .venv && uv venv .venv && uv sync --all-groups
164211

165212
backend-clean:
166213
cd $(BACKEND_DIR) && find . -type d -name "__pycache__" -exec rm -rf {} + && rm -rf .pytest_cache .ruff_cache build dist .mypy_cache
@@ -288,9 +335,7 @@ db-init:
288335

289336
.PHONY: clean install
290337

291-
install:
292-
make backend-install
293-
make frontend-install
338+
install: backend-install frontend-install pre-commit-install
294339

295340
clean:
296341
make backend-clean

README.md

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,94 @@ Pull requests should include tests + documentation updates.
243243

244244
---
245245

246-
## Makefile Overview
246+
## 🪝 Pre-commit Hooks
247247

248-
The Makefile provides **unified commands** for backend, frontend, Docker, DB, and environment management.
248+
This repository uses **[pre-commit](https://pre-commit.com/)** to enforce consistent code quality checks for both the **backend (Python)** and **frontend (TypeScript)**.
249249

250-
View all available commands:
250+
Pre-commit runs automatically on `git commit` and will block commits if checks fail.
251+
252+
---
253+
254+
### What pre-commit checks
255+
256+
- **Backend**
257+
- Ruff linting and formatting
258+
- Python style and correctness checks
259+
- **Frontend**
260+
- ESLint (auto-fix on staged files)
261+
- Prettier formatting (staged files only)
262+
263+
All hooks are configured in the root `.pre-commit-config.yaml`.
264+
265+
> **Note:** Git hooks run in a non-interactive shell
266+
> Make sure that Node.js tools (such as `pnpm`) are available in your system `PATH` so pre-commit hooks can execute successfully.
267+
268+
---
269+
270+
### Installing pre-commit (recommended)
271+
272+
Pre-commit is installed **inside the backend uv environment** and wired up via the Makefile.
273+
274+
After cloning the repo, run:
251275

252276
```bash
253-
make help
277+
make install
254278
```
255279

280+
This will:
281+
282+
- Create the backend `uv` virtual environment (if missing)
283+
- Install Python and frontend dependencies
284+
- Install the git pre-commit hooks
285+
286+
If you only want to (re)install the hooks:
287+
288+
```bash
289+
make pre-commit-install
290+
```
291+
292+
---
293+
294+
### Running pre-commit manually
295+
296+
To run all hooks against all files:
297+
298+
```bash
299+
make pre-commit-run
300+
```
301+
302+
Or directly:
303+
304+
```bash
305+
cd backend
306+
uv run pre-commit run --all-files
307+
```
308+
309+
You can also run pre-commit from **any directory inside the repo**; it always resolves the repo root configuration.
310+
311+
---
312+
313+
### Notes & expectations
314+
315+
- Pre-commit uses the **existing project environments**:
316+
- Python hooks run via `uv`
317+
- Frontend hooks run via `pnpm`
318+
- The tools themselves (`uv`, `pnpm`, `node`) are expected to already be installed on your system
319+
- Hooks are **fast** and only run on staged files by default
320+
- Formatting issues are usually auto-fixed; re-stage files and retry the commit if needed
321+
322+
---
323+
324+
### Skipping hooks (not recommended)
325+
326+
If you must bypass pre-commit temporarily:
327+
328+
```bash
329+
git commit --no-verify
330+
```
331+
332+
Please only do this when absolutely necessary.
333+
256334
---
257335

258336
## Local HTTPS

0 commit comments

Comments
 (0)