docs: consolidate residency workflow and document development environment

Refine the residency documentation to better support implementation-focused
learning.

Highlights:

- introduce the three operational coaching modes and their continuous
  learning loop in AGENTS.md
- replace machine-specific references with portable repository links
- remove Obsidian application metadata from version control
- update the roadmap to standardize on Pyright
- document Docker volume management and container workflows
- document responsibilities of uv, direnv and Nix devShells
- add detailed notes on devShells for future milestones
- record lessons learned, mistakes and next objectives in the June 26 journal

These changes establish the residency workflow while documenting decisions
made during the initial project setup.
This commit is contained in:
kiskaadee committed 2026-06-29 22:21:17 -05:00
1 parent 2d4cd71cff
commit 8783033f74
9 files changed
+337 -40

No files matched your search

-1
View File
@@ -1 +0,0 @@
{}
-1
View File
@@ -1 +0,0 @@
{}
-33
View File
@@ -1,33 +0,0 @@
{
"file-explorer": true,
"global-search": true,
"switcher": true,
"graph": true,
"backlink": true,
"canvas": true,
"outgoing-link": true,
"tag-pane": true,
"footnotes": false,
"properties": true,
"page-preview": true,
"daily-notes": true,
"templates": true,
"note-composer": true,
"command-palette": true,
"slash-command": false,
"editor-status": true,
"bookmarks": true,
"markdown-importer": false,
"zk-prefixer": false,
"random-note": false,
"outline": true,
"word-count": true,
"slides": false,
"audio-recorder": false,
"workspaces": false,
"file-recovery": true,
"publish": false,
"sync": true,
"bases": true,
"webviewer": false
}
+1 -1
View File
@@ -20,7 +20,7 @@ Rebuild the original BiteTrack backend using modern Python technologies and prod
- **Tasks:**
- Configure workspace structure & symlink (`~/todo.md`)
- Initialize Python environment using `uv`
- Configure Ruff, mypy, and code formatter
- Configure Ruff, Pyright, and code formatter
- Setup multi-container Docker Compose file (`FastAPI` & `PostgreSQL`)
- **Acceptance Tests:**
- [ ] Running `docker compose up` starts both FastAPI and PostgreSQL database.
+106
View File
@@ -0,0 +1,106 @@
# Daily Journal: 2026-06-26
## Wins
### Backend Residency
- Created `AGENTS.md`, establishing the permanent operating manual for AI-assisted learning.
- Defined a coaching philosophy centered on maximizing long-term engineering skill acquisition while minimizing unnecessary friction
- Clearly established the boundaries of AI assistance, including the Assistance Hierarchy and Code Generation Policy.
- Introduced three operational modes:
- **Build Mode** for implementation
- **Practice Mode** for isolated skill development
- **Interview Mode** for communication and interview readiness
- Defined a continuous learning loop where implementation reveals weakness, practice addresses them, and interview sessions validate understanding.
### BiteTrack API
- Created the [bitetrack-api](https://github.com/kiskaadee/bitetrack-api) repository
- Initialized the project with UV
- Added the initial development tooling:
- FastAPI
- Ruff
- Pyright
- Pytest
- Added an MIT license
- Configured `.envrc` for local development
- Created an initial `.gitignore` covering secrets, virtual environments, caches and build artifacts.
- Added a minimal `docker-compose.yml` with a PostgreSQL service
- Successfully configured `direnv` and verified that the development environment loads automatically.
- Successfully built and started the PostgreSQL container
## Mistakes and Lessons Learned
### Docker Volume Mapping
Initially mounted the PostgreSQL data volume to:
`/var/lib/bitetrack/data`
This was causing data to be cleared upon container restart because the official PostgreSQL container image stores database files under:
`/var/lib/postgresql/data`
The volume must target PostgreSQL's expected data directory unless the container itself is explicitly reconfigured
**Lesson Learned**: Persistent volumes must be attached to the directory actually used by the application, not to an arbitrary project specific path.
### Understanding `.envrc`
Initially, I treated `.envrc` like a regular `.env` file, unaware that `.envrc` is executed as a shell script.
Therefore, my initial `.envrc` looked like:
```bash
# .envrc
source ".venv/bin/activate"
POSTGRES_USER="username"
POSTGRES_PASSWORD="password"
POSTGRES_DB="db_name"
```
Of course, the virtual environment was loading with no issues, but the environment variables were missing from the project's `PATH`, causing the container to start lacking the key variable environments:
```logs
bitetrack_pgdb | Error: Database is uninitialized and superuser password is not specified.
bitetrack_pgdb | You must specify POSTGRES_PASSWORD to a non-empty value for the
bitetrack_pgdb | superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
bitetrack_pgdb |
bitetrack_pgdb | You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
bitetrack_pgdb | connections without a password. This is *not* recommended.
```
**Lessons learned**:
Variables must be exported: `direnv` evaluates shell code; environment variables only become available to child processes when exported.
The corrected `.envrc` looks like this:
```bash
# .envrc
source ".venv/bin/activate"
export POSTGRES_USER=username
export POSTGRES_PASSWORD=password
export POSTGRES_DB=db_name
```
## Questions
- With NixOS already providing `direnv`, when does it become necessary or advantageous to introduce `devShell`s? which responsibilities belong to each?
- Answered in [[environments]]
- I attempted to namespace the PostgreSQL volume because I expected multiple databases to coexist on this machine. Is naming Docker volumes per application considered good practice? What are the recommended conventions for avoiding collisions while still using PostgreSQL's default data directory?
- Answered in:[[docker#Docker & Containerization Notes#Docker Volume names]]
## Reflection
Today's work was heavily focused on documentation, tooling and process design.
Normally I would consider that a warning sign, but in this case, I believe it was a worthwhile investment because these decisions establish the workflow that will guide the remainder of the learning journey.
The important constraint is that this phase is now complete. Moving forward, my efforts should primarily focused on generate engineering experience rather than additional process.
---
## Tomorrow
Primary Objective:
- Begin implementing Milestone 0 of BiteTrack.
Secondary objectives:
- Complete one short Python practice exercise
- Finish one mock interview focused on today's implementation work or Python fundamentals.
**Important**: No additional changes to the `AGENTS.md` or the backend-residency structure unless implementation exposes a genuine deficiency.
+36
View File
@@ -0,0 +1,36 @@
# **The Anatomy of a devShell**
In [[environments]] we briefly introduced the concept of a devShell.
If we get a little more technical, a devShell is a reproducible, isolated shell environment defined declaratively (usually via a `flake.nix`). It provides a specific set of system packages, compilers, and shared libraries without installing them globally.
The problem it solves: "It works on my machine" syndrome and the lack of standard file-system paths on NixOS.
Imagine a Python project requiring a concrete system-level library (e.g., `libpq` for PostgreSQL, `geos` for PostGIS, or specific versions of `gcc`), pip or uv will fail to compile native extensions because they cannot find these libraries in the standard paths like `/usr/lib`.
When you run `nix develop` in that Python project's directory, Nix reads the declarative configuration (the `flake.nix`) and fetches or builds the exact versions of `libpq`, `geos`, and `gcc` specified. It stores them in the immutable `/nix/store`.
Then, rather than installing them globally, Nix drops you into a new, isolated bash shell. Behind the scenes, it intercepts and rewrites your environment variables—such as `PATH`, `LD_LIBRARY_PATH`, `C_INCLUDE_PATH`, and `PKG_CONFIG_PATH`—to point directly to those specific `/nix/store` paths.
Now, when you run `pip install` or `uv sync` inside this shell, the compiler seamlessly finds the required headers and libraries. It succeeds perfectly, regardless of whether you are on NixOS, macOS, or a completely clean Ubuntu installation.
---
***Note**: Delaying this until it's really necessary during a project, or until Milestone 2 is completed*
**Why This is a Game-Changer for Development**
**Creating your first devShell in NixOS**
## Lectures:
[Easy development environments with Nix and Nix flakes!](https://dev.to/arnu515/easy-development-environments-with-nix-and-nix-flakes-21mb)
[Declarative shell environments with `shell.nix`](https://nix.dev/tutorials/first-steps/declarative-shell.html)
[Making a dev shell with nix flakes](https://fasterthanli.me/series/building-a-rust-service-with-nix/part-10)
[Development shells with Nix: four quick examples (2025)](https://michael.stapelberg.ch/posts/2025-07-27-dev-shells-with-nix-4-quick-examples/)
+102
View File
@@ -8,3 +8,105 @@
## Multi-stage Builds
- Used to keep final production image sizes small by compiling/building in an initial stage, then copying only the built artifacts into a minimal runtime image.
---
## Docker Volume names
**Question**: I attempted to namespace the PostgreSQL volume because I expected multiple databases to coexist on this machine. Is naming Docker volumes per application considered good practice? What are the recommended conventions for avoiding collisions while still using PostgreSQL's default data directory?
**Answer**:
Your concern is real, but the solution is different from changing PostgreSQL's internal data directory.
The **container path** should stay:
```text
/var/lib/postgresql/data
```
The **Docker volume name** is where you namespace.
For example:
```yaml
volumes:
bitetrack_postgres_data:
```
or
```yaml
volumes:
bitetrack-db-data:
```
Then mount it like:
```yaml
volumes:
- bitetrack_postgres_data:/var/lib/postgresql/data
```
The volume name is unique within Docker, while the mount point inside the container remains what PostgreSQL expects. That's the conventional approach and avoids collisions between projects without reconfiguring the database itself.
I applied this by adjusting the mount point name for the BiteTrack database mock:
```yaml
# docker-compose.yml
services:
postgres:
image: postgres:16-alpine
container_name: bitetrack_pgdb
restart: unless-stopped
environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_DB
ports:
- "5432:5432"
volumes:
- bitetrack_data:/var/lib/postgresql/data
volumes:
bitetrack_data:
```
---
## Docker Compose & Container Management Reference
### Container Lifecycle
```bash
# Start service as a detached process:
docker compose up -d
# Stop the service
docker compose down
# Wipe container: this resets the container state by deleting persistent data
docker compose down -v
# List project containers:
docker compose ps
# Include stopped containers:
docker compose ps -a
# Return only container IDs (useful for scripting):
docker compose ps -q
```
### Diagnostics & Internal Connections
* **Health Check via Container Logs:**
* Command: `docker compose logs -f`
* Expected success log for PostgreSQL: `database system is ready to accept connections.`
* **Connect Internally (via `psql`):**
* Jump directly into the container and use the built-in PostgreSQL CLI:
* Command: `docker exec -it <container_name> psql -U <username> -d <database_name>`
### Connection Configuration
* **Port Mapping:** `0.0.0.0:5432 -> 5432/tcp` maps host port 5432 to container port 5432.
* **Connection URL Example:**
```python
DATABASE_URL="postgresql://username:password@localhost:5432/database_name"
```
+88
View File
@@ -0,0 +1,88 @@
# devShells, direnv, env files and secret management
With NixOS already providing `direnv`, when does it become necessary or advantageous to introduce `devShell`s? which responsibilities belong to each?
To answer this accurately, we must establish clear problem statement: managing software dependencies spans multiple layers —from system-level shared libraries to language-specific packages to environment variables. Relying on a single tool to handle all layers inevitably leads to fragile environments, specially on a non-FHS (Filesystem Hierarchy Standard) distribution like NixOS
Let's see an overview of these tools, understand what problems they solve, and how their responsibilities should be divided
## [uv: The Python Speed Demon](https://docs.astral.sh/uv/)
`uv` is powerful Python package and project manager. Just like `pip` or similar package managers like `npm` in the JavaScript ecosystem, `uv`'s primary's job is making sure every dependency used in your project is properly resolved, locked, and installed into an isolated virtual environment at lightning speed. It strictly handles the *language-layer* of your project.
If your project relies on pure Python code, `uv` is practically all you need. However, the illusion breaks the moment your Python package require compiling C-extensions or linking against native system libraries (think `numpy`, `pyscopg2`, or `cryptography`).
To build these packages, `uv` assumes your operating system follows traditional Linux conventions. It blindly reaches into standard directories like `/usr/lib` or `usr/include`, expecting to find compilers, headers, and C-libraries waiting for it. On NixOS, those FHS directories essentially do not exists. As a result, `uv` hits a brick wall, throwing a massive compilation error simply because it cannot find the system-level components it needs.
This is exactly where we need to step down a layer and bring our next tool to bridge the gap.
## Nix devShell (`nix develop`)
Think of a **devShell** as a temporary, isolated workshop for your project.
Many system-level libraries `uv` often crash trying to find them in NixOS. Instead of cluttering your OS with global installs, a devShell quietly rewires your terminal's environment variables (like `PATH` and `LD_LIBRARY_PATH`) to point directly to the exact dependencies you need.
**The Result:** Seamless, crash-free installations that succeed perfectly every time—whether you're on NixOS, macOS, or Ubuntu.
*(Expanded [[devShells]] guide coming soon.)*
## [direnv](https://direnv.net/)
If devShell is your workshop, `direnv` could be an automated assistant, who makes sure the tools are ready to use the second you walk through the door.
`direnv` is a shell extension that keeps a watchful eye on your directories. The moment you `cd` into a project folder containing an `.envrc` file, it automatically loads—or unloads- your environment variables and shell settings.
That way, you don't need to `source .venv/bin/activate` or each time you enter your project.
## The Responsibility Matrix
|**Tool**|**Scope**|**Responsibilities**|
|---|---|---|
|**Nix devShell**|System / OS level|Providing Python interpreters, C compilers, system libraries (e.g., PostgreSQL client libs), and non-Python CLI tools (e.g., `jq`, `docker`).|
|**uv**|Python userland|Resolving and downloading Python packages (FastAPI, SQLAlchemy), writing the lockfile, and managing the local `.venv`.|
|**direnv**|Workflow / Shell level|Automating the activation of the `devShell` and exporting runtime secrets/environment variables (e.g., `DATABASE_URL`).|
## When does it become advantageous to introduce devShells?
If you're developing a pure-Python script that relies on standard libraries or pure-Python packages, you can survive on NixOS with just `uv` (assuming you have a globally installed Python interpreter).
However, introducing a `devShell` becomes **necessary** (not just advantageous), under the following conditions:
- **You require native C extensions:** The moment your FastAPI project interacts with databases using libraries like `psycopg` (PostgreSQL) or handles geospatial data (PostGIS), `uv` will attempt to build these from source or download manylinux wheels. On NixOS, dynamically linked manylinux wheels often fail to execute because the interpreter cannot find the required `.so` files. A `devShell` allows you to inject `stdenv.cc.cc.lib`, `zlib`, or `postgresql` directly into the environment's `LD_LIBRARY_PATH`.
- **You need reproducible system tools:** If your project requires a specific version of a database migration tool, a Node.js frontend build step, or a specific formatting tool, defining these in a `devShell` ensures any developer cloning the repository gets the exact same binaries.
- **You are collaborating across OS boundaries:** A `devShell` abstracts away the host operating system. A colleague on macOS or Ubuntu will get the same underlying system dependencies as you do on NixOS.
### Analyzing the Trade-offs
Choosing to implement this trifecta (`devShell` + `direnv` + `uv`) introduces specific trade-offs:
- **Complexity vs. Reproducibility:** * _Cost:_ You are introducing Nix syntax and flake evaluation into a Python project. Developers unfamiliar with Nix may struggle to update system dependencies.
- _Benefit:_ Absolute guarantee that the environment can be reproduced identically years from now.
- **Performance vs. Isolation:**
- _Cost:_ Evaluating a complex `flake.nix` takes time, though `nix-direnv` mitigates this heavily through caching.
- _Benefit:_ Total isolation. Your FastAPI project's dependencies will not bleed into or be corrupted by your host system's updates.
- **Maintenance Cost:** You now have two sources of truth for dependencies: `flake.nix` for system libraries and `pyproject.toml`/`uv.lock` for Python libraries. You must deliberately decide where a dependency belongs to avoid conflicts (e.g., do not install `ruff` via Nix if you are already managing it via `uv`).
---
## Should I use a devShell for BiteTrack
The project itself may require some PostgreSQL extension or package in the long run, but adding the complexity of a devShell now is overkill, a sensible approach is:
- **Keep using `direnv` now.**
- Introduce `devShell` later, when the environment itself becomes part of the project.
A good mental model is:
- **`.envrc`** answers: _"What environment variables should be available?"_
- **`devShell`** answers: _"What software must exist on this machine to work on this project?"_
Right now the project is simple enough that `direnv` is sufficient. Once we face a brick-wall fighting with installing specific versions of tools like `uv`, PostgreSQL clients, Ruff, Pyright, or other binaries, a `devShell` will become valuable because anyone entering the project gets the exact same toolchain.
+4 -4
View File
@@ -17,10 +17,10 @@
### Tasks
- [x] Configure workspace directories (`docs/`, `journal/`, `project/`)
- [x] Link main `todo.md` file to `~/todo.md`
- [ ] Initialize Python environment using `uv`
- [ ] Set up Ruff for linting and formatting
- [ ] Set up mypy for type checking
- [ ] Write `docker-compose.yml` defining a PostgreSQL service
- [x] Initialize Python environment using `uv`
- [x] Set up Ruff for linting and formatting
- [x] Set up Pyright for type checking
- [x] Write `docker-compose.yml` defining a PostgreSQL service
### Acceptance Tests
- [ ] Docker compose services launch successfully.