DeployFrame Docs

Architecture Layers

Detailed breakdown of each infrastructure layer and component connections

Architecture Layers

This section provides a detailed breakdown of each infrastructure layer, explaining how components connect and depend on each other within the AI SaaS Boilerplate.

Layer Overview

The platform follows a dependency-driven architecture where each layer builds upon the previous one:

Core InfrastructureBusiness LogicAI ServicesFrontend

Each layer provides essential services that upper layers depend on, ensuring clean separation of concerns and maintainable code structure.

Frontend Layer

Next.js Web Application

The frontend layer handles user interface and client-side functionality through AWS Amplify hosting with server-side rendered React application built with JavaScript and Tailwind CSS.

ComponentFile LocationPurpose
Next.js Deploymentlib/frontend/nextjs_stack.pyAWS Amplify hosting and GitHub integration
Configuration Managementlib/frontend/amplify_config_stack.pyEnvironment variables and API endpoint configuration
User Settings APIlib/frontend/api/user_settings_stack.pyFrontend-specific user preferences and profile management

Frontend Dependencies

The frontend layer connects to all other infrastructure layers:

  • Authentication: Cognito user pools for login/registration
  • API Access: All AI service endpoints and business logic APIs
  • Storage: S3 bucket access for file uploads and downloads
  • Real-time Data: AppSync GraphQL for live credit balance updates

API Layer

Request Routing & Authentication

Each component uses API Gateway for HTTP request routing with standardized authentication and CORS configuration.

Service CategoryAuthentication MethodKey Features
AI ServicesCognito User Pool AuthorizationJWT token validation, rate limiting
Payment ServicesCognito + Stripe IntegrationSubscription management, billing
Public APIsIAM AuthorizationPricing information
User ManagementCognito User Pool AuthorizationProfile, settings, preferences

Service-Specific API Patterns

All AI services follow consistent API Gateway patterns with standardized request/response handling, authentication integration, and error management.

Service Layer

AI Services Architecture

The service layer implements all AI functionality through Lambda functions with consistent patterns for authentication, credit management, and error handling.

Service CategoryFile LocationServices IncludedExternal Dependencies
Document Serviceslib/services/document/PDF Chat, OCR, Markdown ConversionOpenAI API, AWS Textract
Image Serviceslib/services/image/AI Generation, Style Transfer, Background OperationsAWS Bedrock
Video Serviceslib/services/video/YouTube Chat, Video SummarizationOpenAI API, YouTube API

Core Services Layer

Authentication System

AWS Cognito provides comprehensive user management with Google OAuth integration and automated user onboarding.

Authentication ComponentFile LocationFunctionality
Cognito User Poollib/core/auth/cognito_stack.pyUser registration, login, OAuth integration
Redirect Patchinglib/core/auth/patch_redirects_stack.pyPost-deployment callback URL updates
Email Templateslib/core/auth/templates/Custom verification and welcome emails

User Onboarding Flow: New users automatically receive 20 credits (BASIC plan), profile initialization, and email verification.

Credits & Billing System

The credit system manages user balances, service usage, and subscription billing through real-time GraphQL APIs.

Credits ComponentFile LocationPurpose
Credit Management APIlib/business/credits/credit_api_stack.pyAppSync GraphQL API for real-time credit tracking
Credit Processinglib/business/credits/credit_handler_stack.pyUsage deduction and monthly distribution
Service Pricinglib/business/credits/service_pricing_stack.pyDynamic pricing configuration per AI service
AppSync Schemalib/business/credits/appsync/schema.graphqlGraphQL type definitions and operations

Payment Processing

Stripe integration handles all payment operations through dedicated APIs with webhook processing for real-time event handling.

Payment ComponentFile LocationFunctionality
Payment Integrationlib/business/payments/payment_integration_stack.pyComplete Stripe integration with three APIs
Webhook APIIncluded in payment integrationReal-time Stripe event processing
Pricing APIIncluded in payment integrationPublic subscription plan information
Payment Management APIIncluded in payment integrationSubscription and billing operations

Core Infrastructure

Infrastructure ComponentFile LocationPurpose
Storage Managementlib/core/storage/storage_stack.pyS3 bucket creation with Cognito integration
Configuration Managementlib/core/config.pyEnvironment variable validation and AWS setup
Event Schedulinglib/core/scheduler/scheduler_role_stack.pyEventBridge for automated tasks
Utility Functionslib/core/utils/Shared utilities, API templates, secure parameters

Data Storage Layer

Database Structure

Data StorePurposeKey Tables/Buckets
DynamoDBStructured dataUser credits, payment history, service pricing cache
S3File storageUser uploads, generated content, temporary processing files
Parameter StoreSecure configurationAPI keys, webhook secrets, service credentials

Storage Organization

Storage TypeLocation PatternAccess Control
Public Filess3://bucket/public/*Public read access
User Filess3://bucket/private/{user-id}/*User-specific via Cognito

Component Dependencies

Next Steps

Now that you understand the detailed architecture:

  • Explore the Backend section for service implementation details
  • Review the Frontend section for user interface architecture
  • Check Customization options for modifying the platform