No description
  • Python 53.3%
  • HTML 46.1%
  • Mako 0.3%
  • Dockerfile 0.3%
Find a file
spark 4fe3cc437e
All checks were successful
FastAPI Backend CI/CD / test (push) Successful in 2m17s
FastAPI Backend CI/CD / build_and_push (push) Successful in 2m23s
CI: simplify build_and_push to plain docker build/push (matches sanima/XtreamTV server flows)
2026-08-28 04:28:18 +05:30
.forgejo/workflows CI: simplify build_and_push to plain docker build/push (matches sanima/XtreamTV server flows) 2026-08-28 04:28:18 +05:30
.github/ISSUE_TEMPLATE Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
alembic Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
api Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
core Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
models Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
repositories Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
schemas Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
services Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
tests Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
utils Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
web Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
.dockerignore Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
.env.example Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
.gitignore Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
__init__.py Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
alembic.ini Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
Dockerfile Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
Dockerfile.pipeline Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
main.py Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
pyproject.toml Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
README.md Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30
uv.lock Initial commit: track-my-assets backend 2026-08-28 02:01:31 +05:30

fastapi-starter

FastAPI starter template with structured logging, per-request IDs, an asyncio background scheduler, and a demo items CRUD to build from.

Run

python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
cp .env.example .env        # then edit .env with your values
uvicorn main:app --reload --port 8000

Docs: http://127.0.0.1:8000/docs · Health: http://127.0.0.1:8000/health

Layout

├── main.py                # FastAPI app, lifespan, asyncio scheduler, middleware wiring
├── api/v1/                # versioned HTTP routes
│   └── demo.py            #   example items CRUD — replace with your resources
├── core/                  # cross-cutting concerns
│   ├── config.py          #   pydantic-settings (.env)
│   ├── logger.py          #   stdlib logger + req_id ContextVar + adapter
│   └── middleware.py      #   RequestIdMiddleware
├── agents/                # agent runtime
│   ├── base.py            #   BaseAgent ABC
│   ├── roles/             #   planner / executor / reviewer
│   ├── orchestrators/     #   chat / task flow coordination
│   ├── tools/             #   db / search / notification tools
│   └── memory/            #   vector + conversation stores
├── services/              # business logic (called by routes)
├── repositories/          # data access layer
├── models/                # pydantic request/response models
├── utils/                 # constants and helpers
└── tests/

Cross-cutting features

Request id + logging

Every request gets a req_id (X-Request-ID header value, or a generated hex UUID) stored in a ContextVar and auto-injected into every log line. Log output is plain text:

2026-05-29 12:00:00 INFO     [a3f1c9...] api.v1.demo:22 item.created

Use the logger anywhere:

from core.logger import get_logger
logger = get_logger(__name__)
logger.info("thing happened", extra={"key": "value"})

Background scheduler

A 24-hour periodic task is wired into the FastAPI lifespan via asyncio.create_task. Add your logic to scheduled_data_fetch() in main.py:

async def scheduled_data_fetch() -> None:
    pass  # TODO: add periodic task logic here

Middleware order

add_middleware adds outward, so requests hit them last-added-first:

RequestIdMiddleware  →  CORSMiddleware  →  route

Configuration

Settings are loaded from .env via pydantic-settings. Key variables:

Variable Default Description
APP_NAME fastapi-starter OpenAPI title
APP_VERSION 0.1.0 OpenAPI version
LOG_LEVEL INFO Root log level
CORS_ORIGINS ["*"] Allowed CORS origins
DATABASE_URL "" Database connection string
EXTERNAL_API_URL "" Downstream service base URL
EXTERNAL_API_KEY "" Downstream service API key