// FastAPI Core Concepts Guide
// Author: {{AUTHOR_NAME}} ({{GITHUB_USERNAME}})

// What you can build with this ruleset:
A foundational FastAPI application with essential features:
- RESTful API endpoints
- Data validation
- Dependency injection
- Authentication
- Documentation
- Error handling
- Testing
- Deployment readiness

// Project Structure
src/
  api/
    routers/        # Route modules
    models/         # Data models
    schemas/        # Pydantic schemas
  core/             # Core functionality
    config.py       # Configuration
    security.py     # Security utilities
    database.py     # Database setup
  services/         # Business logic
  tests/            # Test suite
  utils/            # Utilities
  main.py           # Entry point

// Development Guidelines
1. Basic Concepts:
   - Define routes with decorators
   - Use path operations
   - Implement request/response models
   - Handle query parameters
   - Process request bodies
   - Return proper responses

2. Data Validation:
   - Use Pydantic models
   - Validate request data
   - Handle validation errors
   - Define response models
   - Use field constraints
   - Implement custom validators

3. Error Handling:
   - Use proper status codes
   - Implement error responses
   - Handle exceptions
   - Return error details
   - Log errors properly
   - Provide helpful messages

// Dependencies
Core:
- fastapi>=0.100.0
- pydantic>=2.0.0
- uvicorn>=0.23.0
- sqlalchemy>=2.0.0
- python-jose>=3.3.0
- passlib>=1.7.4

Optional:
- pytest>=7.4.0
- httpx>=0.24.0
- python-multipart>=0.0.6
- python-dotenv>=1.0.0

// Code Examples:

1. Basic CRUD Operations:
```python
from fastapi import FastAPI, HTTPException, Depends
from pydantic import BaseModel
from typing import List, Optional

app = FastAPI()

class Item(BaseModel):
    id: Optional[int] = None
    name: str
    description: str
    price: float

items = []

@app.post("/items/", response_model=Item)
async def create_item(item: Item):
    item.id = len(items) + 1
    items.append(item)
    return item

@app.get("/items/", response_model=List[Item])
async def read_items(skip: int = 0, limit: int = 10):
    return items[skip : skip + limit]

@app.get("/items/{item_id}", response_model=Item)
async def read_item(item_id: int):
    if item_id < 0 or item_id >= len(items):
        raise HTTPException(status_code=404, detail="Item not found")
    return items[item_id - 1]
```

2. Basic Authentication:
```python
from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
from jose import JWTError, jwt
from passlib.context import CryptContext

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")

def verify_password(plain_password: str, hashed_password: str):
    return pwd_context.verify(plain_password, hashed_password)

def get_password_hash(password: str):
    return pwd_context.hash(password)

async def get_current_user(token: str = Depends(oauth2_scheme)):
    credentials_exception = HTTPException(
        status_code=status.HTTP_401_UNAUTHORIZED,
        detail="Could not validate credentials",
        headers={"WWW-Authenticate": "Bearer"},
    )
    try:
        payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
        username: str = payload.get("sub")
        if username is None:
            raise credentials_exception
    except JWTError:
        raise credentials_exception
    return username
```

3. Basic Database Operations:
```python
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from contextlib import contextmanager

SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"
engine = create_engine(SQLALCHEMY_DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()

@contextmanager
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

class DBItem(Base):
    __tablename__ = "items"
    
    id = Column(Integer, primary_key=True, index=True)
    name = Column(String)
    description = Column(String)
    price = Column(Float)

@app.post("/db-items/", response_model=Item)
async def create_db_item(item: Item, db: Session = Depends(get_db)):
    db_item = DBItem(**item.dict())
    db.add(db_item)
    db.commit()
    db.refresh(db_item)
    return db_item
```

// Best Practices:
1. Use proper HTTP methods
2. Implement proper validation
3. Handle errors gracefully
4. Document your API
5. Use dependency injection
6. Write tests
7. Use async when needed
8. Implement proper security
9. Follow REST principles
10. Use proper response models

// Security Considerations:
1. Validate input data
2. Use proper authentication
3. Implement authorization
4. Use HTTPS
5. Hash passwords
6. Implement rate limiting
7. Use secure headers
8. Handle errors safely
9. Validate file uploads
10. Use proper session handling
