b186d0f79780489dd1bfb57bbe81860452bd8573
Backend (FastAPI): - core/auth.py: PBKDF2-HMAC-SHA256 password hashing (120k iterations, random salt), HS256 JWT creation/verification (7-day expiry, HN_SECRET_KEY via config) and get_current_user Bearer dependency - models/user.py: User model (username unique/indexed, password_hash, created_at); schemas/auth.py: register/login/token/user schemas - api/v1/auth.py: POST /api/v1/auth/register (201), /login, /logout (204), GET /me; 400 on duplicate username, 401 on bad credentials, invalid/expired/unknown tokens - requirements: PyJWT; env templates + docker-compose expose HN_SECRET_KEY (dev default, override in production) - tests: 24 new backend tests (hashing, tokens, all endpoints) Frontend (React + TypeScript): - api/client.ts: AUTH_TOKEN localStorage persistence, automatic Bearer token attachment, 401 clears the stored token, typed login/register/logout/me helpers - auth.tsx: AuthProvider (session restore + login/register/logout) and RequireAuth route guard - pages: Login, Register, SignOut and a protected /account placeholder; header shows sign-in/register or user/sign-out - styles: auth component classes in globals.css - tests: unit tests for the client, provider and pages; Playwright E2E spec covering register/login/logout, session restore, invalid token cleanup and protected-route redirects (API mocked) Note: the milestone's /api/auth/* paths map to the project's established /api/v1/* prefix (see M2); the HN_SECRET_KEY default is newzy-dev-secret-change-me.
newzy
A news web application.
newzy is a news web application for discovering, reading, and managing news content. This repository is currently in its initial setup stage — application functionality will be implemented in upcoming milestones.
Project Status
| Milestone | Description | Status |
|---|---|---|
| M1 | Git project setup | Done |
| M2 | Backend setup (FastAPI) | Done |
| M3 | Frontend setup (React + Vite) | Done |
| M4 | Developer environment (Docker) | Done |
| M5+ | News application features | Planned |
See milestones/ for milestone prompts and progress tracking.
Requirements
- Backend (
backend/): Python 3.11+, FastAPI (see backend/README.md) - Frontend (
frontend/): Node.js 18+ (see frontend/README.md) - Docker (optional): for the containerized setup via the root
docker-compose.yml
Getting Started
# 1. Clone the repository
git clone https://gitea.samson.media/daniel/newz-qwen-27b.git newzy
cd newzy
# 2. Check out the integration branch
git checkout develop
# 3. Create your feature branch
git checkout -b feature/<short-description>
# 4. Commit your changes (Conventional Commits)
git add .
git commit -m "feat: add <description>"
# 5. Push and open a pull request
git push -u origin feature/<short-description>
Full contribution guidelines, including branching, merging, and rebase workflows, are in CONTRIBUTING.md.
Developer environment (Docker Compose)
The repository root ships a complete Docker Compose setup: one command starts the FastAPI backend and the Nginx-served production frontend, with a persistent SQLite database on the host.
Prerequisites
- Docker (Docker Desktop or the docker engine + compose plugin v2), with the daemon running
- Optional (only for
make testoutside Docker): Node.js 18+ and Python 3.11+
Quick start
# 1. Configure the environment (defaults are fine for local development)
cp .env.example .env
# 2. Build (if needed) and start both services in the background
make dev
# 3. Open the application
# Frontend: http://localhost:3000
# Backend: http://localhost:8000 (Swagger docs: http://localhost:8000/api/v1/docs)
# 4. Stop everything (the database in ./data is kept)
make stop
Services
| Service | Build context | Image base | What it does |
|---|---|---|---|
backend |
./backend |
python:3.11-slim |
FastAPI app (uvicorn), creates the SQLite schema on startup |
frontend |
./frontend |
node:20-alpine → nginx:1.27-alpine (multi-stage) |
Builds the Vite bundle, serves it via Nginx with SPA routing and an /api proxy to the backend |
Port mappings
| Host port | Container | Service |
|---|---|---|
3000 |
80 |
frontend (Nginx) |
8000 |
8000 |
backend (uvicorn) |
Networking and storage
- Both services share the bridge network
newzy-network(subnet172.28.0.0/16), so the frontend reaches the backend by service name (http://backend:8000). - The SQLite database is stored on the host at
data/db/newzy.dbvia a bind mount (./data/db→/app/data/db). It is excluded from version control (seedata/.gitignore) and survivesmake stop/make restart. frontendonly starts oncebackendreports healthy (/health), sodocker compose upnever serves a frontend with a dead API.
Environment variables
docker compose reads .env from the project root (template:
.env.example). Never commit .env or real secrets.
| Variable | Description | Default | Required |
|---|---|---|---|
DATABASE_URL |
SQLite database path (SQLAlchemy URL) | sqlite:///./data/db/newzy.db |
Yes |
DEBUG |
Debug mode flag | false |
No |
BACKEND_CORS_ORIGINS |
Comma-separated allowed CORS origins | http://localhost:3000,http://localhost:5173 |
No |
FRONTEND_API_URL |
Backend API base URL (relative or absolute) | /api |
No |
Makefile shortcuts
| Command | What it does |
|---|---|
make dev |
Build (if needed) and start both services in the background |
make stop |
Stop and remove containers (data kept) |
make restart |
Recreate and start both services |
make build |
Rebuild all images from scratch |
make logs |
Follow logs of both services |
make status |
Show service status |
make backend-start |
Start the backend only |
make frontend-start |
Start the frontend only |
make test |
Run all unit tests (frontend vitest + backend pytest) |
make e2e |
Run Playwright E2E tests (API calls mocked) |
make shell-backend |
Open a shell in the backend container |
make shell-frontend |
Open a shell in the frontend container |
make clean |
Stop everything, remove containers, volumes and data/ |
Troubleshooting
- Port already in use (
bind: address already in use): stop the other process (lsof -i :3000/lsof -i :8000) or change the host port indocker-compose.yml(e.g."3001:80"). - Frontend starts but shows errors / 502 on API calls: the backend is not
healthy yet — check
make logs backend. The frontend waits for the backend health check on startup; after a slow start, reload the page. docker composenot found: install the Compose v2 plugin (docker compose versionmust print a version).- Database reset:
make cleanremovesdata/(including the SQLite file); tables are recreated on the next backend start. - Slow builds on first run: the first
make devpulls the base images and installs dependencies (~5 minutes). Subsequent builds use the Docker layer cache and finish in seconds. - Ownership issues in
data/(e.g. after running Docker as root): restore withsudo chown -R $(id -un):$(id -gn) data/. - Windows: use WSL2 for best performance; macOS: allow Docker Desktop sufficient disk space (50 GB+ recommended).
Running without Docker
- Frontend:
frontend/README.md—npm run dev(port 5173, proxies/apito :8000) - Backend:
backend/README.md—uvicorn main:app --reload(port 8000)
Documentation
- CONTRIBUTING.md — how to contribute
- docs/branching.md — branch strategy, merge and rebase workflows
- docs/conventions.md — file structure and naming conventions
- docs/commits.md — commit message format and examples
License
MIT © 2026 Daniel Samson
Languages
TypeScript
64.8%
Python
31%
CSS
2.6%
Makefile
0.6%
Dockerfile
0.5%
Other
0.5%