RAG Explainer EP11 | run.py Explained: Flask Startup, Config & Blueprints
Welcome to Episode 11 of the RAG Explainer Series from Secure AI Learning Lab. In the previous episodes, we introduced the RAG application architecture, reviewed the Python dependencies in requirements.txt, and explained how virtual environments isolate project libraries. In this episode, we begin the file-by-file source-code walkthrough of the RAG Explainer application by examining run.py, the primary Python program used to configure and start the Flask application. The explanation follows the code line by line and connects each statement to its role in the overall application architecture. This episode covers: The hierarchical Python project structure in PyCharm Why run.py is the application startup file Importing Python standard libraries and external packages Reading operating-system environment variables Loading application configuration from a .env file Importing and configuring the custom logging system Python functions as reusable application components Using _file_ to locate the application root directory Creating the logs directory The Flask application-factory pattern Creating the Flask application instance Configuring template and static-file directories Loading HTML templates, JavaScript, images, and other static assets Configuring the Flask secret key Reading configuration values with os.getenv Flask session-cookie settings SameSite cookie behavior HTTPOnly cookie protection Secure-cookie behavior in local HTTP development Loading Keycloak configuration for authentication and single sign-on Configuring the document-upload folder Configuring the ChromaDB vector-store directory Setting document chunk size and chunk overlap Selecting the Sentence Transformer embedding model Creating required application directories automatically Organizing Flask REST endpoints with Blueprints Registering route Blueprints with the Flask application Understanding the create_app function Understanding Python’s if _name_ == "__main__" entry point Starting Flask on port 6065 Binding the application to available network interfaces Debug mode and reloader configuration The application configuration includes several important enterprise RAG components: Keycloak for authentication and role-based access Flask for the web application and REST APIs ChromaDB for vector storage Sentence Transformers for embeddings Upload directories for PDF and Word documents Chunking and overlap settings for document processing Centralized application logging A key takeaway from this episode is that run.py does much more than simply launch Flask. It creates the application, loads external configuration, initializes security and storage settings, prepares required directories, registers API routes, and finally starts the web server. This video is useful for Python developers, Flask developers, AI engineers, enterprise architects, and technical leaders who want to understand how a secure RAG application is initialized and organized. Previous Episode: EP10 - Python Virtual Environments, venv and requirements.txt • RAG Explainer EP10 | Python Virtual Enviro... Next Episode: EP12 - Flask Logging Configuration Explained [tbd] Full Course: Retrieval Augmented Generation in Python Flask ChromaDB [tbd] Subscribe to Secure AI Learning Lab for practical Enterprise AI, Secure AI, RAG, Python, Flask, Keycloak, OAuth2/OIDC, ChromaDB, and secure-by-design application architecture. Chapters: 00:00 Introduction 00:08 Beginning the file-by-file code walkthrough 00:33 Why run.py is the Flask startup program 00:48 Importing OS, Flask, and python-dotenv 01:27 What a modern Flask web application does 02:15 Loading variables from the .env file 02:48 Importing the custom logging configuration 03:08 Python functions as first-class components 03:34 Locating and creating the logs directory 04:23 The create_app application-factory function 04:33 Template and static folders 04:59 Flask application configuration 05:03 Secret key and environment-variable defaults 05:29 SameSite session-cookie configuration 05:57 HTTPOnly and secure-cookie settings 06:32 Keycloak configuration 06:44 Upload folder and ChromaDB path 07:08 Chunk size, overlap, and embedding model 07:48 Creating required directories 08:09 Flask Blueprints and route organization 08:49 Registering REST API routes 09:01 Returning the Flask application instance 09:12 Python _name_ == "__main__" 09:30 Starting Flask on port 6065 09:44 Debug mode and disabling the reloader 10:08 Episode summary 10:23 Closing #RAG #Flask #Python #EnterpriseAI #SecureAI

RAG Explainer EP12 | logging_config.py, Rotating Logs & Log Levels

System Design Explained: APIs, Databases, Caching, CDNs, Load Balancing & Production Infra

RAG Crash Course for Beginners

RAG Explainer EP15 | rag_service.py: Embeddings, ChromaDB & File Parsing

How to Build a Scalable RAG System for AI Apps (Full Architecture)

Android 17 sucks. So I put Linux on a phone.

Brian Cox- The Fermi Paradox Will Change How You See The Universe

Blue gradient background - screensaver, mood lighting, ambiance, TV art, focus, study

No Boss, No Money: The Raw Reality of China’s Gen-Z Freelancers

The Linux Kernel is Falling Apart.

The Scariest Chart in Electrical Engineering

How AI agents & Claude skills work (Clearly Explained)

"good health" has become a competition

Peter Hahne: He’s had enough! | A reckoning with Spahn, Merz, and the un-Christian Union

RAG Explained For Beginners

When Celebrities Couldn't Handle Harrison Ford's BRUTAL Honesty

Don't Hang Up On AI Scammers. Do THIS Instead.

Keynote: After the AI Hype – What’s Real, and What’s Next - Richard Campbell - 2026

