File size: 27,297 Bytes
5a81b95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# πŸ“Š Citizen Intelligence Agency Data Model

This document provides a comprehensive view of the data model that powers the Citizen Intelligence Agency platform. It outlines the key data structures, relationships, and organization that enable parliamentary monitoring, political analysis, and transparency.

## πŸ“š Related Architecture Documentation

<div class="documentation-map">

| Document                                            | Focus           | Description                               | Documentation Link                                                              |
| --------------------------------------------------- | --------------- | ----------------------------------------- | ------------------------------------------------------------------------------- |
| **[Architecture](ARCHITECTURE.md)**                 | πŸ›οΈ Architecture | C4 model showing current system structure | [View Source](https://github.com/Hack23/cia/blob/master/ARCHITECTURE.md)         |
| **[Future Architecture](FUTURE_ARCHITECTURE.md)**   | πŸ›οΈ Architecture | C4 model showing future system structure | [View Source](https://github.com/Hack23/cia/blob/master/FUTURE_ARCHITECTURE.md)         |
| **[Mindmaps](MINDMAP.md)**                          | 🧠 Concept      | Current system component relationships    | [View Source](https://github.com/Hack23/cia/blob/master/MINDMAP.md)             |
| **[Future Mindmaps](FUTURE_MINDMAP.md)**            | 🧠 Concept      | Future capability evolution               | [View Source](https://github.com/Hack23/cia/blob/master/FUTURE_MINDMAP.md)      |
| **[SWOT Analysis](SWOT.md)**                        | πŸ’Ό Business     | Current strategic assessment              | [View Source](https://github.com/Hack23/cia/blob/master/SWOT.md)                |
| **[Future SWOT Analysis](FUTURE_SWOT.md)**          | πŸ’Ό Business     | Future strategic opportunities            | [View Source](https://github.com/Hack23/cia/blob/master/FUTURE_SWOT.md)         |
| **[Data Model](DATA_MODEL.md)**                     | πŸ“Š Data         | Current data structures and relationships | [View Source](https://github.com/Hack23/cia/blob/master/DATA_MODEL.md)          |
| **[Future Data Model](FUTURE_DATA_MODEL.md)**       | πŸ“Š Data         | Enhanced political data architecture      | [View Source](https://github.com/Hack23/cia/blob/master/FUTURE_DATA_MODEL.md)   |
| **[Flowcharts](FLOWCHART.md)**                      | πŸ”„ Process      | Current data processing workflows         | [View Source](https://github.com/Hack23/cia/blob/master/FLOWCHART.md)           |
| **[Future Flowcharts](FUTURE_FLOWCHART.md)**        | πŸ”„ Process      | Enhanced AI-driven workflows              | [View Source](https://github.com/Hack23/cia/blob/master/FUTURE_FLOWCHART.md)    |
| **[State Diagrams](STATEDIAGRAM.md)**               | πŸ”„ Behavior     | Current system state transitions          | [View Source](https://github.com/Hack23/cia/blob/master/STATEDIAGRAM.md)        |
| **[Future State Diagrams](FUTURE_STATEDIAGRAM.md)** | πŸ”„ Behavior     | Enhanced adaptive state transitions       | [View Source](https://github.com/Hack23/cia/blob/master/FUTURE_STATEDIAGRAM.md) |
| **[CI/CD Workflows](WORKFLOWS.md)**                 | πŸ”§ DevOps       | Current automation processes              | [View Source](https://github.com/Hack23/cia/blob/master/WORKFLOWS.md)           |
| **[Future Workflows](FUTURE_WORKFLOWS.md)**         | πŸ”§ DevOps       | Enhanced CI/CD with ML                    | [View Source](https://github.com/Hack23/cia/blob/master/FUTURE_WORKFLOWS.md)    |
| **[End-of-Life Strategy](End-of-Life-Strategy.md)** | πŸ“… Lifecycle    | Maintenance and EOL planning              | [View Source](https://github.com/Hack23/cia/blob/master/End-of-Life-Strategy.md) |
| **[Financial Security Plan](FinancialSecurityPlan.md)** | πŸ’° Security | Cost and security implementation          | [View Source](https://github.com/Hack23/cia/blob/master/FinancialSecurityPlan.md) |
| **[CIA Features](https://hack23.com/cia-features.html)** | πŸš€ Features | Platform features overview                | [View on hack23.com](https://hack23.com/cia-features.html)                     |
| **[Threat Model](THREAT_MODEL.md)**                 | πŸ›‘οΈ Security     | Data integrity & abuse threat mapping     | [View Source](https://github.com/Hack23/cia/blob/master/THREAT_MODEL.md)        |

</div>

## 🧩 Core Data Model Overview

The Citizen Intelligence Agency platform is built on a robust data model that integrates political data from multiple sources into a unified analytical framework. The data model reflects three primary domains:

```mermaid
erDiagram
    ParliamentaryData {
        string id
        string documentType
        string status
        date createdDate
        string title
    }
    
    PoliticalEntities {
        string id
        string firstName
        string lastName
        string party
        int bornYear
        string gender
    }
    
    AnalyticalOutput {
        string metricType
        float scoreValue
        date analysisDate
        string description
    }
    
    ParliamentaryData ||--o{ PoliticalEntities : "references"
    PoliticalEntities ||--o{ AnalyticalOutput : "generates"
    ParliamentaryData ||--o{ AnalyticalOutput : "informs"
```

## πŸ“Š Political Entities Data Model

**πŸ‘€ Person Focus:** Illustrates the structure of political persons (politicians) and their relationships to parties, committees, and other entities.

**πŸ›οΈ Organization Focus:** Shows how political organizations are modeled and their relationships within the system.

```mermaid
classDiagram
    class Person {
        +string id
        +string firstName
        +string lastName
        +string party
        +int bornYear
        +string gender
        +string status
        +string electionRegion
        +PersonAssignment[] assignments
        +PersonDetail[] details
    }
    
    class PersonAssignment {
        +string assignmentType
        +string detail
        +date fromDate
        +date toDate
        +string orgCode
        +string roleCode
        +string status
    }
    
    class PersonDetail {
        +string code
        +string detail
        +string detailType
    }
    
    class Party {
        +string id
        +string name
        +string shortCode
        +date registeredDate
        +string website
    }
    
    class Committee {
        +string orgCode
        +string detail
        +boolean active
        +date firstAssignmentDate
        +date lastAssignmentDate
    }
    
    class Ministry {
        +string nameId
        +long totalAssignments
        +date firstAssignmentDate
        +date lastAssignmentDate
    }

    Person "1" *-- "many" PersonAssignment
    Person "1" *-- "many" PersonDetail
    Person "many" -- "1" Party
    PersonAssignment "many" -- "many" Committee
    PersonAssignment "many" -- "many" Ministry
```

## πŸ“‘ Parliamentary Document Data Model

**πŸ“„ Document Focus:** Illustrates the structure of parliamentary documents and their relationships.

**πŸ”„ Process Focus:** Shows how documents flow through the parliamentary process.

```mermaid
classDiagram
    class DocumentData {
        +string id
        +string documentType
        +string title
        +string subTitle
        +string status
        +date madePublicDate
        +string org
        +string rm
        +string label
    }
    
    class DocumentContent {
        +string id
        +string content
    }
    
    class DocumentStatus {
        +string documentCategory
        +string documentId
    }
    
    class DocumentDetail {
        +string code
        +string detailName
        +string text
    }
    
    class DocumentPersonReference {
        +int orderNumber
        +string personReferenceId
        +string referenceName
        +string roleDescription
        +string partyShortCode
    }
    
    class CommitteeDocument {
        +string id
        +string label
        +string title
        +string org
        +string status
        +date createdDate
        +date publicDate
    }
    
    class CommitteeProposal {
        +string header
        +string proposal
        +string decisionType
        +string committeeReport
        +string winner
    }

    DocumentData "1" -- "0..1" DocumentContent
    DocumentData "1" -- "1" DocumentStatus
    DocumentStatus "1" *-- "many" DocumentDetail
    DocumentStatus "1" *-- "many" DocumentPersonReference
    CommitteeDocument "1" -- "many" CommitteeProposal
```

## πŸ—³οΈ Voting Data Model

**πŸ—³οΈ Vote Focus:** Illustrates the structure of voting data from parliamentary sessions.

**πŸ“Š Analysis Focus:** Shows how vote data is organized to enable analytical insights.

```mermaid
classDiagram
    class VoteData {
        +string ballotId
        +string concern
        +string intressentId
        +string issue
        +string ballotType
        +string vote
        +date voteDate
        +string party
        +string firstName
        +string lastName
        +int bornYear
        +string gender
    }
    
    class BallotSummary {
        +string ballotId
        +string concern
        +string issue
        +boolean approved
        +int yesVotes
        +int noVotes
        +int absentVotes
        +int abstainVotes
        +float avgBornYear
    }
    
    class PartyBallotSummary {
        +string ballotId
        +string concern
        +string issue
        +string party
        +boolean approved
        +int partyYesVotes
        +int partyNoVotes
        +int partyAbsentVotes
        +int partyAbstainVotes
        +float partyAvgBornYear
    }
    
    class PoliticianBallotSummary {
        +string ballotId
        +string concern
        +string intressentId
        +string issue
        +string vote
        +boolean won
        +boolean rebel
        +string party
    }

    VoteData "many" -- "1" BallotSummary
    BallotSummary "1" -- "many" PartyBallotSummary
    BallotSummary "1" -- "many" PoliticianBallotSummary
```

## 🌍 External Data Sources Model

**🌐 Integration Focus:** Illustrates the structure of data from external sources like World Bank.

**πŸ”„ Standardization Focus:** Shows how external data is standardized for platform integration.

```mermaid
classDiagram
    class WorldBankData {
        +string countryId
        +string countryValue
        +string indicatorId
        +string indicatorValue
        +string dataValue
        +int yearDate
    }
    
    class Indicator {
        +string id
        +string indicatorName
        +string sourceId
        +string sourceValue
        +string sourceNote
        +string sourceOrganization
    }
    
    class Country {
        +string id
        +string countryName
        +string regionId
        +string regionValue
        +string capitalCity
        +string latitude
        +string longitude
    }
    
    class Topic {
        +string id
        +string value
    }

    WorldBankData "many" -- "1" Country
    WorldBankData "many" -- "1" Indicator
    Indicator "many" -- "many" Topic
```

## πŸ—„οΈ Electoral Data Model

**πŸ—³οΈ Election Focus:** Illustrates the structure of electoral data from the Swedish Election Authority.

**πŸ›οΈ Geographic Focus:** Shows how electoral regions are organized within the system.

```mermaid
classDiagram
    class ElectionRegion {
        +string regionName
        +string countyId
        +string municipalId
    }
    
    class PoliticalParty {
        +string partyId
        +string partyName
        +string shortCode
        +date registeredDate
        +string website
    }
    
    class CountyData {
        +int code
        +string countyName
    }
    
    class MunicipalityData {
        +int code
        +string municipalName
    }
    
    class CountyElectoralRegion {
        +int code
        +string countyName
        +int seats
    }
    
    class CountyElectoralArea {
        +int code
        +string electoralAreaName
        +int numberOfSeats
        +int numberOfVoters
    }
    
    class ParliamentElectoralRegion {
        +string electionRegionName
        +int numberOfSeats
        +int numberOfVoters
    }
    
    class MunicipalityElection {
        +int code
        +string electionRegionName
        +int numberOfSeats
        +int numberOfVoters
    }

    ElectionRegion "1" -- "many" PoliticalParty
    CountyData "1" -- "many" MunicipalityData
    CountyElectoralRegion "1" -- "many" CountyElectoralArea
    CountyData "1" -- "1" CountyElectoralRegion
    MunicipalityData "1" -- "many" MunicipalityElection
    ElectionRegion "1" -- "0..1" CountyData
    ElectionRegion "1" -- "0..1" MunicipalityData
```

## πŸ‘€ User and System Data Model

**πŸ‘€ User Focus:** Illustrates the structure of user accounts and session data.

**πŸ”§ System Focus:** Shows how system configuration and operation data is organized.

```mermaid
classDiagram
    class UserAccount {
        +string userId
        +string username
        +string userPassword
        +string email
        +string userRole
        +string userType
        +date createdDate
        +int numberOfVisits
    }
    
    class ApplicationSession {
        +date createdDate
        +date destroyedDate
        +string ipInformation
        +string userAgentInformation
        +string sessionId
        +string userId
    }
    
    class ApplicationActionEvent {
        +string actionName
        +string applicationOperation
        +date createdDate
        +string page
        +string pageMode
        +string elementId
        +string sessionId
        +string userId
    }
    
    class ApplicationConfiguration {
        +string component
        +string componentTitle
        +string configurationGroup
        +string propertyId
        +string propertyValue
        +date createdDate
        +date updatedDate
    }
    
    class Portal {
        +string portalName
        +string description
        +string portalType
    }
    
    class DomainPortal {
        +string domainName
    }

    ApplicationSession "1" -- "many" ApplicationActionEvent
    UserAccount "1" -- "many" ApplicationSession
    Portal <|-- DomainPortal
```

## πŸ” Analytical Views Data Model

**πŸ“Š Analytics Focus:** Illustrates the structure of analytical views for political metrics.

**πŸ“Š Performance Focus:** Shows how performance metrics are calculated and stored.

```mermaid
classDiagram
    class PoliticianView {
        +string personId
        +string firstName
        +string lastName
        +string party
        +boolean active
        +int totalDocuments
        +int documentsLastYear
        +date firstAssignmentDate
        +date lastAssignmentDate
    }
    
    class PartyView {
        +string party
        +string partyName
        +boolean active
        +int totalDocuments
        +int documentsLastYear
        +int totalAssignments
    }
    
    class CommitteeView {
        +string orgCode
        +string detail
        +boolean active
        +int currentMemberSize
        +int totalAssignments
        +int totalDaysServed
    }
    
    class MinistryView {
        +string nameId
        +boolean active
        +int totalAssignments
        +int totalDaysServed
    }
    
    class PoliticianBallotSummaryView {
        +string personId
        +string firstName
        +string lastName
        +string party
        +float absenceRate
        +float loyaltyRate
        +float rebelRate
        +float successRate
        +int totalVotes
    }
    
    class PoliticianExperienceSummary {
        +string personId
        +string firstName
        +string lastName
        +string experienceLevel
        +string careerPhase
        +string specializationLevel
        +long totalDays
        +long committeeDays
        +long partyDays
    }

    PoliticianView "1" -- "0..1" PoliticianBallotSummaryView
    PoliticianView "1" -- "0..1" PoliticianExperienceSummary
```

## πŸ”„ Data Flow Diagram

This diagram illustrates how data flows through the system from various sources to the analytical outputs and user interfaces.

```mermaid
flowchart TD
    A[External Data Sources] --> B{Data Integration}
    
    B -->|Parliamentary Data| C1[Parliament Data Processing]
    B -->|Electoral Data| C2[Election Data Processing]
    B -->|Economic Data| C3[World Bank Data Processing]
    
    C1 --> D1[Document Entities]
    C1 --> D2[Politician Entities]
    C1 --> D3[Vote Data]
    C1 --> D4[Committee Data]
    
    C2 --> D5[Party Entities]
    C2 --> D6[Electoral Region Data]
    
    C3 --> D7[Indicator Data]
    C3 --> D8[Country Data]
    
    D1 & D2 & D3 & D4 & D5 & D6 & D7 & D8 --> E[Data Storage]
    
    E --> F1[Analytical Processing]
    F1 --> G1[Performance Metrics]
    F1 --> G2[Voting Analysis]
    F1 --> G3[Document Analysis]
    F1 --> G4[Political Network Analysis]
    
    G1 & G2 & G3 & G4 --> H[Materialized Views]
    
    H --> I[Web Application]
    I --> J[User Interface]
    
    classDef sources fill:#bbdefb,stroke:#333,stroke-width:1px,color:black
    classDef integration fill:#a0c8e0,stroke:#333,stroke-width:1px,color:black
    classDef processing fill:#c8e6c9,stroke:#333,stroke-width:1px,color:black
    classDef entities fill:#d1c4e9,stroke:#333,stroke-width:1px,color:black
    classDef storage fill:#f8cecc,stroke:#333,stroke-width:1px,color:black
    classDef analytics fill:#fff2cc,stroke:#333,stroke-width:1px,color:black
    classDef views fill:#ffe0b2,stroke:#333,stroke-width:1px,color:black
    classDef application fill:#dcedc8,stroke:#333,stroke-width:1px,color:black
    
    class A sources
    class B integration
    class C1,C2,C3 processing
    class D1,D2,D3,D4,D5,D6,D7,D8 entities
    class E storage
    class F1 analytics
    class G1,G2,G3,G4 analytics
    class H views
    class I,J application
```

## 🧩 Key Database Tables

| Category | Table Name | Description | Primary Keys | Key Relationships |
|----------|------------|-------------|--------------|-------------------|
| πŸ‘€ **Person Data** | `PERSON_DATA` | Political person entities | `ID` | `PERSON_ASSIGNMENT_DATA`, `PERSON_DETAIL_DATA` |
| πŸ‘€ **Person Data** | `ASSIGNMENT_DATA` | Political assignments | `HJID` | `PERSON_DATA` (many-to-one) |
| πŸ“‘ **Document Data** | `DOCUMENT_DATA` | Parliamentary documents | `ID` | `DOCUMENT_STATUS_CONTAINER` |
| πŸ“‘ **Document Data** | `DOCUMENT_CONTENT_DATA` | Document content | `HJID`, `ID` | `DOCUMENT_DATA` (one-to-one) |
| 🏒 **Committee Data** | `COMMITTEE_DOCUMENT_DATA` | Committee documents | `ID` | `COMMITTEE_PROPOSAL_DATA` |
| πŸ—³οΈ **Vote Data** | `VOTE_DATA` | Parliamentary votes | Composite (`BALLOT_ID`, `CONCERN`, `INTRESSENT_ID`, `ISSUE`) | - |
| 🌍 **World Bank** | `WORLD_BANK_DATA` | Economic indicators | `HJID` | `DATA_ELEMENT` |
| 🌍 **World Bank** | `COUNTRY_ELEMENT` | Country data | `HJID` | `COUNTRIES_ELEMENT` |
| πŸ—„οΈ **Electoral Data** | `SWEDEN_ELECTION_REGION` | Electoral regions | `HJID` | `SWEDEN_POLITICAL_PARTY` |
| πŸ—„οΈ **Electoral Data** | `SWEDEN_POLITICAL_PARTY` | Political parties | `HJID` | `SWEDEN_ELECTION_REGION` |
| πŸ‘€ **User Data** | `USER_ACCOUNT` | User accounts | `HJID` | `APPLICATION_SESSION` |
| πŸ‘€ **User Data** | `APPLICATION_SESSION` | User sessions | `HJID` | `APPLICATION_ACTION_EVENT` |
| πŸ”§ **System Data** | `APPLICATION_CONFIGURATION` | System configuration | `HJID` | - |

## πŸ“Š Materialized Views for Analytics

The CIA platform uses materialized views to provide efficient access to analytical data. These views transform raw data into meaningful insights about political entities and activities.

| View Name | Purpose | Key Metrics | Base Tables |
|-----------|---------|-------------|------------|
| `VIEW_RIKSDAGEN_POLITICIAN` | Politician profile metrics | Activity levels, document counts, assignment history | `PERSON_DATA`, `ASSIGNMENT_DATA` |
| `VIEW_RIKSDAGEN_PARTY` | Party performance metrics | Member counts, document counts, activity levels | `SWEDEN_POLITICAL_PARTY`, related person tables |
| `VIEW_RIKSDAGEN_COMMITTEE` | Committee activity metrics | Member counts, document counts, assignment data | `COMMITTEE_DOCUMENT_DATA`, related assignment tables |
| `VIEW_RIKSDAGEN_POLITICIAN_BALLOT_SUMMARY` | Voting performance | Loyalty rate, rebel rate, success rate, absence rate | `VOTE_DATA` |
| `View_Riksdagen_Vote_Data_Ballot_Summary` | Vote outcome analysis | Yes/no percentages, absence rates, approval stats | `VOTE_DATA` |
| `view_riksdagen_politician_experience_summary` | Experience analysis | Career phase, knowledge areas, leadership profile | `ASSIGNMENT_DATA`, `PERSON_DATA` |

## πŸ”„ Database Relationships

This diagram illustrates key relationships between major tables in the database:

```mermaid
erDiagram
    PERSON_DATA ||--o{ ASSIGNMENT_DATA : has
    PERSON_DATA ||--o{ PERSON_DETAIL_DATA : has
    DOCUMENT_DATA ||--|| DOCUMENT_STATUS_CONTAINER : has
    DOCUMENT_STATUS_CONTAINER ||--o{ DOCUMENT_DETAIL_DATA : contains
    DOCUMENT_STATUS_CONTAINER ||--o{ DOCUMENT_PERSON_REFERENCE_DA_0 : references
    COMMITTEE_DOCUMENT_DATA ||--o{ COMMITTEE_PROPOSAL_DATA : has
    VOTE_DATA }o--|| PERSON_DATA : cast_by
    USER_ACCOUNT ||--o{ APPLICATION_SESSION : has
    APPLICATION_SESSION ||--o{ APPLICATION_ACTION_EVENT : generates
    SWEDEN_ELECTION_REGION ||--o{ SWEDEN_POLITICAL_PARTY : contains
    SWEDEN_COUNTY_DATA ||--o{ SWEDEN_MUNICIPALITY_DATA : contains
    WORLD_BANK_DATA }o--|| COUNTRY_ELEMENT : relates_to
    WORLD_BANK_DATA }o--|| INDICATOR_ELEMENT : measures
```

## πŸ“ˆ Data Flow for Analytics

**πŸ”„ Process Focus:** Illustrates how raw data is transformed into analytical metrics.

**πŸ“Š Metrics Focus:** Shows the key transformations that generate political insights.

```mermaid
sequenceDiagram
    participant DataSource as External Data Sources
    participant ImportService as Import Services
    participant Database as PostgreSQL Database
    participant Analytics as Analytical Processes
    participant Views as Materialized Views
    participant UI as User Interface
    
    DataSource->>ImportService: Raw Political Data
    ImportService->>ImportService: Transform & Validate
    ImportService->>Database: Store Normalized Data
    
    Database->>Analytics: Raw Entity Data
    Analytics->>Analytics: Calculate Metrics
    Analytics->>Database: Store Derived Metrics
    
    Database->>Views: Create/Refresh Views
    Views->>UI: Provide Analytical Data
    UI->>UI: Visualize & Present
```

## πŸ’Ύ PostgreSQL Implementation

The CIA platform uses a PostgreSQL database with:

- 60+ base tables for entity storage
- 30+ materialized views for analytical queries
- Complex relationships modeled through foreign keys
- Composite primary keys for many-to-many relationships
- Audit and tracking capabilities through timestamp fields
- Large text fields for document content (up to 10MB)
- Enumerated types for categorization

### Schema Highlights

```sql
-- Political Person Entity
CREATE TABLE PERSON_DATA (
    ID varchar(255) NOT NULL,
    BORN_YEAR int4,
    ELECTION_REGION varchar(255),
    FIRST_NAME varchar(255),
    LAST_NAME varchar(255),
    GENDER varchar(255),
    PARTY varchar(255),
    STATUS varchar(255),
    PERSON_ASSIGNMENT_DATA_PERSO_0 int8,
    PERSON_DETAIL_DATA_PERSON_DA_0 int8,
    PRIMARY KEY (ID)
);

-- Parliamentary Vote Data
CREATE TABLE VOTE_DATA (
    EMBEDDED_ID_BALLOT_ID varchar(255) NOT NULL,
    EMBEDDED_ID_CONCERN varchar(255) NOT NULL,
    EMBEDDED_ID_INTRESSENT_ID varchar(255) NOT NULL,
    EMBEDDED_ID_ISSUE varchar(255) NOT NULL,
    BALLOT_TYPE varchar(255),
    VOTE varchar(255),
    VOTE_DATE date,
    PARTY varchar(255),
    FIRST_NAME varchar(255),
    LAST_NAME varchar(255),
    BORN_YEAR int4,
    GENDER varchar(255),
    PRIMARY KEY (EMBEDDED_ID_BALLOT_ID, EMBEDDED_ID_CONCERN, EMBEDDED_ID_INTRESSENT_ID, EMBEDDED_ID_ISSUE)
);

-- Political Performance View
CREATE TABLE VIEW_RIKSDAGEN_POLITICIAN_BALLOT_SUMMARY (
    PERSON_ID varchar(255) NOT NULL,
    ABSENCE_RATE float8,
    LOYALTY_RATE float8,
    REBEL_RATE float8,
    SUCCESS_RATE float8,
    TOTAL_VOTES int8,
    FIRST_NAME varchar(255),
    LAST_NAME varchar(255),
    PARTY varchar(255),
    PRIMARY KEY (PERSON_ID)
);
```

## πŸ”„ Data Model Evolution

**πŸš€ Future Focus:** Shows how the current data model will evolve in line with the future architecture vision.

**πŸ” Enhancement Focus:** Illustrates the planned data model improvements.

```mermaid
timeline
    title Data Model Evolution Plan
    section Current Model
        Now : Core political entities
            : Basic analytical views
            : Simple aggregations
    section Near Future
        Q3 2024 : ML-ready data structures
               : Enhanced relationship models
               : Predictive analytics tables
    section Mid-Term
        Q1 2025 : Real-time data streams
               : Natural language processing
               : Network analysis models
    section Long-Term
        Q3 2025 : AI decision support structures
            : Semantic knowledge graphs
            : Autonomous pattern detection
```

## 🧩 Key Data Model Implementation Features

| Feature | Implementation | Purpose | Examples |
|---------|----------------|---------|----------|
| πŸ”‘ **Entity Tracking** | Unique identifiers | Track entities across data sources | `PERSON_DATA.ID`, `DOCUMENT_DATA.ID` |
| πŸ”„ **Historical Tracking** | Date fields | Track changes over time | `FROM_DATE`, `TO_DATE`, `CREATED_DATE` |
| πŸ“Š **Analytical Aggregation** | Materialized views | Pre-compute metrics for performance | `VIEW_RIKSDAGEN_POLITICIAN`, `VIEW_RIKSDAGEN_PARTY` |
| πŸ” **Multi-dimensional Analysis** | Time-based aggregation views | Enable time-series analysis | `*_DAILY_SUMMARY`, `*_MONTHLY_SUMMARY`, `*_ANNUAL_SUMMARY` views |
| 🌐 **External Integration** | Standardized entity mapping | Connect with external data sources | World Bank tables, riksdagen tables |
| πŸ‘€ **User Behavior Tracking** | Session and event tables | Track user interactions | `APPLICATION_SESSION`, `APPLICATION_ACTION_EVENT` |
| πŸ”’ **Security Implementation** | User account structures | Manage authentication and authorization | `USER_ACCOUNT`, `EncryptedValue` |

This data model documentation provides a comprehensive view of the CIA platform's current data structures and relationships. It illustrates how political data is organized, analyzed, and presented to enable transparency and citizen engagement with political processes.

For more detailed information on specific entities, please refer to the [Entity Model Documentation](https://hack23.github.io/cia/service.data.impl/hbm2doc/entities/index.html).

## Related Documentation

- [Architecture Documentation](ARCHITECTURE.md) - System architecture overview
- [Entity Model Documentation](https://hack23.github.io/cia/service.data.impl/hbm2doc/entities/index.html) - Detailed entity documentation
- [Future Vision](FUTURE_MINDMAP.md) - Roadmap for AI-enhanced capabilities
- [MINDMAP Documentation](MINDMAP.md) - Conceptual overview of system components
- [AWS Services Stack](README.md#aws-services-stack) - Cloud deployment architecture