@davoodmehraban89 / Aram / commits / 5209149
Fork 0

docs: specify Peyvast source discovery and governed mapping

davoodmehraban89 committed Oct 23, 2026 at 16:51 UTC 5209149f639c2c942fa654c859133b762a2c535b
6 files changed +366
PROJECT_STATUS.md
+7
@@ -90,6 +90,13 @@ The accepted branch does not include PR #7 desktop/release work, PR #16 alternat
90 2. Reconcile PR #22 documentation and PR #26/27 mapping candidates with the safety fix. Existing drafts do not yet implement the requested persisted old/new preview, user approval, identical-input coalescing or full account/dimension identity.
91 3. Continue the owner-requested read-only Peyvast SQL Server integration and governed DB/Excel mapping design. The customer installation version, schema, supported interface and access remain unverified; no live connector or financial reconciliation is claimed.
92
93 +## Proposed Peyvast and mapping discovery — 2026-10-23
94 +
95 +- Separate candidate branch: `codex/payvast-mapping-discovery-20261023`, stacked on unmerged safety PR #32 at `28d1c57882ec20fc17c2c133bbe62ff56e12973f`.
96 +- Added a proposed shared DB/Excel snapshot and governed mapping design, including old/new preview, authorized approval, unchanged/coalesced duplicates, explicit conflicts, stale-preview rejection, audit and recovery.
97 +- Added a Persian DBA guide and six metadata-only SQL Server SELECT queries. They have not been run on SQL Server or a customer database; runtime, permissions, schema completeness and installation compatibility remain unverified.
98 +- These are design/discovery documents, not a connector, mapping implementation or accepted delivery. No existing candidate is accepted by this change; customer source semantics/access remain required.
99 +
100 ## Control documents
101
102 - [Project log](docs/PROJECT_LOG.md)
docs/PROJECT_LOG.md
+13
@@ -309,3 +309,16 @@ Each new entry must record: UTC timestamp, actor, task/phase, base branch and SH
309 - This follow-up changes only `PROJECT_STATUS.md`, `docs/PROJECT_LOG.md`, `docs/handoff/LATEST_HANDOFF.md`, and the plan publication checkbox. No application/test/protected path changes after the tested code head.
310 - Final successor step: verify the resulting documentation-only commit and its CI, then perform independent remote acceptance. Author must not self-merge; status remains IN_PROGRESS.
311 - Artifacts/releases: NONE. Protected financial data, schema, dependencies and workflow unchanged.
312 +
313 +### 2026-10-23T13:20:34Z — Proposed Peyvast connector/mapping discovery pack prepared
314 +
315 +- Actor: Codex, continuing the owner's Peyvast database and governed mapping direction.
316 +- Dedicated branch: `codex/payvast-mapping-discovery-20261023`; exact stacked base `codex/v1-year-isolation-followup-20261023@28d1c57882ec20fc17c2c133bbe62ff56e12973f`, unmerged PR #32.
317 +- Accepted branch remains `source-data-cleanup@7dc864fd032f0c4ae4d650d89304a01286a6d914`; neither draft is accepted by this task.
318 +- Exact changed files: `PROJECT_STATUS.md`, `docs/PROJECT_LOG.md`, `docs/handoff/LATEST_HANDOFF.md`, `docs/superpowers/specs/2026-10-23-payvast-governed-mapping-design.md`, `docs/integrations/PAYVAST_SQLSERVER_DISCOVERY.md`, `docs/integrations/payvast-schema-discovery.sql`.
319 +- Deliverable: proposed source/snapshot and mapping approval contracts, Persian operator guide, six SQL Server system-metadata SELECT queries. No live connector or application behavior added.
320 +- Verification: independent read-only requirements-note review had no blocking findings; parent independently read all SQL and guide content. Relative links and whitespace checked. Application tests are not rerun for this documentation-only delta; exact stacked base has successful 110-test Backend CI 39959793328.
321 +- SQL Server runtime, customer version/schema/permission completeness and source extraction: NOT_RUN / NOT_VERIFIED. No customer database connection or credentials were available.
322 +- Protected boundary: no source financial values, `data/`, canonical XLSX/PDF, database, application/test code, schema/migration, dependency, workflow, binary or release changed.
323 +- Publication and explicit acceptance: pending in this preparation snapshot; candidate must stay Draft and be reconciled after PR #32 acceptance.
324 +- Artifacts/releases: NONE. Recovery: close the unmerged documentation candidate; no runtime or source data rollback needed.
docs/handoff/LATEST_HANDOFF.md
+8
@@ -20,6 +20,14 @@ This dated correction supersedes the older PR #21 candidate/single-next-action n
20 - Preserve canonical data. No migration, dependency, workflow, source XLSX/PDF, `data/`, financial-source value, ZIP/EXE, tag or release changed.
21 - Next: independent safety review, reconcile dependent drafts, then shared DB/Excel and governed mapping work against documented customer source semantics. A separate design note exists in the task workspace, not as accepted repository functionality.
22
23 +## Separate proposed discovery stack — 2026-10-23
24 +
25 +- Branch `codex/payvast-mapping-discovery-20261023` starts at unmerged PR #32 head `28d1c57882ec20fc17c2c133bbe62ff56e12973f`; do not merge this documentation stack before safety acceptance and base reconciliation.
26 +- New files: `docs/superpowers/specs/2026-10-23-payvast-governed-mapping-design.md`, `docs/integrations/PAYVAST_SQLSERVER_DISCOVERY.md`, `docs/integrations/payvast-schema-discovery.sql`.
27 +- The proposed contract covers Peyvast+Excel provenance and explicit mapping preview/approval/deduplication. The six SQL statements read system metadata only, and were statically reviewed, not executed on SQL Server or customer systems.
28 +- No table/column names or financial classification were inferred. Live version/schema/access, extraction consistency and accounting semantics remain discovery inputs; no connector, source reconciliation, runtime SQL result, accepted implementation or release is claimed.
29 +- This record is prepared before publication; fetch the live candidate/PR for final publication and review status.
30 +
31 ## Accepted repository state
32
33 - Repository: davoodmehraban89/Aram
docs/integrations/PAYVAST_SQLSERVER_DISCOVERY.md new
+34
@@ -0,0 +1,34 @@
1 +# راهنمای شناسایی ساختار پایگاه داده پیوست برای آرام
2 +
3 +این بسته فقط ابزار کمکی DBA برای شناسایی **فراداده** است؛ اتصال‌دهنده محصول نیست. فایل [aram-payvast-schema-discovery.sql](./payvast-schema-discovery.sql) فقط شامل پرس‌وجوهای `SELECT` از فراداده SQL Server است و هیچ ردیف عملیاتی یا مالی را نمی‌خواند.
4 +
5 +**وضعیت بررسی:** فقط بازبینی ایستای محتوا و نحو انجام شده است. فایل روی SQL Server، محیط آزمایشی یا پایگاه داده مشتری اجرا نشده؛ صحت اجرا، کامل‌بودن خروجی، سطح دسترسی و سازگاری با نصب واقعی مشتری تأیید نشده است.
6 +
7 +## روش استفاده توسط DBA
8 +
9 +1. با هویت فقط‌خواندنیِ مورد تأیید مشتری به SQL Server متصل شوید. نام کاربری، رمز عبور، رشته اتصال، توکن یا کلید را در این بسته، مخزن یا خروجی قابل اشتراک قرار ندهید. تنظیم امن اتصال زنده موضوع مرحله بعد است.
10 +2. پایگاه داده موردنظر پیوست را در فهرست انتخاب پایگاه داده SSMS انتخاب کنید. اسکریپت پایگاه داده را تغییر نمی‌دهد؛ در خود فایل هیچ فرمان تعویض پایگاه داده وجود ندارد.
11 +3. متن فایل را بازبینی کنید و در همان پایگاه داده انتخاب‌شده اجرا کنید. اسکریپت هیچ داده، شیء، مجوز یا تنظیمی را تغییر نمی‌دهد و از SQL پویا استفاده نمی‌کند.
12 +4. نتیجه بخش دوم را با پایگاه داده موردنظر تطبیق دهید. شش مجموعه نتیجه را با شماره بخش و زمان اجرای UTC ذخیره کنید؛ این زمان صرفاً زمان شناسایی ساختار است، نه زمان یک snapshot مالی.
13 +5. پیش از اشتراک‌گذاری، نام پایگاه داده و نام‌های قابل شناسایی مشتری را در صورت نیاز حذف یا با برچسب‌های ثابت جایگزین کنید. جایگزینی یک نام باید در تمام بخش‌ها یکسان باشد تا ارتباط‌ها قابل بررسی بمانند. هیچ داده مالی یا نمونه ردیف عملیاتی به این بسته اضافه نکنید.
14 +
15 +## خروجی‌ها چه چیزی را نشان می‌دهند؟
16 +
17 +| بخش | محتوای خروجی |
18 +| --- | --- |
19 +| ۱ | نسخه و ویرایش موتور SQL Server گزارش‌شده توسط همان اتصال |
20 +| ۲ | نام و شناسه پایگاه داده جاری، سطح سازگاری و collation |
21 +| ۳ | جدول‌ها و نماهای کاربریِ قابل مشاهده، همراه schema |
22 +| ۴ | نام و ترتیب ستون‌ها، نوع اعلام‌شده و نوع پایه، طول بر حسب بایت، precision، scale، امکان NULL و مشخصات identity/computed |
23 +| ۵ | ستون‌های کلیدهای اصلی و یکتا و سایر ایندکس‌های یکتا به ترتیب کلید؛ پرچم‌ها تفاوت constraint، ایندکس فیلترشده، غیرفعال یا فرضی را مشخص می‌کنند |
24 +| ۶ | فقط رابطه‌های FK اعلام‌شده و جفت ستون‌های آن‌ها؛ همراه وضعیت غیرفعال/نامطمئن و رفتار مرجع |
25 +
26 +نمایش فراداده به مجوز همان هویت بستگی دارد. **خروجی خالی یا ناقص، نبودن جدول، ستون، کلید یا رابطه را ثابت نمی‌کند.** محدودیت دسترسی یا خطای مشاهده‌شده را همراه نتیجه ثبت کنید؛ این فایل سطح دسترسی را افزایش نمی‌دهد. مقدار `NULL` در برخی ویژگی‌های موتور نیز ممکن است ناشی از پشتیبانی‌نشدن آن ویژگی یا محدودیت محیط باشد.
27 +
28 +وجود ایندکس یکتا به‌تنهایی برای تعیین شناسه پایدار منبع کافی نیست؛ فیلتر، وضعیت و تعریف واقعی آن باید بررسی شود. نبود FK قابل مشاهده نیز مجوز حدس‌زدن ارتباط از روی شباهت نام ستون‌ها نیست. این خروجی‌ها معنای حسابداری، تفکیک شرکت/سال، وضعیت سند، واحد پول یا قواعد نگاشت را مشخص نمی‌کنند.
29 +
30 +## اطلاعات تکمیلی موردنیاز
31 +
32 +نسخه دقیق نرم‌افزار پیوست، مستند رسمی schema یا رابط خواندن پشتیبانی‌شده، تعریف شرکت و سال مالی، معنای سطوح حساب و تفصیلی، کلید پایدار رکورد و روش استخراج سازگار باید از مشتری یا پشتیبانی پیوست دریافت شود. جزئیات بیشتر در [یادداشت الزامات](../superpowers/specs/2026-10-23-payvast-governed-mapping-design.md) آمده است. هیچ نام جدول یا ستون اختصاصی پیوست در این بسته فرض نشده است.
33 +
34 +مبنای مستندات، Microsoft SQL Server است: [SERVERPROPERTY](https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql)، [sys.columns و اتصال به sys.types](https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-columns-transact-sql) و [محدودیت نمایش فراداده](https://learn.microsoft.com/en-us/sql/relational-databases/security/metadata-visibility-configuration). هدف نحوی فایل SQL Server 2019/2022 است؛ این هدف جای تأیید روی نسخه واقعی مشتری را نمی‌گیرد.
docs/integrations/payvast-schema-discovery.sql new
+166
@@ -0,0 +1,166 @@
1 +/*
2 +Aram / Peyvast: metadata-only discovery aid for a DBA.
3 +Target syntax: Microsoft SQL Server 2019 / 2022.
4 +
5 +UNEXECUTED: this file has received static content/syntax review only.
6 +It has NOT been run against SQL Server, a test instance, or a customer database.
7 +It is not a connector and makes no claim about the customer's Peyvast schema.
8 +
9 +In SSMS, select the intended customer database before running this script.
10 +Use the customer's approved read-only identity. This script does not switch
11 +databases, query application/financial rows, or alter data, objects, permissions,
12 +or server/database settings. Every executable statement is a metadata SELECT.
13 +
14 +Metadata visibility depends on the executing identity's permissions. Results
15 +may be incomplete or empty. Empty output is NOT evidence that an object, key,
16 +relationship, or column does not exist. Do not share credentials. Metadata can
17 +identify a customer; redact output consistently before sharing if needed.
18 +
19 +Documentation basis: Microsoft SQL Server documentation, including
20 +SERVERPROPERTY, sys.columns joined to sys.types, and metadata visibility:
21 +https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql
22 +https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-columns-transact-sql
23 +https://learn.microsoft.com/en-us/sql/relational-databases/security/metadata-visibility-configuration
24 +*/
25 +
26 +-- 1. Engine version and edition reported by the connected SQL Server instance.
27 +SELECT
28 + CONVERT(nvarchar(128), SERVERPROPERTY('ProductVersion')) AS product_version,
29 + CONVERT(nvarchar(128), SERVERPROPERTY('ProductMajorVersion')) AS product_major_version,
30 + CONVERT(nvarchar(128), SERVERPROPERTY('ProductLevel')) AS product_level,
31 + CONVERT(nvarchar(128), SERVERPROPERTY('ProductUpdateLevel')) AS product_update_level,
32 + CONVERT(nvarchar(128), SERVERPROPERTY('Edition')) AS edition,
33 + CONVERT(int, SERVERPROPERTY('EngineEdition')) AS engine_edition;
34 +
35 +-- 2. Only the currently selected database and its compatibility/collation.
36 +SELECT
37 + DB_NAME() AS current_database_name,
38 + DB_ID() AS current_database_id,
39 + d.compatibility_level,
40 + d.collation_name
41 +FROM sys.databases AS d
42 +WHERE d.database_id = DB_ID();
43 +
44 +-- 3. Visible user tables and views in the current database.
45 +SELECT
46 + s.name AS schema_name,
47 + o.name AS object_name,
48 + o.object_id,
49 + o.type_desc AS object_type
50 +FROM sys.objects AS o
51 +INNER JOIN sys.schemas AS s
52 + ON s.schema_id = o.schema_id
53 +WHERE o.type IN ('U', 'V')
54 + AND o.is_ms_shipped = 0
55 +ORDER BY s.name, o.name, o.object_id;
56 +
57 +-- 4. Visible column definitions for those tables and views.
58 +-- max_length is in bytes; -1 denotes a MAX/large-value type where applicable.
59 +-- declared_type preserves alias/CLR type identity; base_type may be NULL.
60 +SELECT
61 + s.name AS schema_name,
62 + o.name AS object_name,
63 + o.type_desc AS object_type,
64 + c.column_id,
65 + c.name AS column_name,
66 + ts.name AS declared_type_schema,
67 + ut.name AS declared_type,
68 + bt.name AS base_type,
69 + c.max_length AS max_length_bytes,
70 + c.precision AS numeric_precision,
71 + c.scale AS numeric_scale,
72 + c.is_nullable,
73 + c.is_identity,
74 + c.is_computed,
75 + c.collation_name
76 +FROM sys.columns AS c
77 +INNER JOIN sys.objects AS o
78 + ON o.object_id = c.object_id
79 +INNER JOIN sys.schemas AS s
80 + ON s.schema_id = o.schema_id
81 +INNER JOIN sys.types AS ut
82 + ON ut.user_type_id = c.user_type_id
83 +INNER JOIN sys.schemas AS ts
84 + ON ts.schema_id = ut.schema_id
85 +LEFT JOIN sys.types AS bt
86 + ON bt.system_type_id = c.system_type_id
87 + AND bt.user_type_id = bt.system_type_id
88 +WHERE o.type IN ('U', 'V')
89 + AND o.is_ms_shipped = 0
90 +ORDER BY s.name, o.name, c.column_id;
91 +
92 +-- 5. Declared primary/unique keys and other unique indexes, one row per key
93 +-- column in key order. Included non-key columns are intentionally omitted.
94 +-- Flags distinguish PK/UQ constraints from standalone unique indexes.
95 +-- A filtered or disabled unique index must not be assumed to identify all rows.
96 +SELECT
97 + s.name AS schema_name,
98 + o.name AS object_name,
99 + o.type_desc AS object_type,
100 + i.name AS index_name,
101 + kc.name AS constraint_name,
102 + kc.type_desc AS constraint_type,
103 + i.is_primary_key,
104 + i.is_unique_constraint,
105 + i.is_unique,
106 + i.has_filter,
107 + i.is_disabled,
108 + i.is_hypothetical,
109 + ic.key_ordinal,
110 + c.name AS column_name,
111 + ic.is_descending_key
112 +FROM sys.indexes AS i
113 +INNER JOIN sys.objects AS o
114 + ON o.object_id = i.object_id
115 +INNER JOIN sys.schemas AS s
116 + ON s.schema_id = o.schema_id
117 +INNER JOIN sys.index_columns AS ic
118 + ON ic.object_id = i.object_id
119 + AND ic.index_id = i.index_id
120 +INNER JOIN sys.columns AS c
121 + ON c.object_id = ic.object_id
122 + AND c.column_id = ic.column_id
123 +LEFT JOIN sys.key_constraints AS kc
124 + ON kc.parent_object_id = i.object_id
125 + AND kc.unique_index_id = i.index_id
126 +WHERE o.type IN ('U', 'V')
127 + AND o.is_ms_shipped = 0
128 + AND i.is_unique = 1
129 + AND ic.key_ordinal > 0
130 +ORDER BY s.name, o.name, i.name, ic.key_ordinal;
131 +
132 +-- 6. Declared foreign keys only, one row per paired column in FK order.
133 +-- This does not infer undeclared relationships or accounting semantics.
134 +SELECT
135 + ps.name AS parent_schema,
136 + pt.name AS parent_table,
137 + fk.name AS foreign_key_name,
138 + fkc.constraint_column_id AS column_pair_ordinal,
139 + pc.name AS parent_column,
140 + rs.name AS referenced_schema,
141 + rt.name AS referenced_table,
142 + rc.name AS referenced_column,
143 + fk.is_disabled,
144 + fk.is_not_trusted,
145 + fk.delete_referential_action_desc,
146 + fk.update_referential_action_desc
147 +FROM sys.foreign_keys AS fk
148 +INNER JOIN sys.foreign_key_columns AS fkc
149 + ON fkc.constraint_object_id = fk.object_id
150 +INNER JOIN sys.tables AS pt
151 + ON pt.object_id = fkc.parent_object_id
152 +INNER JOIN sys.schemas AS ps
153 + ON ps.schema_id = pt.schema_id
154 +INNER JOIN sys.columns AS pc
155 + ON pc.object_id = fkc.parent_object_id
156 + AND pc.column_id = fkc.parent_column_id
157 +INNER JOIN sys.tables AS rt
158 + ON rt.object_id = fkc.referenced_object_id
159 +INNER JOIN sys.schemas AS rs
160 + ON rs.schema_id = rt.schema_id
161 +INNER JOIN sys.columns AS rc
162 + ON rc.object_id = fkc.referenced_object_id
163 + AND rc.column_id = fkc.referenced_column_id
164 +WHERE pt.is_ms_shipped = 0
165 + AND rt.is_ms_shipped = 0
166 +ORDER BY ps.name, pt.name, fk.name, fkc.constraint_column_id;
docs/superpowers/specs/2026-10-23-payvast-governed-mapping-design.md new
+138
@@ -0,0 +1,138 @@
1 +# Aram: Peyvast source connector and governed mapping requirements
2 +
3 +Prepared 2026-10-23. Design and acceptance note only; no implementation, repository change, source access, database change, provisioning, or accounting decision is authorized by this document.
4 +
5 +## Purpose and evidence boundary
6 +
7 +Aram must accept accounting data from Peyvast (پیوست) and Excel through a shared canonical representation, then let an authorized user create and maintain explicit mappings with reviewable changes and reliable recovery. Source accounting systems and supplied workbooks remain read-only. Imported snapshots and mapping decisions belong to Aram; neither is written back to Peyvast or the source workbook.
8 +
9 +The official vendor accounting FAQ supplied for this task, [payvast.com/نرم-افزار-حسابداری/](https://payvast.com/نرم-افزار-حسابداری/), identifies Microsoft SQL Server as the default database, mentions SQL Server 2019/2022, and recommends 2022. This is vendor product guidance, not evidence of the customer's installation. The customer's Peyvast edition/build, SQL Server version, database topology, schema, supported extraction interface, credentials, and network access are unknown. No vendor table or column names, connection strings, credentials, or accounting rules are specified or inferred here.
10 +
11 +Repository reference: `davoodmehraban89/Aram`, accepted baseline `source-data-cleanup@7dc864fd032f0c4ae4d650d89304a01286a6d914`, inspected in the task workspace. GitHub remote PR metadata and diffs were read on 2026-10-23. This is a time-bound design snapshot, not an acceptance decision or evidence of later branch state.
12 +
13 +## What exists and what remains
14 +
15 +| Area | Observed baseline or candidate | Remaining requirement |
16 +| --- | --- | --- |
17 +| Fiscal-year model | Baseline has companies, company/year identity, year-owned records, version fields, Draft/Approved/Locked lifecycle, and mutation guards. | Close and independently verify the separate P0 isolation work before extending persistence. Do not assume every foreign-key relationship or reparenting path is isolated because an entry point validates it. |
18 +| Source provenance | Baseline source registration stores year, filename, type, content SHA-256, and upload time; identical registration is idempotent. Source bytes and parsed financial records are not persisted. | Database snapshot provenance, canonical source snapshots, durable row lineage, reproducibility, and cross-input equivalence are not implemented. |
19 +| Excel input | Baseline reads XLSX structure and typed ledger records in memory. Pilot preflight validates a governed workbook with hierarchy, company/year, target, and review fields. | A Pilot preflight is not a live connector, persisted import, mapping editor, or approval service. The legacy ledger parser and Pilot contract have different shapes and require explicit adapters. |
20 +| Mapping persistence | [Draft PR #26](https://github.com/davoodmehraban89/Aram/pull/26), head `185e47f031902a8918c93c8dbb420122e7408403`, is open and unmerged. Its service requires a Draft year, existing same-year account and note, explicit identifiers, and rejects conflicting content at an existing rule/version. Identical service replay returns the existing row. | Account-code-only mapping lacks the required full hierarchical predicate. An integer version does not provide an approved change workflow, active-version policy, audit history, or rollback by itself. |
21 +| Mapping XLSX | [Draft PR #27](https://github.com/davoodmehraban89/Aram/pull/27), head `6c0068a660a3834f042b89d41d62bba82cb3a498`, is open and unmerged, stacked on #26. It parses/exports a five-column Mapping sheet, rejects formulas and oversized archives, and stages imports atomically under caller transaction control. | Its preview is parsing only: no stored old/new diff, authorization, approval, or stale-preview token. It rejects every repeated rule-key/version inside a workbook, including identical repeats, which conflicts with the requested no-op semantics. Its raw note IDs and five-column shape do not cover the governed Pilot hierarchy/target contract. |
22 +| Peyvast | No live Peyvast connector was identified in the inspected baseline. | Customer-specific, read-only extraction, documented translation, and customer-verified reconciliation remain blocked on the facts below. |
23 +
24 +The PR descriptions and test files are implementation evidence, not acceptance or current-CI evidence. This note does not claim either candidate passes its latest CI or is safe to merge. Candidate work must be reconciled with the isolated model and independently reviewed at its exact final head.
25 +
26 +## Source approach
27 +
28 +Recommended order:
29 +
30 +1. Ask the customer/vendor for an official supported read interface: documented read-only views, an export interface, or an API, if available. Prefer a supported interface that exposes the required data and stable identifiers, and assess its authentication, licensing, consistency, and change guarantees. The existence of such an interface is unconfirmed.
31 +2. If no adequate supported interface exists, use documented customer tables through a customer-approved, least-privilege read account. First obtain schema documentation, representative redacted samples, key relationships, version information, and an approved query/extraction contract. Build against those facts; do not infer joins from similarly named fields.
32 +3. Keep Excel as a first-class input route for initial onboarding, disconnected operation, comparison, and mapping exchange. It must feed the same validation and mapping services as the database route.
33 +
34 +A direct table connector offers access to customer detail but is more sensitive to schema changes and transaction semantics. A supported interface reduces coupling when its guarantees are sufficient. These are proposed integration choices, not a claim that Peyvast publishes either interface. Aram's internal application database is a separate concern; the vendor's SQL Server choice does not require moving Aram's own storage or provisioning another provider.
35 +
36 +## Shared canonical contract
37 +
38 +Define and version a canonical input contract before writing an adapter. Names below are Aram concepts, not Peyvast schema names.
39 +
40 +- **Scope:** explicit company identity, explicit fiscal-year identity/calendar and source-to-Aram identity mapping. Identical account codes in different companies or years are distinct. No default company or fallback year is allowed.
41 +- **Account and hierarchy:** stable source account identifier when available, literal text code/name, account level, general/subsidiary hierarchy, and ordered detail/dimension identifiers with their parent context. The current Pilot has detail1 through detail4; the customer's actual meaning and available depth must be confirmed. Preserve missing, explicit empty, and exact-match values distinctly where the approved predicate model needs that distinction.
42 +- **Source facts:** source record key or a documented row locator, original codes, source year/period, row/document type, supplied amounts as exact decimals, currency and unit, and extraction locator. Retain the original source meaning; no inferred balances, sign changes, scale conversion, synthetic codes, target classification, or hierarchy is introduced by an adapter.
43 +- **Provenance:** immutable snapshot ID, connector/input type, customer installation identifier, company/year filter, extraction start/end UTC, supplied as-of/cutoff, interface/schema version, adapter and canonical-contract versions, query/export contract identifier and parameters without secrets, row counts, and deterministic snapshot/content hashes. For Excel retain file SHA-256, sheet/header/row references; for database rows retain documented source keys and extraction boundaries.
44 +- **Validation:** one shared validation report identifies scope, source locator, field, severity, and stable reason code. Unknown accounts, unresolved targets, incomplete hierarchy, and ambiguous matches stay visible and block affected application; they do not cause target inference.
45 +
46 +Database extraction must describe how a consistent view is obtained with the customer's existing supported isolation or backup/export facility. Read-only extraction must not silently enable SQL Server settings, create database objects, modify source data, or change grants. If a consistent snapshot cannot be established, record that limitation and reject acceptance as a reproducible accounting snapshot. Persist a completed snapshot only after extraction and validation complete; failure must not publish a partial snapshot.
47 +
48 +DB and Excel adapters must produce equivalent canonical records when supplied equivalent facts. Preserve literal code text and leading zeros; any normalization requires a documented reversible rule and keeps raw values. Do not equate unknown/null with a wildcard. Source identity and canonical content hashing must distinguish legitimate separate records with equal amounts from accidental replay. Changes in source data create a new immutable snapshot rather than rewriting earlier evidence.
49 +
50 +## Governed mapping model and workflow
51 +
52 +### Identity and scope
53 +
54 +A mapping has a stable Aram rule identifier within company/year, a versioned source predicate, and explicit target identifiers. Its predicate includes account identity, account level, applicable hierarchical dimensions, and any other customer-approved discriminator. Its target resolves to the same company's same fiscal year's permitted statement/section/note/subnote structure. A friendly exported target label is accompanied by a stable scoped identifier; import never guesses a target from a label or treats a foreign installation's raw database row ID as portable.
55 +
56 +The full predicate and target are part of equality, change detection, audit, and approval. Define missing/exact/explicit-any semantics in a versioned contract. Do not choose most-specific, first-match, or another precedence policy to resolve overlaps without an approved accounting rule. Several explicitly approved rules may be legitimate; overlapping rules with unresolved precedence produce an ambiguity, not automatic classification. Account names are display evidence, not unique identity.
57 +
58 +### One path for XLSX and manual edits
59 +
60 +Initial/bulk XLSX import and manual create/edit submit the same canonical mapping proposal. To create an applicable proposal, the service validates the actor's company/year permissions and Draft-year state, validates the source predicate and target, reads the current active mapping revision, and computes a persisted preview before application. Separately authorized diagnostic comparison is permitted for Approved/Locked years, but it cannot issue an applicable approval token or become an applicable proposal. Source workbook fields such as `reviewer` or `approval_status` are historical evidence, not authentication or authority to approve inside Aram.
61 +
62 +Each input row is classified as **new**, **unchanged**, **changed**, **conflicting duplicate**, or **invalid**, with original row locators and deterministic counts. Proposed no-op behavior is mandatory:
63 +
64 +- Repeating a stored mapping with identical predicate and target leaves active mapping state and mapping version unchanged.
65 +- Repeating the same identical mapping within one input is coalesced; report all repeated row locators and count them as unchanged/coalesced, with at most one prospective creation when the rule is new.
66 +- Repeating an identity with different content within one input is a conflict. Show the competing rows and their differences; never choose first or last. No apply is allowed until the proposal is corrected.
67 +- A changed stored mapping displays its complete old and proposed predicate/target, scope, and version. It requires explicit approval from an authorized user before application. Proposed design choice: require the same approval for new rows, including a new-only initial batch, so every nonempty delta has one reviewable meaning.
68 +- Existing mappings absent from an input remain active and unchanged. Removal is a separate explicit, versioned, authorized action; an empty or partial file is never a request to delete existing mappings.
69 +
70 +Preview stores a proposal ID, canonical input hash, actor and scope, source file/proposal provenance, relevant source snapshot and catalog revisions, baseline active-mapping revision, old/new values, validations and counts, and creation/expiry state. Persisting a preview does not change active mappings. Editing a preview creates a new proposal and invalidates its earlier approval.
71 +
72 +Apply first rechecks authorization. For a proposal already successfully applied, return its recorded result without mutation, even if that application advanced the revision or the year later became protected; this is retrieval of an earlier outcome, not another application. For an unapplied proposal, recheck Draft state, proposal integrity, target/account validity, and every relevant baseline revision inside a transaction. Use an optimistic compare-and-set of the mapping revision together with the atomic write. A concurrent mapping edit, relevant catalog/predicate change, or year transition after preview makes the unapplied proposal stale: reject all changes and require a fresh diff and approval. Never refresh the preview invisibly under the previous approval. Use a consumed-proposal/idempotency key so retried application returns the same outcome without another version or event representing a new change.
73 +
74 +Proposed batch behavior: a proposal with any invalid/conflicting row cannot apply. Approval covers the displayed nonempty delta exactly, and the transaction applies all approved changes or none. Unchanged rows do not create mapping versions. A separate audit event may record a no-op import attempt without changing mapping state.
75 +
76 +### Audit, versions, and recovery
77 +
78 +Persist an append-only record of proposal, approver identity/time, exact before/after state, company/year, active revision before/after, reason, source file/proposal hash, and relevant snapshot/catalog versions. Record failures and stale rejection without changing active state. Separate author and approver is configurable only if the customer's role policy calls for it; authenticated authorization and explicit change approval are required in all cases.
79 +
80 +Keep superseded mapping versions and a clear active revision. Rollback is a new authorized proposal showing the current state and the historical state to restore; it creates a new auditable revision rather than deleting history or decrementing a version counter. It is subject to the same scope, target validity, stale-preview and protected-year rules. Historical outputs remain linked to the exact source snapshot and mapping revision used to produce them.
81 +
82 +## Acceptance scenarios
83 +
84 +Use isolated synthetic fixtures for behavioral tests; do not alter canonical XLSX/PDF, `data/`, customer databases, or financial source values. Real integration acceptance later requires customer-supplied evidence and an approved extraction contract.
85 +
86 +| Scenario | Required observable outcome |
87 +| --- | --- |
88 +| Equivalent database and Excel facts | Both adapters yield the same scoped canonical facts and validation results; each retains its own source lineage and immutable snapshot provenance. |
89 +| Customer database access | The account can read only approved objects and cannot write or perform DDL. Extraction executes only the documented reads; no settings, grants, or source objects change. |
90 +| Snapshot changes during extraction | A supported consistent extraction produces one stated as-of snapshot, or extraction fails/reports inconsistency and no completed snapshot is published. |
91 +| Same codes in company A/B or year 1403/1404 | Imports, lookups, notes, mappings, approvals, rollback, and outputs cannot cross scope. Unknown scope is rejected; no fallback occurs. |
92 +| Same account, different hierarchy/detail | Distinct predicates remain distinct. Missing dimension, explicit-any and literal value do not collapse into the same predicate. Unresolved overlap is reported. |
93 +| Leading-zero code and raw source text | Codes survive DB/Excel normalization and round-trip without numeric coercion; raw provenance is recoverable. |
94 +| Exact stored replay | Zero active-state changes, zero additional mapping versions, unchanged active revision. |
95 +| Repeated identical new rows inside XLSX | One proposed new mapping, repeated row locators reported, one mapping after apply. Reimport is a no-op. |
96 +| Conflicting repeated identity | Every competing input row is identified, differences are visible, and the entire proposal cannot apply. |
97 +| Existing target or predicate changes | Old/new values are visible before write; an unauthorized actor or missing approval cannot apply; authorized approval creates one new auditable revision. |
98 +| Partial/empty input | No existing mapping is deleted or retired. A no-op/empty-result message is explicit. |
99 +| Concurrent edit after preview | The older approval attempt is rejected as stale with zero partial changes; a new preview displays the current baseline. Test with two transactions. |
100 +| Year approved/locked after preview | Apply rejects without mutation. Existing Approved/Locked years reject edits, additions, retirement and rollback. Read-only preview remains separately authorized. |
101 +| One invalid row in a mixed batch | No active mapping changes survive; caller errors and retry cannot leave a partial import. |
102 +| Lost response and apply retry | The same approved proposal returns its prior result, with one active revision and no duplicated application. |
103 +| Explicit rollback | A new approved revision restores the chosen permitted historical state; intervening history, approval evidence, source snapshots and past output lineage remain intact. |
104 +| Unknown account, target, or accounting rule | Precise actionable issue; no invented account, target, hierarchy or precedence. |
105 +| Malformed/hostile XLSX | Deterministic bounded rejection of formulas, unexpected schema, unsupported/encrypted/malformed content, excessive size/rows/decompression, and invalid identifiers; no active-state changes. |
106 +
107 +## Dependency order and deliverables
108 +
109 +1. **P0 model isolation:** finish the separately assigned invariant fix and independent review. Cover direct foreign-key assignment, relationship assignment, reparenting, deletion, and old/new protected scopes. Mapping services must build on these model boundaries.
110 +2. **Canonical and mapping contracts:** agree versioned record identities, hierarchy/null semantics, stable targets, active-version model, source snapshot provenance, and authorization boundaries. Reconcile the richer governed Pilot contract with #27's narrow interchange; do not silently replace the approved template or publish incompatible files under the same format version.
111 +3. **Governed mapping backend:** reconcile/rebase #26/#27 against the verified base; add persisted diff proposals, identical-input deduplication, explicit conflict reporting, authorized approval, concurrency rejection, atomic idempotent apply, audit, and rollback. Prove behavior with the scenarios above before integration into UI.
112 +4. **Manual editing and XLSX workflow:** both use that service; present counts, row issues, complete old/new diffs, active scope, approval controls, and recovery history. Unknown-account handling and any carry-forward are explicit proposals subject to the same approval and isolation rules.
113 +5. **Peyvast contract discovery:** obtain the missing facts below. This read-only discovery can proceed alongside mapping work, but no real extraction adapter is represented as ready before its source contract is documented.
114 +6. **Peyvast read-only adapter:** implement only the documented interface against a sanitized fixture/test installation, create immutable canonical snapshots, and compare with an equivalent customer Excel export. Run customer-approved reconciliation on an approved environment without changing source data.
115 +7. **Independent acceptance:** review exact PR heads and required CI, verify protected-data boundaries, record known schema/version support and limits, and obtain accounting-owner acceptance of real reconciliation. Output/release acceptance remains a later gate; this note is not a release or merge authorization.
116 +
117 +## Facts needed for real Peyvast integration
118 +
119 +| Fact or decision | Evidence required / likely owner |
120 +| --- | --- |
121 +| Exact installation | Customer's Peyvast product/edition/build, installed modules/customizations, vendor/support contact, licensed extraction rights and supported interface documentation. |
122 +| Database platform | Actual SQL Server edition/version/build, database and instance topology, compatibility level, collation/encoding, multi-company/year layout, and availability/maintenance constraints; customer DBA. |
123 +| Supported source interface | Confirmation whether official views/API/export exist; documented schema/API version and change guarantees; vendor/customer technical owner. |
124 +| Schema and identity | DDL/data dictionary or equivalent approved documentation, keys, joins, company/year discriminators, account hierarchy and floating-detail semantics, stable row keys and status fields, plus representative redacted rows; vendor/customer DBA. |
125 +| Financial semantics | Fiscal calendar/period bounds, currency/unit/precision, sign conventions, source row grain, posted/draft/void/cancelled treatment, opening/closing handling, and authoritative reconciliation report/filters; accounting owner. Existing historic rules are not automatically generalized to Peyvast. |
126 +| Extraction consistency | Approved snapshot/backup/export mechanism, as-of definition, transaction/isolation guarantees, concurrency behavior, expected data volume, timeout/window, and source revision/change detection; DBA/vendor. |
127 +| Network and identity | Customer-approved host/instance/endpoint, port, DNS/network route/VPN if required, TLS certificate requirements, authentication method, least-privilege object grants, secret delivery/storage/rotation and connection-test authorization; customer IT. Do not put credentials in this note or the repository. |
128 +| Scope and target authority | Authoritative source-to-Aram company/year mapping, account/dimension dictionaries, permitted statement/note/subnote catalog, explicit predicate/overlap rules, authorized editor/approver roles, and lifecycle controls; customer accounting owner. |
129 +| Retention and recovery | Approved source-snapshot retention/location, permissible sensitive fields, audit retention, backup and restore verification, and operational ownership; customer owner/IT. |
130 +| Acceptance fixture | A sanctioned sanitized database/export sample, its equivalent Excel output and exact filters/as-of time, approved expected row counts/totals with hashes, and named accounting reviewer. Expected values must come from supplied evidence, never be invented. |
131 +
132 +Until these facts arrive, useful work is the shared contract, model invariants, governed mapping workflow, fixture-based adapter design, and precise discovery checklist. The live customer connector and accounting reconciliation remain explicitly unverified.
133 +
134 +## Publication context
135 +
136 +This proposed design and metadata-discovery aid are a separate documentation-only task stacked on unmerged safety [PR #32](https://github.com/davoodmehraban89/Aram/pull/32), at `28d1c57882ec20fc17c2c133bbe62ff56e12973f`. PR #32 has successful final-head CI but is not accepted. The accepted branch remains `7dc864fd032f0c4ae4d650d89304a01286a6d914`; do not treat this stack as accepted product functionality.
137 +
138 +The companion [Persian discovery guide](../../integrations/PAYVAST_SQLSERVER_DISCOVERY.md) and [metadata-only SQL](../../integrations/payvast-schema-discovery.sql) are statically reviewed aids only. SQL Server execution, customer permissions, metadata completeness, compatibility and live financial extraction are NOT VERIFIED. No accounting data is read by the script; it queries only system metadata.