# AppDbContextFactory

- File ID: file:1h2hpbe:appdbcontextfactory-cs
- Path: NexusReader.Data/Persistence/AppDbContextFactory.cs
- Role: unknown
- Layer: unknown

## Purpose

Design-time EF Core DbContext factory: locates solution/web project, builds configuration, resolves a Postgres connection (with fallback), configures DbContextOptions (including pgvector) and returns an AppDbContext for design-time tooling (migrations, scaffolding).

## Key Details

Searches upward for NexusReader.slnx to locate Web project's appsettings, supports environment-specific appsettings, falls back to a hard-coded Postgres connection for design-time scenarios, and enables pgvector via UseVector().

## Symbols

- AppDbContextFactory: Design-time EF Core DbContext factory: locates solution/web project, builds configuration, resolves a Postgres connection (with fallback), configures DbContextOptions (including pgvector) and returns an AppDbContext for design-time tooling (migrations, scaffolding).
- CreateDbContext(): Creates and configures an AppDbContext for design-time use by reading environment, locating the Web project for configuration files, resolving a connection string (with fallback), applying Npgsql + pgvector options, and returning the context.
- AppDbContextFactory: Design-time factory to create AppDbContext instances for EF Core tooling.

## Dependencies

- imports NexusReader.Data/Persistence/AppDbContext.cs

## Calls

- No resolved calls.

## Unresolved References

- call-target: NexusReader.Data/Persistence/AppDbContext.cs

## Coverage

- Symbols: 3
- Executable symbols: 1
- Executable symbols with control flow: 1
- Grounded edges: 4
- Unresolved references: 1
- Control-flow fragments: 1
- Unresolved jumps: 1
- Unsupported constructs: 0
- Control-flow coverage: 100%
- Required diagrams: 2
- Generated diagrams: 3

## Control Flow Fragments

- CreateDbContext: 27 nodes, 31 edges, 1 jumps, 0 unsupported constructs

## Diagrams

### AppDbContextFactory Neighborhood

```mermaid
flowchart LR
    class_1g09xpu_appdbcontextfactory("AppDbContextFactory")
    file_1h2hpbe_appdbcontextfactory_cs("AppDbContextFactory")
    method_nwogow_createdbcontext[["CreateDbContext()"]]
    file_1pacvtg_appdbcontext_cs[/"AppDbContext"/]
    type_1tyno9s_appdbcontextfactory[/"AppDbContextFactory"/]
    file_1h2hpbe_appdbcontextfactory_cs -->|AppDbContext| file_1pacvtg_appdbcontext_cs
```

### AppDbContextFactory Execution Overview

```mermaid
flowchart TD
    class_1g09xpu_appdbcontextfactory("AppDbContextFactory")
    method_nwogow_createdbcontext[["CreateDbContext()"]]
    unresolved_unresolved_1tf41qv_call_target{"Unresolved: AppDbContext..ctor"}
    class_1g09xpu_appdbcontextfactory -->|contains| method_nwogow_createdbcontext
    method_nwogow_createdbcontext -->|unresolved call| unresolved_unresolved_1tf41qv_call_target
```

### CreateDbContext() Control Flow

_Warnings: diagram method_nwogow_createdbcontext__fragment_diagram exceeds preferred complexity thresholds (27 nodes, 31 edges)._

