# nunomacastro/edu-pap-3ig-opsa-2526 architecture

> Architecture diagram of the GitHub repository nunomacastro/edu-pap-3ig-opsa-2526, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nunomacastro/edu-pap-3ig-opsa-2526
- Repository: https://github.com/nunomacastro/edu-pap-3ig-opsa-2526

## Overview

1. **What this repository is**
   - This repo is primarily a **specification + prototype** repository for OPSA, not a full production implementation.
   - The core product described is an **ERP financeiro para PME**, with accounting, stock, sales, purchasing, banking, and AI-assisted analysis.

2. **Repository shape**
   - The largest area is **documentation** under `docs/`, especially `docs/planificacao/`.
   - The only substantial executable app code is in `mockup/`, which is a **Vite + React + TypeScript** UI prototype.
   - There is also a small repo-level script area in `scripts/` for validating the documentation/planning structure.

3. **Documentation as the system blueprint**
   - `docs/RF.md` and `docs/RNF.md` define the functional and non-functional requirements.
   - `docs/planificacao/` contains the planning model: roadmap, sprint plans, backlog matrices, and per-module backlog guides.
   - This documentation layer is effectively the **source of truth** for architecture, domain boundaries, and delivery sequencing.

4. **Delivery structure and domain breakdown**
   - The planning docs split the product into functional macro-phases `MF0` through `MF8`.
   - These phases map to domain areas such as:
     - identity/access and company setup,
     - sales and purchasing,
     - inventory and accounting,
     - banking and reconciliation,
     - reporting and exports,
     - AI insights and alerts,
     - quality, performance, and operational hardening.
   - For an architecture diagram, these phases can be shown as **incremental layers over the same ERP core**.

5. **Frontend prototype subsystem**
   - `mockup/` is a **single-page UI prototype** with:
     - `src/app/App.tsx` as the app entry shell,
     - `Layout.tsx` for page structure,
     - `Login.tsx` for authentication UI,
     - a set of module views under `src/app/components/modules/`.
   - The module views mirror the ERP domains: `Dashboard`, `Vendas`, `Compras`, `Inventario`, `Contabilidade`, `Bancos`, `IA`, and `Configuracoes`.

6. **UI composition and shared component layer**
   - The mockup uses a large reusable UI kit in `src/app/components/ui/`, including dialogs, tables, forms, tabs, sidebars, charts, alerts, and inputs.
   - This indicates a **component-driven frontend architecture** with shared primitives across modules rather than isolated page-specific UIs.
   - `AuthContext.tsx` suggests authentication state is managed centrally in the UI prototype.

7. **Main business data flow**
   - The intended flow is: **user logs in → chooses company/role context → works inside domain modules → transactions produce accounting and reporting outputs**.
   - Sales and purchases feed stock movement, accounting entries, and receivables/payables.
   - Banking imports and reconciliation feed treasury state and cash visibility.
   - Reporting modules consume transactional and accounting data to produce balances, VAT maps, SAF-T, and KPIs.

8. **AI subsystem boundary**
   - The AI area is explicitly separate in the docs and in the mockup as its own module.
   - Its job is to generate **insights, alerts, suggestions, and natural-language answers** using existing business data.
   - A critical architectural rule is that AI **does not directly mutate accounting data**; it recommends and explains, but execution stays in the transactional/core system.

9. **Compliance and audit as cross-cutting concerns**
   - The product is designed around Portuguese accounting/fiscal constraints: SNC, IVA, SAF-T, retention rules, and auditability.
   - Planning docs emphasize:
     - role-based access,
     - multi-company access,
     - audit logs,
     - approvals,
     - session/security controls,
     - traceability for sensitive operations.
   - In diagram terms, these are **cross-cutting services** touching every domain module.

10. **Operational and integration boundaries**
   - The roadmap includes external-facing flows such as:
     - email for password recovery and notifications,
     - bank statement imports in CSV/OFX,
     - export formats like PDF, Excel, CSV, and SAF-T.
   - The repository does not show real backend connectors yet, but the architecture clearly anticipates **import/export and integration adapters** as separate concerns from core CRUD flows.

