BUILDING A PRODUCTION-READY GITHUB RAG SYSTEM
Build Chapter 2: Setting Up the Python Project
Part 1: Foundation and Repository Understanding | For engineers learning RAG | About 10 minutes to read, 20 to follow along
Chapter 1 defined what we are building and why. Now we start building. This chapter creates a clean Python 3.11 project with uv, installs the first dependencies, and lays out an empty package structure. There is no application logic yet, and that is deliberate.
Application settings, custom exceptions, and structured logging come next, in Build Chapter 2.1.
What you will take away
• A reproducible project: a pinned Python version, declared dependencies, and a lock file that gives every machine the same environment.
• A src-based package structure, and why it avoids a common class of import mistakes.
• A four-command checkpoint you can run at any time to confirm the setup is healthy.
Prerequisites: a terminal and uv installed [3]. Commands are shown for Windows CMD, with macOS and Linux equivalents in the table in section 4. Series code: Link
For technical leaders: the 60-second version • The decision. Fix the project's foundations on day one: a pinned Python version, a committed lock file, and a src layout. These are cheap now and expensive to retrofit. • The cost. A short, one-time setup and no application code. What it prevents is the familiar "works on my machine" problem, and slower onboarding as the team grows. • The risk it reduces. Different developers and CI running different dependency versions, imports that accidentally resolve to the wrong files, and secrets or generated files committed by mistake. • Questions to ask your team. Is the Python version pinned? Is the lock file committed? Can a new engineer clone the repository and run it with two commands? Does CI use the same lock file as developers? |
1. What we will build
By the end of this chapter the project will look like this. Do not create anything yet; the steps below build it piece by piece.

