# abrooks/clara-factbase architecture

> Architecture diagram of the GitHub repository abrooks/clara-factbase, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abrooks/clara-factbase
- Repository: https://github.com/abrooks/clara-factbase

## Overview

##### Main Components

a) Core Components:
- EAV Engine Layer
- Clara Rules Integration Layer
- Session Management
- Transaction Processing
- DSL (Domain Specific Language) Parser
- Rule/Query System
- Entity Accumulator System

b) External Dependencies:
- Clara Rules Engine
- Clojure/ClojureScript Runtime

**┌─────────────────────────────────────────────────┐**
- Client Code                     │
- ┘
- ↓
**┌─────────────────────────────────────────────────┐**
- ClaraEAV Public API               │
- ┤
- Rules DSL  │  Query DSL  │  Transaction API    │
- ┘
- ↓
**┌─────────────────────────────────────────────────┐**
- Core Processing Layer               │
- ┬───────────┬───────────┬────────────┤
- EAV     │  Session  │   Rule    │  Entity    │
- Engine   │  Manager  │ Processor │Accumulator │
- ┴───────────┴───────────┴────────────┘
- ↓
**┌─────────────────────────────────────────────────┐**
- Clara Rules Engine                 │
- ┘

##### Important Relationships

a) Data Flow:
- How EAV triplets flow from client code through the system
- Transformation process from EAV format to Clara Rules format
- Demonstrate how queries and rules interact with the session

b) Component Interactions:
- How the DSL parser interfaces with Clara Rules
- Relationship between the session manager and EAV engine
- How accumulators transform EAV data back into entity maps

##### Implementation Details to Highlight

- How dsl.clj handles the custom syntax
- How session.cljc manages state
- How rules.cljc integrates with Clara
- Demonstrate how store.cljc handles data persistence

##### Cross-Platform Support
- Clojure/ClojureScript compatibility

##### Notes Section
A notes section explaining:
- Session initialization process
- Transaction data handling
- Rule execution flow
- Query processing

Remember to emphasize the relationship with Clara Rules as this is a key architectural feature, showing how ClaraEAV extends and specializes Clara's functionality for EAV operations.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        CC[Client Code]:::client
    end

    subgraph API["Public API Layer"]
        API_MAIN["Public API Interface"]:::api
        DSL_RULES["Rules DSL"]:::api
        DSL_QUERY["Query DSL"]:::api
        TRANS_API["Transaction API"]:::api
    end

    subgraph Core["Core Processing Layer"]
        EAV["EAV Engine"]:::core
        SESSION["Session Manager"]:::core
        RULES["Rule Processor"]:::core
        ACCUM["Entity Accumulator"]:::core
        STORE["Transaction Store"]:::core
        UTIL["Utility Functions"]:::core
    end

    subgraph External["External Dependencies"]
        CLARA["Clara Rules Engine"]:::external
        CLOJURE["Clojure/ClojureScript Runtime"]:::external
    end

    %% Relationships
    CC --> API_MAIN
    API_MAIN --> DSL_RULES & DSL_QUERY & TRANS_API
    DSL_RULES & DSL_QUERY --> RULES
    TRANS_API --> STORE
    RULES --> EAV
    EAV --> SESSION
    SESSION --> CLARA
    STORE --> SESSION
    ACCUM --> SESSION
    UTIL --> EAV & SESSION & RULES
    CLARA --> CLOJURE

    %% Click Events
    click API_MAIN "https://github.com/abrooks/clara-factbase/blob/jmartin-20230428/src/clara_eav/main.cljc"
    click DSL_RULES "https://github.com/abrooks/clara-factbase/blob/jmartin-20230428/src/clara_eav/dsl.clj"
    click EAV "https://github.com/abrooks/clara-factbase/blob/jmartin-20230428/src/clara_eav/eav.cljc"
    click SESSION "https://github.com/abrooks/clara-factbase/blob/jmartin-20230428/src/clara_eav/session.cljc"
    click RULES "https://github.com/abrooks/clara-factbase/blob/jmartin-20230428/src/clara_eav/rules.cljc"
    click STORE "https://github.com/abrooks/clara-factbase/blob/jmartin-20230428/src/clara_eav/store.cljc"
    click UTIL "https://github.com/abrooks/clara-factbase/blob/jmartin-20230428/src/clara_eav/util.cljc"

    %% Styles
    classDef client fill:#E5E5E5,stroke:#333,stroke-width:2px
    classDef api fill:#B3D9FF,stroke:#333,stroke-width:2px
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px
    classDef external fill:#FFE5B4,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Client Components]:::client
        L2[API Components]:::api
        L3[Core Components]:::core
        L4[External Dependencies]:::external
    end
```
