Initial setup of frontend and backend
This commit is contained in:
42
backend/.dockerignore
Normal file
42
backend/.dockerignore
Normal file
@@ -0,0 +1,42 @@
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.so
|
||||
.Python
|
||||
build/
|
||||
dist/
|
||||
*.egg-info/
|
||||
*.egg
|
||||
|
||||
# Virtual environments
|
||||
.venv/
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# Environment files
|
||||
.env
|
||||
.env.local
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# Testing
|
||||
.pytest_cache/
|
||||
.coverage
|
||||
htmlcov/
|
||||
|
||||
# Database
|
||||
*.db
|
||||
*.sqlite3
|
||||
|
||||
# Git
|
||||
.git/
|
||||
.gitignore
|
||||
|
||||
# Docker
|
||||
Dockerfile
|
||||
docker-compose*.yml
|
||||
9
backend/.env.example
Normal file
9
backend/.env.example
Normal file
@@ -0,0 +1,9 @@
|
||||
# Application settings
|
||||
APP_NAME="Nuzlocke Tracker API"
|
||||
DEBUG=true
|
||||
|
||||
# API settings
|
||||
API_V1_PREFIX="/api/v1"
|
||||
|
||||
# Database settings
|
||||
DATABASE_URL="sqlite:///./nuzlocke.db"
|
||||
48
backend/.gitignore
vendored
Normal file
48
backend/.gitignore
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.so
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# Virtual environments
|
||||
.venv/
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# Environment files
|
||||
.env
|
||||
.env.local
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# Testing
|
||||
.pytest_cache/
|
||||
.coverage
|
||||
htmlcov/
|
||||
|
||||
# Database
|
||||
*.db
|
||||
*.sqlite3
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
21
backend/Dockerfile
Normal file
21
backend/Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
||||
# Development Dockerfile for the backend API
|
||||
FROM python:3.14-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install system dependencies
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Python dependencies
|
||||
COPY pyproject.toml README.md ./
|
||||
COPY src/ ./src/
|
||||
|
||||
RUN pip install --no-cache-dir -e .
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8000
|
||||
|
||||
# Run with hot reload for development
|
||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload", "--app-dir", "src"]
|
||||
68
backend/README.md
Normal file
68
backend/README.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# Nuzlocke Tracker API
|
||||
|
||||
Backend API for the Nuzlocke Tracker application, built with FastAPI.
|
||||
|
||||
## Development Setup
|
||||
|
||||
### Option 1: Docker (Recommended)
|
||||
|
||||
From the project root:
|
||||
```bash
|
||||
docker compose up
|
||||
```
|
||||
|
||||
This starts the API, frontend, and PostgreSQL database with hot reload enabled.
|
||||
|
||||
### Option 2: Local Setup
|
||||
|
||||
1. Create and activate virtual environment:
|
||||
```bash
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
||||
```
|
||||
|
||||
2. Install dependencies:
|
||||
```bash
|
||||
pip install -e ".[dev]"
|
||||
```
|
||||
|
||||
3. Copy environment file:
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
4. Run the development server:
|
||||
```bash
|
||||
uvicorn app.main:app --reload --app-dir src
|
||||
```
|
||||
|
||||
The API will be available at http://localhost:8000
|
||||
|
||||
## API Documentation
|
||||
|
||||
- Swagger UI: http://localhost:8000/docs
|
||||
- ReDoc: http://localhost:8000/redoc
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
backend/
|
||||
├── src/
|
||||
│ └── app/
|
||||
│ ├── api/ # API routes
|
||||
│ ├── core/ # Core configuration
|
||||
│ ├── models/ # Database models
|
||||
│ ├── schemas/ # Pydantic schemas
|
||||
│ └── services/ # Business logic
|
||||
├── tests/ # Test files
|
||||
├── pyproject.toml # Project configuration
|
||||
└── .env.example # Example environment variables
|
||||
```
|
||||
|
||||
## Linting & Formatting
|
||||
|
||||
```bash
|
||||
ruff check . # Check for issues
|
||||
ruff check . --fix # Fix auto-fixable issues
|
||||
ruff format . # Format code
|
||||
```
|
||||
54
backend/pyproject.toml
Normal file
54
backend/pyproject.toml
Normal file
@@ -0,0 +1,54 @@
|
||||
[project]
|
||||
name = "nuzlocke-tracker-api"
|
||||
version = "0.1.0"
|
||||
description = "Backend API for Nuzlocke Tracker"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
dependencies = [
|
||||
"fastapi>=0.115.0",
|
||||
"uvicorn[standard]>=0.34.0",
|
||||
"pydantic>=2.10.0",
|
||||
"pydantic-settings>=2.7.0",
|
||||
"python-dotenv>=1.0.0",
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = [
|
||||
"ruff>=0.9.0",
|
||||
"pytest>=8.0.0",
|
||||
"pytest-asyncio>=0.25.0",
|
||||
"httpx>=0.28.0",
|
||||
]
|
||||
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["src/app"]
|
||||
|
||||
[tool.ruff]
|
||||
target-version = "py312"
|
||||
line-length = 88
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = [
|
||||
"E", # pycodestyle errors
|
||||
"W", # pycodestyle warnings
|
||||
"F", # Pyflakes
|
||||
"I", # isort
|
||||
"B", # flake8-bugbear
|
||||
"C4", # flake8-comprehensions
|
||||
"UP", # pyupgrade
|
||||
"SIM", # flake8-simplify
|
||||
]
|
||||
ignore = [
|
||||
"E501", # line too long (handled by formatter)
|
||||
]
|
||||
|
||||
[tool.ruff.lint.isort]
|
||||
known-first-party = ["app"]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
asyncio_mode = "auto"
|
||||
testpaths = ["tests"]
|
||||
0
backend/src/app/__init__.py
Normal file
0
backend/src/app/__init__.py
Normal file
0
backend/src/app/api/__init__.py
Normal file
0
backend/src/app/api/__init__.py
Normal file
15
backend/src/app/api/health.py
Normal file
15
backend/src/app/api/health.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(tags=["health"])
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def health_check():
|
||||
"""Health check endpoint."""
|
||||
return {"status": "healthy"}
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def root():
|
||||
"""Root endpoint."""
|
||||
return {"message": "Nuzlocke Tracker API", "docs": "/docs"}
|
||||
6
backend/src/app/api/routes.py
Normal file
6
backend/src/app/api/routes.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.api import health
|
||||
|
||||
api_router = APIRouter()
|
||||
api_router.include_router(health.router)
|
||||
0
backend/src/app/core/__init__.py
Normal file
0
backend/src/app/core/__init__.py
Normal file
21
backend/src/app/core/config.py
Normal file
21
backend/src/app/core/config.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
app_name: str = "Nuzlocke Tracker API"
|
||||
debug: bool = False
|
||||
|
||||
# API settings
|
||||
api_v1_prefix: str = "/api/v1"
|
||||
|
||||
# Database settings (for future use)
|
||||
database_url: str = "sqlite:///./nuzlocke.db"
|
||||
|
||||
|
||||
settings = Settings()
|
||||
25
backend/src/app/main.py
Normal file
25
backend/src/app/main.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.api.routes import api_router
|
||||
from app.core.config import settings
|
||||
|
||||
app = FastAPI(
|
||||
title=settings.app_name,
|
||||
openapi_url=f"{settings.api_v1_prefix}/openapi.json",
|
||||
docs_url="/docs",
|
||||
redoc_url="/redoc",
|
||||
)
|
||||
|
||||
# Configure CORS
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["http://localhost:5173", "http://localhost:3000"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Include routers
|
||||
app.include_router(api_router)
|
||||
app.include_router(api_router, prefix=settings.api_v1_prefix)
|
||||
0
backend/src/app/models/__init__.py
Normal file
0
backend/src/app/models/__init__.py
Normal file
0
backend/src/app/schemas/__init__.py
Normal file
0
backend/src/app/schemas/__init__.py
Normal file
0
backend/src/app/services/__init__.py
Normal file
0
backend/src/app/services/__init__.py
Normal file
0
backend/tests/__init__.py
Normal file
0
backend/tests/__init__.py
Normal file
Reference in New Issue
Block a user