Writing / Technical / Build Log · 16 NOV 2026
Setting Up the Workshop Before the First Line of Real Code
How I prepared my machine, my repository and my tools for the Kasarani Ticket Ledger, including the dbt version trap I fell into and the Makefile that runs the whole project.
At CHAN 2024, about 25,000 tickets were scanned at Kasarani for Kenya v Morocco. Organisers estimated about 75,000 people got in. Nobody could show how many seats were on public sale or who bought how many. Nobody could match the tickets sold against the people inside.
That's the problem behind my new project, the Kasarani Ticket Ledger. You can follow the code on GitHub. The first version is due on 20 December 2026, and it's a batch pipeline in four stages:
- A generator written in Python creates a realistic match day: orders, payments, tickets and gate scans. It's built on the real reported numbers.
- A raw layer in PostgreSQL stores those events exactly as they were produced.
- A dbt project turns the raw events into a trusted ticket ledger, a capacity history and a reconciliation report.
- A dashboard in Streamlit shows fans, organisers and gate staff what's really happening.
The streaming version with Kafka and Spark comes later, in April and May 2027. None of that needs Docker, Kafka or Spark yet.
Before any of it, the workshop has to be ready. This post is that setup, written as a record for anyone starting a project like this and as a playbook for my next one. Every tool installed here exists to serve one of those four stages.
My machine: MacBook Air M2, so the commands are for a Mac with Homebrew.
The rule for this project
Setup commands are fine to copy. From the Makefile onward, I write the code myself.
Step 1: Check the tools
Every project stands on other software. The code depends on Python. The data lives in PostgreSQL. The history lives in Git. If one of them is missing or the wrong version, nothing I write will run. A mechanic checks the toolbox before opening the bonnet.
git --version
python3.12 --version
psql --version
brew --version
If anything is missing:
brew install git python@3.12 postgresql@17
brew services start postgresql@17
psql postgres # a prompt means Postgres is awake; \q to leave
--version is the fastest way to prove a tool exists and to see which version is actually running. Versions matter because tools change between releases. Code written for Python 3.12 can break on 3.8.
Postgres needs to be started because it's a server. It sits waiting for connections all day. Python is different. It only runs when you run a script.
Remember: check the foundation before you build.
Step 2: The repository
A repository is a folder that remembers every change ever made to it. That memory is Git. GitHub keeps a copy online, so the work is backed up and other people can see it. For me, the public copy is part of my CV.
On GitHub I created a public repository called kasarani-ticket-ledger with three options set:
- Add a README file: ticked. It's the front page of the project, and I'll write it properly at the end.
- Add .gitignore: the Python template, which already covers the usual clutter.
- Choose a license: MIT, which means "use it freely and keep my name on it." Without a license, nobody is legally allowed to reuse the code.
Then on my Mac:
cd ~/projects
git clone https://github.com/themanbuildingpipelines/kasarani-ticket-ledger.git
cd kasarani-ticket-ledger
code .
git clone downloads the repo and keeps it linked to GitHub. From now on there are two copies, one on my laptop and one online, kept in sync with git push and git pull.
Remember: the repo is the project's memory. GitHub is its public face.
Step 3: The folders
A good folder layout tells anyone who opens the project how it works, before they read a single line of code. Mine follows the data from where it's created to where it's shown.
mkdir -p config generator dashboard tests docs data/raw
touch generator/__init__.py tests/__init__.py
touch docs/decisions.md docs/event-contracts.md config/match_kenya_morocco.yaml
| Folder | What lives there | Lifecycle stage |
|---|---|---|
config/ |
The real CHAN numbers and my labelled assumptions | Settings |
generator/ |
The Python code that simulates match day | Generation |
data/raw/ |
The files the generator writes | Generation |
warehouse/ |
The dbt project that builds clean tables | Storage and transformation |
dashboard/ |
The Streamlit app | Serving |
tests/ |
The proof that the code works | Software engineering |
docs/ |
My decisions and my event contracts | Data management |
Read the table top to bottom and you're reading the data engineering lifecycle. The warehouse/ folder comes later, because dbt creates it.
__init__.py is an empty file that tells Python "this folder is a package you can import from." Without it, a line like from generator.models import Order fails.
Remember: the folder layout should tell the story of the data.
Step 4: The Python environment
Different projects need different versions of the same library. Newcomer Credit might need one version of dbt and this project another. If both share one Python, installing for one can break the other. A virtual environment is a sealed box holding a private Python and its libraries for one project only.
python3.12 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install pydantic pyyaml pytest "psycopg[binary]" "dbt-core<2" "dbt-postgres<2" streamlit pandas
pip freeze > requirements.txt
When the environment is active, the terminal prompt starts with (.venv). Forgetting to activate is the most common beginner mistake. The code suddenly says No module named pydantic and you're confused. Check for (.venv) first.
What each library is for:
- pydantic checks the events have the right shape. It's the data contract in code.
- pyyaml reads the config file.
- pytest runs the tests.
- psycopg lets Python talk to Postgres.
- dbt-core and dbt-postgres are dbt and its Postgres connector.
- streamlit builds the dashboard.
- pandas handles tables of data inside Python.
pip freeze > requirements.txt writes down the exact version of everything installed. Anyone who clones the repo can rebuild the setup with pip install -r requirements.txt. That's reproducibility. The <2 after dbt is called pinning, and Step 7 explains why it's there.
Remember: one project, one environment, and write down the versions.
Step 5: The .gitignore
Some files must never go public. Others are pointless to store. At the bottom of the .gitignore GitHub created, I added:
# project
data/
warehouse/target/
warehouse/logs/
warehouse/dbt_packages/
.DS_Store
There are three kinds of file I never commit:
- Secrets.
.envholds my settings and my salt. Once a password reaches a public repo, assume it's stolen. Bots scan GitHub for leaked keys within minutes. The Python template already ignores.env. - Things I can rebuild.
.venv/comes back fromrequirements.txt.data/comes back when I run the generator.warehouse/target/is rebuilt every time dbt runs. Storing them only bloats the repo. - Junk.
.DS_Storeis a hidden file macOS drops into every folder you open in Finder.
Commit what you wrote by hand. Ignore what a machine can regenerate and anything secret.
Remember: never commit secrets, and never commit anything you can rebuild.
Step 6: The database and the settings
Postgres can hold many databases. This project gets its own, so it never mixes with Newcomer Credit's data. Inside it, schemas work like folders for tables.
createdb kasarani
psql kasarani -c "create schema raw;"
psql kasarani -c "\dn" # raw should be in the list
whoami # Homebrew Postgres creates a user with this name
Then a secret salt:
python3 -c "import secrets; print(secrets.token_hex(16))"
The connection settings live in a file called .env, outside the code. The same code then works on my laptop, a friend's laptop or a cloud server. Only the .env changes.
# .env (real values, never leaves my laptop)
PGHOST=localhost
PGPORT=5432
PGUSER=jimmyokoth
PGPASSWORD=
PGDATABASE=kasarani
PHONE_HASH_SALT=the_32_characters_it_printed
PGPASSWORD stays empty because a Homebrew Postgres trusts connections from your own laptop. Next to it sits .env.example, with the same keys and placeholder values (your_mac_username, change_me). That one goes to GitHub, so anyone who clones the repo knows what to fill in.
Before going further, I checked Git is protecting .env:
git status # should list .env.example and not .env
git check-ignore .env # should print .env
psql -h localhost -U $(whoami) kasarani -c "select current_user, current_database();"
If .env ever shows up in git status, stop and fix .gitignore before doing anything else.
| Setting | Meaning |
|---|---|
PGHOST=localhost |
The database is on this same computer |
PGPORT=5432 |
The door number Postgres listens on, its default |
PGUSER |
Who I log in as |
PGPASSWORD |
Blank, because local connections are trusted |
PGDATABASE |
Which database to use |
PHONE_HASH_SALT |
The secret ingredient for hiding phone numbers |
Three ideas sit behind this step.
Two layers of data. The raw schema holds data exactly as the generator produced it, and I never edit it by hand. Later, dbt builds clean tables in a schema called analytics. If I find a bug in my cleaning logic, I fix the logic and rebuild from the untouched originals. Nothing is lost. You'll hear this called bronze, silver and gold, or staging and marts. It's the same idea every time.
Settings out of code. The code reads PGDATABASE from the environment instead of having "kasarani" typed into it. It's one of the most widely followed rules in software, from a set of principles called the Twelve-Factor App.
The salt. Later I'll hide M-Pesa phone numbers by hashing them. A hash on its own can be cracked, because there are only so many Kenyan phone numbers. Someone could hash every one of them and compare. Mixing in a secret salt first makes that impossible without the salt. That's why the salt lives in .env and never in code.
Remember: keep raw data untouched, build clean data on top, and keep settings out of code.
Step 7: dbt, and the trap I fell into
dbt lets you write data transformations as plain SQL files. It runs them in the right order, tests the results and draws a map of how every table connects to every other. Before dbt, teams kept piles of SQL scripts with no tests and no idea what depended on what.
The trap
When I first ran dbt init warehouse, it failed:
error: unexpected argument 'warehouse' found
Two things were going on. First, I had two programs called dbt on my Mac. One was in the project's .venv. The other was in ~/.local/bin, probably put there by the dbt VS Code extension. When you type a command, your Mac searches a list of folders called the PATH and runs the first match.
Second, the version that ran was dbt 2, a new engine rewritten from scratch. Its commands work differently, and its Postgres support has been unreliable. So I pinned dbt Core below version 2:
pip uninstall -y dbt dbt-core dbt-postgres
pip install "dbt-core<2" "dbt-postgres<2"
rehash
.venv/bin/dbt --version
rehash tells the shell to forget where it last found commands and search again. The version output now says Core with a 1.x number and lists postgres under plugins. If you ever type dbt and get version 2 again, which -a dbt shows every copy in the order they're searched.
The lesson: a big new release can silently break a project. Pinning versions protects you. It became my first decision record in docs/decisions.md: "Pinned dbt Core below 2.0 because the new engine's Postgres support was unreliable when I set up the project."
The setup
With (.venv) showing, in the project root:
dbt init warehouse
| Prompt | Answer | Why |
|---|---|---|
| Database | postgres | Where the data lives |
| host | localhost | Same as .env |
| port | 5432 | Same as .env |
| user | my whoami name |
Same as .env |
| pass | press Enter | Blank, like .env |
| dbname | kasarani | The database I made |
| schema | analytics | Where dbt builds clean tables |
| threads | 4 | How many models dbt can build at once |
Then I tested the connection before writing anything:
cd warehouse
dbt debug # every check must say OK, ending with "All checks passed!"
rm -rf models/example
mkdir -p models/staging models/marts
At the bottom of dbt_project.yml, the example: block became:
models:
warehouse:
staging:
+materialized: view
marts:
+materialized: table
dbt run # "Nothing to do" with no errors is the right result
cd ..
The connection isn't in the repo. dbt saved it to ~/.dbt/profiles.yml in my home folder, so it never reaches GitHub. It's the same principle as .env, applied by dbt itself.
dbt debug comes first because setup problems are far easier to fix on day one than after you've written ten models. A failing dbt debug on day one is good news.
Staging models are light cleanups of raw tables, and views suit them because they're cheap and always current. Marts are the final trusted tables, the ticket ledger and the reconciliation report. They're stored as real tables so the dashboard reads them quickly.
Remember: test the connection before writing the logic, and pin the versions you depend on.
Step 8: The Makefile
I'll run the same few commands hundreds of times this month. A Makefile gives each one a short name. Instead of remembering cd warehouse && dbt build, I type make dbt. Anyone who clones the repo can run the whole project without asking me anything.
A Makefile is a file named exactly Makefile, with a capital M and no extension, in the project root. It holds named shortcuts called targets. The command line under each target must start with a real tab character. Spaces fail with an error mentioning missing separator.
The finished file:
.PHONY: venv test dbt dashboard
venv:
python3.12 -m venv .venv
.venv/bin/pip install -r requirements.txt
test:
.venv/bin/pytest
dbt:
cd warehouse && ../.venv/bin/dbt build
dashboard:
.venv/bin/streamlit run dashboard/app.py
After touch dashboard/app.py, every target ran: make venv printed "Requirement already satisfied", make test reported no tests ran (a pass for now), make dbt found nothing to build and make dashboard opened a blank page.
Line by line, the parts that matter:
.PHONYMake was built to create files, so by default it treats a target name as a file it should produce. If a folder calledtestever existed,make testwould decide there's nothing to do..PHONYtells Make these names are commands, so they always run..venv/bin/in front of every tool Make doesn't see the(.venv)I activated in my terminal. Each Makefile line starts a brand new shell with no environment active, so each tool is called by its full path.cd warehouse && ../.venv/bin/dbt buildThis line holds the two most important lessons in the file. It's one line because each line runs in its own fresh shell. Putcd warehouseon one line anddbt buildon the next, and the second line starts back in the project root.&&keeps them in the same shell and only runs the second command if the first one worked. And aftercd warehouse,.venvisn't next to me anymore. It's one folder up, so the path becomes../.venv/bin/dbt.
Every line answers two questions. What is the name of the thing I want? Where does it live from where I'm standing? That idea comes back in Python imports, in dbt references and in Docker later on.
When it goes wrong, cat -et Makefile is worth remembering. It shows invisible characters. ^I marks a tab and $ marks the end of a line, so a correct target looks like this:
test:$
^I.venv/bin/pytest$
| What you see | What it means | What to do |
|---|---|---|
No rule to make target |
Make can't find that target | Save the file, then check with cat -et Makefile |
missing separator |
A command line starts with spaces | Delete the indent and press Tab once |
No such file or directory |
A path is wrong | Usually the dbt line. Check the ../ |
Remember: if you type a command more than twice, make it a shortcut. Paths are always relative to where you're standing.
Step 9: The first commit
A commit is a snapshot of the project with a message attached. If I break everything next week, I can go back to this exact moment.
git status
I should see .env.example, Makefile, requirements.txt and the warehouse/ files. I must not see .env, .venv/ or warehouse/target/. Then:
git add .
git commit -m "Project skeleton: Python env, Postgres raw schema, dbt Core project, Makefile"
git push
Then I opened the repo on GitHub and looked at it the way a stranger would. Folders, Makefile and requirements are there. No secrets are.
git add chooses what goes into the snapshot. git commit takes the snapshot. git push sends it to GitHub. Small commits with clear messages are easy to undo and easy to explain. One huge commit at the end of the month called "final" says you didn't work like a professional.
Remember: commit when it works, say what changed, and push every day.
The checklist
The workshop is ready when every box is ticked:
-
psql kasaraniconnects and\dnshows therawschema -
git check-ignore .envprints.env -
.venv/bin/dbt --versionshows dbt Core 1.x with the postgres plugin -
dbt debuginsidewarehouse/says "All checks passed!" -
make venv,make test,make dbtandmake dashboardall run - The repo is on GitHub with no
.envand no.venvin it -
docs/decisions.mdhas at least two decisions: pinning dbt, and ignoringdata/
When things go wrong
| Symptom | Likely cause | Fix |
|---|---|---|
No module named ... |
Environment not active | source .venv/bin/activate and check for (.venv) |
dbt init says unexpected argument |
dbt 2 is running | Pin dbt Core below 2, then rehash |
dbt debug connection fails |
Postgres isn't running | brew services start postgresql@17 |
role "..." does not exist |
Wrong username in profile | Compare with whoami and edit ~/.dbt/profiles.yml |
database "kasarani" does not exist |
Database never created | createdb kasarani |
missing separator |
Spaces where a tab is needed | Switch VS Code to tabs and retype the indent |
.env appears in git status |
.gitignore is missing the line |
Add .env before committing |
The whole setup in five sentences
Check your tools before you build. Give the project its own repo, folders and Python environment. Keep secrets and anything you can rebuild out of Git. Keep raw data untouched and build clean data on top with dbt. Make your commands repeatable and commit every time something works.
What I'm reading alongside it
- Fundamentals of Data Engineering (Reis and Housley), Chapter 2 "The Data Engineering Lifecycle", Chapter 8 "Queries, Modeling, and Transformation" and Chapter 10 "Security and Privacy"
- Pro Git, Chapters 1 and 2
- Install packages in a virtual environment using pip and venv
- PostgreSQL schemas
- The Twelve-Factor App, Config
- About dbt projects and About profiles.yml
- GNU Make, An Introduction to Makefiles and Recipe Execution
- How to Write a Git Commit Message by Chris Beams
What's next
The next stage starts with docs/event-contracts.md. I'll write down the exact shape of every event the generator will produce: orders, payments, tickets issued and gate scans. I'll also define the allocation buckets and the capacity history. That document is the foundation for every line of code after it.
See you on the next post. Adios.