# reagento/dishka architecture

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

- Interactive diagram: https://gitdiagram.com/reagento/dishka
- Repository: https://github.com/reagento/dishka

## Overview

##### Project Type and Purpose
- Dishka is a standalone DI framework for Python. Its goal is to manage object lifecycles, resolve dependencies via providers, and integrate seamlessly with several popular frameworks.
- The README emphasizes key features like scopes, finalization, modular providers, and integrations. The purpose is to offer clean, fast, and modular dependency injection to avoid boilerplate like global variables or manual dependency passing.

##### Core Components
a. DI Container:
- Central container that manages dependency lifecycles and caching.
- Elements like the container’s ability to enter and exit different scopes (APP, REQUEST, etc.).
b. Providers:
- That providers can be functions, classes, or methods (using the @provide decorator) and can also manage “finalization” (object release).
c. Dependency Entities:
- Objects described by type hints, including components like Service, DAO, and various other dependency markers.
- How “entities” (e.g. depends_marker, provides_marker) play a role in the resolution process.
d. Scopes:
- How different scopes (APP, REQUEST, etc.) are managed for object lifetimes.
e. Framework Integrations:
- Out the integration modules (for example, for fastapi, flask, aiogram, aiohttp, grpcio, etc.) to show Dishka’s extensibility.
- Each integration module interfaces with the DI container, allowing DI to easily plug into external systems.
f. Plotter and Visualization:
g. Testing & Examples:

##### Relationships and Data Flows
- Document the role of “Scopes” by showing that the container’s operation is filtered by the scope lifecycle (entering/exiting contexts tied to APP, REQUEST, etc.).
- Integrations as distinct external modules or blocks that communicate with the core container, receiving dependencies through decorators or direct lookups.

##### Architectural Patterns and Design Principles
- Use of inversion of control (IoC) – where object creation is decoupled from business logic.
- Modularity: Providers are independent and can be composed into components, as well as integration modules being individually pluggable.
- Design principle of “scoping” for dependency lifetimes to control caching and finalization.

##### Technologies, Frameworks, and Libraries
- Python artifacts like type hints, decorators, and protocols fed into the dependency resolution.
- That Dishka is built around pure Python constructs but offers integrations with many frameworks (like FastAPI, Flask, gRPC, etc.), which are clearly visible in the integrations directories.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Core DI Components"
        subgraph "DI Container"
            DS["Container (Sync)"]:::containerStyle
            DA["Container (Async)"]:::containerStyle
        end
        PRO["Providers"]:::providerStyle
        ENT["Dependency Entities"]:::entityStyle
        SCO["Scopes"]:::scopeStyle
        SCO_DOC["Scopes Documentation"]:::scopeStyle
    end

    subgraph "Integrations and Visualization"
        INT["Framework Integrations"]:::integrationStyle
        PLOT["Plotter & Visualization"]:::plotterStyle
    end

    TEST["Testing & Examples"]:::testStyle

    DS -->|"uses"| PRO
    DA -->|"uses"| PRO
    PRO -->|"creates"| ENT
    DS -->|"manages"| SCO
    DA -->|"manages"| SCO
    SCO -->|"docs"| SCO_DOC

    DS -->|"integrates"| INT
    DA -->|"integrates"| INT

    DS -.->|"documents"| PLOT
    DA -.->|"documents"| PLOT

    PRO -.->|"tested_by"| TEST
    INT -.->|"validated_by"| TEST

    click DS "https://github.com/reagento/dishka/blob/develop/src/dishka/container.py"
    click DA "https://github.com/reagento/dishka/blob/develop/src/dishka/async_container.py"
    click PRO "https://github.com/reagento/dishka/tree/develop/src/dishka/provider/"
    click ENT "https://github.com/reagento/dishka/tree/develop/src/dishka/entities/"
    click SCO "https://github.com/reagento/dishka/blob/develop/src/dishka/entities/scope.py"
    click SCO_DOC "https://github.com/reagento/dishka/blob/develop/docs/advanced/scopes.rst"
    click INT "https://github.com/reagento/dishka/tree/develop/src/dishka/integrations/"
    click PLOT "https://github.com/reagento/dishka/tree/develop/src/dishka/plotter/"
    click TEST "https://github.com/reagento/dishka/tree/develop/examples/"

    classDef containerStyle fill:#ADD8E6,stroke:#000,stroke-width:2px
    classDef providerStyle fill:#90EE90,stroke:#000,stroke-width:2px
    classDef entityStyle fill:#FFFACD,stroke:#000,stroke-width:2px
    classDef scopeStyle fill:#FFB6C1,stroke:#000,stroke-width:2px
    classDef integrationStyle fill:#D3D3D3,stroke:#000,stroke-width:2px
    classDef plotterStyle fill:#FFDAB9,stroke:#000,stroke-width:2px
    classDef testStyle fill:#E6E6FA,stroke:#000,stroke-width:2px
```
