# pebbdev/infinit_track_be architecture

> Architecture diagram of the GitHub repository pebbdev/infinit_track_be, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pebbdev/infinit_track_be
- Repository: https://github.com/pebbdev/infinit_track_be

## Overview

##### Project type and purpose
- This is a standalone backend API service (“Infinite Track – Backend API”) built with Node.js & Express.
- Purpose: manage multi-mode attendance, WFA booking, analytics (discipline index), and automated nightly jobs using a pure Fuzzy AHP engine. It exposes REST endpoints and cron-style jobs.

##### File structure
- Top level: configuration files (.env, ESLint, Prettier, Sequelize), deployment scripts (deploy-production.sh, PM2 config), docs (OpenAPI), and server entry points (src/server.js, src/app.js).
- src/config: environment aggregation (database, cloudinary, index)
- src/models: Sequelize models, migrations, seeders
- src/controllers ↔ src/routes: MVC layers handling HTTP requests
- src/analytics & src/utils: Fuzzy AHP engine and helper functions
- src/jobs: scheduled tasks (autoCheckout, createGeneralAlpha, resolveWfaBookings)
- src/middlewares: authentication, authorization, validation, error handling
- External integrations: Cloudinary, Geoapify, Winston logging
- Database: MySQL/MariaDB via Sequelize ORM
- Process manager: PM2 cluster mode

