백엔드 프레임 설계

This commit is contained in:
HyeongBaeYang committed 2026-06-15 15:53:39 +09:00
1 parent d264104077
commit f7833ba466
62 files changed
+1397

No files matched your search

Binary file not shown.
+33
View File
@@ -0,0 +1,33 @@
[WebServerConfig]
server_name = "NegosiumServer"
port = 9300
process_count = 4
is_ssl = false
is_test = true
[LogConfig]
print_console = true
log_level = "debug"
# docker-compose 네트워크에서는 DB 가 compose 밖에 있으므로 호스트의 DB 에 host.docker.internal 로 접근한다.
[MainDBConfig]
db_type = "postgresql"
name = "negosium_db"
write_host = "host.docker.internal"
write_port = 5432
write_id = "postgres"
write_pw = "password"
read_host = "host.docker.internal"
read_port = 5432
read_id = "postgres"
read_pw = "password"
show_log = false
# 워커 4개 기준: (pool_size + max_overflow) x 2(R/W) x 4 = 320 < max_connections(500)
pool_size = 20
max_overflow = 20
[JwtToken]
access_key = "docker_access_secret_key"
refresh_key = "docker_refresh_secret_key"
access_expire_min = 30
refresh_expire_day = 7
+32
View File
@@ -0,0 +1,32 @@
[WebServerConfig]
server_name = "NegosiumServer"
port = 9300
process_count = 1
is_ssl = false
is_test = true
[LogConfig]
print_console = true
log_level = "debug"
# DB Read/Write 분리. 단일 DB 환경에서는 read/write 동일 호스트로 설정.
[MainDBConfig]
db_type = "postgresql"
name = "negosium_db"
write_host = "127.0.0.1"
write_port = 5432
write_id = "postgres"
write_pw = "password"
read_host = "127.0.0.1"
read_port = 5432
read_id = "postgres"
read_pw = "password"
show_log = false
pool_size = 100
max_overflow = 200
[JwtToken]
access_key = "CHANGE_ME_ACCESS_SECRET_KEY"
refresh_key = "CHANGE_ME_REFRESH_SECRET_KEY"
access_expire_min = 30
refresh_expire_day = 7
+33
View File
@@ -0,0 +1,33 @@
[WebServerConfig]
server_name = "NegosiumServer-Test"
port = 9301
process_count = 1
is_ssl = false
is_test = true
[LogConfig]
print_console = true
log_level = "debug"
# 테스트는 단일 postgres 의 negosium_db 를 사용한다.
# pytest 가 tbl_account 를 TRUNCATE 로 비워 격리하므로, 운영 데이터가 있다면 주의.
[MainDBConfig]
db_type = "postgresql"
name = "negosium_db"
write_host = "127.0.0.1"
write_port = 5432
write_id = "postgres"
write_pw = "password"
read_host = "127.0.0.1"
read_port = 5432
read_id = "postgres"
read_pw = "password"
show_log = false
pool_size = 100
max_overflow = 200
[JwtToken]
access_key = "test_access_secret_key"
refresh_key = "test_refresh_secret_key"
access_expire_min = 30
refresh_expire_day = 7
+37
View File
@@ -0,0 +1,37 @@
import tomllib
from typing import Optional, Type, Dict, TypeVar
from pydantic import BaseModel
class ConfigModel(BaseModel):
pass
# APP_ENV
# local : 로컬 환경(개인 pc)
# dev : 개발환경 (사내 pc)
# prod : 서비스 환경 (클라우드 서버)
#
# 실행시 환경변수 설정
# linux : export APP_ENV=dev
# window : set APP_ENV=dev
class Configs:
ConfigType = TypeVar("ConfigType", bound=ConfigModel)
def __init__(self, file_path: str):
self._settings: Dict[Type["Configs.ConfigType"], "Configs.ConfigType"] = self._load_settings_from_toml(file_path)
def _load_settings_from_toml(self, file_path: str) -> Dict[Type[ConfigType], ConfigType]:
with open(file_path, "rb") as f:
toml_content = tomllib.load(f)
config_subclasses = ConfigModel.__subclasses__()
configs = {
config_class: config_class.model_validate(toml_content[config_class.__name__])
for config_class in config_subclasses
if config_class.__name__ in toml_content
}
return configs
def get(self, config_class: Type[ConfigType]) -> Optional[ConfigType]:
return self._settings.get(config_class)
+41
View File
@@ -0,0 +1,41 @@
from config.config_loader import ConfigModel
class WebServerConfig(ConfigModel):
server_name: str = ""
port: int = 0
process_count: int = 1
is_ssl: bool = False
is_test: bool = False
class LogConfig(ConfigModel):
print_console: bool = True
log_level: str = "debug"
# DB Read/Write 분리 설정.
# 하나의 논리 DB 에 대해 write(주) / read(복제) 접속 정보를 각각 가진다.
class MainDBConfig(ConfigModel):
db_type: str = "postgresql"
name: str = ""
write_host: str = ""
write_port: int = 5432
write_id: str = ""
write_pw: str = ""
read_host: str = ""
read_port: int = 5432
read_id: str = ""
read_pw: str = ""
show_log: bool = False
# 커넥션 풀 사이징. 실제 동시 커넥션 상한 = (pool_size + max_overflow) x 엔진수(R/W=2) x 워커수.
# PostgreSQL max_connections 를 넘지 않도록 설정해야 한다. (예: 10+20=30 x 2 x 5워커 = 300)
pool_size: int = 10
max_overflow: int = 20
class JwtToken(ConfigModel):
access_key: str = ""
refresh_key: str = ""
access_expire_min: int = 30
refresh_expire_day: int = 7
+20
View File
@@ -0,0 +1,20 @@
import os
from config.config_loader import Configs
from config.config_models import WebServerConfig, LogConfig, MainDBConfig, JwtToken
# 실행 환경 결정 (기본 local). 환경변수 APP_ENV 로 변경.
APP_ENV = os.environ.get("APP_ENV", "local")
_config_dir = os.path.dirname(__file__)
_config_file = os.path.join(_config_dir, f"config.{APP_ENV}.toml")
if not os.path.exists(_config_file):
raise FileNotFoundError(f"설정 파일이 없습니다: {_config_file} (APP_ENV={APP_ENV}). config.<env>.toml 을 생성하세요.")
configs = Configs(_config_file)
web_server_config: WebServerConfig = configs.get(WebServerConfig)
log_config: LogConfig = configs.get(LogConfig)
main_db_config: MainDBConfig = configs.get(MainDBConfig)
jwt_token_config: JwtToken = configs.get(JwtToken)