✨ Nuevas funcionalidades: - ✅ Sistema de migraciones Alembic implementado - ✅ Dependencias frontend resueltas (SvelteKit + TypeScript) - ✅ Configuraciones VS Code optimizadas - ✅ GitHub Copilot configuración enterprise - ✅ Testing completo 100% exitoso 🔧 Cambios técnicos: - Alembic: Configuración completa con templates - Frontend: 686 paquetes npm instalados - VS Code: Debugger modernizado (python -> debugpy) - Database: 16 tablas sincronizadas - Docker: 8 servicios funcionando correctamente 🏗️ Arquitectura: - Multi-tenant B2B system ready - Production-ready configuration - Enterprise-grade development environment
187 lines
4.5 KiB
Markdown
187 lines
4.5 KiB
Markdown
# Configuración Avanzada de GitHub Copilot para ServiceManagerWeb
|
|
|
|
## Variables de Contexto Importantes
|
|
|
|
### Configuración del Sistema
|
|
```env
|
|
# Variables críticas a considerar
|
|
DATABASE_URL=postgresql+asyncpg://user:pass@localhost:5432/servicemanager
|
|
REDIS_URL=redis://localhost:6379/0
|
|
JWT_SECRET_KEY=your-secret-key
|
|
TENANT_ISOLATION=strict
|
|
CORS_ORIGINS=["http://localhost:3000", "http://localhost:3001"]
|
|
```
|
|
|
|
### Modelos de Datos Clave
|
|
|
|
#### User Model Completo
|
|
```python
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
tenant_id: Mapped[int] = mapped_column(ForeignKey("tenants.id"))
|
|
email: Mapped[str] = mapped_column(unique=True, index=True)
|
|
role: Mapped[UserRole] = mapped_column(default=UserRole.CLIENT_USER)
|
|
is_active: Mapped[bool] = mapped_column(default=True)
|
|
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow)
|
|
```
|
|
|
|
#### Ticket Workflow States
|
|
```python
|
|
class TicketStatus(str, Enum):
|
|
OPEN = "open"
|
|
IN_PROGRESS = "in_progress"
|
|
PENDING_CLIENT = "pending_client"
|
|
RESOLVED = "resolved"
|
|
CLOSED = "closed"
|
|
CANCELLED = "cancelled"
|
|
```
|
|
|
|
## Reglas de Implementación Específicas
|
|
|
|
### 1. Multi-Tenancy Estricto
|
|
- NUNCA hacer queries sin filtrar por `tenant_id`
|
|
- Middleware de tenant debe estar en toda request
|
|
- Validar permisos a nivel de tenant antes de operaciones
|
|
|
|
### 2. Audit Trail Obligatorio
|
|
```python
|
|
async def log_audit_event(
|
|
action: str,
|
|
resource_type: str,
|
|
resource_id: int,
|
|
user_id: int,
|
|
tenant_id: int,
|
|
details: dict = None
|
|
):
|
|
# Implementar en todas las operaciones CRUD críticas
|
|
```
|
|
|
|
### 3. Error Handling Consistente
|
|
```python
|
|
# Backend
|
|
raise HTTPException(
|
|
status_code=status.HTTP_403_FORBIDDEN,
|
|
detail="Insufficient permissions for tenant resource"
|
|
)
|
|
|
|
# Frontend
|
|
import { toast } from '$lib/stores/toast';
|
|
toast.error("Error al procesar la solicitud");
|
|
```
|
|
|
|
### 4. Performance Patterns
|
|
```python
|
|
# Queries con paginación siempre
|
|
async def get_tickets_paginated(
|
|
db: AsyncSession,
|
|
tenant_id: int,
|
|
skip: int = 0,
|
|
limit: int = 20
|
|
) -> Tuple[List[Ticket], int]:
|
|
# Select con join optimizado + count total
|
|
```
|
|
|
|
## Componentes Frontend Reutilizables
|
|
|
|
### Layout Structure
|
|
```
|
|
+layout.svelte (global)
|
|
├── Header.svelte (navigation)
|
|
├── Sidebar.svelte (menu)
|
|
└── Toast.svelte (notifications)
|
|
```
|
|
|
|
### Form Patterns
|
|
```typescript
|
|
// Validation con Zod
|
|
const createTicketSchema = z.object({
|
|
title: z.string().min(5).max(200),
|
|
description: z.string().min(10),
|
|
priority: z.nativeEnum(TicketPriority),
|
|
category_id: z.number().positive()
|
|
});
|
|
```
|
|
|
|
## Debugging y Logging
|
|
|
|
### Backend Logging
|
|
```python
|
|
import structlog
|
|
logger = structlog.get_logger(__name__)
|
|
|
|
# En cada endpoint
|
|
logger.info(
|
|
"ticket_created",
|
|
ticket_id=ticket.id,
|
|
user_id=current_user.id,
|
|
tenant_id=current_user.tenant_id,
|
|
correlation_id=request.correlation_id
|
|
)
|
|
```
|
|
|
|
### Frontend Error Boundary
|
|
```svelte
|
|
<!-- En +layout.svelte -->
|
|
{#if $page.error}
|
|
<ErrorComponent error={$page.error} />
|
|
{/if}
|
|
```
|
|
|
|
## Comandos de Desarrollo Específicos
|
|
|
|
```bash
|
|
# Backend development
|
|
cd backend && uvicorn app.main:app --reload --port 8000
|
|
|
|
# Frontend internal (admin panel)
|
|
cd frontend-internal && npm run dev -- --port 3001
|
|
|
|
# Frontend client (customer portal)
|
|
cd frontend-client && npm run dev -- --port 3000
|
|
|
|
# Workers
|
|
cd workers && celery -A app.celery worker --loglevel=info
|
|
|
|
# Full stack con Docker
|
|
docker-compose -f docker-compose.dev.yml up
|
|
|
|
# Database operations
|
|
docker-compose exec backend alembic revision --autogenerate -m "Description"
|
|
docker-compose exec backend alembic upgrade head
|
|
|
|
# Testing complete
|
|
docker-compose exec backend pytest -v --cov=app
|
|
```
|
|
|
|
## Code Review Checklist
|
|
|
|
- [ ] ✅ Multi-tenant isolation verificado
|
|
- [ ] 🔒 Autenticación/autorización implementada
|
|
- [ ] 📊 Audit logging en operaciones críticas
|
|
- [ ] 🚀 Performance considerado (índices, paginación)
|
|
- [ ] 🧪 Tests unitarios/integración agregados
|
|
- [ ] 📝 OpenAPI documentation actualizada
|
|
- [ ] 🎨 UI/UX consistente con design system
|
|
- [ ] 🐛 Error handling comprehensivo
|
|
- [ ] 📱 Responsive design verificado
|
|
- [ ] 🔍 Type safety con TypeScript/mypy
|
|
|
|
## Herramientas de Calidad
|
|
|
|
```bash
|
|
# Python quality
|
|
ruff check . --fix
|
|
black .
|
|
mypy .
|
|
bandit -r app/
|
|
safety check
|
|
|
|
# JavaScript/TypeScript quality
|
|
npm run lint
|
|
npm run type-check
|
|
npm run format
|
|
```
|
|
|
|
Esta configuración te ayudará a mantener la calidad enterprise del sistema ServiceManagerWeb. |