11. **Automation around documentation**
   - `docs/planificacao/scripts/` contains Python utilities for maintaining the planning material, such as auditing, migration, and traceability generation.
   - `scripts/validate-planificacao.sh` appears to enforce consistency in the planning structure.
   - These are governance tools, not product runtime components, but they matter because they keep the specification aligned with the delivery model.

12. **What is missing from the repository**
   - There is **no production backend implementation** in the tree shown.
   - There is no persistent data layer code, API service, job worker, or deployment stack yet in the repository contents provided.
   - So the architecture diagram should distinguish between:
     - the **documented target architecture**,
     - the **front-end mockup/prototype**,
     - and the **planning/governance tooling**.

13. **Best diagram framing**
   - Represent OPSA as three layers:
     - **Governance & planning**: requirements, backlogs, sprint docs, validation scripts.
     - **Product prototype**: React/Vite mockup with shared UI and module shells.
     - **Target ERP domain architecture**: identity, company setup, sales, purchasing, inventory, accounting, banking, AI, reporting, audit/compliance.
   - The most important boundaries are between **transactional ERP data**, **AI recommendations**, and **audit/compliance controls**.

Main entry points: [`docs/planificacao/README.md`](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/planificacao/README.md) (Planificação), [`mockup/src/app/App.tsx`](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/App.tsx) (App shell), [`docs/planificacao/backlogs/BACKLOG-MVP.md`](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/planificacao/backlogs/BACKLOG-MVP.md) (Backlogs), [`mockup/src/app/components/ui/button.tsx`](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/components/ui/button.tsx) (UI primitives)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_governance["Governance & planning"]
  node_docs_rf["RF<br/>requirements spec<br/>[RF.md]"]
  node_docs_rnf["RNF<br/>quality spec<br/>[RNF.md]"]
  node_planificacao["Planificação<br/>delivery model<br/>[README.md]"]
  node_backlogs["Backlogs<br/>backlog system<br/>[BACKLOG-MVP.md]"]
  node_mf0_mf4["MF0–MF4<br/>phase guides"]
  node_mf5_mf8["MF5–MF8<br/>phase guides"]
  node_validate_script["Validate plan<br/>governance script"]
end

subgraph group_prototype["Product prototype"]
  node_app_shell["App shell<br/>react shell<br/>[App.tsx]"]
  node_layout["Layout<br/>[Layout.tsx]"]
  node_login["Login<br/>auth view<br/>[Login.tsx]"]
  node_auth_ctx["Auth state<br/>ui context<br/>[AuthContext.tsx]"]
  node_ui_primitives["UI primitives<br/>shared components<br/>[button.tsx]"]
  node_dashboard_view["Dashboard<br/>module view<br/>[Dashboard.tsx]"]
  node_domain_views["ERP modules<br/>module views<br/>[Vendas.tsx]"]
end

subgraph group_target["Target ERP architecture"]
  node_erp_core{{"ERP core<br/>domain platform"}}
  node_identity_setup["Access & setup<br/>domain module"]
  node_sales_purchase["Sales & buying<br/>domain module"]
  node_inventory_accounting["Stock & books<br/>domain module"]
  node_banking_reporting["Banking & reports<br/>domain module"]
  node_ai_layer(("AI insights<br/>assistant layer"))
  node_compliance{{"Audit & compliance<br/>cross-cutting control"}}
  node_integrations[("Imports & exports<br/>adapter boundary")]
end

