Skip to content

founder-pl/ksef

Repository files navigation

KSeF Integration Hub

Uniwersalna platforma integracyjna KSeF z własnym DSL i orkiestracją workflow

License: MIT Python 3.11+ React 18

Architektura TEXT2DSL

┌─────────────────────────────────────────────────────────────────────┐
│                         KSeF INTEGRATION HUB                         │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │                      TEXT2DSL LAYER                          │   │
│  │                                                              │   │
│  │   "Pobierz faktury z KSeF,     ┌──────────────────────┐     │   │
│  │    skategoryzuj przez AI,  ───►│   LLM Converter      │     │   │
│  │    wyślij do Comarch"          │   (Mistral/GPT)      │     │   │
│  │                                └──────────┬───────────┘     │   │
│  │                                           │                  │   │
│  │                                           ▼                  │   │
│  │   ┌──────────────────────────────────────────────────────┐  │   │
│  │   │  workflow:                                            │  │   │
│  │   │    name: "import_and_categorize"                      │  │   │
│  │   │    steps:                                             │  │   │
│  │   │      - action: ksef.fetch_invoices                    │  │   │
│  │   │        params: { date_from: "2026-01-01" }           │  │   │
│  │   │      - action: ai.categorize                          │  │   │
│  │   │      - action: comarch.export                         │  │   │
│  │   └──────────────────────────────────────────────────────┘  │   │
│  │                         YAML DSL                             │   │
│  └─────────────────────────────────────────────────────────────┘   │
│                              │                                      │
│                              ▼                                      │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │                    DSL EXECUTION ENGINE                      │   │
│  │                                                              │   │
│  │  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────┐    │   │
│  │  │  Parser  │─►│ Validator│─►│ Planner  │─►│ Executor │    │   │
│  │  │  (YAML)  │  │ (Schema) │  │  (DAG)   │  │ (Async)  │    │   │
│  │  └──────────┘  └──────────┘  └──────────┘  └──────────┘    │   │
│  └─────────────────────────────────────────────────────────────┘   │
│                              │                                      │
│                              ▼                                      │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │                    ADAPTER REGISTRY                          │   │
│  │                                                              │   │
│  │  ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐           │   │
│  │  │  KSeF   │ │BaseLinkr│ │ Comarch │ │Fakturown│           │   │
│  │  │ Adapter │ │ Adapter │ │ Adapter │ │ Adapter │           │   │
│  │  └─────────┘ └─────────┘ └─────────┘ └─────────┘           │   │
│  └─────────────────────────────────────────────────────────────┘   │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Stack Technologiczny (100% Open Source)

Warstwa Technologia Licencja
DSL Engine Python + Pydantic MIT
Task Queue Celery + Redis BSD
Wizualizacja React Flow MIT
Edytor DSL Monaco Editor MIT
Backend FastAPI MIT
Frontend React + TypeScript MIT
AI/LLM Ollama + Mistral Apache 2.0
Baza danych PostgreSQL PostgreSQL License

Struktura Projektu

ksef-hub/
├── dsl/                        # DSL Core Engine
│   ├── __init__.py
│   ├── schema.py              # Pydantic models for DSL
│   ├── parser.py              # YAML → Internal AST
│   ├── validator.py           # Schema validation
│   ├── executor.py            # Async workflow executor
│   ├── planner.py             # DAG planning
│   └── text2dsl.py            # LLM-based natural language → DSL
│
├── adapters/                   # Integration Adapters
│   ├── __init__.py
│   ├── base.py                # Abstract base adapter
│   ├── registry.py            # Adapter registry
│   ├── ksef.py                # KSeF API adapter
│   ├── baselinker.py          # BaseLinker adapter
│   ├── comarch.py             # Comarch ERP adapter
│   ├── fakturownia.py         # Fakturownia adapter
│   └── validators.py          # CEIDG, Biała Lista adapters
│
├── ai/                         # AI Components
│   ├── __init__.py
│   ├── llm.py                 # LLM client (Ollama)
│   ├── categorizer.py         # Invoice categorization
│   └── anomaly.py             # Anomaly detection
│
├── api/                        # FastAPI Backend
│   ├── __init__.py
│   ├── main.py                # App entry point
│   ├── routes/
│   │   ├── __init__.py
│   │   ├── workflows.py       # Workflow CRUD
│   │   ├── execute.py         # Workflow execution
│   │   └── adapters.py        # Adapter management
│   └── models/
│       ├── __init__.py
│       └── schemas.py         # API schemas
│
├── web/                        # React Frontend
│   ├── package.json
│   ├── src/
│   │   ├── App.tsx
│   │   ├── components/
│   │   │   ├── FlowEditor.tsx     # React Flow visual editor
│   │   │   ├── DSLEditor.tsx      # Monaco YAML editor
│   │   │   ├── Text2DSL.tsx       # Natural language input
│   │   │   └── ExecutionLog.tsx   # Real-time logs
│   │   ├── hooks/
│   │   │   └── useWorkflow.ts
│   │   └── utils/
│   │       └── dsl.ts
│   └── index.html
│
├── workflows/                  # Example Workflows
│   ├── import_invoices.yaml
│   ├── ecommerce_to_ksef.yaml
│   └── monthly_report.yaml
│
├── tests/                      # Tests
│   ├── test_dsl.py
│   ├── test_adapters.py
│   └── test_executor.py
│
├── docs/                       # Documentation
│   ├── DSL_SPECIFICATION.md
│   ├── ADAPTERS.md
│   └── DEPLOYMENT.md
│
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
├── pyproject.toml
└── README.md

Quick Start

# 1. Clone & setup
git clone https://github.com/softreck/ksef-hub.git
cd ksef-hub

# 2. Start services
docker-compose up -d

# 3. Access UI
open http://localhost:3000

DSL Specification

Basic Workflow

workflow:
  name: "import_invoices"
  version: "1.0"
  description: "Import invoices from KSeF and categorize"
  
  triggers:
    - type: schedule
      cron: "0 8 * * *"  # Daily at 8 AM
    
  steps:
    - id: fetch
      action: ksef.fetch_invoices
      params:
        date_from: "{{ today - 1d }}"
        date_to: "{{ today }}"
      
    - id: categorize
      action: ai.categorize
      input: "{{ steps.fetch.output }}"
      params:
        model: "mistral-7b"
        
    - id: export
      action: comarch.export
      input: "{{ steps.categorize.output }}"
      on_error: notify
      
  on_error:
    - action: slack.send
      params:
        channel: "#alerts"
        message: "Workflow failed: {{ error }}"

TEXT2DSL Example

Input (natural language):

Codziennie o 8 rano pobierz nowe faktury z KSeF,
sprawdź czy kontrahenci są na białej liście VAT,
skategoryzuj faktury przez AI i wyślij do Comarch Optima.
Jeśli coś się nie uda, wyślij powiadomienie na Slacka.

Output (DSL):

workflow:
  name: "daily_import"
  triggers:
    - type: schedule
      cron: "0 8 * * *"
  steps:
    - id: fetch
      action: ksef.fetch_invoices
      params:
        date_from: "{{ today - 1d }}"
    - id: validate
      action: whitelist.check_nip
      input: "{{ steps.fetch.output }}"
    - id: categorize
      action: ai.categorize
      input: "{{ steps.validate.output }}"
    - id: export
      action: comarch.export
      input: "{{ steps.categorize.output }}"
  on_error:
    - action: slack.send
      params:
        message: "Import failed: {{ error }}"

License

MIT License - pełna swoboda użycia komercyjnego

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors