# Alexlombana9 Sre Agent Hackathon 2026 Fastapi Backend

> When to Use

- Skill: `tomevault-io/alexlombana9-sre-agent-hackathon-2026-fastapi-backend` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/alexlombana9-sre-agent-hackathon-2026-fastapi-backend`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/alexlombana9-sre-agent-hackathon-2026-fastapi-backend/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/alexlombana9-sre-agent-hackathon-2026-fastapi-backend

---


## When to Use

Load this skill when:
- Creating or modifying FastAPI endpoints in `backend/app/api/`
- Working with SQLAlchemy models or database operations
- Creating Pydantic schemas for request/response validation
- Implementing business logic services in `backend/app/services/`

## Critical Patterns

### Pattern 1: Async Endpoint with DB Session

All endpoints use async and receive the DB session via dependency injection.

```python
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.ext.asyncio import AsyncSession

from app.database import get_db
from app.schemas import IncidentDetail

router = APIRouter()

@router.get("/{incident_id}", response_model=IncidentDetail)
async def get_incident(incident_id: str, db: AsyncSession = Depends(get_db)):
    incident = await incident_service.get_incident(db, incident_id)
    if not incident:
        raise HTTPException(status_code=404, detail="Incident not found")
    return incident
```

### Pattern 2: Service Layer with AsyncSession

All database operations go through service functions, never directly in endpoints.

```python
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models import Incident

async def get_incident(db: AsyncSession, incident_id: str) -> Incident | None:
    stmt = select(Incident).where(Incident.id == incident_id)
    result = await db.execute(stmt)
    return result.scalar_one_or_none()
```

### Pattern 3: Background Tasks for Async Processing

Long-running operations (like agent triage) use FastAPI BackgroundTasks.

```python
from fastapi import BackgroundTasks

@router.post("/", status_code=201)
async def create_incident(
    data: IncidentCreate,
    background_tasks: BackgroundTasks,
    db: AsyncSession = Depends(get_db),
):
    incident = await incident_service.create_incident(db, **data.model_dump())
    background_tasks.add_task(run_triage, incident.id)
    return incident
```

## Anti-Patterns

### Don't: Sync database operations

```python
# Bad - DON'T do this
@router.get("/{id}")
def get_incident(id: str):
    with Session() as db:
        return db.query(Incident).get(id)
```

### Don't: Business logic directly in endpoints

```python
# Bad - DON'T do this
@router.post("/")
async def create(data: IncidentCreate, db: AsyncSession = Depends(get_db)):
    incident = Incident(**data.model_dump())
    db.add(incident)
    await db.commit()  # Logic should be in service layer
    return incident
```

## Quick Reference

| Task | Pattern |
|------|---------|
| Get DB session | `db: AsyncSession = Depends(get_db)` |
| Return 404 | `raise HTTPException(status_code=404, detail="...")` |
| Background task | `background_tasks.add_task(fn, *args)` |
| Multipart upload | `file: UploadFile = File(...)` |
| Query params | `status: str \| None = Query(None)` |
| Pagination | `page: int = Query(1, ge=1), per_page: int = Query(20, ge=1, le=100)` |

---
> Source: [alexlombana9/SRE-Agent-Hackathon-2026](https://github.com/alexlombana9/SRE-Agent-Hackathon-2026) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-06-15 -->

