Skip to content

Commit 4257161

Browse files
Merge pull request #193 from microsoft/ve-Local-readme
docs: added a local setup guide
2 parents 8b61aed + fd9219a commit 4257161

File tree

1 file changed

+335
-0
lines changed

1 file changed

+335
-0
lines changed

docs/LocalSetupGuide.md

Lines changed: 335 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
# Guide to Local Development
2+
3+
This guide provides step-by-step instructions for setting up and running the **Modernize your code solution accelerator** locally for development and testing purposes.
4+
5+
## Requirements
6+
7+
Before you begin, ensure you have the following tools installed:
8+
9+
**Python 3.9 or higher** + PIP
10+
**Node.js 18+** and npm
11+
**Azure CLI** and an Azure Subscription
12+
**Docker Desktop** (optional, for containerized development)
13+
**Visual Studio Code IDE** (recommended)
14+
**Git** for version control
15+
16+
## Local Setup
17+
18+
**Note for macOS Developers:** If you are using macOS on Apple Silicon (ARM64), you may experience compatibility issues with some Azure services. We recommend testing thoroughly and using alternative approaches if needed.
19+
20+
The easiest way to run this accelerator is in a VS Code Dev Container, which will open the project in your local VS Code using the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers):
21+
22+
1. **Start Docker Desktop** (install it if not already installed)
23+
2. **Open the project:** [Open in Dev Containers](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/Modernize-your-code-solution-accelerator)
24+
3. In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window
25+
26+
## Detailed Development Container Setup Instructions
27+
28+
The solution contains a [development container](https://code.visualstudio.com/docs/remote/containers) with all the required tooling to develop and deploy the accelerator. To deploy the Modernize your code Solution Accelerator using the provided development container you will also need:
29+
30+
[Visual Studio Code](https://code.visualstudio.com/)
31+
[Remote containers extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
32+
33+
If you are running this on Windows, we recommend you clone this repository in [WSL](https://code.visualstudio.com/docs/remote/wsl):
34+
35+
```bash
36+
git clone https://github.com/microsoft/Modernize-your-code-solution-accelerator
37+
```
38+
39+
Open the cloned repository in Visual Studio Code and connect to the development container:
40+
41+
```bash
42+
code .
43+
```
44+
45+
!!! tip
46+
Visual Studio Code should recognize the available development container and ask you to open the folder using it. For additional details on connecting to remote containers, please see the [Open an existing folder in a container](https://code.visualstudio.com/docs/remote/containers#_quick-start-open-an-existing-folder-in-a-container) quickstart.
47+
48+
When you start the development container for the first time, the container will be built. This usually takes a few minutes. Please use the development container for all further steps.
49+
50+
The files for the dev container are located in `/.devcontainer/` folder.
51+
52+
## Local Deployment and Debugging
53+
54+
### 1. Clone the Repository
55+
56+
```bash
57+
git clone https://github.com/microsoft/Modernize-your-code-solution-accelerator
58+
cd Modernize-your-code-solution-accelerator
59+
```
60+
61+
### 2. Log into the Azure CLI
62+
63+
• Check your login status using:
64+
```bash
65+
az account show
66+
```
67+
68+
• If not logged in, use:
69+
```bash
70+
az login
71+
```
72+
73+
• To specify a tenant, use:
74+
```bash
75+
az login --tenant <tenant_id>
76+
```
77+
78+
### 3. Create a Resource Group
79+
80+
You can create it either through the Azure Portal or the Azure CLI:
81+
82+
```bash
83+
az group create --name <resource-group-name> --location eastus
84+
```
85+
86+
### 4. Deploy the Infrastructure
87+
88+
You can use the Azure Developer CLI (recommended) or deploy the Bicep template directly:
89+
90+
#### Option A: Using Azure Developer CLI (Recommended)
91+
92+
```bash
93+
# Initialize the environment
94+
azd env new <environment-name>
95+
96+
# Deploy the infrastructure and application
97+
azd up
98+
```
99+
100+
#### Option B: Using Azure CLI with Bicep
101+
102+
```bash
103+
az deployment group create -g <resource-group-name> -f infra/main.bicep --query 'properties.outputs'
104+
```
105+
106+
**Note:** You will be prompted for various parameters including:
107+
- **principalId**: The ObjectID of your user in Entra ID. To find it, use:
108+
```bash
109+
az ad signed-in-user show --query id -o tsv
110+
```
111+
- **Azure AI Service Location**: Choose from supported regions (eastus, japaneast, etc.)
112+
- **Solution Name**: A unique name for your deployment
113+
114+
### 5. Configure Role Assignments
115+
116+
The Bicep deployment includes the assignment of appropriate roles. If you need to add additional permissions for local development, use these commands:
117+
118+
```bash
119+
# Cosmos DB permissions
120+
az cosmosdb sql role assignment create \
121+
--resource-group <resource-group-name> \
122+
--account-name <cosmos-db-account-name> \
123+
--role-definition-name "Cosmos DB Built-in Data Contributor" \
124+
--principal-id <aad-user-object-id> \
125+
--scope /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<cosmos-db-account-name>
126+
127+
# Azure OpenAI permissions
128+
az role assignment create \
129+
--assignee <aad-user-upn> \
130+
--role "Cognitive Services OpenAI User" \
131+
--scope /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.CognitiveServices/accounts/<azure-openai-name>
132+
```
133+
134+
### 6. Create Environment Files
135+
136+
Navigate to the backend directory and create a `.env` file based on the provided `.env.sample`:
137+
138+
```bash
139+
cd src/backend
140+
cp .env.sample .env
141+
```
142+
143+
Also create `.env` files based on the provided `.env.sample` files for frontend:
144+
145+
```bash
146+
cd src/frontend
147+
cp .env.sample .env
148+
```
149+
150+
Fill in the `.env` files with values from your Azure deployment. You can find these in:
151+
- Azure Portal under "Deployments" in your resource group
152+
- Output from the `azd up` command
153+
- Azure resources directly in the portal
154+
155+
### 7. Set up Virtual Environments (Optional)
156+
157+
If you are using `venv`, create and activate your virtual environment for the backend:
158+
159+
```bash
160+
# Backend setup
161+
cd src/backend
162+
python -m venv venv
163+
164+
# Activate virtual environment
165+
# On Windows:
166+
venv\Scripts\activate
167+
# On macOS/Linux:
168+
source venv/bin/activate
169+
```
170+
171+
### 8. Install Python Dependencies
172+
173+
In the backend directory with your virtual environment activated:
174+
175+
```bash
176+
pip install -r requirements.txt
177+
```
178+
179+
### 9. Install Frontend Dependencies
180+
181+
In the frontend directory:
182+
183+
```bash
184+
cd src/frontend
185+
npm install
186+
```
187+
188+
### 10. Run the Application
189+
190+
#### Start the Backend API:
191+
192+
From the `src/backend` directory:
193+
194+
```bash
195+
uvicorn app:app --host 0.0.0.0 --port 8000 --reload
196+
```
197+
198+
#### Start the Frontend:
199+
200+
In a new terminal from the `src/frontend` directory:
201+
202+
```bash
203+
npm run dev
204+
```
205+
206+
### 11. Access the Application
207+
208+
**Frontend:** Open a browser and navigate to `http://localhost:3000`
209+
**API Documentation:** Navigate to `http://localhost:8000/docs` for Swagger documentation
210+
**API Health Check:** Navigate to `http://localhost:8000/health`
211+
212+
## Debugging the Solution Locally
213+
214+
### Backend Debugging
215+
216+
You can debug the API backend running locally with VSCode using the following `launch.json` entry:
217+
218+
```json
219+
{
220+
"name": "Python Debugger: Modernize Code API",
221+
"type": "debugpy",
222+
"request": "launch",
223+
"cwd": "${workspaceFolder}/src/backend",
224+
"module": "uvicorn",
225+
"args": ["app:app", "--reload", "--host", "0.0.0.0", "--port", "8000"],
226+
"jinja": true,
227+
"envFile": "${workspaceFolder}/src/backend/.env"
228+
}
229+
```
230+
231+
### Frontend Debugging
232+
233+
For debugging the React frontend, you can use the browser's developer tools or set up debugging in VS Code with the appropriate extensions.
234+
235+
### Agent System Debugging
236+
237+
To debug the SQL agents system:
238+
239+
1. **Enable debug logging** in your `.env` file:
240+
```
241+
APP_LOGGING_LEVEL=DEBUG
242+
APP_ENV=dev
243+
```
244+
245+
2. **Monitor agent interactions** through the application logs and WebSocket messages
246+
247+
3. **Test individual agents** using the API endpoints directly
248+
249+
## Using Docker for Local Development
250+
251+
### Run with Docker Compose
252+
253+
```bash
254+
# Build and start all services
255+
docker-compose -f docker/docker-compose.yml up --build
256+
257+
# Run in detached mode
258+
docker-compose -f docker/docker-compose.yml up -d --build
259+
```
260+
261+
### Access Services
262+
263+
**Frontend:** `http://localhost:3000`
264+
**Backend:** `http://localhost:8000`
265+
266+
## Troubleshooting
267+
268+
### Common Issues
269+
270+
**Python Module Not Found:**
271+
```bash
272+
# Ensure virtual environment is activated
273+
source venv/bin/activate # Windows: venv\Scripts\activate
274+
pip install -r requirements.txt
275+
```
276+
277+
**Node.js Dependencies Issues:**
278+
```bash
279+
# Clear npm cache and reinstall
280+
npm cache clean --force
281+
rm -rf node_modules package-lock.json
282+
npm install
283+
```
284+
285+
**Port Conflicts:**
286+
```bash
287+
# Check what's using the port
288+
netstat -tulpn | grep :8000 # Linux/Mac
289+
netstat -ano | findstr :8000 # Windows
290+
```
291+
292+
**Azure Authentication Issues:**
293+
```bash
294+
# Re-authenticate
295+
az logout
296+
az login
297+
```
298+
299+
**CORS Issues:**
300+
• Ensure API CORS settings include the web app URL
301+
• Check browser network tab for CORS errors
302+
• Verify API is running on the expected port
303+
304+
**Environment Variables Not Loading:**
305+
• Verify `.env` file is in the correct directory
306+
• Check file permissions (especially on Linux/macOS)
307+
• Ensure no extra spaces in variable assignments
308+
309+
**Agent Initialization Failures:**
310+
• Verify Azure AI Foundry endpoint is correct
311+
• Check Azure OpenAI model deployments are available
312+
• Ensure proper authentication and permissions
313+
314+
### Debug Mode
315+
316+
Enable detailed logging by setting these environment variables in your `.env` file:
317+
318+
```
319+
APP_LOGGING_LEVEL=DEBUG
320+
APP_ENV=dev
321+
AZURE_OPENAI_API_VERSION=2024-08-01-preview
322+
```
323+
324+
### Database Issues
325+
326+
**Using a Different Database in Cosmos:**
327+
328+
You can set the solution up to use a different database in Cosmos. For example, you can name it something like `modernize-dev`. To do this:
329+
330+
1. Change the environment variable `AZURE_COSMOS_DATABASE` to the new database name
331+
2. Create the database in the Cosmos DB account from the Data Explorer pane in the portal
332+
333+
---
334+
335+
For production deployment instructions, see the [Deployment Guide](./DeploymentGuide.md).

0 commit comments

Comments
 (0)