# farishloy/react-native-controlled-mentions architecture

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

- Interactive diagram: https://gitdiagram.com/farishloy/react-native-controlled-mentions
- Repository: https://github.com/farishloy/react-native-controlled-mentions

## Overview

##### Project Type and Purpose
- This is a React Native component library (“react-native-controlled-mentions”) that provides a fully controlled mention input for RN’s TextInput.
- It is not a full-stack app but an open-source UI toolkit with parsing utilities (mentions, hashtags, custom patterns) and an example/demo app.

##### File Structure Analysis
- Top level
- package.json, tsconfig.json, README.md, LICENSE, CHANGELOG.md
- example/mentions-app.tsx – a standalone RN example demonstrating usage
- src/ – core implementation
- tests/ – unit tests for utilities
- src/
- components/ – React components (index.ts exports, mention-input.tsx is the heart of the library)
- utils/ – pure functions (e.g. recursive parser, replaceMentionValues, mentionRegEx)
- types/ – TypeScript type definitions for PartType, Suggestion, MentionData, API props
- index.ts – library entrypoint (exports components, utils, types)
- tests/
- utils.test.ts – validates parsing utilities
- No backend or external services; publishing to npm is the only “deployment.”

##### Key Architectural Patterns
- Separation of concerns: UI components (in components/) are completely decoupled from parsing logic (in utils/) and from type definitions (in types/).
- Fully controlled component pattern: passing value/onChange from parent, leveraging React hooks inside MentionInput.
- Plugin-style partTypes array: extensibility point for multiple mention or pattern types.

##### Main Components
- Consumer App (example or any RN app)
- Renders MentionInput, provides `value` and `onChange`, supplies `partTypes`
- MentionInput (UI Layer)
- Renders RN TextInput under the hood
- Accepts props: value, onChange, partTypes, styling, etc.
- On each keystroke invokes parsing utilities to detect triggers and maintain cursor position
- Calls renderSuggestions callback when needed
- Part Types & Suggestions Renderer (Extension Points)
- MentionPartType: defines trigger (@, #), style, renderSuggestions callback
- PatternPartType: defines regex for custom patterns (URLs, hashtags)
- Parsing Utilities (Business Logic Layer)
- mentionRegEx – core regex for extracting mentions
- replaceMentionValues – transforms mention syntax to plain text or other format
- parseValue – splits a string into parts array of text vs mention vs pattern
- Types Module
- Central definitions for Suggestion, MentionData, PartType, MentionSuggestionsProps
- Tests
- Unit tests for utils; ensure parsing correctness
- Example App
- Illustrates integration of all above; consumes library via local import (or npm)

##### Relationships and Data Flow
- Consumer App → (value,onChange,partTypes) → MentionInput
- MentionInput → Parsing Utilities → parts & suggestions
- MentionInput → renderSuggestions callback → Suggestions UI
- User Interaction (typing, selecting suggestion) → onSuggestionPress → MentionInput → onChange → Consumer App
- Consumer App may call utils (replaceMentionValues or parseValue) to process final string for storage or rendering

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Example App
  subgraph "Example App"
    Example["Consumer App / Example App"]:::example
  end

  %% Component Library
  subgraph "Component Library"
    entry["Library Entry Point"]:::logic

    subgraph "UI Components"
      Barrel["Components Barrel Export"]:::ui
      MentionInput["MentionInput Component"]:::ui
    end

    subgraph "Business Logic / Utilities"
      UtilsIndex["Utils Index"]:::logic
      Utils["Parsing Utilities"]:::logic
    end

    subgraph "Type Definitions"
      TypesIndex["Types Index"]:::types
      Types["Types Module"]:::types
    end
  end

  %% Tests
  subgraph "Tests"
    Tests["Unit Tests for Utilities"]:::tests
  end

  %% Configuration Files
  subgraph "Config & Metadata"
    Package["package.json"]:::config
    TS["tsconfig.json"]:::config
    Readme["README.md"]:::config
    Changelog["CHANGELOG.md"]:::config
    License["LICENSE"]:::config
  end

  %% Relationships
  Example -->|imports| entry
  entry -->|exports| Barrel
  entry -->|exports| UtilsIndex
  entry -->|exports| TypesIndex

  Barrel --> MentionInput
  Example -->|provides props| MentionInput
  MentionInput -->|invokes parseValue| UtilsIndex
  UtilsIndex -->|calls utils.ts| Utils
  Utils -->|returns parts array| MentionInput
  MentionInput -->|"value,onChange"| Example
  MentionInput -->|renderSuggestions callback| Example
  MentionInput -->|uses types| TypesIndex
  Tests -.->|validates| UtilsIndex

  %% Click Events
  click Example "https://github.com/farishloy/react-native-controlled-mentions/blob/master/example/mentions-app.tsx"
  click entry "https://github.com/farishloy/react-native-controlled-mentions/blob/master/src/index.ts"
  click MentionInput "https://github.com/farishloy/react-native-controlled-mentions/blob/master/src/components/mention-input.tsx"
  click Barrel "https://github.com/farishloy/react-native-controlled-mentions/blob/master/src/components/index.ts"
  click UtilsIndex "https://github.com/farishloy/react-native-controlled-mentions/blob/master/src/utils/index.ts"
  click Utils "https://github.com/farishloy/react-native-controlled-mentions/blob/master/src/utils/utils.ts"
  click TypesIndex "https://github.com/farishloy/react-native-controlled-mentions/blob/master/src/types/index.ts"
  click Types "https://github.com/farishloy/react-native-controlled-mentions/blob/master/src/types/types.ts"
  click Tests "https://github.com/farishloy/react-native-controlled-mentions/blob/master/tests/utils.test.ts"
  click Package "https://github.com/farishloy/react-native-controlled-mentions/blob/master/package.json"
  click TS "https://github.com/farishloy/react-native-controlled-mentions/blob/master/tsconfig.json"
  click Readme "https://github.com/farishloy/react-native-controlled-mentions/blob/master/README.md"
  click Changelog "https://github.com/farishloy/react-native-controlled-mentions/blob/master/CHANGELOG.md"
  click License "https://github.com/farishloy/react-native-controlled-mentions/tree/master/LICENSE"

  %% Styles
  classDef ui fill:#D0E8FF,stroke:#004A8F,color:#004A8F
  classDef logic fill:#DFF5D0,stroke:#4A8F00,color:#4A8F00
  classDef types fill:#FFF5D0,stroke:#8F6F00,color:#8F6F00
  classDef tests fill:#EEEEEE,stroke:#888888,color:#555555,stroke-dasharray: 5 5
  classDef example fill:#FFE5D0,stroke:#8F3C00,color:#8F3C00
  classDef config fill:#F0E0FF,stroke:#6F008F,color:#6F008F
```
