# basecamp/name_of_person architecture

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

- Interactive diagram: https://gitdiagram.com/basecamp/name_of_person
- Repository: https://github.com/basecamp/name_of_person

## Overview

##### Project type and purpose
- This is an open-source Ruby gem named “name_of_person” that provides a simple name-parsing and formatting library.
- Its primary purpose is to let any Ruby (especially Rails) application easily attach a unified “name” object to models that have first_name and last_name attributes, and then call presentation methods (full, initials, abbreviated, possessive, sorted, mentionable, etc.).

##### File structure
- Top-level files:
- Gemfile/Gemfile.lock, name_of_person.gemspec, MIT-LICENSE, README.md, Rakefile – standard Ruby gem packaging, dependencies and tasks.
- lib/name_of_person:
- assignable_name.rb – mix-in that defines attribute-assignment logic.
- has_person_name.rb – module to include in models (e.g., ActiveRecord or ActiveModel classes) to wire up the name behavior.
- loaders/active_model_has_person_name.rb & active_record_has_person_name.rb – adapters that detect “has_person_name” inclusion in a model and hook into the correct lifecycle callbacks.
- person_name.rb – core class that encapsulates a name string, parses it, and provides formatting methods.
- test directory:
- unit tests for AssignableName, HasPersonName, PersonName ensuring core behaviors work as expected.

##### README for additional insights
- Describes usage in a Rails ApplicationRecord subclass (activerecord adapter).
- Explains how to require ActiveRecord and/or ActiveModel when used outside of Rails.
- Lists all name-formatting features.
- States the gem is frozen (no further development planned) but can be forked.

##### Detail is key
- Minimal coupling to external frameworks (ActiveModel/Record) to highlight the gem’s extensibility.
- Test suite to document coverage of core vs. integration behavior (optional but useful for maintainers).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Host Application
    subgraph "Host Application"
        PersonModel["Person Model\n(first_name, last_name)"]:::host
    end

    %% Gem Namespace
    subgraph "name_of_person gem"
        Entrypoint["lib/name_of_person.rb"]:::gem
        HasPersonName["HasPersonName"]:::mixin
        AssignableName["AssignableName"]:::mixin
        subgraph "Adapters"
            ActiveModelLoader["ActiveModelHasPersonName"]:::adapter
            ActiveRecordLoader["ActiveRecordHasPersonName"]:::adapter
        end
        PersonName["PersonName"]:::core
        Gemspec["name_of_person.gemspec"]:::gem
    end

    %% External Dependencies
    ActiveModel["ActiveModel"]:::external
    ActiveRecord["ActiveRecord"]:::external

    %% Tests
    subgraph "Test Suite"
        ANTest["test/assignable_name_test.rb"]:::test
        HPTest["test/has_person_name_test.rb"]:::test
        PNTest["test/person_name_test.rb"]:::test
    end

    %% Relationships
    PersonModel -->|"has_person_name"| HasPersonName
    Entrypoint -->|requires| HasPersonName
    Entrypoint -->|requires| AssignableName
    Entrypoint -->|requires| ActiveModelLoader
    Entrypoint -->|requires| ActiveRecordLoader
    Entrypoint -->|requires| PersonName
    Entrypoint -->|gemspec| Gemspec

    HasPersonName -->|includes mix-in| AssignableName
    HasPersonName -->|selects loader| ActiveModelLoader
    HasPersonName -->|selects loader| ActiveRecordLoader
    HasPersonName -->|instantiates| PersonName
    AssignableName -->|intercepts assignment| PersonName

    ActiveModelLoader -->|hooks into| ActiveModel
    ActiveRecordLoader -->|hooks into| ActiveRecord

    ANTest -->|tests| AssignableName
    HPTest -->|tests| HasPersonName
    PNTest -->|tests| PersonName

    %% Click Events
    click AssignableName "https://github.com/basecamp/name_of_person/blob/master/lib/name_of_person/assignable_name.rb"
    click HasPersonName "https://github.com/basecamp/name_of_person/blob/master/lib/name_of_person/has_person_name.rb"
    click ActiveModelLoader "https://github.com/basecamp/name_of_person/blob/master/lib/name_of_person/loaders/active_model_has_person_name.rb"
    click ActiveRecordLoader "https://github.com/basecamp/name_of_person/blob/master/lib/name_of_person/loaders/active_record_has_person_name.rb"
    click PersonName "https://github.com/basecamp/name_of_person/blob/master/lib/name_of_person/person_name.rb"
    click Entrypoint "https://github.com/basecamp/name_of_person/blob/master/lib/name_of_person.rb"
    click Gemspec "https://github.com/basecamp/name_of_person/blob/master/name_of_person.gemspec"
    click ANTest "https://github.com/basecamp/name_of_person/blob/master/test/assignable_name_test.rb"
    click HPTest "https://github.com/basecamp/name_of_person/blob/master/test/has_person_name_test.rb"
    click PNTest "https://github.com/basecamp/name_of_person/blob/master/test/person_name_test.rb"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef adapter fill:#90EE90,stroke:#000,stroke-width:1px
    classDef mixin fill:#FFA500,stroke:#000,stroke-width:1px
    classDef host fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef external fill:#FFC0CB,stroke:#000,stroke-width:1px
    classDef gem fill:#F0E68C,stroke:#000,stroke-width:1px
    classDef test fill:#DDA0DD,stroke:#000,stroke-width:1px
```