##### Key insights from README
- Four functional pillars: multi-mode attendance, WFA recommendation (Fuzzy AHP), nightly automated jobs, analytics/reporting.
- Tech stack: Node.js, Express, Sequelize, JWT/RBAC, Swagger/OpenAPI.
- Cron jobs scheduled in Asia/Jakarta timezone.
- Swagger UI at /docs, health check at /health.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client"]:::external

    %% API Layer
    subgraph "API Layer"
        direction TB
        server["src/server.js"]:::internal
        app["src/app.js"]:::internal
    end

    Client --> server
    server --> app

    %% Middlewares
    subgraph "Middlewares"
        direction TB
        authJwt["authJwt"]:::internal
        roleGuard["roleGuard"]:::internal
        validator["validator"]:::internal
        errorHandler["errorHandler"]:::internal
    end

    app --> authJwt
    app --> roleGuard
    app --> validator
    app --> errorHandler

    %% Routes
    subgraph "Routes"
        direction TB
        attendanceRoutes["attendance.routes.js"]:::internal
        authRoutes["auth.routes.js"]:::internal
        wfaRoutes["wfa.routes.js"]:::internal
        jobsRoutes["jobs.routes.js"]:::internal
        healthRoute["index.js (health route)"]:::internal
    end

    app --> attendanceRoutes
    app --> authRoutes
    app --> wfaRoutes
    app --> jobsRoutes
    app --> healthRoute

    %% Controllers
    subgraph "Controllers"
        direction TB
        attendanceCtrl["attendance.controller.js"]:::internal
        authCtrl["auth.controller.js"]:::internal
        wfaCtrl["wfa.controller.js"]:::internal
        jobsCtrl["jobs.controller.js"]:::internal
    end

    attendanceRoutes --> attendanceCtrl
    authRoutes --> authCtrl
    wfaRoutes --> wfaCtrl
    jobsRoutes --> jobsCtrl
    healthRoute --> jobsCtrl

    %% Analytics Engine
    subgraph "Analytics Engine (Fuzzy AHP)" 
        direction TB
        fahp["fahp.js"]:::internal
        normalization["normalization.js"]:::internal
        labeling["labeling.js"]:::internal
        configFahp["config.fahp.js"]:::internal
        seedFahp["seed.fahp.js"]:::internal
        fuzzyEngine["fuzzyAhpEngine.js"]:::internal
    end

    attendanceCtrl --> fuzzyEngine
    wfaCtrl --> fuzzyEngine
    jobsCtrl --> fuzzyEngine

    fuzzyEngine --> fahp
    fuzzyEngine --> normalization
    fuzzyEngine --> labeling

    %% Models & Database
    subgraph "Models & DB"
        direction TB
        dbConfig["database.js"]:::internal
        dbCli["database-cli.cjs"]:::internal
        modelsIndex["index.js"]:::internal
        modelFiles["*.model.js"]:::internal
        migrations["migrations/"]:::internal
        seeders["seeders/"]:::internal
        MySQLDB["MySQL/MariaDB"]:::db
    end

    app --> dbConfig
    app --> dbCli
    attendanceCtrl --> modelsIndex
    authCtrl --> modelsIndex
    wfaCtrl --> modelsIndex
    jobsCtrl --> modelsIndex

    modelsIndex --> modelFiles
    modelFiles --> migrations
    modelFiles --> seeders
    modelFiles --> MySQLDB

    fuzzyEngine --> MySQLDB

    %% Jobs Scheduler
    subgraph "Scheduled Jobs" 
        direction TB
        scheduler["Job Scheduler"]:::job
        autoCheckout["autoCheckout.job.js"]:::job
        generalAlpha["createGeneralAlpha.job.js"]:::job
        resolveWfa["resolveWfaBookings.job.js"]:::job
    end

    scheduler --> autoCheckout
    scheduler --> generalAlpha
    scheduler --> resolveWfa

    autoCheckout --> fuzzyEngine
    generalAlpha --> fuzzyEngine
    resolveWfa --> fuzzyEngine

    autoCheckout --> modelsIndex
    generalAlpha --> modelsIndex
    resolveWfa --> modelsIndex

    %% External Services
    subgraph "External Services"
        direction TB
        cloudinary["Cloudinary"]:::external
        geoapify["Geoapify"]:::external
        winston["Winston Logger"]:::external
    end

    attendanceCtrl --> cloudinary
    wfaCtrl --> geoapify
    jobsCtrl --> cloudinary
    jobsCtrl --> geoapify
    app --> winston
    jobsCtrl --> winston

    %% Swagger & Docs
    docs["docs/openapi.yaml"]:::external
    swaggerUI["Swagger UI (/docs)"]:::external
    app --> swaggerUI
    swaggerUI --> docs

    %% Deployment & Infra
    pm2["ecosystem.config.js"]:::external
    deploy1["deploy-production.sh"]:::external
    deploy2["quick-production-setup.sh"]:::external
    healthScript["health-check.sh"]:::external

    server --> pm2
    server --> deploy1
    server --> deploy2
    server --> healthScript

    %% Click Events
    click server "https://github.com/pebbdev/infinit_track_be/blob/master/src/server.js"
    click app "https://github.com/pebbdev/infinit_track_be/blob/master/src/app.js"
    click authJwt "https://github.com/pebbdev/infinit_track_be/blob/master/src/middlewares/authJwt.js"
    click roleGuard "https://github.com/pebbdev/infinit_track_be/blob/master/src/middlewares/roleGuard.js"
    click validator "https://github.com/pebbdev/infinit_track_be/blob/master/src/middlewares/validator.js"
    click errorHandler "https://github.com/pebbdev/infinit_track_be/blob/master/src/middlewares/errorHandler.js"
    click attendanceRoutes "https://github.com/pebbdev/infinit_track_be/blob/master/src/routes/attendance.routes.js"
    click authRoutes "https://github.com/pebbdev/infinit_track_be/blob/master/src/routes/auth.routes.js"
    click wfaRoutes "https://github.com/pebbdev/infinit_track_be/blob/master/src/routes/wfa.routes.js"
    click jobsRoutes "https://github.com/pebbdev/infinit_track_be/blob/master/src/routes/jobs.routes.js"
    click healthRoute "https://github.com/pebbdev/infinit_track_be/blob/master/src/routes/index.js"
    click attendanceCtrl "https://github.com/pebbdev/infinit_track_be/blob/master/src/controllers/attendance.controller.js"
    click authCtrl "https://github.com/pebbdev/infinit_track_be/blob/master/src/controllers/auth.controller.js"
    click wfaCtrl "https://github.com/pebbdev/infinit_track_be/blob/master/src/controllers/wfa.controller.js"
    click jobsCtrl "https://github.com/pebbdev/infinit_track_be/blob/master/src/controllers/jobs.controller.js"
    click fahp "https://github.com/pebbdev/infinit_track_be/blob/master/src/analytics/fahp.js"
    click normalization "https://github.com/pebbdev/infinit_track_be/blob/master/src/analytics/normalization.js"
    click labeling "https://github.com/pebbdev/infinit_track_be/blob/master/src/analytics/labeling.js"
    click configFahp "https://github.com/pebbdev/infinit_track_be/blob/master/src/analytics/config.fahp.js"
    click seedFahp "https://github.com/pebbdev/infinit_track_be/blob/master/src/analytics/seed.fahp.js"
    click fuzzyEngine "https://github.com/pebbdev/infinit_track_be/blob/master/src/utils/fuzzyAhpEngine.js"
    click dbConfig "https://github.com/pebbdev/infinit_track_be/blob/master/src/config/database.js"
    click dbCli "https://github.com/pebbdev/infinit_track_be/blob/master/src/config/database-cli.cjs"
    click modelsIndex "https://github.com/pebbdev/infinit_track_be/blob/master/src/models/index.js"
    click modelFiles "https://github.com/pebbdev/infinit_track_be/blob/master/src/models/*.model.js"
    click migrations "https://github.com/pebbdev/infinit_track_be/tree/master/src/models/migrations/"
    click seeders "https://github.com/pebbdev/infinit_track_be/tree/master/src/models/seeders/"
    click autoCheckout "https://github.com/pebbdev/infinit_track_be/blob/master/src/jobs/autoCheckout.job.js"
    click generalAlpha "https://github.com/pebbdev/infinit_track_be/blob/master/src/jobs/createGeneralAlpha.job.js"
    click resolveWfa "https://github.com/pebbdev/infinit_track_be/blob/master/src/jobs/resolveWfaBookings.job.js"
    click cloudinary "https://github.com/pebbdev/infinit_track_be/blob/master/src/config/cloudinary.js"
    click geoapify "https://github.com/pebbdev/infinit_track_be/blob/master/src/utils/geofence.js"
    click winston "https://github.com/pebbdev/infinit_track_be/blob/master/src/utils/logger.js"
    click docs "https://github.com/pebbdev/infinit_track_be/blob/master/docs/openapi.yaml"
    click pm2 "https://github.com/pebbdev/infinit_track_be/blob/master/ecosystem.config.js"
    click deploy1 "https://github.com/pebbdev/infinit_track_be/blob/master/deploy-production.sh"
    click deploy2 "https://github.com/pebbdev/infinit_track_be/blob/master/quick-production-setup.sh"
    click healthScript "https://github.com/pebbdev/infinit_track_be/blob/master/health-check.sh"

    %% Styles
    classDef internal fill:#D0E6FF,stroke:#0366d6,stroke-width:1px;
    classDef external fill:#E6FFED,stroke:#28a745,stroke-width:1px;
    classDef job fill:#FFF5CC,stroke:#d4a017,stroke-width:1px;
    classDef db fill:#E0FFFF,stroke:#20a4f3,stroke-width:1px;
```
