Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ env
.env
/env
./env
.venv/
.pytest_cache/
.codegraph/
.atl/
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
78 changes: 39 additions & 39 deletions README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ flowchart LR

## 🛠️ Stack tecnológico

| Categoría | Tecnología |
|---|---|
| Lenguaje | Python 3.12 |
| Framework web | FastAPI |
| ORM / validación | SQLModel (Pydantic) |
| Base de datos | PostgreSQL (+ migraciones Alembic) |
| Cache / pub-sub | Redis |
| Tareas asíncronas | Celery (broker Redis) |
| Scheduler | APScheduler |
| Autenticación | JWT (python-jose, HS256) |
| Tests | pytest, pytest-cov |
| CI | GitHub Actions |
| Contenedores | Docker & Docker Compose |
| Categoría | Tecnología |
| ----------------- | ---------------------------------- |
| Lenguaje | Python 3.12 |
| Framework web | FastAPI |
| ORM / validación | SQLModel (Pydantic) |
| Base de datos | PostgreSQL (+ migraciones Alembic) |
| Cache / pub-sub | Redis |
| Tareas asíncronas | Celery (broker Redis) |
| Scheduler | APScheduler |
| Autenticación | JWT (python-jose, HS256) |
| Tests | pytest, pytest-cov |
| CI | GitHub Actions |
| Contenedores | Docker & Docker Compose |

---