```mermaid
---
config:
  flowchart:
    defaultRenderer: "elk"
---
flowchart TD
    method_nwogow_createdbcontext__call_43_AppDbContext_ctor[["AppDbContext..ctor"]]
    method_nwogow_createdbcontext__action_12_env_read_12__linear("Read ASPNETCORE_ENVIRONMENT")
    method_nwogow_createdbcontext__action_15_loop_15__loop_body[["while (currentDir != null && !File.Exists(Path.Combine(currentDir.FullName, \\"NexusReader.slnx\\"))) currentDir = currentDir.Parent;"]]
    method_nwogow_createdbcontext__action_15_loop_15__loop_entry("Walk up directories to find solution file")
    method_nwogow_createdbcontext__action_15_loop_15__loop_exit("exit loop")
    method_nwogow_createdbcontext__action_16_createdbcontext_loop_16_0__loop_body[["while (currentDir != null && !File.Exists(Path.Combine(currentDir.FullName, \\"NexusReader.slnx\\")))"]]
    method_nwogow_createdbcontext__action_16_createdbcontext_loop_16_0__loop_entry("currentDir != null && !File.Exists(Path.Combine(currentDir.FullName, \\"NexusReader.slnx\\"))")
    method_nwogow_createdbcontext__action_16_createdbcontext_loop_16_0__loop_exit("Leaves the loop when the condition no longer holds.")
    method_nwogow_createdbcontext__action_21_branch_21__condition{"currentDir != null"}
    method_nwogow_createdbcontext__action_21_branch_21__false("use current working directory")
    method_nwogow_createdbcontext__action_21_branch_21__merge("merge")
    method_nwogow_createdbcontext__action_21_branch_21__true("use src/NexusReader.Web")
    method_nwogow_createdbcontext__action_25_config_build_25__linear("Build configuration from appsettings and environment")
    method_nwogow_createdbcontext__action_33_call_33__linear("Get connection string")
    method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__condition{"string.IsNullOrEmpty(connectionString)"}
    method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__false("false")
    method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__merge("merge")
    method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__true("true")
    method_nwogow_createdbcontext__action_35_guard_clause_35__condition{"string.IsNullOrEmpty(connectionString)"}
    method_nwogow_createdbcontext__action_35_guard_clause_35__false("keep discovered connection")
    method_nwogow_createdbcontext__action_35_guard_clause_35__merge("merge")
    method_nwogow_createdbcontext__action_35_guard_clause_35__true("assign default Postgres connection")
    method_nwogow_createdbcontext__action_41_persistence_config_41__linear("Configure Npgsql with pgvector")
    method_nwogow_createdbcontext__entry(["CreateDbContext entry"])
    method_nwogow_createdbcontext__action_43_createdbcontext_return_43_2__return(["Returns result"])
    method_nwogow_createdbcontext__action_43_return_43__return(["Return configured DbContext"])
    method_nwogow_createdbcontext__implicit_return(["return"])
    method_nwogow_createdbcontext__action_12_env_read_12__linear -->|next| method_nwogow_createdbcontext__action_15_loop_15__loop_entry
    method_nwogow_createdbcontext__action_15_loop_15__loop_body -->|continue| method_nwogow_createdbcontext__action_15_loop_15__loop_entry
    method_nwogow_createdbcontext__action_15_loop_15__loop_entry -->|iterate| method_nwogow_createdbcontext__action_15_loop_15__loop_body
    method_nwogow_createdbcontext__action_15_loop_15__loop_entry -->|exit| method_nwogow_createdbcontext__action_15_loop_15__loop_exit
    method_nwogow_createdbcontext__action_15_loop_15__loop_exit -->|next| method_nwogow_createdbcontext__action_16_createdbcontext_loop_16_0__loop_entry
    method_nwogow_createdbcontext__action_16_createdbcontext_loop_16_0__loop_body -->|continue| method_nwogow_createdbcontext__action_16_createdbcontext_loop_16_0__loop_entry
    method_nwogow_createdbcontext__action_16_createdbcontext_loop_16_0__loop_entry -->|transforms input| method_nwogow_createdbcontext__action_16_createdbcontext_loop_16_0__loop_body
    method_nwogow_createdbcontext__action_16_createdbcontext_loop_16_0__loop_entry -->|Leaves the loop when the condition no longer holds.| method_nwogow_createdbcontext__action_16_createdbcontext_loop_16_0__loop_exit
    method_nwogow_createdbcontext__action_16_createdbcontext_loop_16_0__loop_exit -->|next| method_nwogow_createdbcontext__action_21_branch_21__condition
    method_nwogow_createdbcontext__action_21_branch_21__condition -->|use current working directory| method_nwogow_createdbcontext__action_21_branch_21__false
    method_nwogow_createdbcontext__action_21_branch_21__condition -->|use src / NexusReader.Web| method_nwogow_createdbcontext__action_21_branch_21__true
    method_nwogow_createdbcontext__action_21_branch_21__false -->|next| method_nwogow_createdbcontext__action_21_branch_21__merge
    method_nwogow_createdbcontext__action_21_branch_21__merge -->|next| method_nwogow_createdbcontext__action_25_config_build_25__linear
    method_nwogow_createdbcontext__action_21_branch_21__true -->|next| method_nwogow_createdbcontext__action_21_branch_21__merge
    method_nwogow_createdbcontext__action_25_config_build_25__linear -->|next| method_nwogow_createdbcontext__action_33_call_33__linear
    method_nwogow_createdbcontext__action_33_call_33__linear -->|next| method_nwogow_createdbcontext__action_35_guard_clause_35__condition
    method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__condition -->|false| method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__false
    method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__condition -->|true| method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__true
    method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__false -->|next| method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__merge
    method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__merge -->|next| method_nwogow_createdbcontext__action_41_persistence_config_41__linear
    method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__true -->|next| method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__merge
    method_nwogow_createdbcontext__action_35_guard_clause_35__condition -->|keep discovered connection| method_nwogow_createdbcontext__action_35_guard_clause_35__false
    method_nwogow_createdbcontext__action_35_guard_clause_35__condition -->|assign default Postgres connection| method_nwogow_createdbcontext__action_35_guard_clause_35__true
    method_nwogow_createdbcontext__action_35_guard_clause_35__false -->|next| method_nwogow_createdbcontext__action_35_guard_clause_35__merge
    method_nwogow_createdbcontext__action_35_guard_clause_35__merge -->|next| method_nwogow_createdbcontext__action_35_createdbcontext_branch_35_1__condition
    method_nwogow_createdbcontext__action_35_guard_clause_35__true -->|next| method_nwogow_createdbcontext__action_35_guard_clause_35__merge
    method_nwogow_createdbcontext__action_41_persistence_config_41__linear -->|return| method_nwogow_createdbcontext__action_43_createdbcontext_return_43_2__return
    method_nwogow_createdbcontext__action_43_createdbcontext_return_43_2__return -->|return| method_nwogow_createdbcontext__action_43_return_43__return
    method_nwogow_createdbcontext__action_43_return_43__return -->|optionsBuilder.Options DbContextOptions AppDbContext>| method_nwogow_createdbcontext__call_43_AppDbContext_ctor
    method_nwogow_createdbcontext__call_43_AppDbContext_ctor -->|return| method_nwogow_createdbcontext__implicit_return
    method_nwogow_createdbcontext__entry -->|next| method_nwogow_createdbcontext__action_12_env_read_12__linear
```

## Diagram Validation

- Status: warn
- Warning: Control-flow extraction left 1 unresolved jumps.
- Warning: control-flow: diagram method_nwogow_createdbcontext__fragment_diagram exceeds preferred complexity thresholds (27 nodes, 31 edges).
