chore: initial project setup with backend, frontend, CI/CD, and documentation
Add complete NexaFabric project structure including: - FastAPI backend with SQLAlchemy models, JWT auth, RBAC, audit logging, and provider interfaces - React + TypeScript frontend with Vite, Tailwind CSS, TanStack Query, and Zustand - Docker Compose configuration for PostgreSQL, Redis, API, worker, frontend, and nginx - GitHub Actions and GitLab CI workflows for testing, linting, building, and security scanning - Environment
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
from functools import lru_cache
|
||||
|
||||
from pydantic import AnyHttpUrl, Field
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
|
||||
|
||||
project_name: str = "NexaFabric"
|
||||
environment: str = "development"
|
||||
api_host: str = "0.0.0.0"
|
||||
api_port: int = 8000
|
||||
database_url: str = "sqlite:///./nexafabric.db"
|
||||
redis_url: str = "redis://localhost:6379/0"
|
||||
jwt_secret: str = Field(default="dev-only-change-me")
|
||||
jwt_access_token_minutes: int = 15
|
||||
jwt_refresh_token_days: int = 14
|
||||
token_encryption_key: str = "dev-only-change-me"
|
||||
demo_admin_password: str = "ChangeMe_UseEnvInstead"
|
||||
cors_origins: list[AnyHttpUrl] | list[str] = ["http://localhost:5173", "http://localhost:8080"]
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_settings() -> Settings:
|
||||
return Settings()
|
||||
@@ -0,0 +1,52 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Any
|
||||
|
||||
from jose import jwt
|
||||
from passlib.context import CryptContext
|
||||
|
||||
from app.core.config import get_settings
|
||||
|
||||
|
||||
pwd_context = CryptContext(schemes=["argon2"], deprecated="auto")
|
||||
|
||||
|
||||
def hash_password(password: str) -> str:
|
||||
return pwd_context.hash(password)
|
||||
|
||||
|
||||
def verify_password(password: str, password_hash: str) -> bool:
|
||||
return pwd_context.verify(password, password_hash)
|
||||
|
||||
|
||||
def create_token(subject: str, token_type: str, expires_delta: timedelta, claims: dict[str, Any] | None = None) -> str:
|
||||
settings = get_settings()
|
||||
now = datetime.now(timezone.utc)
|
||||
payload: dict[str, Any] = {
|
||||
"sub": subject,
|
||||
"typ": token_type,
|
||||
"iat": now,
|
||||
"exp": now + expires_delta,
|
||||
}
|
||||
if claims:
|
||||
payload.update(claims)
|
||||
return jwt.encode(payload, settings.jwt_secret, algorithm="HS256")
|
||||
|
||||
|
||||
def create_access_token(subject: str, permissions: list[str]) -> str:
|
||||
settings = get_settings()
|
||||
return create_token(
|
||||
subject,
|
||||
"access",
|
||||
timedelta(minutes=settings.jwt_access_token_minutes),
|
||||
{"permissions": permissions},
|
||||
)
|
||||
|
||||
|
||||
def create_refresh_token(subject: str) -> str:
|
||||
settings = get_settings()
|
||||
return create_token(subject, "refresh", timedelta(days=settings.jwt_refresh_token_days))
|
||||
|
||||
|
||||
def decode_token(token: str) -> dict[str, Any]:
|
||||
return jwt.decode(token, get_settings().jwt_secret, algorithms=["HS256"])
|
||||
|
||||
Reference in New Issue
Block a user