FASE 1: Parts Database - Added part_categories, part_groups, parts, vehicle_parts tables - 12 categories, 190 groups with Spanish translations - API endpoints for categories, groups, parts CRUD FASE 2: Cross-References & Aftermarket - Added manufacturers, aftermarket_parts, part_cross_references tables - 24 manufacturers, quality tier system (economy/standard/premium/oem) - Part number search across OEM and aftermarket FASE 3: Exploded Diagrams - Added diagrams, vehicle_diagrams, diagram_hotspots tables - SVG viewer with zoom controls and interactive hotspots - 3 sample diagrams (brake, oil filter, suspension) FASE 4: Search & VIN Decoder - SQLite FTS5 full-text search with auto-sync triggers - NHTSA VIN decoder API integration with 30-day cache - Unified search endpoint FASE 5: Optimization & UX - API pagination (page/per_page, max 100 items) - Dark mode with localStorage persistence - Keyboard shortcuts (/, Ctrl+K, Escape, Backspace, Ctrl+D) - Breadcrumb navigation - ARIA accessibility (labels, roles, focus management) - Skip link for keyboard users Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
209 lines
19 KiB
Markdown
209 lines
19 KiB
Markdown
# Diagrama de Base de Datos - Catálogo de Autopartes
|
|
|
|
## Diagrama de Relaciones (ERD)
|
|
|
|
```
|
|
┌─────────────────────────────────────────────────────────────────────────────────────────┐
|
|
│ VEHÍCULOS (Existente) │
|
|
└─────────────────────────────────────────────────────────────────────────────────────────┘
|
|
|
|
┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
|
|
│ brands │ │ models │ │ years │ │ engines │
|
|
├──────────────┤ ├──────────────┤ ├──────────────┤ ├──────────────┤
|
|
│ id (PK) │◄────│ brand_id(FK) │ │ id (PK) │ │ id (PK) │
|
|
│ name │ │ id (PK) │ │ year │ │ name │
|
|
│ country │ │ name │ └──────┬───────┘ │ displacement │
|
|
│ founded_year │ │ body_type │ │ │ cylinders │
|
|
└──────────────┘ │ generation │ │ │ fuel_type │
|
|
└──────┬───────┘ │ │ power_hp │
|
|
│ │ └──────┬───────┘
|
|
│ │ │
|
|
▼ ▼ ▼
|
|
┌─────────────────────────────────────────────────────┐
|
|
│ model_year_engine (MYE) │
|
|
├─────────────────────────────────────────────────────┤
|
|
│ id (PK) ◄─────── Identificador único de │
|
|
│ model_id (FK) configuración vehículo │
|
|
│ year_id (FK) │
|
|
│ engine_id (FK) │
|
|
│ trim_level │
|
|
│ drivetrain │
|
|
│ transmission │
|
|
└────────────────────────┬────────────────────────────┘
|
|
│
|
|
│ (1:N)
|
|
▼
|
|
┌─────────────────────────────────────────────────────────────────────────────────────────┐
|
|
│ FASE 1: CATÁLOGO DE PARTES │
|
|
└─────────────────────────────────────────────────────────────────────────────────────────┘
|
|
|
|
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
|
|
│ part_categories │ │ part_groups │ │ parts │
|
|
├──────────────────┤ ├──────────────────┤ ├──────────────────┤
|
|
│ id (PK) │◄────────│ category_id (FK) │◄────────│ group_id (FK) │
|
|
│ name │ │ id (PK) │ │ id (PK) │
|
|
│ name_es │ │ name │ │ oem_part_number │
|
|
│ parent_id (FK)───┼─┐ │ name_es │ │ name │
|
|
│ slug │ │ │ slug │ │ name_es │
|
|
│ icon_name │ │ │ display_order │ │ description │
|
|
│ display_order │◄┘ └──────────────────┘ │ weight_kg │
|
|
└──────────────────┘ │ material │
|
|
│ │ is_discontinued │
|
|
│ (Ej: 12 categorías) │ superseded_by_id │
|
|
│ - Engine └────────┬─────────┘
|
|
│ - Brakes │
|
|
│ - Suspension │
|
|
│ - etc. │
|
|
│
|
|
┌────────────────────────────────────────────┼────────────────┐
|
|
│ │ │
|
|
▼ ▼ │
|
|
┌──────────────────┐ ┌──────────────────┐ │
|
|
│ vehicle_parts │ │ (FASE 2) │ │
|
|
├──────────────────┤ │ aftermarket_parts│ │
|
|
│ id (PK) │ ├──────────────────┤ │
|
|
│ mye_id (FK) ─────┼──► model_year_engine │ oem_part_id (FK)─┼─────────┤
|
|
│ part_id (FK) ────┼──► parts │ manufacturer_id │ │
|
|
│ quantity_required│ │ part_number │ │
|
|
│ position │ │ quality_tier │ │
|
|
│ fitment_notes │ │ price_usd │ │
|
|
└──────────────────┘ └──────────────────┘ │
|
|
│
|
|
┌──────────────────┐ │
|
|
│ part_cross_refs │ │
|
|
├──────────────────┤ │
|
|
│ part_id (FK) ────┼─────────┘
|
|
│ cross_ref_number │
|
|
│ reference_type │
|
|
└──────────────────┘
|
|
|
|
┌─────────────────────────────────────────────────────────────────────────────────────────┐
|
|
│ FASE 2: AFTERMARKET Y FABRICANTES │
|
|
└─────────────────────────────────────────────────────────────────────────────────────────┘
|
|
|
|
┌──────────────────┐ ┌──────────────────┐
|
|
│ manufacturers │◄────────│ aftermarket_parts│
|
|
├──────────────────┤ ├──────────────────┤
|
|
│ id (PK) │ │ manufacturer_id │
|
|
│ name │ │ oem_part_id (FK) │──► parts
|
|
│ type │ │ part_number │
|
|
│ quality_tier │ │ name │
|
|
│ country │ │ price_usd │
|
|
│ logo_url │ │ warranty_months │
|
|
└──────────────────┘ └──────────────────┘
|
|
|
|
┌─────────────────────────────────────────────────────────────────────────────────────────┐
|
|
│ FASE 3: DIAGRAMAS EXPLOSIONADOS │
|
|
└─────────────────────────────────────────────────────────────────────────────────────────┘
|
|
|
|
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
|
|
│ diagrams │ │ vehicle_diagrams │ │diagram_hotspots │
|
|
├──────────────────┤ ├──────────────────┤ ├──────────────────┤
|
|
│ id (PK) │◄────────│ diagram_id (FK) │ │ diagram_id (FK)──┼──► diagrams
|
|
│ name │ │ mye_id (FK) ─────┼──► MYE │ part_id (FK) ────┼──► parts
|
|
│ name_es │ └──────────────────┘ │ callout_number │
|
|
│ group_id (FK)────┼──► part_groups │ shape │
|
|
│ image_path │ │ coords │
|
|
│ thumbnail_path │ └──────────────────┘
|
|
└──────────────────┘
|
|
|
|
┌─────────────────────────────────────────────────────────────────────────────────────────┐
|
|
│ FASE 4: BÚSQUEDA Y VIN │
|
|
└─────────────────────────────────────────────────────────────────────────────────────────┘
|
|
|
|
┌──────────────────┐ ┌──────────────────┐
|
|
│ parts_fts │ │ vin_cache │
|
|
│ (FTS5 Virtual) │ ├──────────────────┤
|
|
├──────────────────┤ │ vin │
|
|
│ oem_part_number │ │ decoded_data │──► JSON from NHTSA
|
|
│ name │ │ mye_id (FK) ─────┼──► model_year_engine
|
|
│ name_es │ │ expires_at │
|
|
│ description │ └──────────────────┘
|
|
└──────────────────┘
|
|
```
|
|
|
|
## Flujo de Navegación del Usuario
|
|
|
|
```
|
|
┌─────────┐ ┌─────────┐ ┌─────────────────┐ ┌────────────────┐
|
|
│ Marcas │───►│ Modelos │───►│ Vehículos │───►│ Categorías │
|
|
│ (brands)│ │(models) │ │(model_year_eng) │ │(part_categories│
|
|
└─────────┘ └─────────┘ └─────────────────┘ └───────┬────────┘
|
|
│
|
|
┌────────────────────────────────────────────────────────┘
|
|
│
|
|
▼
|
|
┌─────────────┐ ┌─────────────┐ ┌─────────────────────────────┐
|
|
│ Grupos │───►│ Partes │───►│ Detalle Parte │
|
|
│(part_groups)│ │ (parts) │ │ + Alternativas Aftermarket │
|
|
└─────────────┘ └─────────────┘ │ + Cross-References │
|
|
│ │ + Diagrama con Hotspots │
|
|
│ └─────────────────────────────┘
|
|
│
|
|
▼
|
|
┌─────────────────────┐
|
|
│ Filtrar por MYE │
|
|
│ (vehicle_parts) │
|
|
│ Cantidad, Posición │
|
|
└─────────────────────┘
|
|
```
|
|
|
|
## Resumen de Tablas por Fase
|
|
|
|
| Fase | Tabla | Registros Esperados | Descripción |
|
|
|------|-------|---------------------|-------------|
|
|
| Base | brands | ~50 | Marcas de vehículos |
|
|
| Base | models | ~2,000 | Modelos de vehículos |
|
|
| Base | years | ~30 | Años (1995-2025) |
|
|
| Base | engines | ~500 | Especificaciones de motores |
|
|
| Base | model_year_engine | ~50,000 | Configuraciones únicas |
|
|
| **F1** | part_categories | 12 | Categorías principales |
|
|
| **F1** | part_groups | ~200 | Subcategorías |
|
|
| **F1** | parts | ~100,000 | Catálogo maestro OEM |
|
|
| **F1** | vehicle_parts | ~500,000 | Fitment por vehículo |
|
|
| **F2** | manufacturers | ~50 | OEM y aftermarket |
|
|
| **F2** | aftermarket_parts | ~300,000 | Alternativas aftermarket |
|
|
| **F2** | part_cross_references | ~200,000 | Números alternativos |
|
|
| **F3** | diagrams | ~5,000 | Diagramas explosionados |
|
|
| **F3** | vehicle_diagrams | ~20,000 | Asignación a vehículos |
|
|
| **F3** | diagram_hotspots | ~50,000 | Áreas clickeables |
|
|
| **F4** | parts_fts | Virtual | Índice full-text |
|
|
| **F4** | vin_cache | Variable | Cache de VINs |
|
|
|
|
## Ejemplo de Datos Relacionados
|
|
|
|
### Un Toyota Camry 2023 2.5L LE completo:
|
|
|
|
```sql
|
|
-- Vehículo
|
|
brands.id = 1 (Toyota)
|
|
models.id = 1 (Camry)
|
|
years.id = 4 (2023)
|
|
engines.id = 1 (2.5L 4-Cyl)
|
|
model_year_engine.id = 1
|
|
|
|
-- Sus partes (via vehicle_parts)
|
|
┌────────────────┬───────────────────────────────┬──────┬──────────┐
|
|
│ OEM # │ Parte │ Cant │ Posición │
|
|
├────────────────┼───────────────────────────────┼──────┼──────────┤
|
|
│ 04152-YZZA1 │ Filtro de Aceite │ 1 │ - │
|
|
│ 17801-0V020 │ Filtro de Aire │ 1 │ - │
|
|
│ 90919-01275 │ Bujía Iridium │ 4 │ - │
|
|
│ 04465-06200 │ Pastillas Freno Delanteras │ 1 │ front │
|
|
│ 04466-06200 │ Pastillas Freno Traseras │ 1 │ rear │
|
|
│ 43512-06190 │ Disco Freno Delantero │ 2 │ front │
|
|
│ 42431-06190 │ Disco Freno Trasero │ 2 │ rear │
|
|
│ 48510-06780 │ Amortiguador Delantero │ 2 │ front │
|
|
│ 48530-06400 │ Amortiguador Trasero │ 2 │ rear │
|
|
└────────────────┴───────────────────────────────┴──────┴──────────┘
|
|
|
|
-- Alternativas para el filtro de aceite (via aftermarket_parts)
|
|
┌────────────────┬─────────┬─────────────────────────────┬─────────┐
|
|
│ Fabricante │ Número │ Nombre │ Precio │
|
|
├────────────────┼─────────┼─────────────────────────────┼─────────┤
|
|
│ Bosch │ 3311 │ Premium Oil Filter │ $12.99 │
|
|
│ Fram │ XG9972 │ Ultra Synthetic Oil Filter │ $8.49 │
|
|
│ WIX │ 57047 │ Oil Filter │ $7.99 │
|
|
└────────────────┴─────────┴─────────────────────────────┴─────────┘
|
|
```
|