# Members App

Community member profiles and cross-platform identity management for Dexxy.

## Purpose

This app manages community members and their identities across multiple platforms. A key feature is identity stitching, which automatically links accounts from different platforms (GitHub, Slack, Discord, etc.) to create unified member profiles.

## Models

### Member

Represents a community member.

| Field | Type | Description |
|-------|------|-------------|
| `workspace` | ForeignKey | Workspace scope |
| `display_name` | CharField | Display name |
| `email` | EmailField | Email address (optional) |
| `avatar_url` | URLField | Profile picture URL (optional) |

### Identity

A platform-specific identity linked to a member.

| Field | Type | Description |
|-------|------|-------------|
| `member` | ForeignKey | The parent member |
| `provider` | CharField | Platform identifier |
| `provider_id` | CharField | User ID on the platform |
| `username` | CharField | Username on the platform |
| `profile_url` | URLField | Link to platform profile (optional) |
| `metadata` | JSONField | Additional platform-specific data |

**Supported Providers:**
- `github`
- `slack`
- `discord`
- `twitter`
- `linkedin`
- `mastodon`
- `discourse`

## Services

### `IdentityStitchingService`

Core service for managing member identities across platforms.

**Key Methods:**

- `find_or_create_member_for_identity(identity_data)` - Finds existing member or creates new one
- `match_by_email(email)` - Find members with matching email
- `match_by_handle(username)` - Find members with similar usernames across platforms
- `merge_members(primary, secondary)` - Combine duplicate member records
- `suggest_merges(workspace)` - Find potential duplicates with confidence scores

**Matching Strategy:**
1. Exact provider + provider_id match (100% confidence)
2. Email match across identities (90% confidence)
3. Similar username patterns (70% confidence)

## GraphQL API

### Queries

- `members(workspace_id)` - List all members in a workspace
- `member(id)` - Get a specific member
- `identities(member_id)` - Get all identities for a member

### Mutations

- `createMember(input)` - Create a new member
- `updateMember(id, input)` - Update member info
- `deleteMember(id)` - Delete a member
- `createIdentity(input)` - Link a new identity to a member
- `deleteIdentity(id)` - Remove an identity link

## Key Patterns

1. **Identity Stitching**: Automatic cross-platform identity linking
2. **Confidence Scoring**: Merge suggestions include confidence levels
3. **Provider Abstraction**: Same model handles all platforms
4. **Flexible Metadata**: JSON field for platform-specific data

## Dependencies

- `accounts.Workspace`
- Used by: `messages.Message` (author), `analytics.Event`, integrations

## File Structure

```
members/
├── models.py      # Member, Identity models
├── services.py    # IdentityStitchingService
├── graphql.py     # GraphQL types, queries, mutations
├── apps.py        # Django app config
└── migrations/    # Database migrations
```