node_docs_rf -->|"defines scope"| node_planificacao
node_docs_rnf -->|"constrains delivery"| node_planificacao
node_planificacao -->|"organizes"| node_backlogs
node_backlogs -->|"phases"| node_mf0_mf4
node_backlogs -->|"phases"| node_mf5_mf8
node_validate_script -.->|"checks consistency"| node_planificacao
node_app_shell -->|"renders"| node_layout
node_app_shell -->|"gates access"| node_login
node_app_shell -->|"hosts"| node_domain_views
node_login -->|"uses"| node_auth_ctx
node_layout -->|"shares primitives"| node_ui_primitives
node_domain_views -->|"composes"| node_ui_primitives
node_dashboard_view -->|"composes"| node_ui_primitives
node_docs_rf -->|"targets"| node_erp_core
node_identity_setup -->|"anchors"| node_erp_core
node_sales_purchase -->|"produces transactions"| node_erp_core
node_inventory_accounting -->|"posts stock and ledger"| node_erp_core
node_banking_reporting -->|"consumes transactions"| node_erp_core
node_ai_layer -->|"analyzes data"| node_erp_core
node_compliance -.->|"governs"| node_identity_setup
node_compliance -.->|"governs"| node_sales_purchase
node_compliance -.->|"governs"| node_inventory_accounting
node_compliance -.->|"governs"| node_banking_reporting
node_compliance -.->|"bounds"| node_ai_layer
node_integrations -->|"imports/exports"| node_banking_reporting
node_integrations -->|"imports/exports"| node_sales_purchase
node_integrations -.->|"logs"| node_compliance

