feat: 웹사이트 표준화 검사 도구 구현

- 4개 검사 엔진: HTML/CSS, 접근성(WCAG), SEO, 성능/보안 (총 50개 항목)
- FastAPI 백엔드 (9개 API, SSE 실시간 진행, PDF/JSON 리포트)
- Next.js 15 프론트엔드 (6개 페이지, 29개 컴포넌트, 반원 게이지 차트)
- Docker Compose 배포 (Backend:8011, Frontend:3011, MongoDB:27022, Redis:6392)
- 전체 테스트 32/32 PASS

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jungwoo choi
2026-02-13 13:57:27 +09:00
parent c37cda5b13
commit b5fa5d96b9
93 changed files with 18735 additions and 22 deletions

View File

View File

@ -0,0 +1,34 @@
"""
Application configuration from environment variables.
"""
from pydantic_settings import BaseSettings
from functools import lru_cache
class Settings(BaseSettings):
"""Application settings loaded from environment variables."""
# MongoDB
MONGODB_URL: str = "mongodb://admin:password123@localhost:27022/"
DB_NAME: str = "web_inspector"
# Redis
REDIS_URL: str = "redis://localhost:6392"
# Inspection
URL_FETCH_TIMEOUT: int = 10
CATEGORY_TIMEOUT: int = 60
MAX_HTML_SIZE: int = 10485760 # 10MB
# Application
PROJECT_NAME: str = "Web Inspector API"
class Config:
env_file = ".env"
case_sensitive = True
@lru_cache()
def get_settings() -> Settings:
return Settings()

View File

@ -0,0 +1,49 @@
"""
MongoDB connection management using Motor async driver.
"""
import logging
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase
from app.core.config import get_settings
logger = logging.getLogger(__name__)
_client: AsyncIOMotorClient | None = None
_db: AsyncIOMotorDatabase | None = None
async def connect_db() -> None:
"""Establish MongoDB connection and create indexes."""
global _client, _db
settings = get_settings()
_client = AsyncIOMotorClient(settings.MONGODB_URL)
_db = _client[settings.DB_NAME]
# Create indexes
await _db.inspections.create_index("inspection_id", unique=True)
await _db.inspections.create_index([("url", 1), ("created_at", -1)])
await _db.inspections.create_index([("created_at", -1)])
# Verify connection
await _client.admin.command("ping")
logger.info("MongoDB connected successfully: %s", settings.DB_NAME)
async def close_db() -> None:
"""Close MongoDB connection."""
global _client, _db
if _client is not None:
_client.close()
_client = None
_db = None
logger.info("MongoDB connection closed")
def get_db() -> AsyncIOMotorDatabase:
"""
Get database instance.
Uses 'if db is None' pattern for pymongo>=4.9 compatibility.
"""
if _db is None:
raise RuntimeError("Database is not connected. Call connect_db() first.")
return _db

110
backend/app/core/redis.py Normal file
View File

@ -0,0 +1,110 @@
"""
Redis connection management using redis-py async client.
"""
import json
import logging
from redis.asyncio import Redis
from app.core.config import get_settings
logger = logging.getLogger(__name__)
_redis: Redis | None = None
async def connect_redis() -> None:
"""Establish Redis connection."""
global _redis
settings = get_settings()
_redis = Redis.from_url(
settings.REDIS_URL,
decode_responses=True,
)
# Verify connection
await _redis.ping()
logger.info("Redis connected successfully: %s", settings.REDIS_URL)
async def close_redis() -> None:
"""Close Redis connection."""
global _redis
if _redis is not None:
await _redis.close()
_redis = None
logger.info("Redis connection closed")
def get_redis() -> Redis:
"""Get Redis instance."""
if _redis is None:
raise RuntimeError("Redis is not connected. Call connect_redis() first.")
return _redis
# --- Helper functions ---
PROGRESS_TTL = 300 # 5 minutes
RESULT_CACHE_TTL = 3600 # 1 hour
RECENT_LIST_TTL = 300 # 5 minutes
async def set_inspection_status(inspection_id: str, status: str) -> None:
"""Set inspection status in Redis with TTL."""
r = get_redis()
key = f"inspection:{inspection_id}:status"
await r.set(key, status, ex=PROGRESS_TTL)
async def get_inspection_status(inspection_id: str) -> str | None:
"""Get inspection status from Redis."""
r = get_redis()
key = f"inspection:{inspection_id}:status"
return await r.get(key)
async def update_category_progress(
inspection_id: str, category: str, progress: int, current_step: str
) -> None:
"""Update category progress in Redis hash."""
r = get_redis()
key = f"inspection:{inspection_id}:progress"
await r.hset(key, mapping={
f"{category}_progress": str(progress),
f"{category}_step": current_step,
f"{category}_status": "completed" if progress >= 100 else "running",
})
await r.expire(key, PROGRESS_TTL)
async def get_current_progress(inspection_id: str) -> dict | None:
"""Get current progress data from Redis."""
r = get_redis()
key = f"inspection:{inspection_id}:progress"
data = await r.hgetall(key)
if not data:
return None
return data
async def publish_event(inspection_id: str, event_data: dict) -> None:
"""Publish an SSE event via Redis Pub/Sub."""
r = get_redis()
channel = f"inspection:{inspection_id}:events"
await r.publish(channel, json.dumps(event_data, ensure_ascii=False))
async def cache_result(inspection_id: str, result: dict) -> None:
"""Cache inspection result in Redis."""
r = get_redis()
key = f"inspection:result:{inspection_id}"
await r.set(key, json.dumps(result, ensure_ascii=False, default=str), ex=RESULT_CACHE_TTL)
async def get_cached_result(inspection_id: str) -> dict | None:
"""Get cached inspection result from Redis."""
r = get_redis()
key = f"inspection:result:{inspection_id}"
data = await r.get(key)
if data:
return json.loads(data)
return None