Expand Down Expand Up @@ -151,23 +151,23 @@ La API estará disponible en `http://localhost:8000` (PostgreSQL y Redis incluid

Crea un archivo `.env` en la raíz del proyecto. `SECRET_KEY` y `ALGORITHM` son **obligatorias** — la aplicación falla al iniciar sin ellas. Si `DATABASE_URL` está definida, tiene prioridad sobre los valores individuales de `POSTGRES_*`.

| Variable | Uso | Valor por defecto | Notas |
|---|---|---|---|
| `POSTGRES_USER` | `db/database.py` | — | Obligatoria |
| `POSTGRES_PASSWORD` | `db/database.py` | — | Obligatoria |
| `POSTGRES_DB` | `db/database.py` | — | Obligatoria |
| `POSTGRES_HOST` | `db/database.py` | — | Obligatoria |
| `POSTGRES_PORT` | `db/database.py` | — | Obligatoria |
| `DATABASE_URL` | `db/database.py` | — | URL completa de SQLAlchemy; tiene prioridad sobre `POSTGRES_*` |
| `REDIS_HOST` | `db/database.py` | `localhost` | |
| `REDIS_PORT` | `db/database.py` | `6379` | |
| `REDIS_DB` | `db/database.py` | `0` | |
| `REDIS_PASSWORD` | Cliente Redis | — | Obligatoria en la configuración con Docker |
| `REDIS_URL` | Celery (`tasks.py`) | — | URL del broker |
| `SECRET_KEY` | Auth | — | **Obligatoria — la aplicación falla al iniciar sin ella** |
| `ALGORITHM` | Auth | — | **Obligatoria — p. ej. `HS256`** |
| `ACCESS_TOKEN_DURATION` | `services/auth_services.py` | `15` | Vigencia del access token en **minutos** |
| `REFRESH_TOKEN_DURATION` | `services/auth_services.py` | `7` | Vigencia del refresh token en **días** |
| Variable | Uso | Valor por defecto | Notas |
| ------------------------ | --------------------------- | ----------------- | -------------------------------------------------------------- |
| `POSTGRES_USER` | `db/database.py` | — | Obligatoria |
| `POSTGRES_PASSWORD` | `db/database.py` | — | Obligatoria |
| `POSTGRES_DB` | `db/database.py` | — | Obligatoria |
| `POSTGRES_HOST` | `db/database.py` | — | Obligatoria |
| `POSTGRES_PORT` | `db/database.py` | — | Obligatoria |
| `DATABASE_URL` | `db/database.py` | — | URL completa de SQLAlchemy; tiene prioridad sobre `POSTGRES_*` |
| `REDIS_HOST` | `db/database.py` | `localhost` | |
| `REDIS_PORT` | `db/database.py` | `6379` | |
| `REDIS_DB` | `db/database.py` | `0` | |
| `REDIS_PASSWORD` | Cliente Redis | — | Obligatoria en la configuración con Docker |
| `REDIS_URL` | Celery (`tasks.py`) | — | URL del broker |
| `SECRET_KEY` | Auth | — | **Obligatoria — la aplicación falla al iniciar sin ella** |
| `ALGORITHM` | Auth | — | **Obligatoria — p. ej. `HS256`** |
| `ACCESS_TOKEN_DURATION` | `services/auth_services.py` | `15` | Vigencia del access token en **minutos** |
| `REFRESH_TOKEN_DURATION` | `services/auth_services.py` | `7` | Vigencia del refresh token en **días** |

Ejemplo para copiar y pegar (valores ficticios únicamente — genera los tuyos):

Expand Down Expand Up @@ -208,18 +208,18 @@ Una vez que el servidor esté en ejecución:

## 🧪 Testing

| Comando | Qué hace |
|---|---|
| `pytest -q --disable-warnings` | Ejecuta la suite completa (requiere Redis en `localhost:6379`) |
| `pytest -vv` | Ejecución en modo verbose |
| `pytest --cov=./api/v1 --cov-report=html` | Cobertura de los routers → `htmlcov/index.html` |
| `pytest --cov=. --cov-report=html` | Cobertura del proyecto completo → `htmlcov/index.html` |
| `src/ci-test.sh` | Entrada de CI — termina con error si un test falla |
| Comando | Qué hace |
| ----------------------------------------- | -------------------------------------------------------------- |
| `pytest -q --disable-warnings` | Ejecuta la suite completa (requiere Redis en `localhost:6379`) |
| `pytest -vv` | Ejecución en modo verbose |
| `pytest --cov=./api/v1 --cov-report=html` | Cobertura de los routers → `htmlcov/index.html` |
| `pytest --cov=. --cov-report=html` | Cobertura del proyecto completo → `htmlcov/index.html` |
| `src/ci-test.sh` | Entrada de CI — termina con error si un test falla |

Notas:

- Los tests se ejecutan sobre **SQLite** (`test/conftest.py`) con **Redis en `localhost:6379`**.
- `src/test.sh` inicia Redis por ti (`docker start redis-stack`) antes de ejecutar pytest.
- `src/test.sh` inicia Redis por ti (`docker compose up -d redis`) antes de ejecutar pytest.
- Los requisitos están separados: `requirements.txt` (app) vs `requirements-test.txt` (pytest, pytest-cov, …).

**CI:** GitHub Actions (`.github/workflows/test.yaml`) se ejecuta en cada push / PR a `main`: pytest sobre `./test/test_routers`, más una pasada de flake8 no bloqueante.
Expand Down Expand Up @@ -250,7 +250,7 @@ Store image files under docs/images/.

## ⚠️ Limitaciones conocidas

Lista honesta de lo que *aún* no está implementado — cada punto indica por qué importa:
Lista honesta de lo que _aún_ no está implementado — cada punto indica por qué importa:

1. **Canales de notificación** — la entrega en tiempo real es solo WebSocket + dentro de la aplicación; no hay email ni push móvil. No se han implementado el restablecimiento de contraseña ni la verificación de email.
2. **Despliegue de instancia única** — la demo corre en una sola VM local; el escalado horizontal y el fan-out de WebSocket entre múltiples instancias no se han probado bajo carga.
Expand Down
78 changes: 39 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ flowchart LR

## 🛠️ Tech stack

| Category | Technology |
|---|---|
| Language | Python 3.12 |
| Web framework | FastAPI |
| ORM / validation | SQLModel (Pydantic) |
| Database | PostgreSQL (+ Alembic migrations) |
| Cache / pub-sub | Redis |
| Async tasks | Celery (Redis broker) |
| Scheduler | APScheduler |
| Auth | JWT (python-jose, HS256) |
| Tests | pytest, pytest-cov |
| CI | GitHub Actions |
| Containers | Docker & Docker Compose |
| Category | Technology |
| ---------------- | --------------------------------- |
| Language | Python 3.12 |
| Web framework | FastAPI |
| ORM / validation | SQLModel (Pydantic) |
| Database | PostgreSQL (+ Alembic migrations) |
| Cache / pub-sub | Redis |
| Async tasks | Celery (Redis broker) |
| Scheduler | APScheduler |
| Auth | JWT (python-jose, HS256) |
| Tests | pytest, pytest-cov |
| CI | GitHub Actions |
| Containers | Docker & Docker Compose |

---

Expand Down Expand Up @@ -151,23 +151,23 @@ The API will be available at `http://localhost:8000` (PostgreSQL and Redis inclu

Create a `.env` file at the project root. `SECRET_KEY` and `ALGORITHM` are **required** — the app fails at startup without them. If `DATABASE_URL` is set, it takes precedence over the individual `POSTGRES_*` values.

| Variable | Used in | Default | Notes |
|---|---|---|---|
| `POSTGRES_USER` | `db/database.py` | — | Required |
| `POSTGRES_PASSWORD` | `db/database.py` | — | Required |
| `POSTGRES_DB` | `db/database.py` | — | Required |
| `POSTGRES_HOST` | `db/database.py` | — | Required |
| `POSTGRES_PORT` | `db/database.py` | — | Required |
| `DATABASE_URL` | `db/database.py` | — | Full SQLAlchemy URL; takes precedence over `POSTGRES_*` |
| `REDIS_HOST` | `db/database.py` | `localhost` | |
| `REDIS_PORT` | `db/database.py` | `6379` | |
| `REDIS_DB` | `db/database.py` | `0` | |
| `REDIS_PASSWORD` | Redis client | — | Required in the Docker setup |
| `REDIS_URL` | Celery (`tasks.py`) | — | Broker URL |
| `SECRET_KEY` | auth | — | **Required — startup fails without it** |
| `ALGORITHM` | auth | — | **Required — e.g. `HS256`** |
| `ACCESS_TOKEN_DURATION` | `services/auth_services.py` | `15` | Access token lifetime in **minutes** |
| `REFRESH_TOKEN_DURATION` | `services/auth_services.py` | `7` | Refresh token lifetime in **days** |
| Variable | Used in | Default | Notes |
| ------------------------ | --------------------------- | ----------- | ------------------------------------------------------- |
| `POSTGRES_USER` | `db/database.py` | — | Required |
| `POSTGRES_PASSWORD` | `db/database.py` | — | Required |
| `POSTGRES_DB` | `db/database.py` | — | Required |
| `POSTGRES_HOST` | `db/database.py` | — | Required |
| `POSTGRES_PORT` | `db/database.py` | — | Required |
| `DATABASE_URL` | `db/database.py` | — | Full SQLAlchemy URL; takes precedence over `POSTGRES_*` |
| `REDIS_HOST` | `db/database.py` | `localhost` | |
| `REDIS_PORT` | `db/database.py` | `6379` | |
| `REDIS_DB` | `db/database.py` | `0` | |
| `REDIS_PASSWORD` | Redis client | — | Required in the Docker setup |
| `REDIS_URL` | Celery (`tasks.py`) | — | Broker URL |
| `SECRET_KEY` | auth | — | **Required — startup fails without it** |
| `ALGORITHM` | auth | — | **Required — e.g. `HS256`** |
| `ACCESS_TOKEN_DURATION` | `services/auth_services.py` | `15` | Access token lifetime in **minutes** |
| `REFRESH_TOKEN_DURATION` | `services/auth_services.py` | `7` | Refresh token lifetime in **days** |

Copy-pasteable example (fake values only — generate your own):

Expand Down Expand Up @@ -208,18 +208,18 @@ Once the server is running:

## 🧪 Testing

| Command | What it does |
|---|---|
| `pytest -q --disable-warnings` | Run the full suite (needs Redis on `localhost:6379`) |
| `pytest -vv` | Verbose run |
| `pytest --cov=./api/v1 --cov-report=html` | Coverage of routers → `htmlcov/index.html` |
| `pytest --cov=. --cov-report=html` | Full-project coverage → `htmlcov/index.html` |
| `src/ci-test.sh` | CI entrypoint — exits non-zero on test failure |
| Command | What it does |
| ----------------------------------------- | ---------------------------------------------------- |
| `pytest -q --disable-warnings` | Run the full suite (needs Redis on `localhost:6379`) |
| `pytest -vv` | Verbose run |
| `pytest --cov=./api/v1 --cov-report=html` | Coverage of routers → `htmlcov/index.html` |
| `pytest --cov=. --cov-report=html` | Full-project coverage → `htmlcov/index.html` |
| `src/ci-test.sh` | CI entrypoint — exits non-zero on test failure |

Notes:

- Tests run against **SQLite** (`test/conftest.py`) with **Redis at `localhost:6379`**.
- `src/test.sh` starts Redis for you (`docker start redis-stack`) before running pytest.
- `src/test.sh` starts Redis for you (`docker compose up -d redis`) before running pytest.
- Requirements are split: `requirements.txt` (app) vs `requirements-test.txt` (pytest, pytest-cov, …).

**CI:** GitHub Actions (`.github/workflows/test.yaml`) runs on every push / PR to `main`: pytest over `./test/test_routers`, plus a non-blocking flake8 lint pass.
Expand Down Expand Up @@ -250,7 +250,7 @@ Store image files under docs/images/.

## ⚠️ Known limitations

Honest list of what is *not* there yet — each entry includes why it matters:
Honest list of what is _not_ there yet — each entry includes why it matters:

1. **Notification channels** — real-time delivery is WebSocket + in-app only; no email or mobile push. Password reset and email verification are not implemented.
2. **Single-instance deployment** — the demo runs on a single local VM; horizontal scaling and multi-instance WebSocket fan-out have not been load-tested.
Expand Down
105 changes: 105 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
[project]
name = "api-de-tareas-con-fastapi"
version = "0.1.0"
description = "Task management API built with FastAPI, SQLModel, Redis, Celery and WebSockets"
readme = "README.md"
authors = [
{ name = "Mirko Stamm" }
]
requires-python = ">=3.12"
dependencies = [
"alembic==1.15.2",
"annotated-types==0.7.0",
"anyio==4.9.0",
"certifi==2025.1.31",
"charset-normalizer==3.4.1",
"click==8.1.8",
"dnspython==2.7.0",
"ecdsa==0.19.1",
"email_validator==2.2.0",
"fastapi==0.115.12",
"fastapi-cli==0.0.7",
"greenlet==3.1.1",
"h11==0.14.0",
"httpcore==1.0.8",
"httptools==0.6.4",
"httpx==0.28.1",
"idna==3.10",
"Jinja2==3.1.6",
"Mako==1.3.10",
"markdown-it-py==3.0.0",
"MarkupSafe==3.0.2",
"mdurl==0.1.2",
"Naked==0.1.32",
"passlib==1.7.4",
"psycopg2-binary==2.9.10",
"pyasn1==0.4.8",
"pycryptodome==3.22.0",
"pydantic==2.11.4",
"pydantic_core==2.33.2",
"Pygments==2.19.1",
"python-dotenv==1.1.0",
"python-jose==3.4.0",
"python-multipart==0.0.20",
"PyYAML==6.0.2",
"requests==2.32.3",
"rich==14.0.0",
"rich-toolkit==0.14.1",
"rsa==4.9",
"shellescape==3.8.1",
"shellingham==1.5.4",
"six==1.17.0",
"sniffio==1.3.1",
"SQLAlchemy==2.0.40",
"sqlmodel==0.0.24",
"starlette==0.46.1",
"typer==0.15.2",
"typing-inspection==0.4.0",
"typing_extensions==4.13.2",
"urllib3==2.4.0",
"uvicorn==0.34.0",
"uvloop==0.21.0",
"watchfiles==1.0.5",
"websockets==15.0.1",
"Deprecated==1.2.18",
"limits==5.1.0",
"slowapi==0.1.9",
"wrapt==1.17.2",
"redis==6.1.0",
"apscheduler==3.11.0",
"tzlocal==5.3.1",
"amqp==5.3.1",
"billiard==4.2.1",
"celery==5.5.3",
"click-didyoumean==0.3.1",
"click-plugins==1.1.1",
"click-repl==0.3.0",
"kombu==5.5.4",
"prompt-toolkit==3.0.51",
"python-dateutil==2.9.0.post0",
"tzdata==2025.2",
"vine==5.1.0",
"wcwidth==0.2.13",
"structlog==26.1.0",
]

[dependency-groups]

dev = [
"pytest==8.3.5",
"pytest-asyncio==0.26.0",
"pytest-cov==6.1.1",
"pytest-mock==3.14.0",
"pytest-xdist==3.6.1",
"pluggy==1.5.0",
"coverage==7.8.0",
"iniconfig==2.1.0",
"packaging==24.2",
"execnet==2.1.1",
"psutil==7.0.0",
"cffi==1.17.1",
"pycparser==2.22",
"cryptography==44.0.2",
"asyncpg==0.30.0",
"asgi-lifespan==2.1.0",
]
6 changes: 3 additions & 3 deletions src/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# set -e # <- 🔒 Termina el script si ocurre un error

# Activar entorno virtual
source env/bin/activate || echo "No se pudo activar el entorno virtual, probablemente en CI"
source .venv/bin/activate || echo "No se pudo activar el entorno virtual, probablemente en CI"

echo "🚀 Iniciando tests..."

echo "📦 Levantando contenedores de Redis"
docker start redis-stack
docker compose up -d redis

echo "🔍 Ejecutando Pytest"
pytest -q --disable-warnings

echo "✅ Test finalizados correctamente"

echo "🛑 Deteniendo contenedores"
docker stop redis-stack
docker compose stop redis

echo "🧹 Eliminando cachés de tests"
# find . -type d -name "__pycache__" -exec rm -r {} + && rm -rf .pytest_cache
13 changes: 6 additions & 7 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ def test_db():
print(f"Error al eliminar test.db: {e}")
raise


@pytest.fixture(scope="session")
def redis_host():
return os.getenv("REDIS_HOST", "localhost")


# Fixture para tests asíncronos
@pytest_asyncio.fixture(scope="function")
async def async_redis_client():
client = await redis.Redis(host="localhost", port=6379, db=0)
host = os.getenv("REDIS_HOST")
port = os.getenv("REDIS_PORT")
db = os.getenv("REDIS_DB")

client = await redis.Redis(host=host, port=port, db=db)

yield client

await client.flushdb()
Expand Down
Loading
Loading