Skip to main content
Follow this guide to set up VisionaryAI for local development, including both the Next.js frontend and Azure Functions backend.

Prerequisites

Before starting, ensure you have the following installed:
  • Node.js: Version 18.x or higher
  • npm: Version 8.x or higher (or yarn/pnpm)
  • Azure Functions Core Tools: Version 4.x
  • Visual Studio Code: Recommended IDE
  • Git: For version control
  • OpenAI account: For DALL-E 3 and GPT API access
  • Azure account: For Blob Storage and Functions deployment

Installation

Clone the repository

git clone https://github.com/Srijan-D/DALLE3.git
cd DALLE3

Install dependencies

1

Install frontend dependencies

npm install
This installs Next.js, React, Tailwind CSS, and other frontend dependencies.
2

Install backend dependencies

cd azure
npm install
cd ..
This installs Azure Functions SDK, OpenAI client, and Azure Storage SDK.
You can use yarn or pnpm instead of npm if preferred. The project supports all major package managers.

Configuration

OpenAI API setup

1

Get OpenAI API key

  1. Visit OpenAI API Keys
  2. Click “Create new secret key”
  3. Copy the generated API key (starts with sk-)
  4. Note your organization ID from Settings
2

Create environment file

Create a .env.local file in the azure directory:
cd azure
touch .env.local
3

Add OpenAI credentials

Add the following to azure/.env.local:
OPEN_AI_KEY=sk-your-api-key-here
OPEN_AI_ORGANIZATION=org-your-org-id-here
Never commit .env.local files to version control. They should be listed in .gitignore.

Azure Blob Storage setup

1

Create Azure Storage Account

  1. Log in to Azure Portal
  2. Create a new Storage Account
  3. Choose a unique name for your storage account
  4. Select a region close to your users
  5. Use Standard performance tier for development
2

Create images container

  1. Navigate to your Storage Account
  2. Go to “Containers” under Data Storage
  3. Click ”+ Container”
  4. Name it images
  5. Set public access level to “Private”
3

Get storage credentials

  1. In your Storage Account, go to “Access keys”
  2. Copy the storage account name
  3. Copy one of the access keys (key1 or key2)
4

Add to environment file

Add to azure/.env.local:
accountName=your-storage-account-name
accountKey=your-storage-account-key
Azure provides a free tier with 5 GB storage and 20,000 read operations. This is sufficient for development.

Running the application

Start the backend

1

Navigate to Azure directory

cd azure
2

Start Azure Functions

npm run start
Or using Azure Functions Core Tools directly:
func start
3

Verify functions are running

You should see output like:
Functions:

generateImage: [POST] http://localhost:7071/api/generateImage

getChatGPTSuggestion: [GET] http://localhost:7071/api/getChatGPTSuggestion

getImages: [GET] http://localhost:7071/api/getImages
Keep this terminal window open. The functions run on port 7071 by default.

Update frontend API endpoints

For local development, update the API routes to point to your local Azure Functions:
const response = await fetch(
  "http://localhost:7071/api/generateImage",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ prompt }),
  }
);
const response = await fetch(
  "http://localhost:7071/api/getImages",
  {
    cache: "no-store",
  }
);
const response = await fetch(
  "http://localhost:7071/api/getChatGPTSuggestion",
  {
    cache: "no-store",
  }
);

Start the frontend

1

Open new terminal

Navigate to the project root directory.
2

Start Next.js development server

npm run dev
3

Open in browser

The Next.js development server includes hot module replacement (HMR), so changes to frontend code will automatically refresh the browser.

Development workflow

Project structure

Here’s the complete project structure:
visionaryai/
├── app/                        # Next.js 13 App Router
│   ├── api/                    # API route handlers
│   ├── layout.tsx              # Root layout
│   └── page.tsx                # Home page
├── azure/                      # Azure Functions backend
│   ├── src/functions/          # Function implementations
│   ├── lib/                    # Shared utilities
│   └── .env.local              # Local environment variables
├── components/                 # React components
├── lib/                        # Frontend utilities
├── public/                     # Static assets
├── styles/                     # Global styles
└── package.json                # Frontend dependencies

Making changes

  1. Edit files in app/, components/, or lib/
  2. Save the file
  3. Browser automatically refreshes with changes
  4. Check console for any errors

Testing image generation

1

Open the application

2

Get a suggestion

Click “New suggestion” to get an AI-generated prompt idea.
3

Generate an image

Either:
  • Click “Use suggestion” to generate with the AI prompt
  • Enter your own prompt and click “Generate”
4

Monitor progress

  • Watch the toast notification for generation status
  • Check Azure Functions terminal for logs
  • Images appear in the gallery once uploaded
DALL-E 3 image generation typically takes 10-30 seconds. Be patient while the AI creates your image.

Troubleshooting

Problem: Functions fail to start or show errors.Solutions:
  • Verify Azure Functions Core Tools is installed: func --version
  • Check that .env.local exists and has correct credentials
  • Ensure Node.js version is 18.x or higher: node --version
  • Try deleting node_modules and running npm install again
Problem: “Invalid API key” or “Rate limit exceeded” errors.Solutions:
  • Verify API key starts with sk- and is complete
  • Check OpenAI account has available credits
  • Ensure you have access to DALL-E 3 API (may require paid plan)
  • Review OpenAI rate limits
Problem: “Storage account not found” or “Authentication failed”.Solutions:
  • Verify storage account name is correct (no typos)
  • Ensure access key is the full key (very long string)
  • Check that the images container exists
  • Confirm storage account is not behind a firewall
Problem: Generation succeeds but images don’t show in gallery.Solutions:
  • Click “Refresh Images” button
  • Check Azure Portal to verify blobs were uploaded
  • Verify SAS token generation is working (check backend logs)
  • Check browser console for CORS or network errors
Problem: Browser shows CORS policy errors.Solutions:
  • Ensure Azure Functions is running on port 7071
  • Verify API routes are pointing to localhost:7071
  • Configure CORS in Azure Portal for production deployments
  • Check that requests include proper headers

VS Code setup

Recommended VS Code extensions:
  • Azure Functions: Manage and debug Azure Functions
  • Tailwind CSS IntelliSense: Autocomplete for Tailwind classes
  • ES7+ React/Redux/React-Native snippets: React code snippets
  • Prettier: Code formatting
  • ESLint: JavaScript linting

Launch configuration

Create .vscode/launch.json for debugging:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Next.js: debug server-side",
      "type": "node-terminal",
      "request": "launch",
      "command": "npm run dev"
    },
    {
      "name": "Attach to Azure Functions",
      "type": "node",
      "request": "attach",
      "port": 9229,
      "preLaunchTask": "func: host start"
    }
  ]
}

Environment variables reference

Complete list of required environment variables:
# OpenAI Configuration
OPEN_AI_KEY=sk-...
OPEN_AI_ORGANIZATION=org-...

# Azure Storage Configuration
accountName=your-storage-account
accountKey=your-storage-key

Next steps

Architecture overview

Learn how the system components work together

Frontend development

Explore React components and UI patterns

Backend development

Deep dive into Azure Functions and AI integration

API Reference

Explore the complete API documentation

Build docs developers (and LLMs) love