Backend Overview
Understanding the AI SaaS Boilerplate backend architecture and code structure
Backend Overview
The AI SaaS Boilerplate backend is built with Python Lambda functions organized into a clean, modular architecture. This section helps you understand the backend code structure and organization to enable future customization and extension.
Backend Architecture Principles
The backend follows separation of concerns with three main categories:
- Business Logic: Core platform functionality (credits, payments, user management)
- AI Services: Individual AI service implementations (document, image, video processing)
- Shared Components: Common utilities and patterns used across all services
Each Lambda function is self-contained with its own dependencies, while shared utilities provide consistent patterns for authentication, credit management, and API parameter validation across all services.
Backend Code Structure
The backend is organized to mirror the CDK infrastructure, making it easy to understand the relationship between deployment code and business logic:
The structure uses lambda/
folders for single-function services and functions/
folders for services that may contain multiple related functions. This organization makes it easy to locate and modify specific functionality.
Technology Stack
Runtime Environment:
- Python 3.11 for all Lambda functions
- AWS Lambda for serverless compute
- Shared Lambda layers for common dependencies
Key Libraries:
- AWS SDK (boto3): AWS service integration
- Stripe SDK: Payment processing
- OpenAI SDK: AI model integration
- Requests: HTTP client for external APIs
- Pillow: Image processing capabilities
Integration Points:
- DynamoDB: User data and credit management
- S3: File storage and processing
- Parameter Store: Secure configuration management
- AppSync: Real-time GraphQL updates
Backend Organization Categories
The backend is organized into three main categories that correspond to different aspects of the platform:
Business Logic Layer
Core platform functionality that handles user accounts, billing, and credit management. These services power the fundamental business operations of the SaaS platform.
AI Services Layer
Individual AI service implementations that provide the core value proposition. Each service is independently deployable and follows consistent patterns for authentication and credit consumption.
Shared Components Layer
Common utilities and patterns used across all services to ensure consistency, reduce code duplication, and maintain standardized behavior for authentication and credit management.
Backend Components Guide
Integration with Infrastructure
The backend code structure directly corresponds to the CDK infrastructure stacks:
- Each
lambda/
folder corresponds to a Lambda function defined in CDK - Business logic maps to business stacks (credits, payments)
- AI services map to service stacks deployed through the service factory
- Shared utilities are deployed as Lambda layers across multiple functions
This one-to-one mapping makes it easy to understand how code changes affect infrastructure and vice versa.
Next Steps
Now that you understand the backend organization:
- Explore Backend Components for detailed service breakdowns
- Review Customization for guidance on extending and modifying services
- Check Infrastructure to understand how backend code maps to AWS resources