156 lines
3.3 KiB
Markdown
156 lines
3.3 KiB
Markdown
### Data Model
|
|
|
|
# <!-- Title and ID, e.g., #[DM-001] User Account Data Model -->
|
|
|
|
Version: <!-- e.g., 1.0.0 -->
|
|
Status: <!-- Draft | Stable | Deprecated -->
|
|
Last Updated: <!-- YYYY-MM-DD -->
|
|
|
|
## Overview
|
|
|
|
<!-- Brief overview: purpose, primary entities, and how they fit in the larger architecture -->
|
|
|
|
## Entity Definitions
|
|
|
|
### <!-- [ent-001] Entity Name (e.g., User) -->
|
|
|
|
**Description**: <!-- What this entity represents -->
|
|
**Primary Key**: <!-- Field name and type, e.g., id (UUID) -->
|
|
|
|
**Relationships**:
|
|
<!-- Document key relationships using arrow notation:
|
|
- **owns** → Organization (1:many) - User belongs to one org
|
|
- **member_of** ↔ Team (many:many) - User can be in multiple teams
|
|
-->
|
|
|
|
#### Fields
|
|
|
|
```json
|
|
{
|
|
"id": {
|
|
"type": "UUID",
|
|
"required": true,
|
|
"constraints": ["Unique"],
|
|
"indexed": true,
|
|
"description": "Unique identifier"
|
|
},
|
|
"email": {
|
|
"type": "string",
|
|
"required": true,
|
|
"constraints": ["Unique", "Email format"],
|
|
"indexed": true,
|
|
"description": "User's email address"
|
|
},
|
|
"name": {
|
|
"type": "string",
|
|
"required": true,
|
|
"constraints": ["1-255 chars"],
|
|
"description": "User's full name"
|
|
},
|
|
"status": {
|
|
"type": "enum(active|inactive|suspended)",
|
|
"required": true,
|
|
"default": "active",
|
|
"indexed": true,
|
|
"description": "Account status"
|
|
},
|
|
"created_at": {
|
|
"type": "timestamp",
|
|
"required": true,
|
|
"default": "NOW",
|
|
"indexed": true,
|
|
"description": "Creation timestamp"
|
|
},
|
|
"updated_at": {
|
|
"type": "timestamp",
|
|
"required": true,
|
|
"default": "NOW",
|
|
"description": "Last update timestamp"
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Example
|
|
|
|
```json
|
|
{
|
|
"id": "usr_123abc",
|
|
"email": "john.doe@example.com",
|
|
"name": "John Doe",
|
|
"status": "active",
|
|
"created_at": "2024-01-15T10:30:00Z",
|
|
"updated_at": "2024-01-15T10:30:00Z"
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### <!-- [ent-002] Additional Entity -->
|
|
|
|
**Description**: <!-- What this entity represents -->
|
|
**Primary Key**: <!-- Field name and type -->
|
|
|
|
**Relationships**: <!-- Document relationships -->
|
|
|
|
#### Fields
|
|
|
|
```json
|
|
{
|
|
"id": {
|
|
"type": "UUID",
|
|
"required": true,
|
|
"indexed": true,
|
|
"description": "Unique identifier"
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Example
|
|
|
|
```json
|
|
{
|
|
"id": "123"
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Relationships & Cardinality
|
|
|
|
<!-- Document key relationships between entities:
|
|
|
|
### User - Organization Relationship
|
|
**Cardinality**: User many → Organization one
|
|
**Implementation**: Foreign key `organization_id` in User table
|
|
**Cascade Behavior**: On delete, mark users as deleted
|
|
**Description**: Each user belongs to one organization
|
|
|
|
### User - Team Relationship
|
|
**Cardinality**: User many ↔ Team many
|
|
**Implementation**: Join table `user_team_memberships` with user_id, team_id, role, joined_at
|
|
**Description**: Users can be members of multiple teams
|
|
|
|
For complex relationships, reference a Flow Schematic.
|
|
-->
|
|
|
|
## Indexing Strategy
|
|
|
|
<!-- Document indexes for query optimization:
|
|
|
|
### Primary Indexes
|
|
- `id` (Primary Key) - Entity lookups by ID
|
|
- `email` (Unique) - User login/lookup
|
|
- `organization_id` - Query users by organization
|
|
|
|
### Composite Indexes
|
|
- `(organization_id, status)` - Filter active users per org
|
|
- `(created_at, status)` - Time-based queries
|
|
|
|
### Performance Targets
|
|
- Lookup by ID: < 10ms
|
|
- Lookup by email: < 10ms
|
|
- Query by organization: < 100ms for 100k users
|
|
-->
|
|
|
|
---
|