Skip to content

Commit 239ca47

Browse files
committed
refactor: improve code formatting, type hints, and remove unused files/settings
- Remove `pytest.ini` (options moved to `pyproject.toml`) - Update type hints to use `|` syntax (requires Python 3.10+) - Ensure consistent indentation, formatting, and imports across files - Remove unused or redundant configurations in `.env` - Simplify and consolidate optional and dev dependencies in `uv.lock` and `pyproject.toml`
1 parent 49482b6 commit 239ca47

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

+676
-840
lines changed

.github/workflows/test-backend.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: Install uv
4242
uses: astral-sh/setup-uv@v4
4343
with:
44-
version: "latest"
44+
version: "0.5.16"
4545

4646
- name: Install dependencies
4747
run: uv sync --extra test --extra migrations

Taskfile.yml

Lines changed: 117 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,127 @@
22

33
version: '3'
44

5+
vars:
6+
COMPOSE_DEV: docker compose
7+
COMPOSE_PROD: docker compose -f docker-compose.prod.yml
8+
59
tasks:
6-
dev:frontend:
7-
env:
8-
APP_DEBUG: true
9-
cmd: docker compose --profile dev_frontend up -d --build
10+
# ====================
11+
# Development
12+
# ====================
13+
dev:up:
14+
desc: Start all development services
15+
cmds:
16+
- "{{.COMPOSE_DEV}} --profile dev_frontend --profile dev_backend up -d --build"
17+
1018
dev:backend:
19+
desc: Start backend only (with database)
1120
env:
12-
APP_DEBUG: true
13-
cmd: docker compose --profile dev_backend up -d --build
21+
APP_DEBUG: "true"
22+
cmds:
23+
- "{{.COMPOSE_DEV}} --profile dev_backend up -d --build"
24+
25+
dev:frontend:
26+
desc: Start frontend only
27+
env:
28+
APP_DEBUG: "true"
29+
cmds:
30+
- "{{.COMPOSE_DEV}} --profile dev_frontend up -d --build"
31+
1432
dev:down:
33+
desc: Stop all development services
1534
cmds:
16-
- docker compose --profile dev_frontend down
17-
- docker compose --profile dev_backend down
18-
- docker compose --profile dev_db down
35+
- "{{.COMPOSE_DEV}} --profile dev_frontend --profile dev_backend down"
36+
1937
dev:reset:
38+
desc: Reset development environment (removes volumes)
39+
cmds:
40+
- "{{.COMPOSE_DEV}} --profile dev_frontend --profile dev_backend down --volumes"
41+
- "{{.COMPOSE_DEV}} --profile dev_frontend --profile dev_backend up -d --build"
42+
43+
dev:logs:
44+
desc: Tail logs from all development services
45+
cmds:
46+
- "{{.COMPOSE_DEV}} --profile dev_frontend --profile dev_backend logs -f"
47+
48+
dev:logs:backend:
49+
desc: Tail backend logs only
50+
cmds:
51+
- "{{.COMPOSE_DEV}} --profile dev_backend logs -f devbin"
52+
53+
# ====================
54+
# Production
55+
# ====================
56+
prod:up:
57+
desc: Start production services
58+
cmds:
59+
- "{{.COMPOSE_PROD}} up -d"
60+
61+
prod:down:
62+
desc: Stop production services
63+
cmds:
64+
- "{{.COMPOSE_PROD}} down"
65+
66+
prod:logs:
67+
desc: Tail production logs
68+
cmds:
69+
- "{{.COMPOSE_PROD}} logs -f"
70+
71+
# ====================
72+
# Database
73+
# ====================
74+
db:migrate:
75+
desc: Run pending database migrations
76+
cmds:
77+
- "{{.COMPOSE_DEV}} --profile dev_backend run --rm devbin uv run alembic upgrade head"
78+
79+
db:migrate:new:
80+
desc: "Create new migration (usage: task db:migrate:new -- 'description')"
81+
cmds:
82+
- "{{.COMPOSE_DEV}} --profile dev_backend run --rm devbin uv run alembic revision --autogenerate -m '{{.CLI_ARGS}}'"
83+
84+
db:shell:
85+
desc: Open PostgreSQL shell
86+
cmds:
87+
- "{{.COMPOSE_DEV}} exec devbin_db psql -U postgres -d devbin"
88+
89+
# ====================
90+
# Testing
91+
# ====================
92+
test:
93+
desc: Run all backend tests
94+
dir: backend
95+
cmds:
96+
- uv run pytest
97+
98+
test:unit:
99+
desc: Run unit tests only
100+
dir: backend
101+
cmds:
102+
- uv run pytest tests/unit
103+
104+
test:integration:
105+
desc: Run integration tests only
106+
dir: backend
107+
cmds:
108+
- uv run pytest tests/integration
109+
110+
test:cov:
111+
desc: Run tests with coverage report
112+
dir: backend
113+
cmds:
114+
- uv run pytest --cov=app --cov-report=term-missing
115+
116+
# ====================
117+
# Utilities
118+
# ====================
119+
build:
120+
desc: Build all containers
121+
cmds:
122+
- "{{.COMPOSE_DEV}} --profile dev_frontend --profile dev_backend build"
123+
124+
clean:
125+
desc: Remove all containers and volumes
20126
cmds:
21-
- docker compose --profile dev_frontend down
22-
- docker compose --profile dev_backend down --volumes
23-
- docker compose --profile dev_db down --volumes
24-
- docker compose --profile dev_frontend up -d --build
25-
- docker compose --profile dev_backend up -d --build
127+
- "{{.COMPOSE_DEV}} --profile dev_frontend --profile dev_backend down --volumes --remove-orphans"
128+
- "{{.COMPOSE_PROD}} down --volumes --remove-orphans 2>/dev/null || true"

