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:
75
infra/elasticsearch/mappings.json
Normal file
75
infra/elasticsearch/mappings.json
Normal file
@@ -0,0 +1,75 @@
|
||||
{
|
||||
"settings": {
|
||||
"number_of_shards": 1,
|
||||
"number_of_replicas": 0,
|
||||
"analysis": {
|
||||
"analyzer": {
|
||||
"russian_analyzer": {
|
||||
"type": "custom",
|
||||
"tokenizer": "standard",
|
||||
"filter": ["lowercase", "russian_stop", "russian_stemmer"]
|
||||
},
|
||||
"english_analyzer": {
|
||||
"type": "custom",
|
||||
"tokenizer": "standard",
|
||||
"filter": ["lowercase", "english_stop", "english_stemmer"]
|
||||
},
|
||||
"multilingual_analyzer": {
|
||||
"type": "custom",
|
||||
"tokenizer": "standard",
|
||||
"filter": ["lowercase", "russian_stop", "russian_stemmer", "english_stop"]
|
||||
}
|
||||
},
|
||||
"filter": {
|
||||
"russian_stop": {
|
||||
"type": "stop",
|
||||
"stopwords": "_russian_"
|
||||
},
|
||||
"russian_stemmer": {
|
||||
"type": "stemmer",
|
||||
"language": "russian"
|
||||
},
|
||||
"english_stop": {
|
||||
"type": "stop",
|
||||
"stopwords": "_english_"
|
||||
},
|
||||
"english_stemmer": {
|
||||
"type": "stemmer",
|
||||
"language": "english"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"mappings": {
|
||||
"properties": {
|
||||
"doc_id": {"type": "long"},
|
||||
"source": {"type": "keyword"},
|
||||
"title": {
|
||||
"type": "text",
|
||||
"analyzer": "multilingual_analyzer",
|
||||
"fields": {
|
||||
"keyword": {"type": "keyword", "ignore_above": 512},
|
||||
"ru": {"type": "text", "analyzer": "russian_analyzer"},
|
||||
"en": {"type": "text", "analyzer": "english_analyzer"}
|
||||
}
|
||||
},
|
||||
"abstract": {
|
||||
"type": "text",
|
||||
"analyzer": "multilingual_analyzer",
|
||||
"fields": {
|
||||
"ru": {"type": "text", "analyzer": "russian_analyzer"},
|
||||
"en": {"type": "text", "analyzer": "english_analyzer"}
|
||||
}
|
||||
},
|
||||
"authors": {
|
||||
"type": "text",
|
||||
"analyzer": "multilingual_analyzer"
|
||||
},
|
||||
"year": {"type": "integer"},
|
||||
"lang": {"type": "keyword"},
|
||||
"journal": {"type": "keyword", "ignore_above": 512},
|
||||
"doi": {"type": "keyword"},
|
||||
"url": {"type": "keyword", "index": false}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
infra/elasticsearch/setup.sh
Executable file
36
infra/elasticsearch/setup.sh
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
# Создание ES индекса с маппингом для документов
|
||||
# Запускать после старта контейнера Elasticsearch
|
||||
|
||||
set -e
|
||||
|
||||
ES_URL="${ELASTICSEARCH_URL:-http://localhost:9200}"
|
||||
INDEX_NAME="documents"
|
||||
MAPPINGS_FILE="$(dirname "$0")/mappings.json"
|
||||
|
||||
echo "Ожидание готовности Elasticsearch..."
|
||||
until curl -s "$ES_URL/_cluster/health" | grep -qv '"status":"red"'; do
|
||||
sleep 2
|
||||
done
|
||||
echo "Elasticsearch готов."
|
||||
|
||||
# Проверить существование индекса
|
||||
if curl -s -o /dev/null -w "%{http_code}" "$ES_URL/$INDEX_NAME" | grep -q "200"; then
|
||||
echo "Индекс '$INDEX_NAME' уже существует."
|
||||
read -p "Пересоздать? (y/N): " confirm
|
||||
if [[ $confirm != "y" ]]; then
|
||||
echo "Пропускаем."
|
||||
exit 0
|
||||
fi
|
||||
echo "Удаление старого индекса..."
|
||||
curl -s -X DELETE "$ES_URL/$INDEX_NAME"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo "Создание индекса '$INDEX_NAME'..."
|
||||
curl -s -X PUT "$ES_URL/$INDEX_NAME" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d @"$MAPPINGS_FILE" | python3 -m json.tool
|
||||
|
||||
echo ""
|
||||
echo "Индекс '$INDEX_NAME' создан."
|
||||
113
infra/nginx/nginx.conf
Normal file
113
infra/nginx/nginx.conf
Normal file
@@ -0,0 +1,113 @@
|
||||
# Nginx конфиг для academic.jze9.ru
|
||||
# Продакшн: SSL + proxy to FastAPI + React static
|
||||
|
||||
user nginx;
|
||||
worker_processes auto;
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
# Логи
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent"';
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
keepalive_timeout 65;
|
||||
|
||||
# Gzip
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
|
||||
gzip_min_length 1024;
|
||||
gzip_vary on;
|
||||
|
||||
# Лимиты
|
||||
client_max_body_size 100M;
|
||||
proxy_read_timeout 300s;
|
||||
proxy_connect_timeout 30s;
|
||||
proxy_send_timeout 300s;
|
||||
|
||||
# Upstream
|
||||
upstream api {
|
||||
server api:8000;
|
||||
keepalive 32;
|
||||
}
|
||||
|
||||
# HTTP → HTTPS редирект
|
||||
server {
|
||||
listen 80;
|
||||
server_name academic.jze9.ru;
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
# HTTPS основной сервер
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name academic.jze9.ru;
|
||||
|
||||
# SSL (Let's Encrypt)
|
||||
ssl_certificate /etc/letsencrypt/live/academic.jze9.ru/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/academic.jze9.ru/privkey.pem;
|
||||
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
|
||||
ssl_prefer_server_ciphers off;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 1d;
|
||||
|
||||
# HSTS
|
||||
add_header Strict-Transport-Security "max-age=63072000" always;
|
||||
|
||||
# Security headers
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header X-Frame-Options DENY;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
|
||||
# ── API proxy ──────────────────────────────────────────────────────────
|
||||
location /api/ {
|
||||
proxy_pass http://api/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Connection "";
|
||||
}
|
||||
|
||||
# ── WebSocket ──────────────────────────────────────────────────────────
|
||||
location /ws/ {
|
||||
proxy_pass http://api/ws/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
# ── React SPA (статика) ────────────────────────────────────────────────
|
||||
root /var/www/academic;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
expires 1d;
|
||||
add_header Cache-Control "public, no-transform";
|
||||
}
|
||||
|
||||
# Кэшировать статические ресурсы
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2|woff)$ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
}
|
||||
14
infra/postgres/init.sql
Normal file
14
infra/postgres/init.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Инициализация PostgreSQL для Академического помощника
|
||||
-- Выполняется при первом старте контейнера
|
||||
|
||||
-- Расширения
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
CREATE EXTENSION IF NOT EXISTS "pg_trgm"; -- Для нечёткого поиска по тексту
|
||||
|
||||
-- Настройки подключения (уже создан через POSTGRES_USER/POSTGRES_DB env)
|
||||
-- Дополнительные гранты
|
||||
GRANT ALL PRIVILEGES ON DATABASE antiplagiator TO antiplagiator;
|
||||
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO antiplagiator;
|
||||
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO antiplagiator;
|
||||
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO antiplagiator;
|
||||
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO antiplagiator;
|
||||
Reference in New Issue
Block a user