Stack knowledge
Skill zachjxyz/jvn/stacks/python/.claude/skills/stack-knowledge
Project technology stack patterns for FastAPI + PostgreSQL + SQLAlchemy + Alembic + PyTorch + pandasFrom its SKILL.md
npx -y skills add zachjxyz/jvn --skill stack-knowledgeAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
3 things to look at
- reads credentialsReads from 1 credential source: `DATABASE_URL`.
- 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
- runs commandsInstructs the agent to run 1 command, including `alembic revision --autogenerate -m "description"`.
SKILL.md
3.9 KB, 879 tokens by cl100k_base, as published. Nobody here has run it
Stack Knowledge
This skill provides stack-specific patterns for agents making architectural and implementation decisions.
FastAPI
- Async route handlers by default — use
async deffor all endpoints - Dependency injection with
Depends()for database sessions, auth, shared logic - Pydantic V2 models for all request/response schemas — never return raw dicts
- Use
lifespancontext manager for startup/shutdown (DB connections, ML model loading) - Router organization:
src/api/routes/with one router per domain - Error handling:
HTTPExceptionfor expected errors, exception handlers for unexpected - Consistent error shape:
{ "error": str, "message": str, "details": dict } - Background tasks with
BackgroundTasksfor non-blocking operations
PostgreSQL + SQLAlchemy
- SQLAlchemy 2.0 style — use
select(),insert(),update(),delete()statements - Async engine with
create_async_engine()andasync_sessionmaker() - Connection string via
DATABASE_URLenv var - Models in
src/models/with one file per entity - Use
mapped_column()with explicit types — no implicit column inference - Index every column used in WHERE, JOIN, or ORDER BY
- Relationship loading: use
selectinload()for collections,joinedload()for single relations - Session management: request-scoped sessions via
Depends(get_db)
Alembic Migrations
- Config in
alembic.ini, env inalembic/env.py - Development:
alembic revision --autogenerate -m "description" - Production: manually reviewed migrations, never autogenerate blindly
- Always test migrations both up and down (rollback)
- One migration per logical change — don't batch unrelated schema changes
PyTorch / ML
- Models in
src/models/ml/— separate from SQLAlchemy ORM models - Training scripts in
src/training/ - Inference endpoints load models at startup via lifespan, not per-request
- Reproducibility: set seeds (
torch.manual_seed,numpy.random.seed), log hyperparameters - Model versioning: save checkpoints with metadata (epoch, metrics, config)
- Data pipelines in
src/pipelines/— pandas for ETL, torch DataLoaders for training
pandas / Data Processing
- Use
pandasfor data loading, cleaning, transformation - Prefer vectorized operations over iterrows — never loop over DataFrame rows
- Type hints with
pd.DataFrameand column schemas documented - For large datasets: chunked reading with
chunksize, or usepolarsfor performance-critical paths - CSV/Parquet I/O: explicit dtypes on read, compression on write
Testing (pytest)
- Test structure mirrors source:
tests/api/,tests/models/,tests/pipelines/ - Use
httpx.AsyncClientwithASGITransportfor API tests - Fixtures in
conftest.pyfor database sessions, test client, sample data - Use
pytest-asynciofor async test support - Factory fixtures for test data — never hard-code test objects across files
- ML tests: test model forward pass shapes, loss convergence on tiny datasets
Project Structure
src/
├── api/
│ ├── routes/ # FastAPI routers (one per domain)
│ ├── deps.py # Shared dependencies (get_db, get_current_user)
│ └── middleware.py # CORS, auth, logging middleware
├── models/
│ ├── db/ # SQLAlchemy ORM models
│ └── ml/ # PyTorch model definitions
├── schemas/ # Pydantic request/response schemas
├── pipelines/ # Data processing pipelines
├── training/ # ML training scripts
├── services/ # Business logic layer
├── config.py # Settings via pydantic-settings
└── main.py # FastAPI app factory
alembic/ # Database migrations
tests/ # Mirror of src/ structure
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.