|
| 1 | +[](https://github.com/GraphiteTuff/incident-tracker-api/actions/workflows/ci.yml) |
| 2 | + |
| 3 | +# Incident Tracker API |
| 4 | + |
| 5 | +A production-style **FastAPI** service for creating and managing operational incidents, backed by **PostgreSQL** with **Alembic migrations**, **Docker Compose** local dev, and **GitHub Actions CI**. |
| 6 | + |
| 7 | +This project is built to demonstrate real-world backend patterns recruiters look for: clean layering (routes/services/db), config management, migrations, testing, and containerized development. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Highlights |
| 12 | +- ✅ CRUD API for incidents with **severity/status** fields |
| 13 | +- ✅ **OpenAPI / Swagger UI** at `/docs` |
| 14 | +- ✅ PostgreSQL persistence + **Alembic** migrations |
| 15 | +- ✅ Docker Compose (API + DB) |
| 16 | +- ✅ Pytest tests + CI passing on GitHub Actions |
| 17 | +- ✅ CI defaults to SQLite so tests run without provisioning Postgres |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Tech Stack |
| 22 | +- **Python 3.11**, FastAPI |
| 23 | +- SQLAlchemy 2.x |
| 24 | +- PostgreSQL 16 |
| 25 | +- Alembic (schema migrations) |
| 26 | +- Docker / Docker Compose |
| 27 | +- Pytest + GitHub Actions |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Project Structure |
| 32 | +```text |
| 33 | +├─ app/ |
| 34 | +│ ├─ api/routes/ # HTTP endpoints (routers) |
| 35 | +│ ├─ services/ # business logic layer |
| 36 | +│ ├─ schemas/ # request/response validation (Pydantic) |
| 37 | +│ ├─ db/ # SQLAlchemy engine/session/models |
| 38 | +│ ├─ core/ # settings/config |
| 39 | +│ └─ main.py # FastAPI app entrypoint |
| 40 | +├─ alembic/ # migrations |
| 41 | +├─ tests/ # pytest tests |
| 42 | +├─ docker-compose.yml |
| 43 | +├─ Dockerfile |
| 44 | +├─ requirements.txt |
| 45 | +└─ pytest.ini |
| 46 | +``` |
| 47 | +## Quickstart (Docker) |
| 48 | + |
| 49 | +### Recommended: run with Docker so Postgres is available. |
| 50 | + |
| 51 | +1) Create environment file |
| 52 | +cp .env.example .env |
| 53 | +2) Build + run the stack |
| 54 | +docker compose up --build |
| 55 | +3) Open |
| 56 | +- Health: http://localhost:8000/health |
| 57 | +- Docs: http://localhost:8000/docs |
| 58 | + |
| 59 | +## API Overview |
| 60 | +### Health |
| 61 | + |
| 62 | +- GET /health → {"status":"ok"} |
| 63 | + |
| 64 | +## Incidents |
| 65 | + |
| 66 | +- POST /incidents → create |
| 67 | +- GET /incidents → list (supports optional filters) |
| 68 | +- query params: status, severity, service |
| 69 | +- GET /incidents/{id} → fetch one |
| 70 | +- PATCH /incidents/{id} → partial update |
| 71 | +- DELETE /incidents/{id} → delete |
| 72 | + |
| 73 | +## Example Requests |
| 74 | +- Create an incident |
| 75 | + |
| 76 | +curl -X POST "http://localhost:8000/incidents" \ |
| 77 | + -H "Content-Type: application/json" \ |
| 78 | + -d '{ |
| 79 | + "title": "API timeout in checkout", |
| 80 | + "service": "checkout", |
| 81 | + "severity": "SEV2", |
| 82 | + "status": "Investigating", |
| 83 | + "summary": "Timeouts observed from 10:02 UTC. Investigating upstream dependency." |
| 84 | + }' |
| 85 | + |
| 86 | +## List incidents |
| 87 | +- curl "http://localhost:8000/incidents" |
| 88 | + |
| 89 | +## Filter incidents |
| 90 | +- curl "http://localhost:8000/incidents?severity=SEV2&status=Investigating" |
| 91 | + |
| 92 | +## Database Migrations (Alembic) |
| 93 | +- Create a migration (after changing models) |
| 94 | +- docker compose run --rm api alembic -c /app/alembic.ini revision --autogenerate -m "your message" |
| 95 | + |
| 96 | +## Apply migrations |
| 97 | +- docker compose run --rm api alembic -c /app/alembic.ini upgrade head |
| 98 | + |
| 99 | +## Tests |
| 100 | +- Run tests locally |
| 101 | +- pytest -q |
| 102 | + |
| 103 | +## Run tests in Docker |
| 104 | +- docker compose run --rm api pytest -q |
| 105 | + |
| 106 | +## CI |
| 107 | + |
| 108 | +- GitHub Actions runs tests on every push and pull request: |
| 109 | +- Workflow: .github/workflows/ci.yml |
| 110 | + |
| 111 | +## Notes / Design Decisions |
| 112 | +- Settings are environment-driven using pydantic-settings. |
| 113 | +- CI defaults DATABASE_URL to SQLite so unit tests run without provisioning Postgres. |
| 114 | +- Docker uses .env for Postgres connectivity via the db service. |
| 115 | + |
| 116 | +## Roadmap |
| 117 | + |
| 118 | +- Pagination + sorting for list endpoint |
| 119 | +- Incident updates/timeline endpoint (/incidents/{id}/updates) |
| 120 | +- Integration tests using Postgres service in CI |
| 121 | +- Authentication (API key/JWT) + structured request logging |
0 commit comments