- Home
- Courses
- Backend Development with FastAPI
- Data Layer and Auth
Micro Free Course — 100% Free Learning
All lessons in this module are free to learn. Sign in with Google to save your progress.
Data Layer and Auth
SQLAlchemy 2.0 ORM (modern Mapped style); Alembic migrations; Pydantic vs SQLAlchemy models (separation); JWT authentication and OAuth2; role-based authorization patterns.
Module Content
SQLAlchemy 2.0 ORM
The modern SQLAlchemy: typed Mapped columns, declarative style, async support. The standard Python ORM. FIND_VIDEO: search 'sqlalchemy 2.0 tutorial mapped' — recommended channel: ArjanCodes / Mike Bayer talks. Aim for 11 min or under.
Recap — Mapped Columns, Sessions, Query Patterns
SQLAlchemy 2.0's modern style: Mapped types, sessions, select() syntax, common query patterns.
Database Migrations with Alembic
Schema changes as code. Alembic generates migration scripts; running them migrates production safely. FIND_VIDEO: search 'alembic database migrations fastapi tutorial' — recommended channel: ArjanCodes / Pretty Printed. Aim for 10 min or under.
Recap — Manual vs Autogenerate, Migration Patterns
When to autogenerate, when to write by hand, and the patterns for safe schema changes in production.
Pydantic vs SQLAlchemy Models
Why your DB models and your API models should be different types — and how to convert cleanly. FIND_VIDEO: search 'pydantic sqlalchemy separation api models' — recommended channel: ArjanCodes. Aim for 9 min or under.
Recap — Separation of Concerns and Response Shaping
The 'one model per layer' pattern, ORM-to-Pydantic conversion, and avoiding data leaks.
Authentication — JWT & OAuth2
The standard auth pattern: hash passwords, issue JWTs, OAuth2 flow. The auth layer of any modern API. FIND_VIDEO: search 'fastapi jwt authentication oauth2 tutorial' — recommended channel: ArjanCodes / Tech with Tim. Aim for 11 min or under.
Recap — Token-Based Auth Flow
The end-to-end JWT auth: signup, login, hash passwords with bcrypt, issue tokens, validate via dependency.
Authorization — Roles & Permissions
Authentication says who; authorization says what. Roles, permissions, scopes, and the dependency patterns. FIND_VIDEO: search 'fastapi role based access control RBAC' — recommended channel: ArjanCodes. Aim for 10 min or under.
Recap — RBAC Patterns and Scopes
Role-based and permission-based access control in FastAPI, OAuth2 scopes, and the practical patterns for production.