Skip to main content

Basic Building Monolith API with FastAPI Syllabus

1. Header Information

FieldValue
Technical GroupAI Engineering
Topic NameBasic Building Monolith API with FastAPI
Topic Code
Version1.0
Training AudienceFreshers 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

NameCodeDescription
FoundationsUnderstand OS fundamentals (File Descriptors, Sockets), Web concepts (REST, HTTP), and Python Concurrency (asyncio vs Threads vs Processes).
FastAPI CoreMaster FastAPI routing, parameter extraction (Path, Query, Body), and data validation using Pydantic schemas.
DatabaseImplement asynchronous database operations using SQLAlchemy ORM, manage sessions with Dependency Injection, and handle schema migrations with Alembic.
SecuritySecure APIs by implementing OAuth2 Password Flow, issuing/verifying JSON Web Tokens (JWT), and applying Role-Based Access Control (RBAC).
TestingDevelop 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 Pydantic BaseModel and Field validators.
  • Asynchronous Databases & ORM

    • LO-7 - Connect FastAPI to PostgreSQL asynchronously using asyncpg and 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 with Depends() 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 using pytest and httpx.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 TypePercentageDescription
Concept/Lecture40%Concepts, theory (AsyncIO, ORM, Auth flows)
Assignment/Lab40%Hands-on Labs (Building APIs, DB connections)
Guides/Review10%Code reviews, architecture discussions
Test/Quiz/Exam10%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

ComponentQuantityWeight (%)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

RoleResponsibility/Criteria
TraineesCompletion of basic Python syntax. Active participation in labs.
TrainerSenior Backend/Python Engineer with async FastAPI experience.
TrainingDaily theory sessions followed by practical coding labs.
Re-TestAllowed once for the Final Project if GPA < 60 but >= 50.
MarkingCode structure (Repository Pattern), Security, and Test coverage.