Admin Module Documentation
The Admin module handles platform administration and management functions for Lixnet (platform owner). This module provides comprehensive tools for managing users, vendors, transactions, and overall platform operations.
Module Overview
Purpose
The Admin module serves as the central command center for platform administrators, providing:
- User Management: Approve, manage, and monitor all platform users
- Vendor Oversight: Review and approve vendor applications and products
- Transaction Monitoring: Track all financial transactions and commissions
- Platform Analytics: Generate reports and insights on platform performance
Location:
App/admin/
Directory Structure
App/admin/
├── api/ # REST API endpoints for admin operations
│ └── v1/ # API version 1
│ ├── serializers/ # Data serialization for API responses
│ └── views/ # API view controllers
├── models/ # Admin-specific database models
├── views/ # Web interface view controllers
├── forms/ # Django forms for admin interfaces
├── services/ # Business logic for admin operations
├── repositories/ # Data access layer for admin data
├── tests/ # Unit and integration tests
├── utils/ # Utility functions and helpers
├── exceptions/ # Custom exception classes
├── migrations/ # Database migrations for admin models
└── management/ # Custom Django management commands
└── commands/ # Admin-specific Django commands
Key Responsibilities
User Management
Function | Description | Implementation |
---|---|---|
User Approval | Review and approve new user registrations | Admin views and API endpoints for user status management |
Role Assignment | Assign and modify user roles (Business, Reseller, Admin) | UserProfile model management through admin interface |
Profile Management | Edit and update user profiles and information | CRUD operations on User and UserProfile models |
Account Status | Enable, disable, or suspend user accounts | User model status field management |
Vendor Management
Function | Description | Implementation |
---|---|---|
Vendor Verification | Review vendor applications and documentation | Business model verification workflow |
Product Approval | Approve new products and pricing plans | Plan and Feature model management |
Status Management | Activate, deactivate, or suspend vendor accounts | Business model status field updates |
Compliance Monitoring | Ensure vendors comply with platform policies | Automated checks and manual review processes |
Transaction Oversight
Function | Description | Implementation |
---|---|---|
Payment Tracking | Monitor all payment transactions through Pesapal | Integration with Pesapal API for transaction status |
Commission Oversight | Review and approve commission payments to resellers | Commission model management and approval workflows |
Financial Reporting | Generate financial reports and analytics | Aggregation queries on transaction and commission data |
Dispute Resolution | Handle payment disputes and chargebacks | Manual review interface and dispute tracking |
Models and Data Structures
Core Models Used
The Admin module primarily works with existing shared models:
UserProfile Model
class UserProfile(models.Model):
ROLE_CHOICES = [
("business_owner", "Business Owner"),
("reseller", "Reseller"),
("admin", "Admin"),
("pending", "Pending Role")
]
user = models.OneToOneField(User, on_delete=models.CASCADE)
phone = models.CharField(max_length=20)
role = models.CharField(max_length=20, choices=ROLE_CHOICES, default="pending")
industry = models.CharField(max_length=100, null=True, blank=True)
Business Model
class Business(models.Model):
business_name = models.CharField(max_length=100)
business_email = models.EmailField()
industry = models.CharField(max_length=50, choices=INDUSTRY_CHOICES)
company_size = models.CharField(max_length=20, choices=COMPANY_SIZE_CHOICES)
country = models.CharField(max_length=50, choices=COUNTRY_CHOICES)
postal_code = models.CharField(max_length=20)
Plan and Feature Models
class Plan(models.Model):
name = models.CharField(max_length=100)
badge = models.CharField(max_length=50, blank=True, null=True)
description = models.TextField(blank=True, null=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
yearly_price = models.DecimalField(max_digits=10, decimal_places=2)
is_active = models.BooleanField(default=True)
display_order = models.PositiveIntegerField(default=0)
class Feature(models.Model):
plan = models.ForeignKey(Plan, on_delete=models.CASCADE, related_name='features')
name = models.CharField(max_length=100)
value = models.CharField(max_length=100)
API Endpoints
Admin API Endpoints
Location: App/admin/api/v1/
User Management APIs
Endpoint | Method | Purpose | Parameters |
---|---|---|---|
/api/admin/v1/users/ |
GET | List all users with filtering | role, status, search |
/api/admin/v1/users/{id}/ |
GET, PUT, PATCH | Get/update specific user | user_id |
/api/admin/v1/users/{id}/approve/ |
POST | Approve pending user | user_id |
/api/admin/v1/users/{id}/suspend/ |
POST | Suspend user account | user_id, reason |
Business/Vendor Management APIs
Endpoint | Method | Purpose | Parameters |
---|---|---|---|
/api/admin/v1/businesses/ |
GET | List all businesses | industry, country, status |
/api/admin/v1/businesses/{id}/verify/ |
POST | Verify business registration | business_id |
/api/admin/v1/plans/ |
GET, POST | Manage pricing plans | is_active, price_range |
/api/admin/v1/plans/{id}/activate/ |
POST | Activate/deactivate plan | plan_id |
Services and Business Logic
Core Services
Location: App/admin/services/
User Management Service
- approve_user(user_id): Approve pending user registration
- assign_role(user_id, role): Assign or change user role
- suspend_user(user_id, reason): Suspend user account with reason
- bulk_approve_users(user_ids): Batch approve multiple users
Business Management Service
- verify_business(business_id): Verify business registration documents
- approve_product_plan(plan_id): Approve new pricing plan
- generate_business_report(business_id): Generate comprehensive business report
- monitor_compliance(business_id): Check business compliance status
Analytics Service
- get_platform_metrics(): Get overall platform performance metrics
- generate_financial_report(date_range): Generate financial performance report
- get_user_activity_stats(): Get user activity and engagement statistics
- get_commission_analytics(): Get commission payment analytics
Development Guidelines
Adding New Admin Features
- Define the Model: If new data structures are needed, add them to
models/
- Create Service: Implement business logic in
services/admin_service.py
- Build Repository: Add data access methods in
repositories/
- Create API: Add REST endpoints in
api/v1/views/
- Add Web Interface: Create admin interface views in
views/
- Write Tests: Add comprehensive tests in
tests/
Security Considerations
- Authentication: All admin endpoints require admin role verification
- Authorization: Implement permission checks for sensitive operations
- Audit Logging: Log all admin actions for compliance and security
- Data Validation: Validate all input data through serializers and forms
Testing Strategy
- Unit Tests: Test individual services and utilities
- Integration Tests: Test API endpoints and database interactions
- Permission Tests: Verify access controls and role-based permissions
- Performance Tests: Test admin dashboard performance with large datasets
Note: The Admin module is critical for platform operations. All changes should be thoroughly tested and reviewed before deployment. Consider the impact on other modules when making modifications.