System architecture
The application follows a three-tier architecture:Frontend layer
Frontend layer
Next.js 13 application with React Server Components and client-side interactivity for user interface and state management.
API middleware layer
API middleware layer
Next.js API Routes that act as a proxy between the frontend and Azure Functions backend.
Backend layer
Backend layer
Azure Functions providing serverless compute for OpenAI API integration and Azure Blob Storage management.
Communication flow
The following diagram illustrates how the frontend and backend communicate:Image generation flow
Azure Function processes request
The
generateImage function calls DALL-E 3 API, downloads the generated image, and uploads it to Azure Blob Storage.Image retrieval flow
Azure Function retrieves images
The
getImages function lists all blobs from Azure Storage, generates SAS tokens for secure access, and returns sorted image URLs.Key architectural decisions
Why Azure Functions? Serverless functions provide automatic scaling, reduced operational overhead, and cost-effective compute for AI workloads with variable demand.
Why proxy through Next.js API Routes? This pattern keeps Azure Function URLs and configuration private, enables request transformation, and provides a consistent API interface for the frontend.
SAS Token security: Azure Blob Storage uses Shared Access Signature (SAS) tokens with 30-minute expiration to provide temporary, secure access to generated images without exposing storage account keys.
Technology stack
- Frontend
- Backend
- AI Models
- Framework: Next.js 13.2.4 with App Router
- UI Library: React 18.2.0
- Styling: Tailwind CSS 3.3.2
- State Management: SWR 2.1.1 for data fetching
- Notifications: react-hot-toast 2.4.0
- Analytics: Vercel Analytics
Data flow
State management with SWR
VisionaryAI uses SWR (Stale-While-Revalidate) for efficient data fetching and caching:SWR provides automatic revalidation, optimistic updates, and caching, reducing unnecessary API calls and improving user experience.
Azure Blob Storage integration
Generated images are stored in Azure Blob Storage with a naming convention that includes the prompt and timestamp:Scalability considerations
- Serverless compute: Azure Functions automatically scale based on demand
- CDN-ready: Blob Storage URLs can be fronted with Azure CDN for global distribution
- Stateless design: No session state maintained on backend, enabling horizontal scaling
- Caching strategy: SWR implements client-side caching to reduce API calls
Next steps
Frontend development
Explore React components and client-side architecture
Backend development
Deep dive into Azure Functions and OpenAI integration