From 2139ac1317a153167c338e0f64246759d5e37227 Mon Sep 17 00:00:00 2001 From: ReLoia Date: Sun, 12 Apr 2026 22:20:10 +0200 Subject: [PATCH] refactor: reorganize the whole project layout Co-authored-by: gabdevele --- app/api/proxy/router.py | 5 +++-- app/{db => integrations}/__init__.py | 0 app/{utils => integrations}/docker/__init__.py | 6 +++--- app/{utils => integrations}/docker/compose.py | 4 ++-- app/{utils => integrations}/docker/editor.py | 4 ++-- app/{utils => integrations}/docker/models.py | 0 app/{utils => integrations}/docker/ports.py | 0 app/{utils/proxy => repositories}/__init__.py | 0 app/{db => repositories}/auth.py | 3 ++- app/{db => repositories}/proxy.py | 7 ++++--- app/services/__init__.py | 0 app/services/proxy/__init__.py | 0 app/{utils => services}/proxy/manager.py | 2 +- app/{utils => services}/proxy/types.py | 0 app/{utils => services}/proxy/validator.py | 0 tests/api/test_proxy.py | 2 +- 16 files changed, 18 insertions(+), 15 deletions(-) rename app/{db => integrations}/__init__.py (100%) rename app/{utils => integrations}/docker/__init__.py (59%) rename app/{utils => integrations}/docker/compose.py (94%) rename app/{utils => integrations}/docker/editor.py (90%) rename app/{utils => integrations}/docker/models.py (100%) rename app/{utils => integrations}/docker/ports.py (100%) rename app/{utils/proxy => repositories}/__init__.py (100%) rename app/{db => repositories}/auth.py (99%) rename app/{db => repositories}/proxy.py (98%) create mode 100644 app/services/__init__.py create mode 100644 app/services/proxy/__init__.py rename app/{utils => services}/proxy/manager.py (72%) rename app/{utils => services}/proxy/types.py (100%) rename app/{utils => services}/proxy/validator.py (100%) diff --git a/app/api/proxy/router.py b/app/api/proxy/router.py index 0f662be..c6b8988 100644 --- a/app/api/proxy/router.py +++ b/app/api/proxy/router.py @@ -1,4 +1,3 @@ -from core.security import require_authenticated_user from db.proxy import ( create_proxy, delete_proxy, @@ -9,8 +8,10 @@ from db.proxy import ( list_proxies as list_proxy_documents, ) from fastapi import APIRouter, Depends, HTTPException, status + +from core.security import require_authenticated_user from models.proxy import ProxyCreateInput, ProxyUpdateInput -from utils.proxy.validator import ProxyCodeValidationError, validate_proxy_code +from services.proxy.validator import ProxyCodeValidationError, validate_proxy_code router = APIRouter( prefix="/proxy", diff --git a/app/db/__init__.py b/app/integrations/__init__.py similarity index 100% rename from app/db/__init__.py rename to app/integrations/__init__.py diff --git a/app/utils/docker/__init__.py b/app/integrations/docker/__init__.py similarity index 59% rename from app/utils/docker/__init__.py rename to app/integrations/docker/__init__.py index 524a2c9..2483ddd 100644 --- a/app/utils/docker/__init__.py +++ b/app/integrations/docker/__init__.py @@ -1,11 +1,11 @@ -from utils.docker.compose import ( +from integrations.docker.compose import ( find_docker_compose, get_all_services, get_services, get_visible_folders, ) -from utils.docker.editor import change_port -from utils.docker.models import DockerService +from integrations.docker.editor import change_port +from integrations.docker.models import DockerService __all__ = [ "DockerService", diff --git a/app/utils/docker/compose.py b/app/integrations/docker/compose.py similarity index 94% rename from app/utils/docker/compose.py rename to app/integrations/docker/compose.py index e6157e5..c77aa5c 100644 --- a/app/utils/docker/compose.py +++ b/app/integrations/docker/compose.py @@ -2,8 +2,8 @@ from pathlib import Path import yaml -from utils.docker.models import DockerService -from utils.docker.ports import _get_service_port +from integrations.docker.models import DockerService +from integrations.docker.ports import _get_service_port COMPOSE_NAMES = ( "compose.yml", diff --git a/app/utils/docker/editor.py b/app/integrations/docker/editor.py similarity index 90% rename from app/utils/docker/editor.py rename to app/integrations/docker/editor.py index 59ef637..dbd952a 100644 --- a/app/utils/docker/editor.py +++ b/app/integrations/docker/editor.py @@ -2,8 +2,8 @@ from pathlib import Path import yaml -from utils.docker.compose import find_docker_compose -from utils.docker.ports import _get_port_index, _replace_port_in_mapping +from integrations.docker.compose import find_docker_compose +from integrations.docker.ports import _get_port_index, _replace_port_in_mapping def _backup_path_for(compose_path: Path) -> Path: diff --git a/app/utils/docker/models.py b/app/integrations/docker/models.py similarity index 100% rename from app/utils/docker/models.py rename to app/integrations/docker/models.py diff --git a/app/utils/docker/ports.py b/app/integrations/docker/ports.py similarity index 100% rename from app/utils/docker/ports.py rename to app/integrations/docker/ports.py diff --git a/app/utils/proxy/__init__.py b/app/repositories/__init__.py similarity index 100% rename from app/utils/proxy/__init__.py rename to app/repositories/__init__.py diff --git a/app/db/auth.py b/app/repositories/auth.py similarity index 99% rename from app/db/auth.py rename to app/repositories/auth.py index 1269e42..c6dc35f 100644 --- a/app/db/auth.py +++ b/app/repositories/auth.py @@ -2,9 +2,10 @@ from collections.abc import Mapping from datetime import UTC, datetime from typing import Any +from motor.motor_asyncio import AsyncIOMotorCollection + from core.mongodb import get_database from models.auth import AuthUserDocument -from motor.motor_asyncio import AsyncIOMotorCollection USERS_COLLECTION_NAME = "auth_users" REVOKED_COLLECTION_NAME = "revoked_tokens" diff --git a/app/db/proxy.py b/app/repositories/proxy.py similarity index 98% rename from app/db/proxy.py rename to app/repositories/proxy.py index ad9e9be..bb3b317 100644 --- a/app/db/proxy.py +++ b/app/repositories/proxy.py @@ -2,12 +2,13 @@ from collections.abc import Mapping from datetime import UTC, datetime from typing import Any +from motor.motor_asyncio import AsyncIOMotorCollection +from pymongo import ReturnDocument + from core.mongodb import get_database from models.proxy import ProxyDocument, ProxyUpdateInput from models.service import ServiceEndpointDocument -from motor.motor_asyncio import AsyncIOMotorCollection -from pymongo import ReturnDocument -from utils.proxy.types import ServiceConfig +from services.proxy.types import ServiceConfig COLLECTION_NAME = "proxies" diff --git a/app/services/__init__.py b/app/services/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/services/proxy/__init__.py b/app/services/proxy/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/utils/proxy/manager.py b/app/services/proxy/manager.py similarity index 72% rename from app/utils/proxy/manager.py rename to app/services/proxy/manager.py index 58ad605..9bf0c5d 100644 --- a/app/utils/proxy/manager.py +++ b/app/services/proxy/manager.py @@ -1,4 +1,4 @@ -from utils.proxy.types import ServiceConfig +from services.proxy.types import ServiceConfig async def create_proxy( diff --git a/app/utils/proxy/types.py b/app/services/proxy/types.py similarity index 100% rename from app/utils/proxy/types.py rename to app/services/proxy/types.py diff --git a/app/utils/proxy/validator.py b/app/services/proxy/validator.py similarity index 100% rename from app/utils/proxy/validator.py rename to app/services/proxy/validator.py diff --git a/tests/api/test_proxy.py b/tests/api/test_proxy.py index 27962f6..a7683c7 100644 --- a/tests/api/test_proxy.py +++ b/tests/api/test_proxy.py @@ -3,7 +3,7 @@ import importlib from core.security import get_auth_context, require_authenticated_user from models.proxy import ProxyDocument from models.service import ServiceEndpointDocument -from utils.proxy.validator import ProxyCodeValidationError +from services.proxy.validator import ProxyCodeValidationError proxy_router_module = importlib.import_module("api.proxy.router")