feat: Implement core application structure, AI extraction, persistence, and Telegram bot modules with updated configuration and dependencies.

This commit is contained in:
Marco Gallegos
2025-12-18 12:15:04 -06:00
parent 7276e480b0
commit 899482580e
45 changed files with 1157 additions and 225 deletions

0
app/audit/__init__.py Normal file
View File

28
app/audit/logs.py Normal file
View File

@@ -0,0 +1,28 @@
"""
Logging configuration and handlers.
"""
import logging
import sys
from app.config import config
def setup_logging():
"""
Sets up a centralized logging configuration for the application.
"""
log_level = config.LOG_LEVEL.upper()
# Remove any existing handlers
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
logging.basicConfig(
level=log_level,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
stream=sys.stdout
)
logging.getLogger("sqlalchemy.engine").setLevel(logging.WARNING)
logging.getLogger("uvicorn.access").setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
logger.info(f"Logging configured with level {log_level}")

38
app/audit/raw_storage.py Normal file
View File

@@ -0,0 +1,38 @@
"""
Handles storage of raw, original input files for audit purposes.
"""
import logging
import os
from uuid import uuid4
logger = logging.getLogger(__name__)
# A simple file-based storage. In production, you'd use S3 or a similar service.
RAW_STORAGE_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "raw_storage")
os.makedirs(RAW_STORAGE_PATH, exist_ok=True)
def save_raw_input(data: bytes, input_type: str) -> str:
"""
Saves the original input data to a file.
Args:
data: The raw bytes of the input.
input_type: The type of input (e.g., 'image', 'audio').
Returns:
The path to the saved file.
"""
try:
file_extension = input_type # e.g., 'jpg', 'mp3'
file_name = f"{uuid4()}.{file_extension}"
file_path = os.path.join(RAW_STORAGE_PATH, file_name)
with open(file_path, "wb") as f:
f.write(data)
logger.info(f"Saved raw input to {file_path}")
return file_path
except Exception as e:
logger.error(f"Failed to save raw input: {e}")
return ""