architect/_archive/2025-11-26-cleanup/cifra/04_LANGUAGE_SPECIFICATION.md

CIFRA — Спецификация языка

Версия: 2.0.0
Дата: 2025-11-10


Синтаксис .cifra файлов

Структура файла

project:
  name: string
  type: string
  version: string

modules:
  - module_name

entities:
  EntityName:
    fields: {}

workflows:
  workflow_name: {}

permissions:
  roles: {}

theme:
  colors: {}

integrations:
  service_name: {}

Project

project:
  name: "My Application"
  type: crm | erp | admin_panel | ecommerce | cms
  version: "1.0.0"
  description: "Application description"

Modules

modules:
  - contacts
  - deals
  - companies

# Или с настройками
modules:
  contacts:
    enabled: true
    entities: [Contact, Company]

Entities

entities:
  Contact:
    table_name: contacts  # optional

    fields:
      # Базовые типы
      name: {type: string, required: true}
      email: {type: email, unique: true}
      phone: {type: phone}
      age: {type: integer, min: 0, max: 150}
      bio: {type: text}
      is_active: {type: boolean, default: true}

      # Деньги и числа
      balance: {type: money, currency: USD}
      price: {type: decimal, precision: 10, scale: 2}

      # Даты
      created_at: {type: datetime, auto_now_add: true}
      updated_at: {type: datetime, auto_now: true}
      birthday: {type: date}

      # Выбор
      status: {type: choice, choices: [active, inactive, pending]}

      # Связи
      company: {type: reference, entity: Company}
      tags: {type: many_to_many, entity: Tag}

      # Файлы
      avatar: {type: file, allowed_types: [image/*]}
      documents: {type: file[], max_count: 10}

      # JSON
      metadata: {type: json}
      settings: {type: json_schema, schema: {...}}

    # Индексы
    indexes:
      - [email]
      - [company, status]

    # Валидация
    validators:
      - unique_email
      - valid_age_range

Workflows

workflows:
  deal_pipeline:
    trigger: entity.Deal.stage_changed

    steps:
      - name: Send notification
        when: stage == 'won'
        action: send_notification
        params:
          template: deal_won
          recipients: [assigned_user]

      - name: Create invoice
        when: stage == 'won'
        action: create_entity
        params:
          entity: Invoice
          data:
            deal_id: "{{deal.id}}"
            amount: "{{deal.amount}}"

Permissions

permissions:
  roles:
    admin:
      - "*"  # All permissions

    manager:
      - contact:view
      - contact:create
      - contact:update
      - deal:*

    user:
      - contact:view_own
      - deal:view_own

  # ABAC rules
  rules:
    - name: Can edit own contacts
      effect: allow
      actions: [contact:update]
      conditions:
        contact.owner_id: "{{user.id}}"

Theme

theme:
  name: material

  colors:
    primary: "#3f51b5"
    secondary: "#ff4081"
    success: "#4caf50"
    error: "#f44336"

  typography:
    font_family: "Roboto, sans-serif"
    heading_size: 24px
    body_size: 14px

  layout:
    sidebar_position: left
    sidebar_collapsible: true

Integrations

integrations:
  stripe:
    enabled: true
    api_key: ${STRIPE_API_KEY}
    webhook_url: /api/webhooks/stripe

  sendgrid:
    enabled: true
    api_key: ${SENDGRID_API_KEY}
    from_email: noreply@example.com

  s3:
    enabled: true
    bucket: my-bucket
    region: us-east-1

Naming conventions

Entities: PascalCase (Contact, DealStage)
Fields: snake_case (first_name, created_at)
Modules: lowercase (contacts, deals)
Workflows: snake_case (deal_pipeline)
Permissions: colon-separated (contact:view)


Следующий документ: DATA_LAYER.md →