# Sources App

Data source definitions for Dexxy.

## Purpose

This app defines the abstraction layer for external data sources. A Source represents a channel, repository, or stream from which Dexxy ingests content. Sources provide a unified interface regardless of the underlying platform.

## Models

### Source

Represents a data source from any supported platform.

| Field | Type | Description |
|-------|------|-------------|
| `workspace` | ForeignKey | Workspace scope |
| `kind` | CharField | Source type |
| `name` | CharField | Display name |
| `external_id` | CharField | ID in the source platform |
| `metadata` | JSONField | Platform-specific configuration |

**Source Kinds:**
- `slack_channel` - Slack channel
- `discord_channel` - Discord channel
- `github_repo` - GitHub repository
- `discourse_category` - Discourse forum category
- `twitter_stream` - Twitter/X stream

## GraphQL API

### Queries

- `sources(workspace_id)` - List all sources in a workspace
- `source(id)` - Get a specific source

### Mutations

- `createSource(input)` - Create a new source
- `updateSource(id, input)` - Update source details
- `deleteSource(id)` - Delete a source

## Key Patterns

1. **Platform Abstraction**: Common interface for all platforms
2. **External ID Mapping**: Links to original platform resource
3. **Flexible Metadata**: JSON field for platform-specific config

## Usage Examples

```python
from sources.models import Source

# Create a GitHub repo source
github_source = Source.objects.create(
    workspace=workspace,
    kind="github_repo",
    name="myorg/myrepo",
    external_id="12345678",
    metadata={
        "owner": "myorg",
        "repo": "myrepo",
        "default_branch": "main"
    }
)

# Create a Slack channel source
slack_source = Source.objects.create(
    workspace=workspace,
    kind="slack_channel",
    name="#general",
    external_id="C0123456789",
    metadata={
        "team_id": "T0123456789",
        "is_private": False
    }
)
```

## Relationship to Other Apps

```
Source
├── Threads (messages app)
│   └── Messages
└── Integration Models
    └── GitHubRepository (integrations app)
```

Sources are the bridge between integrations and content. When an integration syncs data, it creates/updates Threads linked to a Source.

## Dependencies

- `accounts.Workspace`
- Used by: `messages.Thread`, `integrations.GitHubRepository`

## File Structure

```
sources/
├── models.py      # Source model
├── graphql.py     # GraphQL types, queries, mutations
├── apps.py        # Django app config
└── migrations/    # Database migrations
```
