Skip to main content
This guide provides comprehensive instructions for installing and deploying VisionaryAI in both development and production environments.

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
VisionaryAI uses TypeScript 5.0.2 and modern ES6+ features. Ensure your development environment supports these technologies.

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:
Fork the repository first if you plan to make customizations or contribute back to the project.

Install dependencies

Install all required npm packages:
This installs the following key dependencies:

Configure OpenAI client

VisionaryAI uses the OpenAI SDK for API communication. The configuration is located in openai.ts:
Create a .env.local file in the project root:
Add .env.local to your .gitignore file to prevent accidentally committing sensitive API keys. The repository includes .env.local in .gitignore by default.

Configure Next.js

The project uses next.config.js for framework configuration:
Add your Azure Storage account domain to the 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:
Location: app/api/generateImage/route.ts
This endpoint forwards image generation requests to Azure Functions.
Location: app/api/getImages/route.ts
Retrieves the list of generated images from Azure Blob Storage.
Location: app/api/suggestion/route.ts
Fetches AI-generated prompt suggestions from ChatGPT.

Set up SWR data fetching

VisionaryAI uses SWR for efficient data fetching. The fetcher functions are in the lib directory:
These fetchers are used in the React components:

Run the development server

Start the Next.js development server:
The application will be available at http://localhost:3000.
Next.js supports Fast Refresh, so your changes will appear instantly without losing component state.

Part 2: Azure Functions setup

The backend uses Azure Functions for serverless compute.

Install Azure dependencies

This installs:

Configure local settings

Create local.settings.json in the azure directory:
The local.settings.json file is gitignored by default. Never commit this file to version control as it contains sensitive credentials.

Understanding Azure Functions

VisionaryAI includes four Azure Functions:
1

generateImage function

Location: azure/src/functions/generateImage.jsHandles DALL-E 3 image generation and Azure Blob Storage upload:
Images are stored with filenames like prompt_timestamp.png for easy sorting and identification.
2

getImages function

Location: azure/src/functions/getImages.jsRetrieves all images from Azure Blob Storage:
3

getChatGPTSuggestion function

Location: azure/src/functions/getChatGPTSuggestion.jsGenerates creative prompt suggestions using ChatGPT:
Modify the prompt in this function to customize the style and type of suggestions ChatGPT generates.
4

generateSASToken function

Location: azure/lib/generateSASToken.jsCreates secure SAS tokens for blob access:
SAS tokens expire after 24 hours (86400 seconds) for security. Adjust expiresOn if you need different expiration times.

Configure OpenAI for Azure Functions

The OpenAI configuration for Azure Functions is in azure/lib/openai.js:

Start Azure Functions locally

The functions will be available at:
  • http://localhost:7071/api/generateImage
  • http://localhost:7071/api/getImages
  • http://localhost:7071/api/getChatGPTSuggestion
  • http://localhost:7071/api/generateSASToken
Azure Functions Core Tools must be installed globally. Install with: npm install -g azure-functions-core-tools@4

Part 3: Azure Blob Storage setup

Configure Azure Blob Storage to store generated images.
1

Create a storage account

In the Azure Portal:
  • 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
2

Create the images container

After the storage account is created:
  • Go to Containers in the left menu
  • Click + Container
  • Name it images (must match the code)
  • Set public access level to Private
  • Click Create
3

Get access credentials

Navigate to Access Keys under Security + networking:
  • Copy the Storage account name
  • Click Show keys and copy key1
  • Add these to your environment configuration
Never expose your storage account key publicly. Use SAS tokens for client-side access and keep account keys in secure environment variables.

Part 4: Production deployment

Deploy VisionaryAI to production environments.

Deploy Azure Functions

1

Install Azure CLI

Download and install the Azure CLI.
2

Login to Azure

Or use VS Code Azure extension to login visually.
3

Deploy functions

From the azure directory:
4

Configure application settings

Add environment variables to your Azure Function App:

Deploy Next.js app

VisionaryAI can be deployed to Vercel, Azure Static Web Apps, or any Node.js hosting:
Vercel is recommended for Next.js deployments as it provides optimal performance and automatic deployments from Git.

Update API endpoints

After deploying Azure Functions, update the endpoints in your Next.js app:
Or use environment variables:

Verification

After installation, verify everything works:
1

Test Azure Functions

Check the function endpoints are responding:
2

Test Next.js app

Open your deployed URL and:
  • Verify the UI loads correctly
  • Click “New suggestion” to test ChatGPT integration
  • Generate a test image
  • Confirm the image appears in the gallery
3

Check Azure Storage

In the Azure Portal:
  • Navigate to your storage account
  • Open the images container
  • Verify generated images appear with correct naming

Performance optimization

Add caching headers to Azure Blob Storage:
Adjust SWR settings for better performance:
Enable Azure CDN for your blob storage:
  • Reduces latency for global users
  • Lowers costs by caching images
  • Improves load times significantly

Troubleshooting

Common issues:
  • Verify you have the correct Azure CLI version
  • Check that host.json exists in the azure directory
  • Ensure function app name is globally unique
  • Review deployment logs: func azure functionapp logstream your-app-name
Add CORS configuration to Azure Functions:
Verify:
  • 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
For help or questions, reach out to @Srijan_Dby on Twitter or open an issue on GitHub.