# jamesmoss/flywheel architecture

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

- Interactive diagram: https://gitdiagram.com/jamesmoss/flywheel
- Repository: https://github.com/jamesmoss/flywheel

## Overview

##### Main Components

a. Core Components:
- Config Manager
- Repository Manager
- Query Engine
- Document Manager
- Formatter System
- Storage Layer

b. Supporting Components:
- Caching Layer (APC/APCu)
- File System Interface

##### Component Relationships and Data Flow

**Application Layer (Client Code)**
- ↓
**Repository Interface Layer**
- ↓
**Query/Document Processing Layer**
- ↓
**Storage/Formatting Layer**
- ↓
**File System Layer**

##### Specific Implementation Details

a. Repository Manager:
- Connections to Query Engine and Document Manager
- CRUD operations (store, update, delete, findById)
- To Config Manager for initialization

b. Query Engine:
- Query Builder component
- Predicate Processing
- To Caching Layer (optional APC/APCu)
- Query Execution flow

c. Document Manager:
- Document Interface
- To Formatter System
- Document validation and processing

d. Formatter System:
- Available formatters (JSON, YAML, Markdown)
- To Storage Layer
- Format conversion flow

##### Implementation Notes

Important details:

- Document the flat-file storage structure
- Query execution flow
- Caching integration points
- Formatter selection process
- Serverless nature of the system

##### The caching integration points

This design should reflect Flywheel's core principles of simplicity and efficiency while showing its complete architectural structure.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        APP[Application Code]
    end

    subgraph Repository_Layer
        RM[Repository Manager]:::core
        NR[Nested Repository]:::core
        CM[Config Manager]:::core
    end

    subgraph Query_Processing
        QE[Query Engine]:::query
        QB[Query Builder]:::query
        QX[Query Executer]:::query
        PR[Predicate Processing]:::query
        CQ[Cached Query]:::cache
    end

    subgraph Document_Layer
        DM[Document Manager]:::core
        DI[Document Interface]:::interface
    end

    subgraph Format_Layer
        FS[Formatter System]:::formatter
        JSON[JSON Formatter]:::formatter
        YAML[YAML Formatter]:::formatter
        MD[Markdown Formatter]:::formatter
    end

    subgraph Storage_Layer
        SL[Storage Layer]:::storage
        FS_INT[File System Interface]:::storage
        CACHE[APC/APCu Cache]:::cache
    end

    %% Connections
    APP --> RM
    RM --> CM
    RM --> QE
    RM --> DM
    NR --> RM
    QE --> QB
    QB --> QX
    QX --> PR
    QE -.-> CQ
    CQ -.-> CACHE
    DM --> DI
    DM --> FS
    FS --> JSON
    FS --> YAML
    FS --> MD
    FS --> SL
    SL --> FS_INT

    %% Click Events
    click CM "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/Config.php"
    click RM "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/Repository.php"
    click NR "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/NestedRepository.php"
    click QE "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/Query.php"
    click QX "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/QueryExecuter.php"
    click PR "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/Predicate.php"
    click CQ "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/CachedQuery.php"
    click DM "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/Document.php"
    click DI "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/DocumentInterface.php"
    click FS "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/Formatter/FormatInterface.php"
    click JSON "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/Formatter/JSON.php"
    click YAML "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/Formatter/YAML.php"
    click MD "https://github.com/jamesmoss/flywheel/blob/master/src/JamesMoss/Flywheel/Formatter/Markdown.php"
    click SL "https://github.com/jamesmoss/flywheel/tree/master/test/JamesMoss/Flywheel/fixtures/datastore/"

    %% Styles
    classDef core fill:#2374ab
    classDef query fill:#ffd400
    classDef formatter fill:#9c528b
    classDef storage fill:#1ba345
    classDef cache fill:#cccccc,stroke-dasharray: 5 5
    classDef interface fill:#ffffff,stroke:#000000

    %% Legend
    subgraph Legend
        L1[Core Component]:::core
        L2[Query Component]:::query
        L3[Formatter Component]:::formatter
        L4[Storage Component]:::storage
        L5[Cache/Optional]:::cache
        L6[Interface]:::interface
    end
```
