# kimduarte/kim architecture

> Architecture diagram of the GitHub repository kimduarte/kim, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kimduarte/kim
- Repository: https://github.com/kimduarte/kim

## Overview

SGP/COLOG is a vehicle-donation asset-management system being migrated from a spreadsheet and Apps Script to a website and TiDB-backed service. The evidenced import workflow sends spreadsheet rows in batches, validates the full import before writing, and then stores the records. The website homepage is explicitly a placeholder; the sampled material does not establish the future management-screen workflow. Apps Script and migration capabilities are represented only where documented; their source was not sampled.

Main entry points: [`site/app/api/importar/route.ts`](https://github.com/kimduarte/kim/blob/main/site/app/api/importar/route.ts) (Import endpoint), [`site/lib/db.ts`](https://github.com/kimduarte/kim/blob/main/site/lib/db.ts) (Database connections), [`site/app/api/setup/route.ts`](https://github.com/kimduarte/kim/blob/main/site/app/api/setup/route.ts) (Setup endpoint), [`apps-script/EnviarParaOSite.gs`](https://github.com/kimduarte/kim/blob/main/apps-script/EnviarParaOSite.gs) (Batch sender)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_import["Spreadsheet import"]
  node_sender["Batch sender<br/>[EnviarParaOSite.gs]"]
  node_legacy["Apps Script interface"]
end

subgraph group_service["Site service"]
  node_import_api["Import endpoint<br/>[route.ts]"]
  node_column_map["Column mapping"]
  node_home["Placeholder homepage<br/>[page.tsx]"]
end

subgraph group_storage["Database"]
  node_db_access["Database connections<br/>[db.ts]"]
  node_schema["Vehicle schema"]
end

subgraph group_setup["Initial setup"]
  node_setup_api["Setup endpoint<br/>[route.ts]"]
end

node_operator(("Spreadsheet operator"))
node_sheet["Vehicle spreadsheet"]
node_tidb[("TiDB Cloud")]

node_operator -->|"edits"| node_sheet
node_sheet -->|"provides rows"| node_sender
node_sender -->|"sends batches"| node_import_api
node_import_api -->|"maps and validates"| node_column_map
node_import_api -->|"queries and writes"| node_db_access
node_db_access -->|"connects and queries"| node_tidb
node_operator -.->|"uses"| node_legacy
node_setup_api -->|"opens connection"| node_db_access
node_setup_api -->|"creates and checks schema"| node_tidb
node_schema -.->|"defines tables"| node_tidb

click node_sender "https://github.com/kimduarte/kim/blob/main/apps-script/EnviarParaOSite.gs"
click node_legacy "https://github.com/kimduarte/kim/blob/main/apps-script/PaginaCompleta.html"
click node_import_api "https://github.com/kimduarte/kim/blob/main/site/app/api/importar/route.ts"
click node_column_map "https://github.com/kimduarte/kim/blob/main/site/lib/colunas-veiculos.ts"
click node_home "https://github.com/kimduarte/kim/blob/main/site/app/page.tsx"
click node_setup_api "https://github.com/kimduarte/kim/blob/main/site/app/api/setup/route.ts"
click node_db_access "https://github.com/kimduarte/kim/blob/main/site/lib/db.ts"
click node_schema "https://github.com/kimduarte/kim/blob/main/site/db/01-criar-tabelas.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sender,node_legacy toneBlue
class node_import_api,node_column_map,node_home,node_tidb toneAmber
class node_db_access,node_schema toneMint
class node_setup_api toneRose
class node_operator,node_sheet toneIndigo
```

## Components

### Spreadsheet import

- [Batch sender](https://github.com/kimduarte/kim/blob/main/apps-script/EnviarParaOSite.gs): `apps-script/EnviarParaOSite.gs`
- [Apps Script interface](https://github.com/kimduarte/kim/blob/main/apps-script/PaginaCompleta.html): `apps-script/PaginaCompleta.html`

### Site service

- [Import endpoint](https://github.com/kimduarte/kim/blob/main/site/app/api/importar/route.ts): `site/app/api/importar/route.ts`
- [Column mapping](https://github.com/kimduarte/kim/blob/main/site/lib/colunas-veiculos.ts): `site/lib/colunas-veiculos.ts`
- [Placeholder homepage](https://github.com/kimduarte/kim/blob/main/site/app/page.tsx): `site/app/page.tsx`

### Database

- [Database connections](https://github.com/kimduarte/kim/blob/main/site/lib/db.ts): `site/lib/db.ts`
- [Vehicle schema](https://github.com/kimduarte/kim/blob/main/site/db/01-criar-tabelas.sql): `site/db/01-criar-tabelas.sql`

### Initial setup

- [Setup endpoint](https://github.com/kimduarte/kim/blob/main/site/app/api/setup/route.ts): `site/app/api/setup/route.ts`

### Other components

- **Spreadsheet operator**
- **Vehicle spreadsheet**
- **TiDB Cloud**

## Connections

- Spreadsheet operator → Vehicle spreadsheet: edits
- Vehicle spreadsheet → Batch sender: provides rows
- Batch sender → Import endpoint: sends batches
- Import endpoint → Column mapping: maps and validates
- Import endpoint → Database connections: queries and writes
- Database connections → TiDB Cloud: connects and queries
- Spreadsheet operator → Apps Script interface: uses
- Setup endpoint → Database connections: opens connection
- Setup endpoint → TiDB Cloud: creates and checks schema
- Vehicle schema → TiDB Cloud: defines tables
