Initial commit: ERV Platform MVP - FastAPI + React
This commit is contained in:
0
backend/app/__init__.py
Normal file
0
backend/app/__init__.py
Normal file
0
backend/app/api/__init__.py
Normal file
0
backend/app/api/__init__.py
Normal file
68
backend/app/config.py
Normal file
68
backend/app/config.py
Normal file
@@ -0,0 +1,68 @@
|
||||
"""
|
||||
Конфигурация приложения
|
||||
"""
|
||||
from pydantic_settings import BaseSettings
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
# App
|
||||
app_name: str = "ERV Insurance Platform"
|
||||
app_env: str = "development"
|
||||
debug: bool = True
|
||||
|
||||
# API
|
||||
api_v1_prefix: str = "/api/v1"
|
||||
backend_url: str = "http://localhost:8100"
|
||||
frontend_url: str = "http://localhost:5173"
|
||||
|
||||
# PostgreSQL
|
||||
postgres_host: str = "147.45.189.234"
|
||||
postgres_port: int = 5432
|
||||
postgres_db: str = "default_db"
|
||||
postgres_user: str = "gen_user"
|
||||
postgres_password: str = "2~~9_^kVsU?2\\S"
|
||||
|
||||
# Redis
|
||||
redis_host: str = "localhost"
|
||||
redis_port: int = 6379
|
||||
redis_password: str = "CRM_Redis_Pass_2025_Secure!"
|
||||
redis_db: int = 0
|
||||
redis_prefix: str = "erv:"
|
||||
|
||||
# RabbitMQ
|
||||
rabbitmq_host: str = "185.197.75.249"
|
||||
rabbitmq_port: int = 5672
|
||||
rabbitmq_user: str = "admin"
|
||||
rabbitmq_password: str = "tyejvtej"
|
||||
rabbitmq_vhost: str = "/"
|
||||
|
||||
# OCR Service
|
||||
ocr_api_url: str = "http://147.45.146.17:8001"
|
||||
|
||||
# OpenRouter AI
|
||||
openrouter_api_key: str = "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"
|
||||
openrouter_model: str = "google/gemini-2.0-flash-001"
|
||||
|
||||
# FlightAware
|
||||
flightaware_api_key: str = "Puz0cdxAHzAEqMRZwtdeqBUSm9naJfwK"
|
||||
|
||||
# CORS
|
||||
cors_origins: list = [
|
||||
"http://localhost:5173",
|
||||
"http://147.45.146.17:5173",
|
||||
"https://erv-claims.clientright.ru"
|
||||
]
|
||||
|
||||
class Config:
|
||||
env_file = "../.env"
|
||||
case_sensitive = False
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def get_settings() -> Settings:
|
||||
return Settings()
|
||||
|
||||
|
||||
settings = get_settings()
|
||||
|
||||
176
backend/app/main.py
Normal file
176
backend/app/main.py
Normal file
@@ -0,0 +1,176 @@
|
||||
"""
|
||||
ERV Insurance Platform - FastAPI Backend
|
||||
"""
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import JSONResponse
|
||||
from app.config import settings
|
||||
import redis
|
||||
import asyncpg
|
||||
|
||||
# Создаём FastAPI приложение
|
||||
app = FastAPI(
|
||||
title="ERV Insurance Platform API",
|
||||
description="API для обработки страховых обращений с OCR, AI и интеграциями",
|
||||
version="1.0.0",
|
||||
docs_url="/docs",
|
||||
redoc_url="/redoc"
|
||||
)
|
||||
|
||||
# CORS middleware
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=settings.cors_origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
# ============================================
|
||||
# HEALTH CHECKS
|
||||
# ============================================
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
"""Главная страница API"""
|
||||
return {
|
||||
"message": "🚀 ERV Insurance Platform API",
|
||||
"version": "1.0.0",
|
||||
"docs": f"{settings.backend_url}/docs",
|
||||
"status": "running"
|
||||
}
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
"""Проверка здоровья сервисов"""
|
||||
health_status = {
|
||||
"api": "ok",
|
||||
"redis": "checking",
|
||||
"postgres": "checking",
|
||||
"ocr": "checking"
|
||||
}
|
||||
|
||||
# Проверка Redis
|
||||
try:
|
||||
r = redis.Redis(
|
||||
host=settings.redis_host,
|
||||
port=settings.redis_port,
|
||||
password=settings.redis_password,
|
||||
decode_responses=True
|
||||
)
|
||||
r.ping()
|
||||
health_status["redis"] = "ok"
|
||||
except Exception as e:
|
||||
health_status["redis"] = f"error: {str(e)}"
|
||||
|
||||
# Проверка PostgreSQL
|
||||
try:
|
||||
conn = await asyncpg.connect(
|
||||
host=settings.postgres_host,
|
||||
port=settings.postgres_port,
|
||||
database=settings.postgres_db,
|
||||
user=settings.postgres_user,
|
||||
password=settings.postgres_password
|
||||
)
|
||||
await conn.execute("SELECT 1")
|
||||
await conn.close()
|
||||
health_status["postgres"] = "ok"
|
||||
except Exception as e:
|
||||
health_status["postgres"] = f"error: {str(e)}"
|
||||
|
||||
# Проверка OCR
|
||||
import httpx
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(f"{settings.ocr_api_url}/", timeout=5.0)
|
||||
health_status["ocr"] = "ok" if response.status_code in [200, 404] else "unreachable"
|
||||
except Exception as e:
|
||||
health_status["ocr"] = f"error: {str(e)}"
|
||||
|
||||
all_ok = all(v == "ok" for v in health_status.values())
|
||||
|
||||
return JSONResponse(
|
||||
status_code=200 if all_ok else 503,
|
||||
content={
|
||||
"status": "healthy" if all_ok else "degraded",
|
||||
"services": health_status
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# ============================================
|
||||
# API V1 ENDPOINTS
|
||||
# ============================================
|
||||
|
||||
@app.get("/api/v1/test")
|
||||
async def test_endpoint():
|
||||
"""Тестовый endpoint"""
|
||||
return {
|
||||
"message": "✅ API работает!",
|
||||
"env": settings.app_env,
|
||||
"debug": settings.debug,
|
||||
"services": {
|
||||
"redis": f"{settings.redis_host}:{settings.redis_port}",
|
||||
"postgres": f"{settings.postgres_host}:{settings.postgres_port}",
|
||||
"rabbitmq": f"{settings.rabbitmq_host}:{settings.rabbitmq_port}",
|
||||
"ocr": settings.ocr_api_url
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@app.get("/api/v1/info")
|
||||
async def get_info():
|
||||
"""Информация о платформе"""
|
||||
return {
|
||||
"platform": "ERV Insurance Claims",
|
||||
"version": "1.0.0",
|
||||
"features": [
|
||||
"OCR документов (паспорт, билеты)",
|
||||
"AI автозаполнение (Gemini Vision)",
|
||||
"Проверка рейсов (FlightAware)",
|
||||
"СБП выплаты",
|
||||
"Интеграция с CRM"
|
||||
],
|
||||
"tech_stack": {
|
||||
"backend": "Python FastAPI",
|
||||
"frontend": "React TypeScript",
|
||||
"database": "PostgreSQL + MySQL",
|
||||
"cache": "Redis",
|
||||
"queue": "RabbitMQ",
|
||||
"storage": "S3 Timeweb",
|
||||
"ocr": "Internal Service",
|
||||
"ai": "OpenRouter Gemini 2.0"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# ============================================
|
||||
# STARTUP/SHUTDOWN
|
||||
# ============================================
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
"""При старте приложения"""
|
||||
print("🚀 ERV Insurance Platform запускается...")
|
||||
print(f"📍 Backend URL: {settings.backend_url}")
|
||||
print(f"📍 API Docs: {settings.backend_url}/docs")
|
||||
print(f"🔗 Frontend URL: {settings.frontend_url}")
|
||||
|
||||
|
||||
@app.on_event("shutdown")
|
||||
async def shutdown_event():
|
||||
"""При остановке приложения"""
|
||||
print("👋 ERV Insurance Platform остановлен")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(
|
||||
"main:app",
|
||||
host="0.0.0.0",
|
||||
port=8100,
|
||||
reload=True
|
||||
)
|
||||
|
||||
46
backend/requirements.txt
Normal file
46
backend/requirements.txt
Normal file
@@ -0,0 +1,46 @@
|
||||
# Core FastAPI
|
||||
fastapi==0.115.0
|
||||
uvicorn[standard]==0.32.0
|
||||
python-multipart==0.0.12
|
||||
websockets==14.1
|
||||
|
||||
# Database
|
||||
sqlalchemy[asyncio]==2.0.35
|
||||
asyncpg==0.30.0
|
||||
aiomysql==0.2.0
|
||||
alembic==1.14.0
|
||||
|
||||
# Redis & RabbitMQ
|
||||
redis==5.2.0
|
||||
hiredis==3.0.0
|
||||
aio-pika==9.4.3
|
||||
|
||||
# HTTP & File operations
|
||||
httpx==0.27.2
|
||||
aiofiles==24.1.0
|
||||
|
||||
# S3
|
||||
boto3==1.35.56
|
||||
aioboto3==13.2.0
|
||||
|
||||
# Validation
|
||||
pydantic==2.10.0
|
||||
pydantic-settings==2.6.0
|
||||
email-validator==2.2.0
|
||||
|
||||
# Security
|
||||
python-jose[cryptography]==3.3.0
|
||||
passlib[bcrypt]==1.7.4
|
||||
|
||||
# Utils
|
||||
python-dotenv==1.0.1
|
||||
python-slugify==8.0.4
|
||||
pytz==2024.2
|
||||
|
||||
# Logging
|
||||
structlog==24.4.0
|
||||
|
||||
# Testing
|
||||
pytest==8.3.3
|
||||
pytest-asyncio==0.24.0
|
||||
pytest-cov==6.0.0
|
||||
Reference in New Issue
Block a user