# onjin/runenv architecture

> Architecture diagram of the GitHub repository onjin/runenv, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/onjin/runenv
- Repository: https://github.com/onjin/runenv

## Overview

##### Main Components

a) Core Components:
- Environment File Parser
- CLI Interface
- Python API
- Environment Manager
- File System Interface

b) Integration Points:
- External Applications
- Python Web Frameworks
- Operating System Environment

**┌─ Application Layer ─────────────────────┐**
- External Apps / Web Frameworks          │
- ┬────────────────────┘
- ↓
**┌─ Interface Layer ─────────────────────────────────────┐**
- ┌─────────────┐            ┌──────────────┐          │
- CLI Tool   │            │  Python API  │          │
- ┬──────┘            └───────┬──────┘          │
- ┼───────────────────────────┼─────────────────┘

**┌────────▼───────────────────────────▼─────────────────┐**
- Core Processing Layer                                 │
- ┌─────────────────────┐    ┌────────────────────┐    │
- Environment Manager │◄──►│ Environment Parser  │    │
- ┘    └────────────────────┘    │
- ┬────────────────┘

**┌───────────────────────────────────▼────────────────┐**
- Storage Layer                                       │
- ┌──────────────┐    ┌───────────────────────────┐  │
- .env File  │◄──►│ Operating System ENV Vars │  │
- ┘    └───────────────────────────┘  │
- ┘

##### Component Details

a) Interface Layer:
- CLI Tool: Handles command-line operations (runenv command)
- Python API: Provides load_env and create_env functions

b) Core Processing:
- Environment Manager: Handles variable loading, prefixing, and stripping
- Environment Parser: Processes .env file syntax and variable interpolation

c) Storage Layer:
- File System Interface: Handles .env file reading
- OS Environment Interface: Manages system environment variables

##### Key Interactions to Highlight

- File search patterns (parent directory traversal)
- Variable prefix handling
- Environment variable interpolation
- Framework integration points

##### Implementation Details

- src/runenv/ as the core implementation
- tests/ for testing infrastructure
- Support for various .env file formats

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Application Layer"
        ExternalApps["External Applications"]
        WebFrameworks["Python Web Frameworks"]
    end

    subgraph "Interface Layer"
        CLI["CLI Tool"]
        API["Python API"]:::api
    end

    subgraph "Core Processing Layer"
        EnvManager["Environment Manager"]:::core
        EnvParser["Environment Parser"]:::core
    end

    subgraph "Storage Layer"
        EnvFile[".env Files"]:::storage
        OSEnv["OS Environment Variables"]:::storage
    end

    subgraph "Testing Infrastructure"
        TestSuite["Test Suite"]:::test
        EnvTests["Environment Tests"]:::test
        SearchTests["Search Tests"]:::test
    end

    %% Connections
    ExternalApps --> CLI
    WebFrameworks --> API
    CLI --> EnvManager
    API --> EnvManager
    EnvManager <--> EnvParser
    EnvParser --> EnvFile
    EnvParser --> OSEnv
    EnvManager --> OSEnv
    TestSuite --> EnvManager
    TestSuite --> EnvTests
    TestSuite --> SearchTests

    %% Click Events
    click API "https://github.com/onjin/runenv/blob/master/src/runenv/__init__.py"
    click EnvManager "https://github.com/onjin/runenv/blob/master/src/runenv/__init__.py"
    click TestSuite "https://github.com/onjin/runenv/blob/master/tests/test_runenv.py"
    click EnvTests "https://github.com/onjin/runenv/blob/master/tests/env.test"
    click SearchTests "https://github.com/onjin/runenv/tree/master/tests/search_parent/"

    %% Styling
    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef core fill:#4CAF50,stroke:#2E7D32,color:white
    classDef storage fill:#FFC107,stroke:#FFA000,color:black
    classDef test fill:#9C27B0,stroke:#6A1B9A,color:white

    %% Legend
    subgraph Legend
        L1["Interface Components"]:::api
        L2["Core Components"]:::core
        L3["Storage Components"]:::storage
        L4["Testing Components"]:::test
    end
```
