# Monetarie SPB - Feature Enhancement Plan
## Beyond Legacy: Making Monetarie SPB Superior to CRK Evolution

**Date:** 2026-02-06
**Context:** Full analysis of legacy CRK Evolution (admin + user) vs current Monetarie SPB frontend
**Goal:** Not replicate but SURPASS the legacy system leveraging modern stack

---

## Executive Summary

The legacy CRK Evolution system has:
- **58 Angular modules** (lazy-loaded)
- **32 WebAPI controllers** (~70 endpoints)
- **400+ discrete RBAC functionalities**
- **20+ report types**, **12 export formats**
- **18+ integration services**

Our current Monetarie SPB frontend has:
- **21 routes** (9 admin + 7 operator + 5 global)
- **15 critical gaps** identified
- Most views are stubs or use mock data
- No message creation, no real reports, settings not persisted

**Target:** Build a modern SPB admin that covers ALL legacy features with modern UX improvements.

---

## PRIORITY 1 - Critical for Demo (Must Have)

### 1.1 Operations Monitor (Mon-Oper) - THE CORE SCREEN
**Legacy:** Primary screen for ALL SPB messaging - filter, send, cancel, convert, reprocess
**Current:** Basic message list with mock data
**Enhancement:**
- Real-time operations table with WebSocket updates
- Filters: date range, message type, status, clearing, ISPB, value range
- Actions: Send, Cancel, Retry, Convert (STR-PAG), Reprocess
- XML viewer (raw + formatted BACEN standard)
- Customizable TAG columns per message type
- Auto-refresh timer (configurable per user)
- Copy message / Copy batch capability

### 1.2 Generic Request (ReqGen) - Message Creation
**Legacy:** Can create ANY of 1,222 BACEN message types via dynamic JSON forms
**Current:** ZERO message creation capability
**Enhancement:**
- Dynamic form generator from message type templates
- Category-based message type selector (37 categories)
- Template save/load for frequently used messages
- XML preview before sending
- Balance check before STR operations
- Dual custody support for high-value operations

### 1.3 Dashboard with Real Data
**Legacy:** Balance panels (reserve, CIP, SELIC), alerts, notifications
**Current:** Hardcoded mock stats
**Enhancement:**
- Live reserve balance (predicted + confirmed)
- CIP payment chamber balance
- Message volume charts (real-time)
- Alert notifications panel
- System date display with open/close status
- Clearing entity status indicators
- NOC-style metrics (already built in Core command center)

### 1.4 RBAC with 400+ Functionalities
**Legacy:** 3-tier RBAC: Users -> Groups -> Funcionalidades (400+ discrete permissions)
**Current:** 3 roles (super_admin/admin/operator), 16 generic permissions, NO enforcement
**Enhancement:**
- Full functionality tree (400+ items from legacy enums)
- Per-component permission checks
- Group-based message type access (which groups can see/create which messages)
- Company/Branch scoping
- Dual custody for sensitive operations
- Pending operations approval workflow

### 1.5 Authorization Levels (Alcadas)
**Legacy:** Define value limits per user/group/legacy system, approval workflow
**Current:** DOES NOT EXIST
**Enhancement:**
- Alcada registration (generic + per message type)
- Value ranges: min, max, daily limit
- Visto (Visa/Approval) configuration
- Monitor de Vistos - real-time approval queue
- Batch approve/reject
- Print XML for review

---

## PRIORITY 2 - Important for Completeness

### 2.1 Integration Monitor
**Legacy:** Lists all messages from legacy systems, protocol reprocessing
**Current:** MonitoringView with simulated metrics
**Enhancement:**
- Real integration status from NATS JetStream
- Protocol-level tracking
- Reprocessing capability
- Non-integrated messages view

