U

Documentation Architecture Diagrams

Architecture Diagrams

Visual overview of the planning data model, Excel import pipeline, and calculation services.

Planning Data Model

Each row in plan_line_items represents one planning cell, identified by the combination of 3 core dimensions plus up to 7 optional extended dimensions.

flowchart TD
    PLI["plan_line_items\n(un rând = o celulă)"]

    subgraph CORE["Dimensiuni de bază"]
        T["TIME\ntime_key\n2026-07"]
        E["ENTITY\nentity_code\nRO / BG"]
        A["ACCOUNT\naccount_code\nARR / COGS"]
    end

    subgraph EXT["Dimensiuni extinse (nullable)"]
        CC["COST_CENTER\ncost_center_code\nIT / HR / MKT"]
        PR["PRODUCT\nproduct_code\nSKU-001"]
        CH["CHANNEL\nchannel_code\nONLINE / RETAIL"]
        PJ["PROJECT\nproject_code\nCAP-2026"]
        DP["DEPARTMENT\ndepartment_code\nFIN / SALES"]
        CS["CUSTOMER_SEGMENT\ncustomer_segment_code\nENT / SME / B2C"]
        GE["GEOGRAPHY\ngeography_code\nEU / APAC"]
    end

    AMT["amount\n138 893.63"]

    CORE --> PLI
    EXT --> PLI
    PLI --> AMT

    classDef core fill:#f1f5f9,stroke:#334155,color:#0f172a,stroke-width:1px;
    classDef ext fill:#f0fdf4,stroke:#16a34a,color:#0f172a,stroke-width:1px;
    classDef cell fill:#eff6ff,stroke:#2563eb,color:#0f172a,stroke-width:2px;
    classDef amt fill:#fefce8,stroke:#ca8a04,color:#0f172a,stroke-width:1px;
    class T,E,A core;
    class CC,PR,CH,PJ,DP,CS,GE ext;
    class PLI cell;
    class AMT amt;
                        
Core dimensions (required) Extended dimensions (nullable — NULL = "all") Planning cell Value

Excel Import Pipeline

The importer auto-detects the file format (4 or 11 columns) and is fully backward-compatible. Files over 500 rows are processed asynchronously via a queue job.

flowchart LR
    subgraph INPUT["Input Excel (.xlsx)"]
        F4["Format clasic (4 col)\ntime_key, entity_code,\naccount_code, amount"]
        F11["Format extins (11 col)\n+ cost_center_code\n+ product_code\n+ channel_code\n+ project_code\n+ department_code\n+ customer_segment_code\n+ geography_code"]
    end

    DET["Detectare format\nPlanImportController\nnumărare coloane header"]

    F4 --> DET
    F11 --> DET

    DET --> VAL["Validare rânduri\n• time_key format YYYY-MM\n• amount numeric\n• dim codes uppercase"]

    VAL -->|"valid"| PARSE["Parsare dimensiuni\ncol 5–11 opționale\nempty → NULL"]
    VAL -->|"invalid"| ERR["Eroare validare\nrând + motiv"]

    PARSE --> PREV["Preview (sync)\nprimele 10 rânduri"]
    PARSE --> JOB["Import job (async)\n> 500 rânduri"]

    PREV --> UPSERT
    JOB --> UPSERT

    UPSERT["DbalUpsert\nIdentitate: toate 10 dim\nNULL tratat ca IS NULL\nINSERT sau UPDATE amount"]

    UPSERT --> DB["plan_line_items\n✓ date salvate"]

    classDef input fill:#f0fdf4,stroke:#16a34a,color:#0f172a,stroke-width:1px;
    classDef proc fill:#f8fafc,stroke:#334155,color:#0f172a,stroke-width:1px;
    classDef ok fill:#eff6ff,stroke:#2563eb,color:#0f172a,stroke-width:1px;
    classDef err fill:#fef2f2,stroke:#dc2626,color:#0f172a,stroke-width:1px;
    class F4,F11 input;
    class DET,VAL,PARSE,PREV,JOB,UPSERT proc;
    class DB ok;
    class ERR err;
                        
Format Column order
Classic (4 col) time_key, entity_code, account_code, amount
Extended (11 col) time_key, entity_code, account_code, amount, cost_center_code, product_code, channel_code, project_code, department_code, customer_segment_code, geography_code

Calculation Pipeline

Three calculation services read from and write back to plan_line_items using a 9-dimension pipe-separated cell key. All services preserve extended dimensions.

flowchart TD
    DATA["plan_line_items\ndate brute importate"]

    DATA --> CALC["PlanningCalculationService\nRecalculare formule\ntime|entity|account|cc|prod|ch|proj|dept|seg|geo"]
    DATA --> ALLOC["AllocationSimulatorService\nAlocare procentuală\nsursă → destinație"]
    DATA --> DBP["DriverBasedPlanningService\nDriver-Based Planning\nbase_row × driver_value"]

    CALC -->|"upsert"| RES["plan_line_items\nvalori calculate"]
    ALLOC -->|"upsert"| RES
    DBP -->|"upsert"| RES

    RES --> GRID["Grid view\n11 coloane"]
    RES --> EXPORT["Export Excel\n11 coloane"]
    RES --> REPORT["Version summary\nsumar pe cont"]
    RES --> VAR["Variance & compare\ndelta amount + %"]

    classDef svc fill:#faf5ff,stroke:#7c3aed,color:#0f172a,stroke-width:1px;
    classDef data fill:#f8fafc,stroke:#334155,color:#0f172a,stroke-width:1px;
    classDef out fill:#eff6ff,stroke:#2563eb,color:#0f172a,stroke-width:1px;
    class CALC,ALLOC,DBP svc;
    class DATA,RES data;
    class GRID,EXPORT,REPORT,VAR out;
                        
Service PHP class Purpose
Formula engine PlanningCalculationService Applies formula expressions (e.g. {REVENUE}-{COST}) across grouped cells
Allocation AllocationSimulatorService Distributes a source amount proportionally across multiple target rows
DBP DriverBasedPlanningService Multiplies base_row.amount × driver_value and creates new output rows