# AI Debug Platform

The web platform for the AI Debug ecosystem, providing a comprehensive interface for debugging, testing, and team collaboration.

## Overview

AI Debug Platform is a Phoenix LiveView application that serves as the main web interface for the AI Debug system. It provides:

- **Web Dashboard**: Real-time monitoring and management of debugging sessions
- **Test Runner Interface**: Execute and monitor AI-generated test suites
- **Team Collaboration**: Multi-user support with team management
- **API Gateway**: RESTful API for external tools and MCP server communication
- **Authentication**: Secure user authentication and session management

## Architecture

This package is part of a larger monorepo structure:

```
ai-debug-platform/
├── lib/
│   ├── ai_debug_platform/          # Business logic and domain models
│   └── ai_debug_platform_web/      # Web layer (controllers, views, LiveView)
├── assets/                         # Frontend assets (JS, CSS)
├── priv/                          # Static files and migrations
└── config/                        # Configuration files
```

## Dependencies

- **ai_debug_test_engine**: Core test execution engine (local dependency)
- **Phoenix Framework**: Web framework with LiveView for real-time features
- **PostgreSQL**: Database for storing sessions, tests, and user data
- **Guardian**: JWT-based authentication
- **Tesla**: HTTP client for MCP server communication

## Features

### 1. Dashboard
- Real-time session monitoring
- Performance metrics visualization
- System health indicators

### 2. Test Management
- AI-generated test suite execution
- Test result visualization
- Historical test data analysis

### 3. Team Features
- User management
- Team creation and collaboration
- Role-based access control

### 4. API Integration
- RESTful endpoints for external tools
- WebSocket support for real-time updates
- MCP server communication bridge

## Getting Started

### Prerequisites
- Elixir 1.14+
- Phoenix 1.7+
- PostgreSQL 14+
- Node.js 16+ (for assets)

### Installation

1. Install dependencies:
```bash
mix deps.get
```

2. Create and migrate database:
```bash
mix ecto.setup
```

3. Install Node.js dependencies:
```bash
cd assets && npm install
```

4. Start the Phoenix server:
```bash
mix phx.server
```

Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.

## Development

### Running Tests
```bash
mix test
```

### Code Quality
```bash
mix format
mix credo
```

### Database Management
```bash
# Create migration
mix ecto.gen.migration create_users

# Run migrations
mix ecto.migrate

# Rollback
mix ecto.rollback
```

## API Endpoints

### Session Management
- `POST /api/sessions` - Create debugging session
- `GET /api/sessions` - List all sessions
- `GET /api/sessions/:id` - Get session details
- `DELETE /api/sessions/:id` - Close session

### Test Execution
- `POST /api/tests/run` - Execute test suite
- `GET /api/tests/:id/results` - Get test results

### MCP Integration
- `POST /api/mcp/execute` - Execute MCP command
- `GET /api/mcp/status` - Get MCP server status

## Configuration

### Environment Variables
- `DATABASE_URL` - PostgreSQL connection string
- `SECRET_KEY_BASE` - Phoenix secret key
- `PHX_HOST` - Production hostname
- `MCP_SERVER_URL` - MCP server endpoint

### Custom Configuration
Edit `config/config.exs` for application-wide settings.

## Production Deployment

1. Build assets:
```bash
mix assets.deploy
```

2. Create release:
```bash
MIX_ENV=prod mix release
```

3. Run migrations:
```bash
_build/prod/rel/ai_debug_platform/bin/ai_debug_platform eval "AiDebugPlatform.Release.migrate"
```

4. Start server:
```bash
_build/prod/rel/ai_debug_platform/bin/ai_debug_platform start
```

## Contributing

This is an internal package of the AI Debug monorepo. Please refer to the main repository guidelines for contribution instructions.

## License

Copyright (c) 2024 AI Debug Team. All rights reserved.