diff --git a/apps/devops/README.md b/apps/devops/README.md index d4f2587..588044f 100644 --- a/apps/devops/README.md +++ b/apps/devops/README.md @@ -2,12 +2,19 @@ This is a template backend service based on fastapi + mongodb app To start development in local, go to the root directory of the project YOUR_WORKSPACE_PATH/devops/ ```bash -cd scripts/mongodb -docker compose -f scripts/mongodb/docker-compose.yml up -d +docker compose -f app/scripts/mongodb/docker-compose.yml up -d ``` - Then run the app ```bash -uvicorn main:app --reload +uvicorn app.main:app --reload +``` + +In case a new dependency is added, run the following command to update the requirements.txt file +```bash +# optional: if you have not installed pipreqs +pip3 install pipreqs + +# generate requirements.txt +pipreqs . --force ``` diff --git a/apps/devops/bootstrap/__init__.py b/apps/devops/app/__init__.py similarity index 100% rename from apps/devops/bootstrap/__init__.py rename to apps/devops/app/__init__.py diff --git a/apps/devops/common/__init__.py b/apps/devops/app/bootstrap/__init__.py similarity index 100% rename from apps/devops/common/__init__.py rename to apps/devops/app/bootstrap/__init__.py diff --git a/apps/devops/bootstrap/application.py b/apps/devops/app/bootstrap/application.py similarity index 86% rename from apps/devops/bootstrap/application.py rename to apps/devops/app/bootstrap/application.py index 36a1616..24223b6 100644 --- a/apps/devops/bootstrap/application.py +++ b/apps/devops/app/bootstrap/application.py @@ -2,14 +2,14 @@ import logging from fastapi import FastAPI from fastapi.openapi.utils import get_openapi -from providers import common -from providers.logger import register_logger -from providers import router -from providers import database -from providers import metrics -from providers import probes -from providers import exception_handler -from common.config.app_settings import app_settings +from app.providers import common +from app.providers.logger import register_logger +from app.providers import router +from app.providers import database +from app.providers import metrics +from app.providers import probes +from app.providers import exception_handler +from app.common.config.app_settings import app_settings def create_app() -> FastAPI: logging.info("App initializing") diff --git a/apps/devops/common/config/__init__.py b/apps/devops/app/common/__init__.py similarity index 100% rename from apps/devops/common/config/__init__.py rename to apps/devops/app/common/__init__.py diff --git a/apps/devops/common/daos/__init__.py b/apps/devops/app/common/config/__init__.py similarity index 100% rename from apps/devops/common/daos/__init__.py rename to apps/devops/app/common/config/__init__.py diff --git a/apps/devops/common/config/app_settings.py b/apps/devops/app/common/config/app_settings.py similarity index 100% rename from apps/devops/common/config/app_settings.py rename to apps/devops/app/common/config/app_settings.py diff --git a/apps/devops/common/config/log_settings.py b/apps/devops/app/common/config/log_settings.py similarity index 100% rename from apps/devops/common/config/log_settings.py rename to apps/devops/app/common/config/log_settings.py diff --git a/apps/devops/common/config/site_settings.py b/apps/devops/app/common/config/site_settings.py similarity index 100% rename from apps/devops/common/config/site_settings.py rename to apps/devops/app/common/config/site_settings.py diff --git a/apps/devops/common/log/__init__.py b/apps/devops/app/common/daos/__init__.py similarity index 100% rename from apps/devops/common/log/__init__.py rename to apps/devops/app/common/daos/__init__.py diff --git a/apps/devops/app/common/daos/hello_world/__init__.py b/apps/devops/app/common/daos/hello_world/__init__.py new file mode 100644 index 0000000..b953163 --- /dev/null +++ b/apps/devops/app/common/daos/hello_world/__init__.py @@ -0,0 +1,3 @@ +from app.common.daos.hello_world.hello_world_dao import HelloWorldDao + +hello_world_dao = HelloWorldDao() diff --git a/apps/devops/common/daos/hello_world/hello_world_dao.py b/apps/devops/app/common/daos/hello_world/hello_world_dao.py similarity index 93% rename from apps/devops/common/daos/hello_world/hello_world_dao.py rename to apps/devops/app/common/daos/hello_world/hello_world_dao.py index 88d8f8c..3b3a112 100644 --- a/apps/devops/common/daos/hello_world/hello_world_dao.py +++ b/apps/devops/app/common/daos/hello_world/hello_world_dao.py @@ -1,4 +1,4 @@ -from common.models.hello_world.hello_world import HelloWorld +from app.common.models.hello_world.hello_world import HelloWorld class HelloWorldDao: def __init__(self): diff --git a/apps/devops/common/models/hello_world/__init__.py b/apps/devops/app/common/log/__init__.py similarity index 100% rename from apps/devops/common/models/hello_world/__init__.py rename to apps/devops/app/common/log/__init__.py diff --git a/apps/devops/common/log/application_logger.py b/apps/devops/app/common/log/application_logger.py similarity index 87% rename from apps/devops/common/log/application_logger.py rename to apps/devops/app/common/log/application_logger.py index 67ec321..896c044 100644 --- a/apps/devops/common/log/application_logger.py +++ b/apps/devops/app/common/log/application_logger.py @@ -1,5 +1,5 @@ from .base_logger import LoggerBase -from common.config.app_settings import app_settings +from app.common.config.app_settings import app_settings class ApplicationLogger(LoggerBase): def __init__(self, application_activities: dict[str, any] = {}) -> None: diff --git a/apps/devops/common/log/base_logger.py b/apps/devops/app/common/log/base_logger.py similarity index 98% rename from apps/devops/common/log/base_logger.py rename to apps/devops/app/common/log/base_logger.py index 24f7bb0..a370296 100644 --- a/apps/devops/common/log/base_logger.py +++ b/apps/devops/app/common/log/base_logger.py @@ -1,5 +1,5 @@ from loguru import logger as guru_logger -from common.config.log_settings import log_settings +from app.common.config.log_settings import log_settings from typing import Dict, Any, Optional import socket import json @@ -9,7 +9,7 @@ import sys import inspect import logging -from common.log.json_sink import JsonSink +from app.common.log.json_sink import JsonSink class LoggerBase: binded_loggers = {} diff --git a/apps/devops/common/log/json_sink.py b/apps/devops/app/common/log/json_sink.py similarity index 100% rename from apps/devops/common/log/json_sink.py rename to apps/devops/app/common/log/json_sink.py diff --git a/apps/devops/app/common/models/__init__.py b/apps/devops/app/common/models/__init__.py new file mode 100644 index 0000000..2535cbb --- /dev/null +++ b/apps/devops/app/common/models/__init__.py @@ -0,0 +1,4 @@ +from app.common.models.hello_world.hello_world import HelloWorld + +# list of beanie document models +db_models = [HelloWorld] \ No newline at end of file diff --git a/apps/devops/providers/__init__.py b/apps/devops/app/common/models/hello_world/__init__.py similarity index 100% rename from apps/devops/providers/__init__.py rename to apps/devops/app/common/models/hello_world/__init__.py diff --git a/apps/devops/common/models/hello_world/hello_world.py b/apps/devops/app/common/models/hello_world/hello_world.py similarity index 100% rename from apps/devops/common/models/hello_world/hello_world.py rename to apps/devops/app/common/models/hello_world/hello_world.py diff --git a/apps/devops/common/probes/__init__.py b/apps/devops/app/common/probes/__init__.py similarity index 100% rename from apps/devops/common/probes/__init__.py rename to apps/devops/app/common/probes/__init__.py diff --git a/apps/devops/common/probes/adapters.py b/apps/devops/app/common/probes/adapters.py similarity index 100% rename from apps/devops/common/probes/adapters.py rename to apps/devops/app/common/probes/adapters.py diff --git a/apps/devops/app/envs/alpha.yml b/apps/devops/app/envs/alpha.yml new file mode 100644 index 0000000..e69de29 diff --git a/apps/devops/app/envs/prod.yml b/apps/devops/app/envs/prod.yml new file mode 100644 index 0000000..e69de29 diff --git a/apps/devops/main.py b/apps/devops/app/main.py similarity index 76% rename from apps/devops/main.py rename to apps/devops/app/main.py index c8bf0ba..559d7ed 100644 --- a/apps/devops/main.py +++ b/apps/devops/app/main.py @@ -1,6 +1,6 @@ from fastapi.responses import RedirectResponse -from common.config.site_settings import site_settings -from bootstrap.application import create_app +from app.common.config.site_settings import site_settings +from app.bootstrap.application import create_app app = create_app() diff --git a/apps/devops/app/providers/__init__.py b/apps/devops/app/providers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/devops/providers/common.py b/apps/devops/app/providers/common.py similarity index 92% rename from apps/devops/providers/common.py rename to apps/devops/app/providers/common.py index b7b1aa5..64a9a44 100644 --- a/apps/devops/providers/common.py +++ b/apps/devops/app/providers/common.py @@ -1,5 +1,5 @@ from fastapi.middleware.cors import CORSMiddleware -from common.config.site_settings import site_settings +from app.common.config.site_settings import site_settings def register(app): diff --git a/apps/devops/providers/database.py b/apps/devops/app/providers/database.py similarity index 88% rename from apps/devops/providers/database.py rename to apps/devops/app/providers/database.py index fa311bd..8716b8e 100644 --- a/apps/devops/providers/database.py +++ b/apps/devops/app/providers/database.py @@ -1,9 +1,9 @@ import asyncio -from common.config.app_settings import app_settings +from app.common.config.app_settings import app_settings from beanie import init_beanie from motor.motor_asyncio import AsyncIOMotorClient -from common.models import db_models -from common.probes import ProbeResult +from app.common.models import db_models +from app.common.probes import ProbeResult client = AsyncIOMotorClient( app_settings.APP_MONGODB_URI, diff --git a/apps/devops/providers/exception_handler.py b/apps/devops/app/providers/exception_handler.py similarity index 100% rename from apps/devops/providers/exception_handler.py rename to apps/devops/app/providers/exception_handler.py diff --git a/apps/devops/providers/logger.py b/apps/devops/app/providers/logger.py similarity index 70% rename from apps/devops/providers/logger.py rename to apps/devops/app/providers/logger.py index 6eb1e22..2785603 100644 --- a/apps/devops/providers/logger.py +++ b/apps/devops/app/providers/logger.py @@ -1,5 +1,4 @@ -from loguru import logger as guru_logger -from common.log.base_logger import LoggerBase +from app.common.log.base_logger import LoggerBase def register_logger(): diff --git a/apps/devops/providers/metrics.py b/apps/devops/app/providers/metrics.py similarity index 88% rename from apps/devops/providers/metrics.py rename to apps/devops/app/providers/metrics.py index c2270b7..1ae941a 100644 --- a/apps/devops/providers/metrics.py +++ b/apps/devops/app/providers/metrics.py @@ -1,6 +1,6 @@ import logging from prometheus_fastapi_instrumentator import Instrumentator -from common.config.app_settings import app_settings +from app.common.config.app_settings import app_settings def register(app): instrumentator = ( diff --git a/apps/devops/providers/probes.py b/apps/devops/app/providers/probes.py similarity index 87% rename from apps/devops/providers/probes.py rename to apps/devops/app/providers/probes.py index 7c5b5d8..883e3d6 100644 --- a/apps/devops/providers/probes.py +++ b/apps/devops/app/providers/probes.py @@ -1,5 +1,5 @@ -from common.probes import ProbeManager, ProbeType -from common.probes.adapters import FastAPIAdapter +from app.common.probes import ProbeManager, ProbeType +from app.common.probes.adapters import FastAPIAdapter from .database import check_database_initialized def register(app): diff --git a/apps/devops/providers/router.py b/apps/devops/app/providers/router.py similarity index 96% rename from apps/devops/providers/router.py rename to apps/devops/app/providers/router.py index 5b91f75..b273eb8 100644 --- a/apps/devops/providers/router.py +++ b/apps/devops/app/providers/router.py @@ -1,4 +1,4 @@ -from routes import api_router +from app.routes import api_router from starlette import routing diff --git a/apps/devops/providers/scheduler.py b/apps/devops/app/providers/scheduler.py similarity index 100% rename from apps/devops/providers/scheduler.py rename to apps/devops/app/providers/scheduler.py diff --git a/apps/devops/routes/__init__.py b/apps/devops/app/routes/__init__.py similarity index 71% rename from apps/devops/routes/__init__.py rename to apps/devops/app/routes/__init__.py index d698f6b..9644f27 100644 --- a/apps/devops/routes/__init__.py +++ b/apps/devops/app/routes/__init__.py @@ -1,5 +1,5 @@ from fastapi import APIRouter -from routes.hello_world import router as hello_world_router +from app.routes.hello_world import router as hello_world_router api_router = APIRouter() diff --git a/apps/devops/routes/hello_world/__init__.py b/apps/devops/app/routes/hello_world/__init__.py similarity index 100% rename from apps/devops/routes/hello_world/__init__.py rename to apps/devops/app/routes/hello_world/__init__.py diff --git a/apps/devops/routes/hello_world/apis.py b/apps/devops/app/routes/hello_world/apis.py similarity index 88% rename from apps/devops/routes/hello_world/apis.py rename to apps/devops/app/routes/hello_world/apis.py index d2983c9..dfb8cf0 100644 --- a/apps/devops/routes/hello_world/apis.py +++ b/apps/devops/app/routes/hello_world/apis.py @@ -1,7 +1,7 @@ from fastapi import APIRouter from loguru import logger -from common.daos.hello_world import hello_world_dao +from app.common.daos.hello_world import hello_world_dao router = APIRouter() diff --git a/apps/devops/scripts/mongodb/docker-compose.yml b/apps/devops/app/scripts/mongodb/docker-compose.yml similarity index 100% rename from apps/devops/scripts/mongodb/docker-compose.yml rename to apps/devops/app/scripts/mongodb/docker-compose.yml diff --git a/apps/devops/common/daos/hello_world/__init__.py b/apps/devops/common/daos/hello_world/__init__.py deleted file mode 100644 index f8a7a2d..0000000 --- a/apps/devops/common/daos/hello_world/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from common.daos.hello_world.hello_world_dao import HelloWorldDao - -hello_world_dao = HelloWorldDao() diff --git a/apps/devops/common/models/__init__.py b/apps/devops/common/models/__init__.py deleted file mode 100644 index a6dc240..0000000 --- a/apps/devops/common/models/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from common.models.hello_world.hello_world import HelloWorld - -# list of beanie document models -db_models = [HelloWorld] \ No newline at end of file diff --git a/apps/devops/requirements.txt b/apps/devops/requirements.txt index 295004e..056543d 100644 --- a/apps/devops/requirements.txt +++ b/apps/devops/requirements.txt @@ -1,30 +1,10 @@ -annotated-types==0.7.0 -anyio==4.9.0 beanie==1.29.0 -click==8.2.0 -dnspython==2.7.0 -exceptiongroup==1.3.0 fastapi==0.115.12 -h11==0.16.0 -httptools==0.6.4 -idna==3.10 -lazy-model==0.2.0 loguru==0.7.3 motor==3.7.0 -prometheus-fastapi-instrumentator==7.1.0 -prometheus_client==0.21.1 -pydantic==2.11.4 -pydantic-settings==2.9.1 -pydantic_core==2.33.2 -pymongo==4.12.1 -python-dotenv==1.1.0 -PyYAML==6.0.2 -sniffio==1.3.1 +prometheus_fastapi_instrumentator==7.1.0 +pydantic_settings==2.9.1 +pytest==7.1.2 starlette==0.46.2 -toml==0.10.2 -typing-inspection==0.4.0 -typing_extensions==4.13.2 uvicorn==0.34.2 -uvloop==0.21.0 -watchfiles==1.0.5 -websockets==15.0.1 +httpx==0.24.0 \ No newline at end of file diff --git a/apps/devops/tests/__init__.py b/apps/devops/tests/__init__.py new file mode 100644 index 0000000..e69de29