# neonkid/python-mf-data architecture

> Architecture diagram of the GitHub repository neonkid/python-mf-data, 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/neonkid/python-mf-data
- Repository: https://github.com/neonkid/python-mf-data

## Overview

##### Main Components

a) Core Framework Layer:
- Common module (/pymfdata/common)
- Database Specific Modules:
- RDB module (/pymfdata/rdb)
- MongoDB module (/pymfdata/mongodb)

b) Integration Layer:
- Supported Frameworks:
- FastAPI
- Falcon
- Other microframeworks

c) Database Layer:
- Primary Support:
- SQLAlchemy (RDB)
- MongoDB (in development)
- Database Dialects:
- PostgreSQL
- MySQL
- Oracle
- SQL Server
- SQLite

##### Component Relationships

**[Microframeworks Layer]**
- ↓
**[Python-MF-Data Core]**
- ↓
**[Database Adapters]**
- ↓
**[Databases]**

##### Detailed Component Breakdown

a) Core Framework Components:
**[Common Module]**
- Base UseCase
- Shared Utilities

**[RDB Module]**
- Connection Management
- Repository Pattern
- Transaction Handling
- Unit of Work Pattern
- Migration Support
- Mapping Utilities

**[MongoDB Module]**
- Connection Management
- Repository Pattern

##### Key Architectural Patterns to Highlight

a) Repository Pattern:
- Relationship between Repository protocols and implementations
- Generic type system for entities and primary keys

b) Unit of Work Pattern:
- Transaction management flow
- Session management and scoping

c) Connection Management:
- Both synchronous and asynchronous paths
- Connection pooling configuration

##### Implementation Details

a) Session Management:
**[Connection Factory]**
- ↓
**[Session Factory]**
- ↓
**[Scoped Sessions]**

b) Transaction Flow:
**[Transactional Decorator]**
- ↓
**[Unit of Work]**
- ↓
**[Repository]**
- ↓
**[Database]**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Application
        FastAPI["FastAPI"]
        Falcon["Falcon"]
    end

    subgraph PythonMFData["Python-MF-Data Framework"]
        subgraph CommonModule["Common Module"]
            BaseUseCase["Base Use Case Definitions"]:::common
            SharedUtils["Shared Utilities"]:::common
        end

        subgraph RDBModule["RDB Module"]
            ConnMgmt["Connection Management"]:::rdb
            RepoPattern["Repository Pattern"]:::rdb
            TransMgmt["Transaction Management"]:::rdb
            ORMMapping["ORM Mapping"]:::rdb
            Migration["Migration Support"]:::rdb
            UnitOfWork["Unit of Work Pattern"]:::rdb
        end

        subgraph MongoModule["MongoDB Module"]
            MongoConn["Connection Management"]:::mongo
            MongoRepo["Repository Pattern"]:::mongo
        end
    end

    subgraph DatabaseLayer["Database Layer"]
        SQLAlchemy[(SQLAlchemy)]:::db
        MongoDB[(MongoDB)]:::db
    end

    %% Application to Framework connections
    FastAPI --> CommonModule
    Falcon --> CommonModule

    %% Common Module internal connections
    BaseUseCase --> SharedUtils

    %% RDB Module connections
    ConnMgmt --> SQLAlchemy
    RepoPattern --> UnitOfWork
    TransMgmt --> UnitOfWork
    UnitOfWork --> SQLAlchemy
    ORMMapping --> SQLAlchemy
    Migration --> SQLAlchemy

    %% MongoDB Module connections
    MongoConn --> MongoDB
    MongoRepo --> MongoDB

    %% Click events for component mapping
    click CommonModule "https://github.com/NEONKID/python-mf-data/tree/main/pymfdata/common/"
    click BaseUseCase "https://github.com/NEONKID/python-mf-data/blob/main/pymfdata/common/usecase.py"
    click RDBModule "https://github.com/NEONKID/python-mf-data/tree/main/pymfdata/rdb/"
    click ConnMgmt "https://github.com/NEONKID/python-mf-data/blob/main/pymfdata/rdb/connection.py"
    click RepoPattern "https://github.com/NEONKID/python-mf-data/blob/main/pymfdata/rdb/repository.py"
    click TransMgmt "https://github.com/NEONKID/python-mf-data/blob/main/pymfdata/rdb/transaction.py"
    click ORMMapping "https://github.com/NEONKID/python-mf-data/blob/main/pymfdata/rdb/mapper.py"
    click Migration "https://github.com/NEONKID/python-mf-data/blob/main/pymfdata/rdb/migration.py"
    click UnitOfWork "https://github.com/NEONKID/python-mf-data/blob/main/pymfdata/rdb/usecase.py"
    click MongoModule "https://github.com/NEONKID/python-mf-data/tree/main/pymfdata/mongodb/"
    click MongoConn "https://github.com/NEONKID/python-mf-data/blob/main/pymfdata/mongodb/connection.py"
    click MongoRepo "https://github.com/NEONKID/python-mf-data/blob/main/pymfdata/mongodb/repository.py"

    %% Styling
    classDef common fill:#6495ED
    classDef rdb fill:#98FB98
    classDef mongo fill:#DDA0DD
    classDef db fill:#A9A9A9
    
    %% Legend
    subgraph Legend
        Common["Common Components"]:::common
        RDB["RDB Components"]:::rdb
        Mongo["MongoDB Components"]:::mongo
        DB["Databases"]:::db
    end
```
