README.md

# PrivateModule

[![Hex.pm](https://img.shields.io/hexpm/v/private_module.svg)](https://hex.pm/packages/private_module)
[![Documentation](https://img.shields.io/badge/documentation-hexdocs-blue.svg)](https://hexdocs.pm/private_module)

PrivateModule is an Elixir library that introduces the concept of private modules - modules that can only be used within their parent module. This helps enforce encapsulation and prevents external access to internal implementation details.

## Installation

Add `private_module` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:private_module, "~> 0.1.0", runtime: false}
  ]
end
```

Then add the `:private_module` compiler to your project configuration:

```elixir
def project do
  [
    # ... other configuration
    compilers: [:private_module] ++ Mix.compilers(),
    # ... other configuration
  ]
end
```

## Usage

To mark a module as private, simply `use PrivateModule`:

```elixir
defmodule MyApp.UserService do
  def create_user(params) do
    validated_params = Validator.validate(params)
    # ... implementation
  end

  defmodule Validator do
    use PrivateModule

    def validate(params) do
      # Private validation logic
      params
    end
  end
end
```

In this example:
- ✅ `MyApp.UserService` can call `MyApp.UserService.Validator.validate/1`
- ❌ Any other module (like `MyApp.AccountService`) cannot call `MyApp.UserService.Validator.validate/1`

## Error Messages

When a privacy violation is detected, you'll see a clear error message:

```
error: Module MyApp.SomeOtherModule is not allowed to call private module MyApp.UserService.Validator
 at lib/my_app/some_other_module.ex:15
```

## Development

To set up the development environment:

```bash
git clone https://github.com/bit4bit/private_module.git
cd private_module
mix deps.get
mix test
```

### Running Tests

```bash
mix test
```

### Code Quality

```bash
mix credo
mix dialyzer
```

## Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass
6. Submit a pull request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.