# `Bylaw.Credo.Check.Ecto.OwnContextForSchema`
[🔗](https://github.com/ryanzidago/bylaw/blob/v0.1.0-alpha.1/lib/bylaw/credo/check/ecto/own_context_for_schema.ex#L1)

## Basics

> #### This check is disabled by default. {: .neutral}
>
> [Learn how to enable it](`e:credo:config_file.html#checks`) via `.credo.exs`.

This check has a base priority of `higher` and works with any version of Elixir.

## Explanation

Each Ecto schema using a configured schema wrapper should live under its own dedicated context module.

## Examples

Configure the schema wrapper modules that identify application schemas:

```elixir
{Bylaw.Credo.Check.Ecto.OwnContextForSchema,
 [
   schema_modules: [MyApp.Schema]
 ]}
```

Avoid:
`ToolCall` is nested under the `Runs` context:

      defmodule MyApp.Runs.ToolCall do
        use MyApp.Schema
      end

Prefer:
`ToolCall` has its own context:

      defmodule MyApp.ToolCalls.ToolCall do
        use MyApp.Schema
      end

## Notes

Keeping one schema per context ensures that context modules stay small
and focused. When a schema is nested under another schema's context
(e.g. `MyApp.Runs.ToolCall`), the context tends to accumulate
unrelated responsibilities.

This check uses static AST analysis, so it favors clear source-level patterns over runtime behavior.

## Options

Configure options in `.credo.exs` with the check tuple:

```elixir
%{
  configs: [
    %{
      name: "default",
      checks: [
        {Bylaw.Credo.Check.Ecto.OwnContextForSchema,
         [
           schema_modules: [MyApp.Schema],
           excluded_modules: ["MyApp.Legacy.LegacySchema"]
         ]}
      ]
    }
  ]
}
```

- `:schema_modules` - Schema wrapper modules that identify application schemas to check.
- `:excluded_modules` - List of fully qualified module names (as strings) to exclude from this check.

## Usage

Add this check to Credo's `checks:` list in `.credo.exs`:

```elixir
%{
  configs: [
    %{
      name: "default",
      checks: [
        {Bylaw.Credo.Check.Ecto.OwnContextForSchema,
         [
           schema_modules: [MyApp.Schema]
         ]}
      ]
    }
  ]
}
```

## Check-Specific Parameters

Use the following parameters to configure this check:

### `:schema_modules`

  Schema wrapper modules that identify application schemas to check.

*This parameter defaults to* `[]`.

### `:excluded_modules`

  List of fully qualified module names (as strings) to exclude from this check.

*This parameter defaults to* `[]`.

## General Parameters

Like with all checks, [general params](`e:credo:check_params.html`) can be applied.

Parameters can be configured via the [`.credo.exs` config file](`e:credo:config_file.html`).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
