Athena
Home
Environments
Environments
  • Development Server
  • Production
Home
Environments
Environments
  • Development Server
  • Production
  1. API Reference
  • Getting Started
    • Start Guide
  • Installation & Setup
    • Windows
  • Architecture
  • Guide
    • Bundles
      • Backend
    • Permissions
      • Frontend
    • Developers
      • Commit Lint
      • RESTful API
    • Workflows
      • Workflow Variables
  • API Reference
    • Authentication
      • Sign In
      • Logout
    • User
      • Get Authenticated User using Multiplai App Access Token
      • Get Authenticated User using Basic Token
    • Workspace
      • Get Workspaces Metrics
      • Get Workspaces
      • Update a Workspace
      • Retrieve a workspace
      • Delete a Workspace
    • Provider
      • Get Providers
      • Retrieve a Provider
      • Update a Provider
      • Create a Provider
      • Delete a Provider
    • Account
      • Get Accounts
      • Update an Account
      • Create an Account
      • Delete an Account
      • Retrieve an Account
    • Agent
      • Get Agents
      • Update an Agent
      • Create an Agent
      • Delete an Agent
      • Retrieve an Agent
      • Run an Agent
      • Train an Agent
      • Generate an Agent
      • Share Agent
      • Get Agent Leaderboard
    • Workflow
      • Get Workflows
      • Create a Workflow
      • Retrieve a Workflow
      • Update a Workflow
      • Delete a Workflow
      • Trigger a webhook
      • Share Workflow
      • Generate Workflow
    • Workflow Execution
      • Get Workflow Executions
      • Get Workflow Execution Counts
      • Retrieve a Workflow Execution
      • Delete a Workflow Execution
    • Prompt
      • Get Prompts
      • Create a Prompt
      • Retrieve a Prompt
      • Update a Prompt
      • Delete a Prompt
      • Run a prompt
    • Memory
      • Get Memories
      • Retrieve a Memory
      • Update a Memory
      • Delete a Memory
    • Thread
      • Get Threads
      • Retrieve a Thread
      • Update a Thread
      • Delete a Thread
      • Create a Thread
      • Run a Thread
      • Generate Thread Name
    • Message
      • Get Messages
      • Retrieve a Message
      • Update a Message
      • Delete a Message
      • Create a Message
    • Large Language Model
      • Get Large Language Models
      • Retrieve a Large Language Model
    • Command Room Task
      • Store Command Room Task
      • Remove Command Room Task
    • Metrics
      • Get Agents Metrics
      • Get Workflows Metrics
      • Get Threads Metrics
      • Get Messages Metrics
      • Get Workflow Executions Metrics
  • Schemas
    • Resources
      • User
      • Workspace
      • Provider
      • Account
      • Agent
      • Workflow
      • Share
      • WorkflowExecution
      • WorkflowExecutionData
      • Prompt
      • Memory
      • Thread
      • Attachment
      • Media
      • Tool
      • Message
      • LargeLanguageModel
      • AgentLeaderboard
    • Utils
      • Pagination
        • PaginationMeta
        • PaginationLinks
      • Provider
        • AuthenticationConfig
      • Profile
        • ProfilePhotoConfig
      • Workflow
        • WorkflowExecutionDataWorkflowData
        • Node
        • Edge
  1. API Reference

User

Introduction#

The User system in Athena serves as the foundational layer for identity, authentication, and access control across the entire platform. It implements a sophisticated dual-authentication architecture that seamlessly integrates Laravel's native authentication with external OAuth providers, specifically Multiplai.
This documentation explains the technical implementation, architectural decisions, and design patterns used in the User system.

Architecture Overview#

Core Components#

The User system is built around several key components that work together to provide comprehensive user management:
1.
User Model - Central entity representing platform users
2.
Dual Authentication System - Sanctum + Multiplai OAuth integration
3.
Workspace Integration - Multi-tenant workspace-based access control
4.
Repository Pattern - Data access abstraction layer
5.
Filtering System - Flexible user search and filtering capabilities