backend/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ APP_ALLOW_CORS_WILDCARD=true
3434
# APP_CORS_DOMAINS=["https://devbin.example.com","https://app.devbin.example.com"]
3535
# APP_ALLOW_CORS_WILDCARD=false
3636

37-
# Trusted Hosts (for X-Forwarded-For header)
37+
# Trusted Hosts (for X-Forwarded-For header) - supports CIDR notation
38+
# Examples: ["127.0.0.1", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]
3839
APP_TRUSTED_HOSTS=["127.0.0.1"]
3940

4041
# Paste Configuration

backend/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ COPY pyproject.toml uv.lock ./
3939
# Install dependencies
4040
# --frozen: Use exact versions from uv.lock (reproducible builds)
4141
# --no-dev: Exclude development dependencies
42-
# --extra migrations: Include migrations group (psycopg2-binary)
42+
# --extra production: Include any production related dependencies (redis, aiocache etc...)
4343
# --no-cache: Prevent uv cache bloat in image
44-
RUN uv sync --frozen --no-dev --extra migrations --no-cache
44+
RUN uv sync --frozen --no-default-groups --extra production --no-cache
4545

4646
# ============================================
4747
# Stage 3: Runtime - Production Image
4848
# ============================================
4949
FROM base AS runtime
5050

5151
# Copy uv for runtime execution
52-
COPY --from=ghcr.io/astral-sh/uv:0.5.16 /uv /uvx /usr/local/bin/
52+
COPY --from=ghcr.io/astral-sh/uv:0.9.18 /uv /uvx /usr/local/bin/
5353

5454
# Copy installed dependencies from builder stage
5555
# This excludes build tools (gcc, g++, libpq-dev)

backend/TESTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This guide explains how to run tests locally and in CI/CD.
77
### 1. Install Test Dependencies
88

99
```bash
10-
uv sync --extra test
10+
uv sync --group test
1111
```
1212