### 2.2 Reports
**Legacy:** 18+ report types via Telerik Reporting
**Current:** Stub "not implemented"
**Enhancement:**
- Audit log report
- Users x Groups report
- Users x Functionalities report
- Bank reserve statement (Extrato)
- Message movement report
- Message statistics (quarterly BACEN submission)
- Returned TEDs report
- Export: PDF, Excel, CSV

### 2.3 Day Opening/Closing
**Legacy:** System date management, closing modes (manual/STR0016/time-based)
**Current:** DOES NOT EXIST
**Enhancement:**
- Open/Close system date
- Configure closing type
- Pending operations check before close
- Balance validation on open
- STR0016 auto-receive handling

### 2.4 Settings Persistence
**Legacy:** 9 configuration groups, all persisted to DB
**Current:** 4 tabs with simulated saves (not persisted)
**Enhancement:**
- Persist all settings via backend API
- Add missing config groups: Connections, Special configs, Revocation
- Domain import (BACEN spreadsheets)
- Holiday calendar management

### 2.5 Entity Management (Financial Institutions)
**Legacy:** Full IF directory with STR018/019 auto-updates, XML import
**Current:** Basic CRUD with mock data
**Enhancement:**
- Real ISPB data from seeds (494 institutions)
- Active/Inactive filtering
- Compensation code, SISBACEN code
- STR018/019 event handling for auto-update
- Bank branch registry (CAF502)

---

## PRIORITY 3 - Advanced Features (Beyond Legacy)

### 3.1 Real-time WebSocket Updates (NEW - Legacy didn't have)
- Phoenix Channels for live message state changes
- Push notifications for alcada approvals
- Real-time clearing status updates
- Live balance ticker

### 3.2 Command Center Dashboard (NEW - Built in Core)
- NOC-style unified view
- Cross-system health monitoring
- NATS JetStream metrics
- Alert rule engine with evaluator

### 3.3 SSO Ecosystem Navigation (NEW)
- Single sign-on across PIX/SPB/NPC/STA/Core
- Module switcher in header
- Unified user session

### 3.4 API-First Architecture (NEW)
- Full REST API for all operations (legacy used WCF/ASMX)
- GraphQL for complex queries
- Webhook support for external integrations
- Rate limiting and throttling

### 3.5 Message Scheduling (Enhanced)
- Visual schedule grid (Gantt-like)
- Drag-and-drop time windows
- GEN0001 automation scheduler
- Batch operation scheduling

### 3.6 Tariff Management (Enhanced)
- Visual tariff table with comparison
- Tariff history and audit trail
- TIB (interbank) tariff monitoring
- Auto-calculation of tariff costs

---

## Implementation Phases

### Phase 1: Backend API Routes (4-6 hours)
Add missing API endpoints to bacen_gateway:
- `/api/operations` - Full CRUD with filtering, state changes
- `/api/operations/:id/send` - Send to clearing
- `/api/operations/:id/cancel` - Cancel operation
- `/api/alcadas` - Authorization level CRUD
- `/api/vistos` - Approval workflow
- `/api/reports` - Report generation
- `/api/settings` - Persist settings
- `/api/clearings` - Clearing house status
- `/api/tariffs` - Tariff management
- `/api/functionalities` - RBAC tree

### Phase 2: Frontend Core Views (6-8 hours)
Build the critical views:
1. **OperationsMonitor** - THE main screen
2. **GenericRequest** - Message creation
3. **AlcadaConfig** - Authorization levels
4. **VistosMonitor** - Approval workflow
5. **Dashboard** - Real data integration

### Phase 3: Frontend Supporting Views (4-6 hours)
6. **ReportsView** - Full report generation
7. **DayManagement** - Open/Close system date
8. **TariffView** - Tariff management
9. **ClearingStatus** - External entity monitoring
10. **IntegrationMonitor** - NATS integration status

### Phase 4: RBAC & Permissions (2-3 hours)
11. Full functionality tree in DB
12. Per-component permission enforcement
13. Pending operations workflow
14. Group-message association

---

