- TypeScript 99.6%
- Dockerfile 0.3%
- JavaScript 0.1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
CI Quality / Quality Pipeline (push) Successful in 40s
Reviewed-on: #1 |
||
| .forgejo/workflows | ||
| .idea | ||
| docs | ||
| examples | ||
| src | ||
| tests | ||
| .dockerignore | ||
| .env.example | ||
| .gitignore | ||
| .prettierrc | ||
| docker-compose.yml | ||
| Dockerfile | ||
| eslint.config.js | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| vitest.config.ts | ||
ASELSAN IVME Integration Service
IQVizyon sistemindeki MongoDB ve InfluxDB verilerini ASELSAN IVME MES REST formatina donusturen, token tabanli ve production deployment'a hazir Fastify API servisidir.
Mimari Ozet
routes -> controllers -> send service -> mongo/influx services
-> transformers
-> validators
-> aselsan client -> token service
ASELSAN'a HTTP istegi yalnizca aselsanClient.service.ts icinden atilir.
Token secimi token.service.ts icinde, Authorization header uretimi ASELSAN
client icinde yapilir.
Teknoloji Secimi
- Node.js 20+ ve TypeScript
- Fastify, Swagger/OpenAPI
- MongoDB native driver
- InfluxDB client
- undici HTTP client
- zod validation
- pino logging ve secret redaction
- Vitest, ESLint, Prettier
- Docker multi-stage production image
Veri Kaynaklari
MongoDB collectionlari:
machines,products,projects,alarmscompanies,organizations,stop_typesshift_plan,machine_shift_assignmentreport_program,users,iqv_machine_datas
InfluxDB:
- Bucket:
INFLUX_BUCKET, varsayilanchampion - Measurement:
machines.machine_code - Field filtresi:
machines.connection_details.selected_keys - Sorgular pivot edilmis, range ve limit kontrollu calisir.
Mes_ProcessParameterssadece onayli CNC/IoT alanlarini flat record olarak uretir; IP, MQTT, app metadata ve debug alanlari payload'a tasinmaz.
ASELSAN Veri Setleri
ASELSAN entegrasyonunda toplam 14 veri servisi vardir (13 resmi + 1 internal APS):
Mes_MachinesMes_ProductionOrdersMes_ProductionLogsMes_CycleTimesMes_ProcessParametersMes_ScrapProductsMes_ReworkLogsMes_KPIsMes_OEEMes_MachineOccupancyMes_ApsPredictionHistoryMes_OEE_Occupancy_KPISMes_OperatorPerformanceStandardDurations
Ana entegrasyon API sayisi 26'dir: 13 adet GET /api/mapping/* preview endpointi
ve 13 adet POST /api/aselsan/send/* gonderim endpointi. Ek sistem/test
endpointleriyle birlikte yaklasik 33 endpoint vardir: GET /health, GET /docs,
auth testleri, Mongo testleri ve Influx test endpointi.
Mes_ProcessParameters whitelist
CNC alanlari: connection, time_cut_time_cumulative,
time_cycle_time_cumulative, time_online_time_cumulative,
status_status_code, status_alarm_code, status_alarm_message,
spindle_feed, spindle_speed, servo_speed, servo_load,
servo_max_current, position_x, position_y, position_z,
program_name, program_sequence, part_counter.
IoT alanlari: Tem1, Hum, Noise, E_V1, E_V2, E_V3, E_A1,
E_A2, E_A3, E_FQ, PAT, E_PRT, E_ETAC, E_ETGC.
Gonderilmeyen alanlar: LanIP, IP, ip, topic, Topic, MQTT,
mqtt, app, source_app, mqtt-influx, connection_details,
selected_keys, E_ETR1, E_ETR2, E_ETR3, E_ETR4.
Noktali CNC alanlari normalize edilir: spindle.speed -> spindle_speed,
program.name -> program_name, part.counter -> part_counter gibi.
Her field ayri bir Mes_ProcessParameters kaydidir; nested Parameters
array'i uretilmez.
Detayli ASELSAN endpoint karsilastirmasi ve IQVizyon mapping karsiliklari icin: docs/aselsan-endpoint-mapping.md
Guvenlik Yaklasimi
- Helmet, CORS, rate limit ve body limit aktif.
ENABLE_SWAGGER=falseile Swagger production'da kapatilabilir.- Token, cookie, x-api-key, Mongo URI, Influx token ve MQTT secret alanlari loglarda maskelenir.
- Token yoksa ASELSAN'a request atilmaz.
- Test/live token ayrimi
ASELSAN_SEND_MODEile yapilir. - Payloadlar ASELSAN'a gitmeden once validator hattindan gecer.
- Payloadlar Excel
ColumnName_ENsozlugundeki alanlarla sinirlidir; Excel disi alan varsa validation error doner.
Canli Oncesi ASELSAN Konfigurasyonu
Canli gonderim oncesi asagidaki env ayarlari kullanilir:
| Env | Varsayilan | Aciklama |
|---|---|---|
ASELSAN_ID_MODE |
intMap |
Mongo ObjectId string yerine deterministik integer ID mapping |
ASELSAN_ID_MAP_COLLECTION |
iqv_aselsan_id_map |
ID mapping MongoDB collection adi |
ASELSAN_AUTH_SCHEME |
raw |
Authorization: {token} (Bearer prefix yok) |
ASELSAN_PAYLOAD_MODE |
dataOnly |
Body formati { "data": [] } |
ASELSAN_NULL_FIELD_MODE |
include |
null alanlari payload'da tut (omit ile cikarilabilir) |
ASELSAN_EMPTY_JSON_STRING_MODE |
null |
Bos JSON alanlari icin null, "[]", "{}" veya "" |
ASELSAN_SAMPLING_FIELD_NAME |
SampingPeriodMs |
ProcessParameters outbound alan adi (ODG) |
ID mapping: sourceType + sourceId her zaman ayni pozitif integer dondurur. Mapping
MongoDB'de persistent saklanir; test ortaminda in-memory fallback kullanilir.
Outbound payload'dan ODG disi alanlar (or. MachineID, CycleTimeID, OrderID,
RecordID) cikarilir. Mes_OperatorPerformance alarms tabanli hesaplanir.
Dokumandaki ornek proje/urun/makine/product_id/operator_id degerleri yalnizca test/fixture icindir; uygulama kodunda hardcoded kullanilmaz.
Kurulum
cd C:\Users\muham\Desktop\iqv-aselsan\aselsan-ivme-integration
npm.cmd install
Copy-Item .env.example .env
Linux:
npm install
cp .env.example .env
Detayli kurulum icin docs/INSTALLATION.md dosyasina bak.
Calistirma
Windows PowerShell:
npm.cmd run dev
npm.cmd run build
npm.cmd start
npm.cmd test
npm.cmd run lint
Linux bash:
npm run dev
npm run build
npm start
npm test
npm run lint
Docker:
docker compose up --build -d
Swagger
http://localhost:3000/docs
Production'da kapatmak icin:
ENABLE_SWAGGER=false
Endpointler
Health:
GET /health
Test:
GET /api/test/auth/statusGET /api/test/auth/headersGET /api/test/mongo/machinesGET /api/test/mongo/projectsGET /api/test/influx/:machineCode
Toplam veri servisleri: 13. Ana mapping/send endpointleri: 26. Sistem/test endpointleri dahil toplam endpoint sayisi yaklasik 33'tur.
Mapping preview:
GET /api/mapping/mes-machinesGET /api/mapping/mes-production-ordersGET /api/mapping/mes-production-logsGET /api/mapping/mes-cycle-timesGET /api/mapping/mes-process-parameters?machineCode=3dyazici&range=-1hGET /api/mapping/mes-scrap-productsGET /api/mapping/mes-rework-logsGET /api/mapping/mes-kpisGET /api/mapping/mes-oeeGET /api/mapping/mes-machine-occupancyGET /api/mapping/mes-aps-prediction-historyGET /api/mapping/mes-oee-occupancy-kpisGET /api/mapping/mes-operator-performanceGET /api/mapping/standard-durations
Mes_OperatorPerformance operasyon baslangic/bitis araligi ve alarms
collection start/stop kayitlari uzerinden hesaplanir. Alarms kaydi
bulunamazsa operator iliskisi korunur; WorkingHours=0, EfficiencyPercentage=0,
ErrorRate=100 olarak donebilir. Dokumandaki ornek proje/urun/makine/product_id/
operator_id degerleri yalnizca test/fixture icindir; uygulama kodunda hardcoded
kullanilmaz.
ASELSAN send:
POST /api/aselsan/send/mes-machinesPOST /api/aselsan/send/mes-production-ordersPOST /api/aselsan/send/mes-production-logsPOST /api/aselsan/send/mes-cycle-timesPOST /api/aselsan/send/mes-process-parametersPOST /api/aselsan/send/mes-scrap-productsPOST /api/aselsan/send/mes-rework-logsPOST /api/aselsan/send/mes-kpisPOST /api/aselsan/send/mes-oeePOST /api/aselsan/send/mes-machine-occupancyPOST /api/aselsan/send/mes-aps-prediction-historyPOST /api/aselsan/send/mes-oee-occupancy-kpisPOST /api/aselsan/send/mes-operator-performancePOST /api/aselsan/send/standard-durationsPOST /api/aselsan/send/all
Mock ASELSAN receiver (local test):
POST /api/mock-aselsan/:datasetGET /api/mock-aselsan/requestsGET /api/mock-aselsan/requests/:idDELETE /api/mock-aselsan/requests
Local Mock ASELSAN Test Akisi
Gercek ASELSAN API'sine POST atilmadan once, send endpointlerinin local mock receiver'a POST attigini dogrulamak icin:
Adim 1 — .env icinde (.env.example ile ayni):
PORT=3042
ASELSAN_BASE_URL=http://localhost:3042/api/mock-aselsan/
ASELSAN_SEND_MODE=test
ASELSAN_TEST_TOKEN=mock-test-token
ASELSAN_AUTH_TYPE=bearer
ASELSAN_PAYLOAD_MODE=dataOnly
ASELSAN_ENDPOINT_MES_MACHINES=PostMachine
ASELSAN_ENDPOINT_MES_PRODUCTION_ORDERS=PostProductionOrders
ASELSAN_ENDPOINT_MES_PROCESS_PARAMETERS=PostProcessParameters
Gercek ASELSAN URL yalnizca yorum satirinda birakilir:
# REAL_ASELSAN_BASE_URL=https://api.ahtapot.xyz/api/IntegrationIqvizyon/
Adim 2:
npm.cmd run dev
Adim 3 — Postman veya curl ile send endpointlerini cagirin:
curl -X POST "http://localhost:3042/api/aselsan/send/mes-machines?limit=10"
curl -X POST "http://localhost:3042/api/aselsan/send/mes-production-orders?limit=10"
curl -X POST "http://localhost:3042/api/aselsan/send/mes-process-parameters?machineCode=3dyazici&limit=10"
Servis su adrese POST atar: http://localhost:3042/api/mock-aselsan/PostMachine
Adim 4 — Mock receiver'a gelen kayitlari gormek icin:
curl http://localhost:3042/api/mock-aselsan/requests
Adim 5 — Store temizlemek icin:
curl -X DELETE http://localhost:3042/api/mock-aselsan/requests
POST /api/aselsan/send/all resmi API kapsamindaki 13 veri setini gonderir;
Mes_ApsPredictionHistory default olarak haric tutulur.
Local mock test (StandardDurations):
curl -X DELETE http://localhost:3042/api/mock-aselsan/requests
curl -X POST "http://localhost:3042/api/aselsan/send/standard-durations?limit=5"
curl http://localhost:3042/api/mock-aselsan/requests
Local mock test (DigitalMaturity / OEE Occupancy KPIs):
curl -X DELETE http://localhost:3042/api/mock-aselsan/requests
curl -X POST "http://localhost:3042/api/aselsan/send/mes-oee-occupancy-kpis?limit=2"
curl http://localhost:3042/api/mock-aselsan/requests
Beklenen mock kayit: endpoint=PostDigitalMaturityOEEOccupancyKPIs, dataset=mes-oee-occupancy-kpis,
payloadMode=dataOnly, unknownFields=[], yeni tarih alanlari (WeeklyStartDate vb.), eski split
tarih alanlari (WeeklyOEEStartDate vb.) yok.
Mes_ProductionLogs notu: BREAK/END kayitlarinda StartTime ve Duration, ayni stage
icindeki ayni machine_id'ye ait onceki Operation_Start kaydina baglidir. Baslangic
kaydi bulunamazsa null kalir — bu validasyon hatasi degildir. Duration dolu kayitlari
gormek icin: GET /api/mapping/mes-production-logs?onlyWithDuration=true
TS02 Kontrollu Veri Dogrulama Senaryosu
Mapping preview ve send endpointleri ortak filtreleri destekler:
GET /api/mapping/mes-production-orders?projectCode=TS02&productCode=telefon_tutacağı&machineCodes=3dyazici,3dyazici_2&dateFrom=2026-03-06T00:00:00.000Z&dateTo=2026-05-09T00:00:00.000Z&limit=20
GET /api/mapping/mes-production-logs?projectCode=TS02&productCode=telefon_tutacağı&onlyWithDuration=true&limit=50
POST /api/aselsan/send/all?projectCode=TS02&productCode=telefon_tutacağı&machineCodes=3dyazici,3dyazici_2&limit=20
Desteklenen filtreler: projectCode, productCode, machineCode, machineCodes, dateFrom, dateTo, limit.
Ornek curl
curl http://localhost:3000/health
curl http://localhost:3000/api/test/auth/status
curl "http://localhost:3000/api/mapping/mes-process-parameters?machineCode=3dyazici&range=-1h&limit=10"
curl -X POST "http://localhost:3000/api/aselsan/send/mes-machines?limit=50"
curl -X POST http://localhost:3000/api/aselsan/send/all \
-H "content-type: application/json" \
-d "{\"machineCode\":\"3dyazici\",\"range\":\"-1h\",\"limit\":10}"
Komutlar
npm run typecheck
npm run build
npm run lint
npm test
npm audit
Production Notlari
.envdosyasini git'e ekleme.NODE_ENV=production,LOG_LEVEL=info,ENABLE_SWAGGER=falsekullan.ASELSAN_SEND_MODE=liveyapmadan once gercek siparis/is emri/stok alanlarini dogrula.- MongoDB ve InfluxDB connection string/token degerlerini secret manager veya deployment secret mekanizmasi ile ver.
Analytics Worker
Uzun donem 180 gunluk OEE/KPI ve agir InfluxDB hesaplari icin Python tabanli ayri bir analytics worker eklenebilir. Bu API, worker'in urettigi ozetleri yeni servis/transformer katmani ile ASELSAN'a gonderecek sekilde genisletilebilir.