# Newzy - News Web Application A modern news web application built with FastAPI backend and a responsive frontend. ## Overview Newzy is a news platform that allows users to browse, read, and subscribe to news articles organized by categories and authors. ## Project Structure ``` newzy/ ├── data/ # Local SQLite data directory │ └── db/ │ └── newzy.db # Persisted database (excluded from git) ├── backend/ # FastAPI backend API │ ├── api/ # API versioning │ ├── core/ # Core functionality │ ├── db/ # Database layer │ ├── models/ # SQLAlchemy models │ ├── schemas/ # Pydantic schemas │ ├── tests/ # Unit tests │ └── main.py # Application entry point ├── frontend/ # Frontend application (Vite + React) ├── docker-compose.yml # Docker Compose configuration ├── .env # Environment variables (do not commit) ├── .env.example # Template for environment variables ├── Makefile # Development shortcuts ├── README.md # This file └── CONTRIBUTING.md # Contribution guidelines ``` ## Quick Start ### Prerequisites - **Docker** (version 20.10+) - **Docker Compose** (v2.0+) - **Node.js** 18+ (for local development) - **npm** or **yarn** ### Docker Development Setup ```bash # Start all services make dev # or docker compose up -d --build # Access the application # Frontend: http://localhost:3000 # Backend: http://localhost:8000 # Stop all services make stop # or docker compose down # View logs make logs # or docker compose logs -f backend frontend # Restart services make restart ``` ### Local Development (without Docker) ```bash # Install backend dependencies cd backend python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -r requirements.txt # Run the application uvicorn main:app --reload # Install frontend dependencies (in new terminal) cd frontend npm install # Run the frontend npm run dev ``` ## Docker Services Overview | Service | Description | Default Port | |----------|----------------------------------|--------------| | backend | FastAPI API server | 8000 | | frontend | Vite + React application (nginx) | 3000 | ### Port Mappings - **Frontend**: Host port `3000` → Container port `80` - **Backend**: Host port `8000` → Container port `8000` ### Network Configuration Services communicate via an internal Docker bridge network: - Network driver: `bridge` - Subnet: `172.28.0.0/16` ### Volume Persistence - SQLite database is persisted in volume mounted at `/data/db/newzy.db` - Database files are excluded from version control via `.gitignore` ## Environment Variables | Variable | Description | Default | Required | |-----------------------|--------------------------------------------|------------------------------------------|----------| | `DATABASE_URL` | SQLite database path | `sqlite:///./data/db/newzy.db` | Yes | | `DEBUG` | Debug mode flag | `false` | No | | `BACKEND_CORS_ORIGINS`| Allowed frontend CORS origins | `http://localhost:3000,http://localhost:5173` | No | | `FRONTEND_API_URL` | Backend API base URL for frontend | `/api` | No | To use custom environment variables: ```bash cp .env.example .env # Edit .env with your configuration docker compose up -d --build ``` ## Development Commands (Makefile) | Command | Description | |-----------------|--------------------------------------------------| | `dev` | Start all services in background | | `stop` | Stop all containers | | `restart` | Stop and restart services with rebuild | | `backend-start` | Start only the backend service | | `frontend-start`| Start only the frontend service | | `test` | Run all tests (frontend + backend) | | `clean` | Remove containers, volumes, and cached images | | `build` | Rebuild images with no cache | | `logs` | View logs for all services | | `shell-backend` | Open bash shell in backend container | | `shell-frontend`| Open shell in frontend container | ## Troubleshooting ### Container won't start ```bash # Check logs docker compose logs backend docker compose logs frontend # Rebuild with fresh cache docker compose down docker compose build --no-cache docker compose up -d ``` ### Port already in use ```bash # Find what's using port 3000 or 8000 lsof -i :3000 # or :8000 # Change port in docker-compose.yml if needed ``` ### Database corruption ```bash # Remove data volume and restart docker compose down -v docker compose up -d --build ``` ### Services not communicating ```bash # Ensure both services are running docker compose ps # Check network connectivity from backend to frontend docker compose exec backend curl http://frontend:3000/health ``` ## API Endpoints - `GET /health` - Health check - `GET /api/v1/version` - Version information More endpoints will be added in subsequent milestones. ## Security Notes - Never commit `.env` files to version control - Environment variables are loaded from `.env.example` template - SQLite database stored locally, not in container (volume mounted) - CORS configured with specific frontend origins only ## Performance Tips - Use `make dev` for hot-reload enabled backend (requires separate volume mount) - Avoid `--build` on subsequent runs to leverage Docker cache - For production, consider PostgreSQL instead of SQLite ## License MIT License - See LICENSE file for details.