## Route Structure (Target)

### Admin Routes (expanded from 9 to 25+)
```
/admin/dashboard          - Enhanced dashboard with balances
/admin/operations         - Operations monitor (main screen)
/admin/operations/new     - Generic request (message creation)
/admin/operations/vistos  - Approval monitor
/admin/alcadas            - Authorization levels config
/admin/alcadas/vistos     - Visa/approval config
/admin/entities           - Financial institutions
/admin/entities/branches  - Bank branches
/admin/users              - Users CRUD
/admin/groups             - Groups CRUD with functionality tree
/admin/permissions        - RBAC functionality tree
/admin/messages           - Message catalog browser
/admin/transactions       - Transaction monitor
/admin/reports            - Report generation
/admin/reports/audit      - Audit log
/admin/settings           - System settings (persisted)
/admin/settings/day       - Day open/close
/admin/settings/schedule  - Message schedule grid
/admin/settings/holidays  - Holiday calendar
/admin/settings/domains   - Domain import/management
/admin/clearings          - Clearing house status
/admin/tariffs            - Tariff management
/admin/integrations       - Integration monitor
/admin/automation         - Send/query automation
/admin/alerts             - Alert configuration
```

### Operator Routes (expanded from 7 to 15+)
```
/operator/dashboard       - Operator dashboard with balances
/operator/operations      - Operations monitor (send/cancel)
/operator/operations/new  - Create new operation
/operator/vistos          - Pending approvals
/operator/messages        - Received messages
/operator/bacen-messages  - BACEN message browser
/operator/transactions    - Transaction browser
/operator/payments        - Payment operations
/operator/monitoring      - System monitoring
/operator/reports         - Available reports
/operator/clearings       - Clearing status
/operator/alerts          - Alert inbox
/operator/notices         - Internal notices
```

---

## Message Group Access Control

Define which user groups can VIEW and/or CREATE each message category:

| Category | Admin View | Admin Create | Operator View | Operator Create |
|----------|-----------|-------------|--------------|----------------|
| STR | yes | yes (with alcada) | yes | yes (with alcada) |
| PAG | yes | yes | yes | yes |
| LPI | yes | yes | yes | yes |
| GEN | yes | yes | yes | no |
| CAM | yes | yes (forex only) | view only | no |
| SEL | yes | yes | yes | no |
| DDA | yes | yes | yes | yes |
| CIR | yes | yes | yes | yes |
| LDL | yes | view only | yes | no |
| CTP | yes | yes | yes | no |
| SME | yes | yes | yes | no |
| SLB | yes | view only | yes | no |
| TES | yes | view only | yes | no |

---

## Comparative Advantage Over Legacy

| Feature | Legacy (CRK Evolution) | Monetarie SPB |
|---------|----------------------|------------|
| Architecture | .NET 6 + SQL Server + MQ | Elixir/Phoenix + PostgreSQL + NATS |
| Frontend | Angular (custom) | Vue 3 + Vuetify 3 (modern) |
| Real-time | Polling (manual refresh) | WebSocket (Phoenix Channels) |
| Messaging | IBM MQ (proprietary) | NATS JetStream (cloud-native) |
| Deployment | Windows Server + IIS | Kubernetes (GKE) + auto-scaling |
| Monitoring | None built-in | Grafana + Prometheus + Command Center |
| SSO | AD/SiteMinder | OAuth2 ecosystem-wide |
| API | WCF/ASMX (SOAP) | REST + WebSocket (modern) |
| i18n | 4 languages | 3 (expandable) |
| Scalability | Single server | Horizontal (K8s replicas) |
| Cost | Windows + SQL Server licenses | Open source stack |
| Multi-tenant | Single institution | Multi-institution SaaS |
| Ledger | SQL-based | TigerBeetle (OLTP optimized) |

---

*Generated from comprehensive analysis of CRK Evolution Admin (400+ features) and User (58 modules) systems.*
