How weibeu/flask-discord works
Main Components
a) Client Application Layer:
• Flask application that uses this extension
• Main routes (/login, /callback, /me)
• Flask-Discord extension integration point
b) Flask-Discord Extension Core:
• DiscordOAuth2Session (main client class)
• HTTP handling layer (_http.py)
• Configuration management (configs.py)
• Exception handling (exceptions.py)
c) Models Layer:
• User model
• Guild model
• Connections model
• Integration model
• Base model (shared functionality)
d) External Services:
• Discord OAuth2 API
• Discord Bot API (for bot token functionality)
Component Relationships
[Client Flask App] → [Flask-Discord Extension] → [Discord OAuth2 API]
• ↘ [Discord Bot API]
[Flask-Discord Extension] → [Models Layer]
• → [Types Layer]
• → [Utils]
Specific Elements
a) Authentication Flow:
1. Login request
2. Discord authorization
3. Callback handling
4. Session creation
5. User data fetching
b) Data Models:
• Hierarchy of models starting from the base model
• Relationships between different models (User, Guild, etc.)
Important Technical Details to Highlight
• OAuth2 session management
• Caching mechanism (using cachetools)
• Authorization decorators (@requires_authorization)
• Error handling (Unauthorized exceptions)
• Configuration management
Top Level:
[Client Application]
• ↓
[Flask-Discord Extension]
• ↓
[External Services]
Middle Layer (Extension Internals):
[DiscordOAuth2Session]
• ↓
[HTTP Layer] → [Models] → [Types]
• ↓
[Utils & Configs]
Additional Notes
• A note about development vs. production configurations
• Security considerations (OAUTHLIB_INSECURE_TRANSPORT)
• Required environment variables and configuration
• Optional bot token functionality
Remember to:
• Use consistent styling
• Version information
• Document any assumptions
• Both synchronous and asynchronous flows