feat: initial microservices project structure

Services:
- api: FastAPI gateway with JWT auth, async endpoints, WebSocket
- worker-gpu: CUDA sentence-transformers, FAISS IVFFlat, Ollama LLM
- worker-indexer: Winnowing+MinHash plagiarism detection, PDF/DOCX extraction
- worker-notifier: SMTP email notifications
- worker-gost: GOST 7.1-2003 and GOST R 7.0.5-2008 formatting

Infrastructure:
- docker-compose.yml (production) + docker-compose.dev.yml (hot reload)
- Nginx reverse proxy + WebSocket support
- PostgreSQL 16 with Alembic migrations
- Elasticsearch 8 with Russian/English analyzers
- MinIO, RabbitMQ, Redis, Ollama

Frontend:
- React 18 + Vite + TypeScript + TailwindCSS + Zustand + React Query v5
- 9 pages: Home, Search, Cabinet, Task, Check, Bibliography, Pricing, Login, Register

Scripts:
- Parser stubs: OpenAlex, КиберЛенинка, arXiv (Phase 0 - to be filled)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jze9
2026-05-24 19:42:39 +05:00
commit 7758315632
120 changed files with 9500 additions and 0 deletions

View File

View File

@@ -0,0 +1,90 @@
"""Alembic env.py — настройка среды для миграций (async режим)."""
import asyncio
import os
from logging.config import fileConfig
from alembic import context
from sqlalchemy import pool
from sqlalchemy.engine import Connection
from sqlalchemy.ext.asyncio import async_engine_from_config
# Импорт всех моделей для автоопределения изменений
from app.database import Base
import app.models # noqa: F401 — регистрирует все модели
# Alembic Config
config = context.config
# Настройка логирования
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# Целевые метаданные для автогенерации
target_metadata = Base.metadata
# Читаем DATABASE URL из переменной окружения (синхронный psycopg2 для Alembic)
def get_url() -> str:
host = os.getenv("POSTGRES_HOST", "postgres")
port = os.getenv("POSTGRES_PORT", "5432")
db = os.getenv("POSTGRES_DB", "antiplagiator")
user = os.getenv("POSTGRES_USER", "antiplagiator")
password = os.getenv("POSTGRES_PASSWORD", "changeme")
return f"postgresql+psycopg2://{user}:{password}@{host}:{port}/{db}"
def run_migrations_offline() -> None:
"""Запустить миграции в 'offline' режиме (без реального соединения с БД)."""
url = get_url()
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
compare_type=True,
compare_server_default=True,
)
with context.begin_transaction():
context.run_migrations()
def do_run_migrations(connection: Connection) -> None:
"""Выполнить миграции с реальным соединением."""
context.configure(
connection=connection,
target_metadata=target_metadata,
compare_type=True,
compare_server_default=True,
)
with context.begin_transaction():
context.run_migrations()
async def run_async_migrations() -> None:
"""Запустить миграции в async режиме."""
configuration = config.get_section(config.config_ini_section) or {}
configuration["sqlalchemy.url"] = get_url()
connectable = async_engine_from_config(
configuration,
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
async with connectable.connect() as connection:
await connection.run_sync(do_run_migrations)
await connectable.dispose()
def run_migrations_online() -> None:
"""Запустить миграции в 'online' режиме."""
asyncio.run(run_async_migrations())
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View File

@@ -0,0 +1,24 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
def upgrade() -> None:
${upgrades if upgrades else "pass"}
def downgrade() -> None:
${downgrades if downgrades else "pass"}

View File

@@ -0,0 +1,113 @@
"""Начальная схема базы данных.
Revision ID: 001
Revises:
Create Date: 2024-01-01 00:00:00.000000
Создаёт таблицы: users, tasks, documents, fingerprints, usage_logs
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers
revision = "001"
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
"""Создать все таблицы."""
# ── users ──────────────────────────────────────────────────────────────────
op.create_table(
"users",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
sa.Column("email", sa.String(255), nullable=False),
sa.Column("hashed_password", sa.String(255), nullable=False),
sa.Column("name", sa.String(255), nullable=False),
sa.Column("is_verified", sa.Boolean(), nullable=False, server_default="false"),
sa.Column("plan", sa.String(20), nullable=False, server_default="free"),
sa.Column("verification_token", sa.String(255), nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
)
op.create_index("ix_users_email", "users", ["email"], unique=True)
# ── tasks ──────────────────────────────────────────────────────────────────
op.create_table(
"tasks",
sa.Column("id", sa.String(36), primary_key=True),
sa.Column("user_id", sa.Integer(), sa.ForeignKey("users.id", ondelete="CASCADE")),
sa.Column("type", sa.String(20), nullable=False),
sa.Column("status", sa.String(20), nullable=False, server_default="queued"),
sa.Column("celery_task_id", sa.String(255), nullable=True),
sa.Column("input_data", sa.JSON(), nullable=False, server_default="{}"),
sa.Column("result", sa.JSON(), nullable=True),
sa.Column("error", sa.Text(), nullable=True),
sa.Column("queue_position", sa.Integer(), nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True),
)
op.create_index("ix_tasks_user_id", "tasks", ["user_id"])
op.create_index("ix_tasks_status", "tasks", ["status"])
# ── documents ──────────────────────────────────────────────────────────────
op.create_table(
"documents",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
sa.Column("source", sa.String(50), nullable=False),
sa.Column("ext_id", sa.String(255), nullable=False),
sa.Column("doi", sa.String(255), nullable=True),
sa.Column("title", sa.Text(), nullable=False),
sa.Column("authors", sa.JSON(), nullable=False, server_default="[]"),
sa.Column("year", sa.Integer(), nullable=True),
sa.Column("lang", sa.String(10), nullable=True),
sa.Column("journal", sa.Text(), nullable=True),
sa.Column("volume", sa.String(50), nullable=True),
sa.Column("issue", sa.String(50), nullable=True),
sa.Column("pages", sa.String(50), nullable=True),
sa.Column("abstract", sa.Text(), nullable=True),
sa.Column("url", sa.Text(), nullable=True),
sa.Column("minio_key", sa.Text(), nullable=True),
sa.Column("faiss_id", sa.Integer(), nullable=True),
sa.Column("indexed_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
)
op.create_index("ix_documents_ext_id", "documents", ["ext_id"], unique=True)
op.create_index("ix_documents_doi", "documents", ["doi"])
op.create_index("ix_documents_source", "documents", ["source"])
op.create_index("ix_documents_year", "documents", ["year"])
op.create_index("ix_documents_lang", "documents", ["lang"])
op.create_index("ix_documents_faiss_id", "documents", ["faiss_id"])
# ── fingerprints ───────────────────────────────────────────────────────────
op.create_table(
"fingerprints",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
sa.Column("doc_id", sa.Integer(), sa.ForeignKey("documents.id", ondelete="CASCADE")),
sa.Column("hash_value", sa.BigInteger(), nullable=False),
sa.Column("position", sa.Integer(), nullable=False),
)
op.create_index("ix_fingerprints_doc_id", "fingerprints", ["doc_id"])
op.create_index("ix_fingerprints_hash_value", "fingerprints", ["hash_value"])
# ── usage_logs ─────────────────────────────────────────────────────────────
op.create_table(
"usage_logs",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
sa.Column("user_id", sa.Integer(), sa.ForeignKey("users.id", ondelete="CASCADE")),
sa.Column("action", sa.String(50), nullable=False),
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
)
op.create_index("ix_usage_logs_user_id", "usage_logs", ["user_id"])
op.create_index("ix_usage_logs_created_at", "usage_logs", ["created_at"])
def downgrade() -> None:
"""Удалить все таблицы."""
op.drop_table("usage_logs")
op.drop_table("fingerprints")
op.drop_table("documents")
op.drop_table("tasks")
op.drop_table("users")