Backend Components
Detailed breakdown of each backend service category and implementation structure
Backend Components
This section provides a detailed breakdown of each backend component category, explaining the purpose and organization of services within the AI SaaS Boilerplate backend architecture.
Business Logic Layer
The business logic layer handles core platform functionality including user management, credit systems, and payment processing. These services form the foundation of the SaaS platform's business operations.
Credits Management
Component | File Location | Purpose |
---|---|---|
Credit Handling | backend/business/credits/credit_handling/lambda/ | Credit consumption, distribution, and balance management |
Service Pricing | backend/business/credits/service_pricing/lambda/ | Dynamic pricing logic for AI services |
Credit Handling manages the core credit system operations:
- Credit Consumption: Validates and deducts credits when users access AI services
- Monthly Distribution: Automatically distributes credits based on subscription plans
- Balance Management: Real-time credit balance updates and tracking
- Usage Analytics: Tracks credit consumption patterns and service usage
Service Pricing handles dynamic pricing for AI services:
- Cost Calculation: Determines credit costs for different service operations
- Pricing Configuration: Manages pricing rules and service-specific costs
- Cache Management: Optimizes pricing lookups for performance
Payment Processing
Component | File Location | Purpose |
---|---|---|
Payment Handling | backend/business/payments/payment_handling/lambda/ | Subscription management and billing operations |
Pricing API | backend/business/payments/pricing/lambda/ | Public pricing information for subscription plans |
Webhook Processing | backend/business/payments/webhook/lambda/ | Real-time Stripe event handling |
Payment Handling manages subscription lifecycle:
- Subscription Creation: Creates and manages user subscription plans
- Billing Operations: Handles subscription changes, cancellations, and renewals
- Payment Methods: Manages customer payment methods and billing information
- Invoice Management: Processes invoices and payment confirmations
Pricing API provides public pricing information:
- Plan Information: Returns available subscription plans and pricing
- Public Access: Accessible to unauthenticated users for pricing display
- Cache Optimization: Caches Stripe pricing data for performance
Webhook Processing handles real-time Stripe events:
- Event Validation: Verifies Stripe webhook signatures for security
- Credit Allocation: Automatically allocates credits based on successful payments
- Status Updates: Updates user subscription status based on payment events
- Failed Payment Handling: Manages subscription suspensions and retries
User Management
Component | File Location | Purpose |
---|---|---|
User Onboarding | backend/business/user/onboarding/lambda/ | New user setup and initial credit allocation |
User Onboarding handles new user initialization:
- Account Setup: Creates user profiles and initial configuration
- Credit Allocation: Provides initial credits (20 credits for BASIC plan)
- Welcome Process: Triggers welcome emails and setup notifications
- Profile Initialization: Sets up user preferences and default settings
AI Services Layer
The AI services layer contains all the individual AI service implementations that provide the core value proposition of the platform. Each service follows consistent patterns for authentication, credit management, and error handling.
Document Processing Services
Service | File Location | Functionality | External Dependencies |
---|---|---|---|
PDF Chat | backend/services/document/pdf_chat/functions/ | Interactive conversations with uploaded documents | OpenAI API |
OCR | backend/services/document/ocr/lambda/ | Text extraction from images and scanned documents | AWS Textract |
Markdown Conversion | backend/services/document/markdown_conversion/lambda/ | Document format transformation to markdown | None |
PDF Chat enables interactive document conversations:
- Document Processing: Extracts and processes text from uploaded PDF files
- Conversation Interface: Provides chat-based interaction with document content
- Context Management: Maintains conversation context and document references
- AI Integration: Uses OpenAI models for natural language understanding
OCR (Optical Character Recognition) extracts text from images:
- Image Processing: Handles various image formats and quality levels
- Text Extraction: Uses AWS Textract for accurate text recognition
- Format Preservation: Maintains text layout and structure when possible
- Multi-language Support: Supports text extraction in multiple languages
Markdown Conversion transforms documents:
- Format Support: Converts various document formats to markdown
- Structure Preservation: Maintains document hierarchy and formatting
- Clean Output: Produces well-formatted markdown suitable for various uses
Image Processing Services
Service | File Location | Functionality | External Dependencies |
---|---|---|---|
AI Image Generation | backend/services/image/generation/lambda/ | Text-to-image generation, image edditing using AI models | AWS Bedrock |
Style Transfer | backend/services/image/style_transfer/lambda/ | Artistic style transformation of photos | None |
AI Image Generation creates images from text prompts:
- Text-to-Image: Generates high-quality images from descriptive text
- Model Integration: Uses AWS Bedrock's Titan Image Generator v2
- Parameter Control: Supports various generation parameters (size, style, quality)
- Output Management: Handles image storage and delivery to users
Style Transfer transforms photo aesthetics:
- Artistic Transformation: Applies various artistic styles to uploaded photos
- Style Options: Provides multiple pre-defined artistic styles and effects
- Quality Preservation: Maintains image quality during transformation
- Batch Processing: Supports processing multiple images efficiently
Video Processing Services
Service | File Location | Functionality | External Dependencies |
---|---|---|---|
YouTube Chat | backend/services/video/video_chat/functions/ | Interactive Q&A with YouTube video content | OpenAI API, YouTube API |
Video Summarization | backend/services/video/video_summarizer/lambda/ | Automated video content summarization | OpenAI API, YouTube API |
YouTube Chat enables video content interaction:
- Video Analysis: Processes YouTube video content for interaction
- Question Answering: Provides intelligent responses about video content
- Context Awareness: Maintains awareness of video timeline and content structure
- Real-time Interaction: Supports dynamic conversation about video topics
Video Summarization creates content summaries:
- Content Extraction: Analyzes video content and audio transcripts
- Summary Generation: Creates concise, informative video summaries
- Key Points Identification: Highlights important topics and themes
- Multiple Formats: Supports different summary lengths and formats
Shared Components Layer
The shared components provide common functionality used across all AI services, ensuring consistency and reducing code duplication.
Shared Utilities
Component | File Location | Purpose |
---|---|---|
Credit Management | backend/services/shared/python/credit_management.py | Common credit validation and consumption logic |
Route Parameters Loader | backend/services/shared/python/route_params_loader.py | Standardized API parameter validation and processing |
Credit Management Utility provides consistent credit handling:
- Credit Validation: Ensures users have sufficient credits before service execution
- Usage Tracking: Records credit consumption for analytics and billing
- Error Handling: Provides standardized responses for insufficient credits
- Integration: Seamlessly integrates with all AI services
Route Parameters Loader standardizes API processing:
- Parameter Validation: Validates incoming API request parameters
- Data Sanitization: Cleans and normalizes user input data
- Error Responses: Provides consistent error messaging for invalid requests
- Format Handling: Supports multiple input formats (JSON, form data, multipart)
Frontend-Specific Backend Services
User Settings API
Component | File Location | Purpose |
---|---|---|
User Settings | backend/frontend/api/user_settings/lambda/ | User preferences and profile management |
User Settings API manages user preferences:
- Profile Management: Handles user profile updates and preferences
- Settings Persistence: Stores user configuration and customization options
- Preference Sync: Synchronizes settings across different platform features
- API Integration: Provides dedicated endpoints for frontend user management
Service Integration Patterns
Next Steps
Now that you understand the backend components:
- Review Customization for guidance on extending and modifying services
- Explore Infrastructure to understand the deployment architecture
- Check Frontend to see how these backend services integrate with the user interface