From 39bcd1c16e83140cfa974b7af174d74b950f004f Mon Sep 17 00:00:00 2001 From: bokho Date: Sun, 14 Dec 2025 16:53:08 +0300 Subject: [PATCH] backend initialized --- backend/requirements.txt | 13 +++++++ backend/src/__init__.py | 4 +++ backend/src/application/__init__.py | 4 +++ backend/src/domain/__init__.py | 4 +++ backend/src/infrastructure/__init__.py | 4 +++ backend/src/presentation/__init__.py | 4 +++ backend/src/shared/__init__.py | 4 +++ backend/src/shared/config.py | 48 ++++++++++++++++++++++++++ backend/src/shared/exceptions.py | 35 +++++++++++++++++++ 9 files changed, 120 insertions(+) create mode 100644 backend/requirements.txt create mode 100644 backend/src/__init__.py create mode 100644 backend/src/application/__init__.py create mode 100644 backend/src/domain/__init__.py create mode 100644 backend/src/infrastructure/__init__.py create mode 100644 backend/src/presentation/__init__.py create mode 100644 backend/src/shared/__init__.py create mode 100644 backend/src/shared/config.py create mode 100644 backend/src/shared/exceptions.py diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..40dec95 --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,13 @@ +fastapi==0.104.1 +uvicorn[standard]==0.24.0 +sqlalchemy[asyncio]==2.0.23 +asyncpg==0.29.0 +alembic==1.12.1 +pydantic==2.5.0 +pydantic-settings==2.1.0 +python-multipart==0.0.6 +httpx==0.25.2 +PyMuPDF==1.23.8 +Pillow==10.2.0 +dishka==0.7.0 + diff --git a/backend/src/__init__.py b/backend/src/__init__.py new file mode 100644 index 0000000..d18a9ef --- /dev/null +++ b/backend/src/__init__.py @@ -0,0 +1,4 @@ +""" +ИИ-юрист система +""" + diff --git a/backend/src/application/__init__.py b/backend/src/application/__init__.py new file mode 100644 index 0000000..836f8d1 --- /dev/null +++ b/backend/src/application/__init__.py @@ -0,0 +1,4 @@ +""" +Application layer +""" + diff --git a/backend/src/domain/__init__.py b/backend/src/domain/__init__.py new file mode 100644 index 0000000..7e8decd --- /dev/null +++ b/backend/src/domain/__init__.py @@ -0,0 +1,4 @@ +""" +Domain layer +""" + diff --git a/backend/src/infrastructure/__init__.py b/backend/src/infrastructure/__init__.py new file mode 100644 index 0000000..a0b510e --- /dev/null +++ b/backend/src/infrastructure/__init__.py @@ -0,0 +1,4 @@ +""" +Infrastructure layer +""" + diff --git a/backend/src/presentation/__init__.py b/backend/src/presentation/__init__.py new file mode 100644 index 0000000..a6a752d --- /dev/null +++ b/backend/src/presentation/__init__.py @@ -0,0 +1,4 @@ +""" +Presentation layer +""" + diff --git a/backend/src/shared/__init__.py b/backend/src/shared/__init__.py new file mode 100644 index 0000000..a4fb19c --- /dev/null +++ b/backend/src/shared/__init__.py @@ -0,0 +1,4 @@ +""" +Shared utilities +""" + diff --git a/backend/src/shared/config.py b/backend/src/shared/config.py new file mode 100644 index 0000000..0486964 --- /dev/null +++ b/backend/src/shared/config.py @@ -0,0 +1,48 @@ +""" +Конфигурация приложения + +""" +from pydantic_settings import BaseSettings +from typing import Optional + + +class Settings(BaseSettings): + """Настройки (загружаются из .env автоматически)""" + + POSTGRES_HOST: str = "localhost" + POSTGRES_PORT: int = 5432 + POSTGRES_USER: str = "postgres" + POSTGRES_PASSWORD: str = "postgres" + POSTGRES_DB: str = "lawyer_ai" + + QDRANT_HOST: str = "localhost" + QDRANT_PORT: int = 6333 + + REDIS_HOST: str = "localhost" + REDIS_PORT: int = 6379 + + TELEGRAM_BOT_TOKEN: Optional[str] = None + YANDEX_OCR_API_KEY: Optional[str] = None + DEEPSEEK_API_KEY: Optional[str] = None + + YANDEX_OCR_API_URL: str = "https://vision.api.cloud.yandex.net/vision/v1/batchAnalyze" + DEEPSEEK_API_URL: str = "https://api.deepseek.com/v1/chat/completions" + + APP_NAME: str = "ИИ-юрист" + DEBUG: bool = False + SECRET_KEY: str = "your-secret-key-change-in-production" + CORS_ORIGINS: list[str] = ["*"] + + @property + def database_url(self) -> str: + """Вычисляемый URL подключения""" + return f"postgresql://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}@{self.POSTGRES_HOST}:{self.POSTGRES_PORT}/{self.POSTGRES_DB}" + + class Config: + env_file = ".env" + case_sensitive = True + + +settings = Settings() + + diff --git a/backend/src/shared/exceptions.py b/backend/src/shared/exceptions.py new file mode 100644 index 0000000..10162c0 --- /dev/null +++ b/backend/src/shared/exceptions.py @@ -0,0 +1,35 @@ +""" +Кастомные исключения приложения +""" + + +class LawyerAIException(Exception): + """Базовое исключение приложения""" + pass + + +class NotFoundError(LawyerAIException): + """Ресурс не найден""" + pass + + +class UnauthorizedError(LawyerAIException): + """Пользователь не авторизован""" + pass + + +class ForbiddenError(LawyerAIException): + """Доступ запрещен""" + pass + + +class ValidationError(LawyerAIException): + """Ошибка валидации данных""" + pass + + +class DatabaseError(LawyerAIException): + """Ошибка базы данных""" + pass + +