System Design Philosophy#

The User system follows these architectural principles:
Separation of Concerns: Authentication, authorization, and user management are distinct layers
Extensibility: OAuth integration allows easy addition of new authentication providers
Security First: Multiple authentication methods with proper token management
Workspace-Centric: All user operations are scoped to workspaces for multi-tenancy

User Model Implementation#

Database Schema Design#

The User model is designed with flexibility and extensibility in mind:

Smart Name Handling#

The system implements intelligent name management through model boot events:
This ensures consistent full name generation whether users are created via direct registration or OAuth synchronization.

Relationship Architecture#

The User model establishes several critical relationships:
Primary Workspace: BelongsTo relationship for default workspace
Workspaces: BelongsToMany with pivot data for multi-workspace access
Accounts: HasMany for OAuth provider accounts
Workflows: HasMany for user-owned workflows
These relationships enable the multi-tenant architecture while maintaining data integrity.

Authentication Architecture#

Dual Authentication Strategy#

Athena implements a unique dual authentication system through the MultiplaiMiddleware:

Multiplai OAuth Integration#

The OAuth integration uses a custom Socialite provider that:
1.
Token Validation: Validates OAuth tokens against Multiplai API
2.
User Synchronization: Automatically syncs user data via SyncAction
3.
Seamless Login: Logs users in without additional authentication steps

Sanctum Token Management#

For API access, the system uses Laravel Sanctum with:
Scoped Tokens: Tokens are properly scoped with permissions
Expiration Handling: Tokens have configurable expiration times
Revocation Support: Users can revoke tokens through logout

Workspace Integration#

Multi-Tenant Architecture#

The User system is deeply integrated with Athena's workspace-based multi-tenancy:

Access Control Implementation#

User access is controlled through several layers:
1.
Authentication: Verifies user identity
2.
Workspace Membership: Ensures user belongs to workspace
3.
Role-Based Permissions: Uses Spatie Permission package
4.
Request Authorization: Validates specific action permissions

Workspace-Scoped Operations#

All user operations (listing, searching, etc.) are automatically scoped to workspaces:

Repository Pattern Implementation#

Data Access Abstraction#

The User system uses the Repository pattern to abstract data access:

Filter System Architecture#

The filtering system is modular and extensible:
1.
SearchFilter: Implements full-text search across name, email, first_name, last_name
2.
WorkspaceFilter: Ensures all queries are workspace-scoped
3.
Extensible Design: New filters can be easily added

Query Optimization#

The repository implements efficient querying:
Eager Loading: Automatically loads related data when requested
Pagination: Built-in pagination support for large datasets
Sorting: Flexible sorting by multiple fields

Security Implementation#

Authentication Security#

The system implements multiple security layers:
1.
Password Hashing: Uses Laravel's bcrypt hashing
2.
Token Security: Sanctum tokens are cryptographically secure
3.
OAuth Validation: Multiplai tokens are validated against external API
4.
Session Management: Proper session handling and regeneration

Data Protection#

Sensitive data is protected through:

Access Control Security#

Workspace Isolation: Users can only access data within their workspaces
Request Validation: All requests are validated before processing
Authorization Checks: Every action is authorized before execution

Profile Management#

Photo Upload System#

The User model includes sophisticated profile photo management:

Profile Data Integrity#

The system ensures profile data consistency:
Name Synchronization: Automatically updates full name when components change
Email Uniqueness: Enforces unique email constraints
Data Validation: Comprehensive validation rules for all profile fields

Integration Points#

OAuth Provider Integration#

The system is designed to easily integrate with new OAuth providers:
1.
Provider Configuration: Stored in database with flexible authentication config
2.
Socialite Integration: Custom providers can be easily added
3.
User Synchronization: Flexible sync actions for different provider data formats

External API Integration#

The User system integrates with external APIs:
Multiplai API: For user data synchronization and validation
Profile Photos: Secure storage and retrieval system
Workspace APIs: Cross-system data consistency

