Add modular app structure for L1 server refactoring
Phase 2 of the full modernization: - App factory pattern with create_app() - Settings via dataclass with env vars - Dependency injection container - Router stubs for auth, storage, api, recipes, cache, runs - Service layer stubs for run, recipe, cache - Repository layer placeholder Routes are stubs that import from legacy server.py during migration. Next: Migrate each router fully with templates. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
72
app/config.py
Normal file
72
app/config.py
Normal file
@@ -0,0 +1,72 @@
|
||||
"""
|
||||
L1 Server Configuration.
|
||||
|
||||
Environment-based configuration with sensible defaults.
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class Settings:
|
||||
"""Application settings loaded from environment."""
|
||||
|
||||
# Server
|
||||
host: str = field(default_factory=lambda: os.environ.get("HOST", "0.0.0.0"))
|
||||
port: int = field(default_factory=lambda: int(os.environ.get("PORT", "8000")))
|
||||
debug: bool = field(default_factory=lambda: os.environ.get("DEBUG", "").lower() == "true")
|
||||
|
||||
# Cache
|
||||
cache_dir: Path = field(
|
||||
default_factory=lambda: Path(os.environ.get("CACHE_DIR", "/data/cache"))
|
||||
)
|
||||
|
||||
# Redis
|
||||
redis_url: str = field(
|
||||
default_factory=lambda: os.environ.get("REDIS_URL", "redis://localhost:6379/5")
|
||||
)
|
||||
|
||||
# Database
|
||||
database_url: str = field(
|
||||
default_factory=lambda: os.environ.get(
|
||||
"DATABASE_URL", "postgresql://artdag:artdag@localhost:5432/artdag"
|
||||
)
|
||||
)
|
||||
|
||||
# IPFS
|
||||
ipfs_api: str = field(
|
||||
default_factory=lambda: os.environ.get("IPFS_API", "/dns/localhost/tcp/5001")
|
||||
)
|
||||
ipfs_gateway_url: str = field(
|
||||
default_factory=lambda: os.environ.get("IPFS_GATEWAY_URL", "https://ipfs.io/ipfs")
|
||||
)
|
||||
|
||||
# L2 Server
|
||||
l2_server: Optional[str] = field(
|
||||
default_factory=lambda: os.environ.get("L2_SERVER")
|
||||
)
|
||||
l2_domain: Optional[str] = field(
|
||||
default_factory=lambda: os.environ.get("L2_DOMAIN")
|
||||
)
|
||||
|
||||
# Derived paths
|
||||
@property
|
||||
def plan_cache_dir(self) -> Path:
|
||||
return self.cache_dir / "plans"
|
||||
|
||||
@property
|
||||
def analysis_cache_dir(self) -> Path:
|
||||
return self.cache_dir / "analysis"
|
||||
|
||||
def ensure_dirs(self) -> None:
|
||||
"""Create required directories."""
|
||||
self.cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
self.plan_cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
self.analysis_cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
# Singleton settings instance
|
||||
settings = Settings()
|
||||
Reference in New Issue
Block a user