1313
### 2. Start Test Database
@@ -52,7 +52,7 @@ tests/
5252
└── security/ # Security-focused tests
5353
```
5454

55-
## Local Development
55+
## Local Development on tests
5656

5757
### Managing Test Database
5858

backend/alembic/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22
from logging.config import fileConfig
33

4-
from alembic import context
54
from sqlalchemy import engine_from_config, pool
65

6+
from alembic import context
77
from app.db.models import *
88

99
# this is the Alembic Config object, which provides

backend/alembic/versions/08393764144d_add_delete_edit_tokens_and_deleted_at.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
"""Add Delete, Edit tokens and deleted at
1+
"""Add Delete, Edit tokens and deleted at
22
33
Revision ID: 08393764144d
44
Revises: 7c45e2617d61
55
Create Date: 2025-12-17 22:00:02.736745
66
77
"""
8-
from typing import Sequence, Union
8+
from collections.abc import Sequence
99

1010
import sqlalchemy as sa
11+
1112
from alembic import op
1213

1314
# revision identifiers, used by Alembic.
1415
revision: str = '08393764144d'
15-
down_revision: Union[str, Sequence[str], None] = '7c45e2617d61'
16-
branch_labels: Union[str, Sequence[str], None] = None
17-
depends_on: Union[str, Sequence[str], None] = None
16+
down_revision: str | Sequence[str] | None = '7c45e2617d61'
17+
branch_labels: str | Sequence[str] | None = None
18+
depends_on: str | Sequence[str] | None = None
1819

1920

2021
def upgrade() -> None:

backend/alembic/versions/20251219_203917_hash_existing_tokens.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
77
"""
88

9-
from typing import Sequence, Union
9+
from collections.abc import Sequence
1010

1111
import sqlalchemy as sa
12-
from alembic import op
1312
from argon2 import PasswordHasher
1413

14+
from alembic import op
15+
1516
# revision identifiers, used by Alembic.
1617
revision: str = "0ed6c1042110"
17-
down_revision: Union[str, Sequence[str], None] = "08393764144d"
18-
branch_labels: Union[str, Sequence[str], None] = None
19-
depends_on: Union[str, Sequence[str], None] = None
18+
down_revision: str | Sequence[str] | None = "08393764144d"
19+
branch_labels: str | Sequence[str] | None = None
20+
depends_on: str | Sequence[str] | None = None
2021

2122
# Configure Argon2 with same parameters as token_utils.py
2223
ph = PasswordHasher(

backend/alembic/versions/4e57d32ab2ac_add_paste_indexes.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
Create Date: 2025-12-25 20:15:09.567249
66
77
"""
8-
from typing import Sequence, Union
8+
from collections.abc import Sequence
99

1010
from alembic import op
11-
import sqlalchemy as sa
12-
1311

1412
# revision identifiers, used by Alembic.
1513
revision: str = '4e57d32ab2ac'
16-
down_revision: Union[str, Sequence[str], None] = '6c5a2c764fb8'
17-
branch_labels: Union[str, Sequence[str], None] = None
18-
depends_on: Union[str, Sequence[str], None] = None
14+
down_revision: str | Sequence[str] | None = '6c5a2c764fb8'
15+
branch_labels: str | Sequence[str] | None = None
16+
depends_on: str | Sequence[str] | None = None
1917

2018

2119
def upgrade() -> None:

backend/alembic/versions/6c5a2c764fb8_add_compression_fields.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
Create Date: 2025-12-25 13:23:44.911166
66
77
"""
8-
from typing import Sequence, Union
8+
from collections.abc import Sequence
99

10-
from alembic import op
1110
import sqlalchemy as sa
1211

12+
from alembic import op
1313

1414
# revision identifiers, used by Alembic.
1515
revision: str = '6c5a2c764fb8'
16-
down_revision: Union[str, Sequence[str], None] = '0ed6c1042110'
17-
branch_labels: Union[str, Sequence[str], None] = None
18-
depends_on: Union[str, Sequence[str], None] = None
16+
down_revision: str | Sequence[str] | None = '0ed6c1042110'
17+
branch_labels: str | Sequence[str] | None = None
18+
depends_on: str | Sequence[str] | None = None
1919

2020

2121
def upgrade() -> None:

0 commit comments

Comments
 (0)