File size: 4,150 Bytes
25f22bf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# Backend Requirements
## Overview
This document outlines the technical requirements for the Flask API backend of the Lin application.
## Python Dependencies
The backend will require the following Python packages:
### Core Dependencies
- Flask: Web framework
- Flask-CORS: Cross-Origin Resource Sharing support
- Flask-JWT-Extended: JWT token management
- Flask-SQLAlchemy: ORM for database interactions
- Flask-Migrate: Database migration support
- python-dotenv: Environment variable management
- requests: HTTP library for API calls
- requests-oauthlib: OAuth support
- apscheduler: Task scheduling
- supabase: Supabase client for database operations
- pandas: Data manipulation
- gradio-client: Hugging Face API client
### Development Dependencies
- pytest: Testing framework
- pytest-cov: Test coverage reporting
- flake8: Code linting
- black: Code formatting
## Environment Variables
The backend will require the following environment variables:
- SUPABASE_URL: Supabase project URL
- SUPABASE_KEY: Supabase API key
- CLIENT_ID: LinkedIn OAuth client ID
- CLIENT_SECRET: LinkedIn OAuth client secret
- REDIRECT_URL: LinkedIn OAuth redirect URL
- HUGGING_KEY: Hugging Face API key
- JWT_SECRET_KEY: Secret key for JWT token generation
- DATABASE_URL: Database connection string (if using PostgreSQL directly)
## Database Requirements
The application will use Supabase as the primary database, which is based on PostgreSQL. The following tables will be needed:
### Users
- id (UUID)
- email (string)
- password_hash (string)
- created_at (timestamp)
- email_confirmed_at (timestamp)
### Social_network
- id (UUID)
- user_id (UUID, foreign key to Users)
- social_network (string)
- account_name (string)
- token (string)
- sub (string)
- given_name (string)
- family_name (string)
- picture (string)
- created_at (timestamp)
### Source
- id (UUID)
- user_id (UUID, foreign key to Users)
- source (string)
- category (string)
- last_update (timestamp)
- created_at (timestamp)
### Post_content
- id (UUID)
- social_account_id (UUID, foreign key to Social_network)
- text_content (text)
- image_content_url (bytea or URL)
- is_published (boolean)
- sched (UUID)
- created_at (timestamp)
- scheduled_at (timestamp)
### Scheduling
- id (UUID)
- social_account_id (UUID, foreign key to Social_network)
- schedule_time (string)
- adjusted_time (string)
- created_at (timestamp)
## API Requirements
### Authentication
- JWT-based authentication
- Password hashing with bcrypt
- Email confirmation flow
- Password reset functionality
### Security
- CORS policy configuration
- Input validation and sanitization
- Rate limiting for API endpoints
- Secure headers implementation
### Error Handling
- Consistent error response format
- Proper HTTP status codes
- Logging of errors for debugging
- Validation error handling
## Integration Requirements
### LinkedIn API
- OAuth2 authentication flow
- Post creation and publishing
- User profile information retrieval
- Image upload support
### Hugging Face API
- Content generation using Gradio client
- Error handling for API failures
- Timeout handling for long-running requests
### Scheduling System
- APScheduler for task management
- Conflict resolution for overlapping schedules
- Automatic adjustment of schedule times
- Persistent storage of scheduled tasks
## Deployment Requirements
### Server
- Python 3.8+
- WSGI server (Gunicorn recommended)
- Reverse proxy (Nginx recommended)
- SSL certificate for HTTPS
### Scalability
- Stateless design for horizontal scaling
- Database connection pooling
- Caching strategy for frequently accessed data
- Background task processing for long-running operations
### Monitoring
- Logging configuration
- Health check endpoints
- Performance monitoring
- Error tracking integration
## Testing Requirements
### Unit Tests
- Model validation tests
- Service layer tests
- Utility function tests
### Integration Tests
- API endpoint tests
- Database integration tests
- External API integration tests
### Test Coverage
- Minimum 80% code coverage
- Testing of edge cases
- Mocking of external dependencies
- Continuous integration setup |