Event System#

The User system triggers events for:
User Creation: Registered event fired on user creation
Profile Updates: Model events for data consistency
Authentication Events: Login/logout event handling

Performance Considerations#

Database Optimization#

The system implements several performance optimizations:
1.
Indexing: Proper database indexes on frequently queried fields
2.
Relationship Loading: Efficient eager loading to prevent N+1 queries
3.
Query Scoping: Automatic workspace scoping reduces query complexity

Caching Strategy#

User Data: Frequently accessed user data can be cached
OAuth Tokens: Token validation results are cached
Workspace Membership: Workspace associations are cached

Scalability Design#

The architecture supports scaling through:
Stateless Authentication: Token-based auth supports horizontal scaling
Database Sharding: Workspace-based data partitioning potential
Microservice Ready: Clean boundaries enable service extraction

Testing Architecture#

Test Coverage Strategy#

The User system includes comprehensive testing:
1.
Unit Tests: Individual component testing
2.
Feature Tests: End-to-end workflow testing
3.
Integration Tests: OAuth and external API testing

Testing Patterns#


Design Patterns Used#

Repository Pattern#

Abstracts data access logic and provides consistent interface for user operations.

Factory Pattern#

Used for creating test users and OAuth provider configurations.

Observer Pattern#

Model observers handle automated tasks like name synchronization.

Strategy Pattern#

Multiple authentication strategies (Sanctum, OAuth) handled through unified interface.

Decorator Pattern#

Middleware decorates requests with authentication and workspace context.

Configuration and Environment#

Environment Variables#

The User system requires specific environment configuration:
# OAuth Configuration
MULTIPLAI_CLIENT_ID=your_client_id
MULTIPLAI_CLIENT_SECRET=your_client_secret
MULTIPLAI_URL=https://api.multiplai.tech

# Authentication Configuration
SANCTUM_STATEFUL_DOMAINS=localhost,127.0.0.1
SESSION_LIFETIME=120

Service Provider Configuration#

Key services are configured in AppServiceProvider:
Socialite Providers: Custom OAuth provider registration
Sanctum Configuration: Token expiration and scoping
Permission Configuration: Role and permission setup

Error Handling Strategy#

Exception Hierarchy#

The system implements structured exception handling:
1.
Authentication Exceptions: Unified handling for auth failures
2.
Authorization Exceptions: Workspace access violations
3.
Validation Exceptions: Input validation failures
4.
Model Exceptions: Database and model operation failures

Graceful Degradation#

The dual authentication system provides graceful fallbacks:
OAuth Failure: Falls back to Sanctum authentication
External API Failure: Continues with cached data
Workspace Resolution: Provides clear error messages

Monitoring and Observability#

Logging Strategy#

The User system implements comprehensive logging:

Metrics and Monitoring#

Important metrics to monitor:
Authentication Success/Failure Rates
User Creation Trends
OAuth Synchronization Performance
Workspace Access Patterns

Future Considerations#

Planned Enhancements#

1.
Multi-Factor Authentication: Additional security layer
2.
Social Login Expansion: More OAuth provider support
3.
Advanced User Analytics: User behavior tracking
4.
Enhanced Profile Management: Rich profile data support

Scalability Roadmap#

Microservice Migration: Potential extraction to dedicated user service
Advanced Caching: Redis-based caching layer
Database Optimization: Advanced indexing and query optimization
API Rate Limiting: Enhanced rate limiting for user operations

Conclusion#

The User system in Athena represents a sophisticated, scalable implementation of modern authentication and user management. By combining Laravel's robust authentication foundation with flexible OAuth integration and workspace-based multi-tenancy, it provides a secure, extensible platform for user identity management.
The system's architecture emphasizes security, performance, and maintainability while providing the flexibility needed for future enhancements and scaling requirements.
Modified at 2025-06-20 03:26:27
Previous
Logout
Next
Get Authenticated User using Multiplai App Access Token
Built with