Basic Building Monolith API with FastAPI Syllabus
1. Header Information
| Field | Value |
|---|---|
| Technical Group | AI Engineering |
| Topic Name | Basic Building Monolith API with FastAPI |
| Topic Code | |
| Version | 1.0 |
| Training Audience | Freshers with basic Python programming knowledge who have completed the AI Fundamentals, LangChain / LangGraph workflow |
2. Course Objectives
This topic introduces the foundational concepts required to build modern, high-performance web APIs using Python and FastAPI. Trainees will start with operating system fundamentals and asynchronous programming, then deep-dive into FastAPI's core mechanics including Pydantic data modeling, asynchronous database integration with SQLAlchemy and Alembic, Dependency Injection, and security implementations (JWT/OAuth2 and RBAC). The course culminates in building a complete, authenticated Monolith API.
[!NOTE] This topic equips trainees with the necessary skills to design, build, and secure modern backend applications utilizing the full power of FastAPI, asynchronous I/O, and structured data validation.
Output Standards table
| Name | Code | Description |
|---|---|---|
| Foundations | Understand OS fundamentals (File Descriptors, Sockets), Web concepts (REST, HTTP), and Python Concurrency (asyncio vs Threads vs Processes). | |
| FastAPI Core | Master FastAPI routing, parameter extraction (Path, Query, Body), and data validation using Pydantic schemas. | |
| Database | Implement asynchronous database operations using SQLAlchemy ORM, manage sessions with Dependency Injection, and handle schema migrations with Alembic. | |
| Security | Secure APIs by implementing OAuth2 Password Flow, issuing/verifying JSON Web Tokens (JWT), and applying Role-Based Access Control (RBAC). | |
| Testing | Develop resilient applications by writing asynchronous tests with Pytest and TestClient, mocking databases, and leveraging custom Middleware. |
Detailed Learning Outcomes (LOs)
-
OS, Web & Concurrency Foundations
LO-1- Explain File Descriptors, Socket Programming, and the Event Loop architecture.LO-2- Distinguish between Threading, Multiprocessing, and asyncio in Python to optimize I/O-bound vs CPU-bound tasks.LO-3- Define core web concepts including HTTP methods, status codes, and the principles of REST Architecture.
-
FastAPI Fundamentals & Pydantic
LO-4- Set up a FastAPI application and utilize Uvicorn as an ASGI server.LO-5- Extract and validate Path, Query, Body, Header, and Cookie parameters.LO-6- Define structured JSON payloads and response models using PydanticBaseModelandFieldvalidators.
-
Asynchronous Databases & ORM
LO-7- Connect FastAPI to PostgreSQL asynchronously usingasyncpgand SQLAlchemy 2.0.LO-8- Define SQLAlchemy ORM models using Declarative Base and configure async engine/session for non-blocking database queries.LO-9- Manage incremental database schema changes using Alembic migrations.
-
Dependency Injection & Architecture
LO-10- Utilize dependency injection withDepends()to share logic, inject sessions, and enforce state.LO-11- Implement the Repository Pattern to decouple database CRUD operations from routing logic.
-
Authentication & Authorization
LO-12- Secure passwords using hashing libraries (e.g., bcrypt via Passlib).LO-13- Implement the OAuth2 Password Bearer flow and issue JWTs (HS256/RS256).LO-14- Enforce Role-Based Access Control (RBAC) to differentiate admin and regular user endpoints.LO-15- Configure Cross-Origin Resource Sharing (CORS) for external frontend integration.
-
Testing & Middleware
LO-16- Write unit and integration tests usingpytestandhttpx.AsyncClient.LO-17- Mock dependencies, specifically injecting an in-memory SQLite database for test isolation.LO-18- Build custom ASGI Middleware (e.g., request logging, timing) and global Exception Handlers.
3. Topic Outline
- Unit 01: OS Fundamentals, Concurrency, & Web Concepts
- Unit 02: FastAPI Foundations & Data Modeling with Pydantic
- Unit 03: Async Database Setup & SQLAlchemy ORM
- Unit 04: Dependency Injection & CRUD Repository Pattern
- Unit 05: Authentication (JWT, OAuth2) & Authorization (RBAC, CORS)
- Unit 06: Testing (Pytest, Mocking) & Middleware
4. Time Allocation
| Activity Type | Percentage | Description |
|---|---|---|
| Concept/Lecture | 40% | Concepts, theory (AsyncIO, ORM, Auth flows) |
| Assignment/Lab | 40% | Hands-on Labs (Building APIs, DB connections) |
| Guides/Review | 10% | Code reviews, architecture discussions |
| Test/Quiz/Exam | 10% | Daily Quizzes, Final Project |
5. Training Materials & Environments
Textbooks & Guides
- Internal Knowledge Base:
- Introduction to Operating Systems (01-foundation-and-inputs)
- Data Modeling with Pydantic (02-data-modeling-pydantic)
- Database Setup & ORM (03-database-setup)
- CRUD & Dependency Injection (04-crud-and-dependency-injection)
- Authentication JWT (05-authentication)
- Authorization & RBAC (06-authorization)
- Testing & Middleware (07-testing-and-middleware)
References
Technical Requirements
- Python 3.9+
- Docker & Docker Compose (for PostgreSQL setup)
- IDE: VS Code / PyCharm
- Testing tool: Postman / Insomnia / cURL
- Packages:
fastapi,uvicorn,sqlalchemy,asyncpg,alembic,pydantic,pyjwt,passlib,pytest,httpx
6. Assessment Scheme
| Component | Quantity | Weight (%) | Note |
|---|---|---|---|
| Quiz | ? | ?% | Daily quizzes after each unit |
| Assignments | ? | ?% | Lab exercises (Endpoints, DB setup, Auth) |
| Final Project | ? | ?% | Build a fully authenticated Monolith API |
Pass Criteria
- Total topic GPA >= 60/100
- Completed 100% of Quizzes and Assignments
- Successful demo of the Final Monolith API Project
7. Training Delivery Principles
| Role | Responsibility/Criteria |
|---|---|
| Trainees | Completion of basic Python syntax. Active participation in labs. |
| Trainer | Senior Backend/Python Engineer with async FastAPI experience. |
| Training | Daily theory sessions followed by practical coding labs. |
| Re-Test | Allowed once for the Final Project if GPA < 60 but >= 50. |
| Marking | Code structure (Repository Pattern), Security, and Test coverage. |