architect/_archive/2025-11-26-cleanup/cifra/12_DEVELOPER_GUIDE.md

CIFRA — Руководство разработчика

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


CLI Reference

Основные команды

# Init project
cifra init <project-name> --template crm

# Generate code
cifra generate <config.cifra>

# Run application
cifra run <config.cifra> --port 8000 --reload

# Migrations
cifra migrate up
cifra migrate down
cifra migrate create "add user table"

# Database
cifra db create
cifra db seed
cifra db backup

# Export/Import
cifra export Contact --format csv
cifra import contacts.csv --entity Contact

# Hub
cifra hub search payment
cifra hub install stripe-integration

# Deploy
cifra deploy production --provider aws

# Test
cifra test --coverage

Code Generation

Что генерируется

project/
├── backend/
│   ├── models.py          # SQLAlchemy models
│   ├── schemas.py         # Pydantic schemas
│   ├── api.py             # FastAPI routes
│   └── crud.py            # CRUD operations
│
├── frontend/
│   ├── components/        # React/Vue components
│   ├── pages/             # Pages
│   └── api/               # API client
│
└── migrations/            # Alembic migrations

Backend (FastAPI)

# Generated API
@app.get("/api/contacts")
async def list_contacts(
    skip: int = 0,
    limit: int = 100,
    db: Session = Depends(get_db)
):
    contacts = await Contact.list(db, skip=skip, limit=limit)
    return contacts

Extending CIFRA

Custom field type

from cifra.fields import BaseField

class IPAddressField(BaseField):
    def validate(self, value):
        # Validate IP address format
        ...

    def to_db_type(self):
        return String(15)

Custom validator

from cifra.validators import Validator

class CustomValidator(Validator):
    def validate(self, value, entity):
        if not self.is_valid(value):
            raise ValueError("Invalid value")

Backend Deep Dive

Почему FastAPI?

Преимущества:
- ✅ Async support
- ✅ Auto-documentation (OpenAPI)
- ✅ Type hints (Pydantic)
- ✅ High performance
- ✅ Modern Python (3.11+)

vs Django:
- FastAPI: 20,000 req/s
- Django: 2,000 req/s
- 10x faster!


Testing

import pytest
from cifra.testing import TestClient

@pytest.fixture
def client():
    return TestClient(app)

def test_create_contact(client):
    response = client.post("/api/contacts", json={
        "name": "John Doe",
        "email": "john@example.com"
    })
    assert response.status_code == 201

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