click node_docs_rf "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/RF.md"
click node_docs_rnf "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/RNF.md"
click node_planificacao "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/planificacao/README.md"
click node_backlogs "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/planificacao/backlogs/BACKLOG-MVP.md"
click node_mf0_mf4 "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/planificacao/guias-bk/MF0/BK-MF0-01-registo-login-e-logout-com-cookies-httponly.md"
click node_mf5_mf8 "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/planificacao/guias-bk/MF5/BK-MF5-01-interface-intuitiva-clara-e-consistente-entre-modulos-vendas-compras-inventario-contabilidade.md"
click node_validate_script "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/scripts/validate-planificacao.sh"
click node_app_shell "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/App.tsx"
click node_layout "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/components/Layout.tsx"
click node_login "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/components/Login.tsx"
click node_auth_ctx "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/context/AuthContext.tsx"
click node_ui_primitives "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/components/ui/button.tsx"
click node_dashboard_view "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/components/modules/Dashboard.tsx"
click node_domain_views "https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/components/modules/Vendas.tsx"

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_docs_rf,node_docs_rnf,node_planificacao,node_backlogs,node_mf0_mf4,node_mf5_mf8,node_validate_script toneBlue
class node_app_shell,node_layout,node_login,node_auth_ctx,node_ui_primitives,node_dashboard_view,node_domain_views toneAmber
class node_erp_core,node_identity_setup,node_sales_purchase,node_inventory_accounting,node_banking_reporting,node_ai_layer,node_compliance,node_integrations toneMint
```

## Components

### Governance & planning

Requirements, roadmap, backlog, sprint planning, and validation tooling that define the target system.

- [RF](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/RF.md): requirements spec · Functional requirements and product scope for the OPSA ERP. · `docs/RF.md`
- [RNF](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/RNF.md): quality spec · Non-functional requirements covering performance, security, usability, and compliance. · `docs/RNF.md`
- [Planificação](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/planificacao/README.md): delivery model · Roadmap, sprints, backlog structure, and implementation sequencing. · `docs/planificacao/README.md`
- [Backlogs](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/planificacao/backlogs/BACKLOG-MVP.md): backlog system · Canonical backlog matrices and per-phase planning artifacts. · `docs/planificacao/backlogs/BACKLOG-MVP.md`
- [MF0–MF4](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/planificacao/guias-bk/MF0/BK-MF0-01-registo-login-e-logout-com-cookies-httponly.md): phase guides · Core delivery phases covering identity, sales, stock, accounting, banking, reporting, and AI. · `docs/planificacao/guias-bk/MF0/BK-MF0-01-registo-login-e-logout-com-cookies-httponly.md`
- [MF5–MF8](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/docs/planificacao/guias-bk/MF5/BK-MF5-01-interface-intuitiva-clara-e-consistente-entre-modulos-vendas-compras-inventario-contabilidade.md): phase guides · Quality, performance, security, hardening, observability, and localization phases. · `docs/planificacao/guias-bk/MF5/BK-MF5-01-interface-intuitiva-clara-e-consistente-entre-modulos-vendas-compras-inventario-contabilidade.md`
- [Validate plan](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/scripts/validate-planificacao.sh): governance script · Shell validation for the planning documentation structure. · `scripts/validate-planificacao.sh`

### Product prototype

Vite + React UI mockup that demonstrates the ERP shell and module structure.

- [App shell](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/App.tsx): react shell · Entry point and top-level UI composition for the prototype. · `mockup/src/app/App.tsx`
- [Layout](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/components/Layout.tsx): ui layout · Page framing, navigation structure, and shared shell behavior. · `mockup/src/app/components/Layout.tsx`
- [Login](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/components/Login.tsx): auth view · Authentication screen used by the prototype to enter the ERP. · `mockup/src/app/components/Login.tsx`
- [Auth state](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/context/AuthContext.tsx): ui context · Centralized login and session state for the mockup. · `mockup/src/app/context/AuthContext.tsx`
- [UI primitives](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/components/ui/button.tsx): shared components · Reusable dialogs, tables, forms, navigation, charts, and feedback components. · `mockup/src/app/components/ui/button.tsx`
- [Dashboard](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/components/modules/Dashboard.tsx): module view · Overview screen for KPIs, alerts, and summary activity. · `mockup/src/app/components/modules/Dashboard.tsx`
- [ERP modules](https://github.com/nunomacastro/edu-pap-3ig-opsa-2526/blob/main/mockup/src/app/components/modules/Vendas.tsx): module views · Domain screens for Vendas, Compras, Inventario, Contabilidade, Bancos, IA, and Configuracoes. · `mockup/src/app/components/modules/Vendas.tsx`

### Target ERP architecture

Documented functional domains and cross-cutting controls for the intended OPSA product.

- **ERP core**: domain platform · Target transactional backbone for company context, master data, and business operations.
- **Access & setup**: domain module · Users, roles, company setup, fiscal periods, and base master data.
- **Sales & buying**: domain module · Invoices, credit notes, receipts, supplier bills, approvals, and automated postings.
- **Stock & books**: domain module · Inventory movements, costing, manual entries, trial balance, and financial statements.
- **Banking & reports**: domain module · Cash accounts, statement import, reconciliation, treasury, SAF-T, and KPIs.
- **AI insights**: assistant layer · Recommendations, explanations, alerts, and natural-language answers using business data only.
- **Audit & compliance**: cross-cutting control · RBAC, multi-company access, auditability, approvals, retention, and fiscal constraints.
- **Imports & exports**: adapter boundary · Email, CSV/OFX imports, and PDF/Excel/CSV/SAF-T outputs as external interfaces.

## Connections

- RF → Planificação: defines scope
- RNF → Planificação: constrains delivery
- Planificação → Backlogs: organizes
- Backlogs → MF0–MF4: phases
- Backlogs → MF5–MF8: phases
- Validate plan → Planificação: checks consistency
- App shell → Layout: renders
- App shell → Login: gates access
- App shell → ERP modules: hosts
- Login → Auth state: uses
- Layout → UI primitives: shares primitives
- ERP modules → UI primitives: composes
- Dashboard → UI primitives: composes
- RF → ERP core: targets
- Access & setup → ERP core: anchors
- Sales & buying → ERP core: produces transactions
- Stock & books → ERP core: posts stock and ledger
- Banking & reports → ERP core: consumes transactions
- AI insights → ERP core: analyzes data
- Audit & compliance → Access & setup: governs
- Audit & compliance → Sales & buying: governs
- Audit & compliance → Stock & books: governs
- Audit & compliance → Banking & reports: governs
- Audit & compliance → AI insights: bounds
- Imports & exports → Banking & reports: imports/exports
- Imports & exports → Sales & buying: imports/exports
- Imports & exports → Audit & compliance: logs
