Local Development
Best practices and workflows for local development with Magnet AI.
Development Environment
Recommended Setup
- Operating System: macOS, Linux, or Windows with WSL2
- Python: 3.12+ with virtual environment
- Node.js: 18+ with npm or yarn
- IDE: VS Code with recommended extensions
- Database: PostgreSQL for production-like environment
Directory Structure
Keep your workspace organized:
magnet-ai/
├── api/ # Backend (Litestar)
│ ├── .venv/ # Python virtual environment
│ ├── src/ # Source code
│ └── tests/ # Tests
├── web/ # Frontend (Nx Monorepo)
│ ├── apps/ # Applications (admin, panel)
│ ├── packages/ # Shared libraries
│ └── documentation/ # This documentation
└── docker/ # Docker configurationBackend Development
Virtual Environment
Always use a virtual environment:
cd api
poetry shellInstalling Dependencies
Using Poetry (Recommended)
poetry installRunning the Backend
Development Server
uvicorn app:app --reload --env-file="../.env"The server runs with:
- Auto-reload enabled
- Debug mode (if configured in .env)
- CORS enabled for local frontend
Custom Port
uvicorn app:app --reload --env-file="../.env" --port 8001Environment Variables
Create .env in the root directory (or api/.env if running standalone):
# Required
OPENAI_API_KEY=sk-...
# Database
DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/magnet_ai
# Application
DEBUG_MODE=true
LOG_LEVEL=DEBUG
# External Services
VECTOR_DB_TYPE=POSTGRESDatabase Workflow
Run Migrations
npm run db:migrateApply Migrations
npm run db:upgradeReset Database
npm run db:resetCode Style
Format Code
ruff format src/Lint Code
ruff check src/Type Checking
mypy src/Debugging
Using pdb
Add breakpoint:
import pdb; pdb.set_trace()Using VS Code Debugger
Create .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Litestar",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": ["app:app", "--reload", "--port", "8000"],
"jinja": true,
"justMyCode": true
}
]
}Frontend Development
Installing Dependencies
cd web
yarn installRunning the Frontend
Development Server
User Panel:
yarn nx dev magnet-panelAdmin Console:
yarn nx dev magnet-adminAccess at:
- Panel:
http://localhost:4200(or similar) - Admin:
http://localhost:4201(or similar)
Hot Reload
Changes to TypeScript/Vue files automatically reload the browser.
Code Style
Format & Lint
yarn lintType Checking
yarn type-checkBrowser DevTools
Use Vue.js devtools extension for debugging Vue components.
Full Stack Development
Running Both Services
With Docker Database (Recommended)
Use this command to start the database in Docker along with the API and Web services:
npm run dev:dockerWith External Database
If you have an external database configured in .env, use:
npm run devThese commands start:
- API:
http://localhost:8000 - Web Apps:
http://localhost:3000&http://localhost:3001
API Testing
Using curl
# List agents
curl http://localhost:8000/api/agentsUsing Postman
- Import API collection
- Set base URL:
http://localhost:8000 - Create requests for endpoints
Database Management
Using DBeaver
Universal database tool:
brew install --cask dbeaver-communityConnect to localhost:5432 (User: postgres, Pass: postgres or as defined in .env).
Plugin Development
Creating a Plugin
Plugins in Magnet AI are typically Python modules integrated via the PluginRegistry.
- Create plugin directory in
api/src/plugins/. - Implement your plugin logic.
- Register it in
api/src/core/server/plugin_registry.pyor via the dynamic loader.
Plugin Testing
Create tests/test_my_plugin.py and run:
pytest tests/test_my_plugin.pyPerformance Monitoring
Backend Performance
Litestar provides built-in instrumentation hooks. You can also use standard Python profiling tools.
Frontend Performance
Vue DevTools
- Install Vue.js devtools extension
- Use Performance tab
- Record interactions
- Analyze render performance
Logging
Backend Logging
Configure in api/src/core/config/logging.py. Magnet AI uses structlog for structured logging.
Use in code:
import structlog
logger = structlog.get_logger()
logger.info("event_name", key="value")
logger.error("error_event", error=str(e))Frontend Logging
Use console methods:
console.log('Debug info')
console.warn('Warning')
console.error('Error')Common Workflows
Adding a New Feature
- Create feature branch
- Implement backend API (Litestar Controller)
- Write backend tests
- Implement frontend UI (Vue Components)
- Write frontend tests
- Test integration
- Create pull request
Fixing a Bug
- Reproduce the bug
- Write a failing test
- Fix the bug
- Verify test passes
- Commit and PR
Code Review Checklist
- [ ] Tests pass
- [ ] Code formatted (Ruff/Prettier)
- [ ] No lint errors
- [ ] Documentation updated
- [ ] Changes reviewed
Next Steps
- Testing - Testing guide
- Run with Docker Compose - Start the full stack (app + database) in Docker
- Plugin Development - Create plugins