# Scopes: Project vs Global

## The Problem

Command line tools typically operate in one of two modes:
1.  **Global**: Like a centralized database (e.g., standard notes apps).
2.  **Local**: Only in the current folder (e.g., `git`).

For a developer-focused note tool, neither is sufficient. You want context-aware notes ("TODOs for *this* project") but occasionally need global notes ("Grocery list") without leaving your terminal. Furthermore, in nested repository structures (monorepos), "Local" is ambiguous.

## The Solution: Heuristic Scope Detection

Padz implements a git-aware scope detection algorithm to robustly identify the "Project Root".

### 1. The Scopes
-   **Project**: Bound to a specific code repository. Data lives in `<repo_root>/.padz/`.
-   **Global**: Bound to the user. Data lives in the OS-appropriate data directory (via `directories` crate).

### 2. Detection Logic

-   **Location**: `src/padz/init.rs` — function `find_project_root`
-   **Algorithm**:
    1.  Start at `CWD` (Current Working Directory).
    2.  Check for **Evidence**: Does this directory have BOTH `.git` AND `.padz`?
    3.  **Match**: If yes, this is the Project Root.
    4.  **No Match**: Move to parent directory.
    5.  **Stop**: If we reach `HOME` or filesystem root, return `None`.

**Why require both `.git` AND `.padz`?**
This dual-check is the strictness filter:
-   If we only checked `.git`: We might accidentally use a parent repo (e.g., when working in a sub-repo inside a monorepo).
-   If we only checked `.padz`: We lose the semantic binding to the "Project" concept.

The result is that you must explicitly `padz init` in a repo to opt-in to project scope. This prevents accidental pollution of parent directories.

### 3. Scope Resolution Flow

The scope is resolved during `padz::init::initialize`:
1.  If `-g` flag is present → Force `Scope::Global`.
2.  Otherwise → Run `find_project_root(cwd)`.
    -   Found → `Scope::Project`.
    -   Not Found → `Scope::Project` with `cwd/.padz` as path (may need `init`).

### 4. Nested Repositories

When working in nested repos (e.g., `parent-repo/child-repo`):
- If only `parent-repo` has `.padz`, starting from `child-repo` will find and use `parent-repo`
- If both have `.padz`, the innermost one (closest to cwd) wins
- If neither has `.padz`, scope resolution returns `None` and uses `cwd/.padz` as default