2. Why project structure matters
A prototype can start as a single file, such as github_rag.py. This project will not stay that small. Over the series it will grow to include repository connectors, file policies, a metadata inventory, extraction and parsing, code-aware chunking, embeddings, vector storage, hybrid retrieval, reranking, grounded generation, citations, guardrails, evaluation, an agent, and cloud deployment.
One file holding all of that would be hard to understand and harder to test. Instead we divide the application into packages by responsibility, and add new ones only when they are needed:
Package or folder | Responsibility | Introduced in |
core | Shared foundations: settings, logging, application exceptions. | Build Chapter 2.1 |
domain | Enums, Pydantic data models, shared definitions. | Build Chapter 3 |
connectors | Access to repositories. The first version reads a local directory; a later one connects to GitHub. | Phase 2 chapters |
inventory | File classification and policies, content hashing, inventory generation and serialization. | Phase 2 chapters |
config | External configuration files, including the future file-policy YAML. | Phase 2 chapters |
artifacts | Generated development output: inventory JSON, extraction summaries, chunk inspection files, evaluation results. | Throughout |
tests | Automated tests. | Throughout |
3. Why Python 3.11 and uv
Python
Python is the common language for RAG and AI applications because its ecosystem covers text and source-code processing, data validation, embedding models, vector databases, LLM integrations, evaluation frameworks, web services, and agent frameworks. We pin Python 3.11 so that every reader, and later every deployment, runs the same interpreter.
Python 3.11 also supports modern type annotations:
def find_file(path: str | None) -> str:
...Type annotations will help us follow the data as it moves through the system:
repository file -> inventory record -> extracted document -> parsed document
-> chunk -> embedding -> retrieval result -> citationuv
We will use uv to manage Python versions, the project environment, dependencies, dependency locking, and running the application. A uv project keeps its configuration and dependencies in pyproject.toml, maintains an isolated virtual environment, and records exact resolved versions in a lock file [1]. You get one consistent workflow instead of juggling venv, pip, and separate dependency files.
The commands you will meet most often:
uv init create a project
uv add pydantic add a dependency
uv sync make the environment match the lock file
uv run python run Python inside the project environment4. Step 1: Verify the prerequisites
The commands in this chapter are written for Windows CMD. If you use macOS or Linux, this table gives the equivalents. The uv commands are identical on every platform.
Task | Windows CMD | macOS / Linux |
Create a directory | mkdir name | mkdir -p name |
Create an empty file | type nul > file | touch file |
Show a file | type file | cat file |
List files | dir | ls -a |
Show the folder tree | tree /f | tree -a -I '.venv|.git|__pycache__' |
Path separator | \ (src\github_rag) | / (src/github_rag) |
Check that uv is available. If it is not installed, follow the installation guide [3].
uv --version
Example output (your version will differ):
uv 0.x.xCheck which Python versions uv can see, and install 3.11 if it is missing:
uv python list
uv python install 3.11
uv run --python 3.11 python --version
Expected output:
Python 3.11.x5. Step 2: Create the project directory
Move to the folder where you keep projects. On Windows CMD the /d option changes the drive and the directory together.
cd /d D:\Users\YourUserName\Desktop\projects
mkdir github-rag
cd github-ragThe cd command with no argument prints the current location, which should end in github-rag. Every command from here on runs inside this folder, which we call the project root.
6. Step 3: Initialize the project
uv init --package --python 3.11Both options matter:
• --package creates a src layout and a build system, so the project is installed into its own environment and import github_rag works. A packaged project is described in the uv documentation [2].
• --python 3.11 writes the .python-version file and sets requires-python, so Python is pinned from the first commit.
Why not plain uv init? With the uv version we tested (0.11), plain uv init creates a single main.py script and no build system. Our package would never be installed, and the import test at the end of this chapter would fail with ModuleNotFoundError. Newer versions may change defaults, so keep the two options. |
Check what was generated:
dir /a
Expected: .gitignore .python-version README.md pyproject.toml srcConfirm the Python pin and the interpreter the project uses:
type .python-version
3.11
uv run python --version
Python 3.11.xIf you ever need to change the pinned version later, run uv python pin <version> and then uv sync.
7. Understanding pyproject.toml
Open the file:
type pyproject.tomlReplace the placeholder description and remove the [project.scripts] block that uv generated. The starter code it pointed to will be replaced in a moment, and we add a real entry point in Chapter 2.1. The result should look like this (your authors entry and uv_build version limits may differ):
[project]
name = "github-rag"
version = "0.1.0"
description = "A GitHub repository RAG system"
readme = "README.md"
requires-python = ">=3.11"
dependencies = []
[build-system]
requires = ["uv_build>=0.11.32,<0.12.0"]
build-backend = "uv_build"Field | Meaning |
name | The project (distribution) name. |
requires-python | The oldest Python version the project supports. |
dependencies | Runtime dependencies. uv fills this in when you run uv add. |
build-system | Tells uv how to build and install the package into the environment. Without it the package is not importable. |
Project name versus package name
The project name uses a hyphen and the Python package name uses an underscore. They are related but not interchangeable:
name = "github-rag" # project name, used by uv and pip
import github_rag # package name, used in Python code
import github-rag # invalid Python: a hyphen is a minus sign8. Step 4: Install the foundational dependencies
uv add pydantic pydantic-settings pyyaml structlogThis adds four packages to pyproject.toml and creates uv.lock. The broad declarations live in pyproject.toml; uv.lock records the exact resolved versions [1].
Package | What we use it for |
pydantic | Defining and validating structured models: repository references and files, inventories, extracted documents, chunks, retrieval results, citations. |
pydantic-settings | Managing settings such as logging level, configuration and artifact directories, embedding model name, vector-database settings, cloud project information. |
pyyaml | Reading file policies from YAML, so rules stay out of the code (example below). |
structlog | Structured logging with named fields, instead of relying on print() statements. |
A sketch of the YAML file policy we will write in a later chapter:
excluded_directories:
- .git
- .venv
- node_modules
supported_extensions:
- .py
- .sql
- .md
- .yamlTest the installation:
uv run python -c "import pydantic, pydantic_settings, yaml, structlog; print('Dependencies ready')"
Expected output:
Dependencies ready9. Step 5: Create the packages and folders
The src layout keeps importable application code in a directory separate from documentation, tests, configuration, and generated files. It also ensures that Python imports the installed package and not whatever happens to sit in the project root [4].
uv has already created src\github_rag. Add the four subpackages and the three supporting folders:
mkdir src\github_rag\core
mkdir src\github_rag\domain
mkdir src\github_rag\connectors
mkdir src\github_rag\inventory
mkdir config
mkdir artifacts
mkdir testsCreate the init.py files
Each package needs an init.py. Create the four new ones as empty files:
type nul > src\github_rag\core\__init__.py
type nul > src\github_rag\domain\__init__.py
type nul > src\github_rag\connectors\__init__.py
type nul > src\github_rag\inventory\__init__.pyThen open each file and give it the one-line description below. For src\github_rag\__init__.py, which uv created with a starter main() function, replace the whole content with the docstring.
File | Content |
src\github_rag\__init__.py | """GitHub repository Retrieval-Augmented Generation application.""" |
src\github_rag\core\__init__.py | """Core configuration, logging, and exception components.""" |
src\github_rag\domain\__init__.py | """Domain models and enums for the GitHub RAG application.""" |
src\github_rag\connectors\__init__.py | """Repository connector interfaces and implementations.""" |
src\github_rag\inventory\__init__.py | """Repository inventory generation components.""" |
These docstrings state the purpose of each package. Nothing is exported through init.py yet; we add exports only when the code behind them exists.
10. Step 6: Review .gitignore
uv already generated a .gitignore covering Python cache files and the virtual environment. Open it and add the following:
# Local environment variables
.env
# Generated artifacts (keep the folder, ignore its contents)
artifacts/*
!artifacts/.gitkeep
# Testing outputs
.pytest_cache/
.coverage
htmlcov/
# IDE configuration
.vscode/
.idea/• .env is excluded because it may later hold sensitive settings such as API keys.
• The contents of artifacts are excluded because inventory, extraction, and chunk-inspection files are generated locally.
• uv.lock must not be ignored. For an application, committing the lock file reproduces the same resolved environment on every machine.
Git does not track empty folders, so a fresh clone would be missing config, artifacts, and tests. Add a placeholder file to each:
type nul > config\.gitkeep
type nul > artifacts\.gitkeep
type nul > tests\.gitkeep11. Step 7: Verify the setup
Run these four commands from the project root. Use them as a checkpoint whenever something seems wrong.
uv sync
uv run python --version
uv run python -c "import github_rag; print('Package ready')"
uv run python -m compileall src
Expected:
(uv sync) the environment is created or confirmed up to date
Python 3.11.x
Package ready
(compileall) each package is listed and compiled, with no SyntaxErrorIf the import works, Python can find the package under src\github_rag, which confirms that the build system, the src layout, and the environment are all in place.
Finally, compare your folder with the structure from section 1:
tree /fYour output also lists .venv, pycache, and the .gitkeep files. These are expected local files and can be ignored.
12. Common setup problems
Symptom | Likely cause | Fix |
'uv' is not recognized as an internal or external command | The terminal was opened before uv was installed. | Close and reopen the terminal, then run uv --version. |
Python is not 3.11 | The pin was changed or the environment is out of date. | Run uv python pin 3.11, then uv sync, then check again. |
ModuleNotFoundError: No module named 'github_rag' | The command was not run from the project root, or the project was created without --package. | Run dir pyproject.toml to confirm the location, check that [build-system] exists, then run uv sync. |
ImportError: cannot import name 'main' | The generated [project.scripts] block still points to the removed starter code. | Delete the [project.scripts] block from pyproject.toml. |
'type nul' fails in PowerShell | These commands are for CMD. | In PowerShell use New-Item name -ItemType File. |
Conclusion and next chapter
We now have a pinned Python version, installed dependencies with a lock file, a src-based package, five importable packages with descriptions, supporting folders, a hardened .gitignore, and a repeatable checkpoint. We deliberately did not add models, connectors, parsing, embeddings, or retrieval. Each of those arrives when its responsibility is clear and we have a small test to prove it works.
Next, Build Chapter 2.1: Building the Application Foundation. It covers:
• Custom application exceptions and a common GitHubRagError
• Typed application settings with environment-variable overrides
• Structured logging
• Public exports through core/__init__.py
• The application entry point, run with python -m github_rag
• Final startup and syntax tests
About SNPaul Infotech We help engineering and data teams design, evaluate, and secure retrieval and GenAI systems like this one. If you are weighing RAG for your own repositories or documents, get in touch: www.snpaulinfotech.com |
References
[1] Astral. Working on projects (uv)
[2] Astral. Creating projects (uv)
[3] Astral. Installing uv
[4] Python Packaging User Guide. src layout vs flat layout


Comments