System requirements
Before installing VisionaryAI, ensure your system meets these requirements:- Node.js: Version 18.15.9 or higher
- npm/yarn/pnpm: Latest stable version
- Git: Version 2.0 or higher
- Azure CLI: Version 2.0 or higher (for Azure Functions deployment)
- VS Code: Recommended with Azure Functions extension
Part 1: Next.js application setup
The frontend is built with Next.js 13 using the App Router architecture.Clone the repository
Start by cloning the VisionaryAI repository:Install dependencies
Install all required npm packages:Configure OpenAI client
VisionaryAI uses the OpenAI SDK for API communication. The configuration is located inopenai.ts:
.env.local file in the project root:
Configure Next.js
The project usesnext.config.js for framework configuration:
images.domains array to allow Next.js Image optimization for generated images.Understanding the API routes
Next.js API routes act as a proxy to Azure Functions. Here’s how they’re structured:Generate image endpoint
Generate image endpoint
app/api/generateImage/route.tsGet images endpoint
Get images endpoint
app/api/getImages/route.tsChatGPT suggestion endpoint
ChatGPT suggestion endpoint
app/api/suggestion/route.tsSet up SWR data fetching
VisionaryAI uses SWR for efficient data fetching. The fetcher functions are in thelib directory:
Run the development server
Start the Next.js development server:http://localhost:3000.
Part 2: Azure Functions setup
The backend uses Azure Functions for serverless compute.Navigate to Azure directory
Install Azure dependencies
Configure local settings
Createlocal.settings.json in the azure directory:
Understanding Azure Functions
VisionaryAI includes four Azure Functions:generateImage function
azure/src/functions/generateImage.jsHandles DALL-E 3 image generation and Azure Blob Storage upload:prompt_timestamp.png for easy sorting and identification.getImages function
azure/src/functions/getImages.jsRetrieves all images from Azure Blob Storage:getChatGPTSuggestion function
azure/src/functions/getChatGPTSuggestion.jsGenerates creative prompt suggestions using ChatGPT:generateSASToken function
azure/lib/generateSASToken.jsCreates secure SAS tokens for blob access:expiresOn if you need different expiration times.Configure OpenAI for Azure Functions
The OpenAI configuration for Azure Functions is inazure/lib/openai.js:
Start Azure Functions locally
http://localhost:7071/api/generateImagehttp://localhost:7071/api/getImageshttp://localhost:7071/api/getChatGPTSuggestionhttp://localhost:7071/api/generateSASToken
npm install -g azure-functions-core-tools@4Part 3: Azure Blob Storage setup
Configure Azure Blob Storage to store generated images.Create a storage account
- Navigate to Storage Accounts
- Click + Create
- Select subscription and resource group
- Enter a globally unique account name
- Choose region (same as your Functions app for best performance)
- Select performance tier (Standard is sufficient)
- Click Review + Create
Create the images container
- Go to Containers in the left menu
- Click + Container
- Name it
images(must match the code) - Set public access level to Private
- Click Create
Get access credentials
- Copy the Storage account name
- Click Show keys and copy key1
- Add these to your environment configuration
Part 4: Production deployment
Deploy VisionaryAI to production environments.Deploy Azure Functions
Install Azure CLI
Login to Azure
Deploy functions
azure directory:Configure application settings
Deploy Next.js app
VisionaryAI can be deployed to Vercel, Azure Static Web Apps, or any Node.js hosting:Update API endpoints
After deploying Azure Functions, update the endpoints in your Next.js app:Verification
After installation, verify everything works:Test Azure Functions
Test Next.js app
- Verify the UI loads correctly
- Click “New suggestion” to test ChatGPT integration
- Generate a test image
- Confirm the image appears in the gallery
Check Azure Storage
- Navigate to your storage account
- Open the
imagescontainer - Verify generated images appear with correct naming
Performance optimization
Enable image caching
Enable image caching
Optimize SWR configuration
Optimize SWR configuration
Use CDN for static assets
Use CDN for static assets
- Reduces latency for global users
- Lowers costs by caching images
- Improves load times significantly
Troubleshooting
Azure Functions deployment fails
Azure Functions deployment fails
- Verify you have the correct Azure CLI version
- Check that
host.jsonexists in the azure directory - Ensure function app name is globally unique
- Review deployment logs:
func azure functionapp logstream your-app-name
CORS errors in production
CORS errors in production
Images not persisting
Images not persisting
- Storage account connection string is correct
- Container permissions allow write access
- SAS token has correct permissions (read + write)
- Function app has network access to storage account
Next steps
With VisionaryAI installed, you can:- Customize the UI by editing components in
components/ - Modify ChatGPT prompts in
azure/src/functions/getChatGPTSuggestion.js - Add image metadata storage for better organization
- Implement user authentication and private galleries
- Add image editing features like variations or inpainting
- Set up monitoring with Azure Application Insights