Skip to content

Commit 240e5a5

Browse files
Merge pull request #1 from justgithubaccount/feat/sync-env-with-helm
feat: sync env config with Helm values
2 parents d540be4 + 936dac0 commit 240e5a5

File tree

7 files changed

+123
-88
lines changed

7 files changed

+123
-88
lines changed

.claude/CLAUDE.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CLAUDE.md
22

3-
Этот файл содержит контекст для Claude Code при работе с проектом.
3+
Контекст для Claude Code при работе с проектом.
44

55
## О проекте
66

@@ -36,22 +36,35 @@ app/
3636
│ ├── config.py # Pydantic Settings
3737
│ ├── db.py # SQLModel database
3838
│ ├── health.py # Health endpoint
39-
│ └── llm_client.py # OpenRouter client
40-
├── models/ # SQLModel entities
41-
├── schemas/ # API request/response
42-
├── services/ # ChatService
43-
├── integrations/ # Notion, BehaviorManager
44-
├── behavior/ # Behavior models
45-
└── observability/ # OpenTelemetry tracing
39+
│ ├── llm_client.py # OpenRouter client
40+
│ └── project_memory.py # In-memory fallback
41+
├── models/
42+
│ ├── chat.py # Chat models
43+
│ └── db_models.py # SQLModel entities
44+
├── schemas/
45+
│ ├── chat.py # Chat request/response
46+
│ └── projects.py # Project schemas
47+
├── services/
48+
│ └── chat_service.py # ChatService бизнес-логика
49+
├── integrations/
50+
│ ├── notion_client.py # Notion API client
51+
│ └── behavior_manager.py # Behavior loading
52+
├── behavior/
53+
│ └── models.py # Behavior models
54+
└── observability/
55+
└── tracing.py # OpenTelemetry setup
4656
```
4757

48-
## Ключевые файлы
58+
## API Endpoints
4959

50-
- `app/main.py` — точка входа, lifespan context manager
51-
- `app/api.py` — все API endpoints
52-
- `app/core/config.py` — Settings с SettingsConfigDict
53-
- `app/core/llm_client.py` — OpenRouterClient
54-
- `app/services/chat_service.py` — бизнес-логика чатов
60+
- `GET /` — status
61+
- `GET /health` — health check
62+
- `POST /api/v1/chat` — standalone chat
63+
- `POST /api/v1/projects` — create project
64+
- `GET /api/v1/projects` — list projects
65+
- `POST /api/v1/projects/{id}/chat` — chat in project
66+
- `GET /api/v1/projects/{id}/history` — chat history
67+
- `GET /api/v1/behavior/schema` — current behavior
5568

5669
## Стек
5770

@@ -61,15 +74,20 @@ app/
6174
- OpenTelemetry (traces, logs, metrics)
6275
- OpenRouter (LLM)
6376
- uv (package manager)
77+
- structlog (logging)
78+
- httpx (HTTP client)
79+
- notion-client (Notion API)
6480

6581
## Конвенции
6682

6783
- Pydantic v2: `model_config = SettingsConfigDict(...)` вместо `class Config`
6884
- Datetime: `datetime.now(UTC)` вместо `datetime.utcnow()`
6985
- FastAPI: lifespan context manager вместо `@app.on_event`
7086
- Тесты: `OTEL_SDK_DISABLED=true` для отключения трейсинга
87+
- Логирование: `enrich_context(event="name").info("message")`
7188

7289
## Связанные репозитории
7390

74-
- `app-crewai-cluster` — CrewAI агенты (отдельный сервис)
75-
- `app-release` — Helm charts и GitOps
91+
- `app-poly-gitops-k8s` — GitOps манифесты (ArgoCD Applications)
92+
- `app-poly-gitops-helm` — Helm chart для сервисов
93+
- `app-poly-gitops-crewai` — CrewAI мониторинг

.env.example

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,37 @@
11
# =============================================================================
2-
# Chat API Configuration
2+
# Chat API Configuration (synced with Helm values)
33
# =============================================================================
44

55
# -----------------------------------------------------------------------------
6-
# LLM Provider (OpenRouter)
6+
# OpenRouter LLM
77
# -----------------------------------------------------------------------------
88
OPENROUTER_API_KEY=sk-or-v1-...
9-
OPENROUTER_MODEL=anthropic/claude-opus-4
109
OPENROUTER_API_URL=https://openrouter.ai/api/v1/chat/completions
11-
OPENROUTER_HTTP_REFERER=https://your-app.com
12-
OPENROUTER_X_TITLE=Chat API
13-
14-
# Legacy (if using LiteLLM proxy or OpenAI directly)
15-
OPENAI_API_KEY=
16-
LLM_API_URL=http://localhost:4000
17-
CHAT_MODEL=openai/gpt-4.1
10+
OPENROUTER_MODEL=anthropic/claude-sonnet-4
1811

1912
# -----------------------------------------------------------------------------
2013
# Database
2114
# -----------------------------------------------------------------------------
2215
# SQLite (default for local dev)
2316
DATABASE_URL=sqlite:///db.sqlite3
2417

25-
# PostgreSQL (docker-compose)
26-
POSTGRES_USER=chatuser
27-
POSTGRES_PASSWORD=changeme
28-
POSTGRES_DB=chatdb
29-
# DATABASE_URL=postgresql://chatuser:changeme@localhost:5432/chatdb
30-
31-
# -----------------------------------------------------------------------------
32-
# Notion Integration (optional)
33-
# -----------------------------------------------------------------------------
34-
NOTION_TOKEN=
35-
NOTION_PAGE_ID=
18+
# PostgreSQL (production via PGO secret)
19+
# DATABASE_URL=postgresql://user:pass@host:5432/chatdb
3620

3721
# -----------------------------------------------------------------------------
38-
# OpenTelemetry (observability)
22+
# OpenTelemetry
3923
# -----------------------------------------------------------------------------
4024
OTEL_SERVICE_NAME=chat-api
4125
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
42-
ENVIRONMENT=development
43-
44-
# Kubernetes metadata (auto-populated in K8s)
45-
K8S_POD_NAME=
46-
K8S_NAMESPACE=
47-
K8S_NODE_NAME=
48-
K8S_DEPLOYMENT_NAME=
26+
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
27+
OTEL_TRACES_EXPORTER=otlp
28+
OTEL_LOGS_EXPORTER=otlp
4929

50-
# Disable OTEL for local dev/testing
30+
# Disable for local dev/testing
5131
# OTEL_SDK_DISABLED=true
5232

5333
# -----------------------------------------------------------------------------
5434
# Application
5535
# -----------------------------------------------------------------------------
56-
PROJECT_NAME=ChatMicroservice
36+
ENVIRONMENT=development
37+
LOG_LEVEL=INFO

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ build/
1212
.coverage
1313
htmlcov/
1414
*.sqlite3
15+
node_modules/

.releaserc.json

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,77 @@
44
[
55
"@semantic-release/commit-analyzer",
66
{
7+
"preset": "conventionalcommits",
78
"releaseRules": [
89
{"type": "feat", "release": "minor"},
910
{"type": "fix", "release": "patch"},
1011
{"type": "perf", "release": "patch"},
1112
{"type": "revert", "release": "patch"},
1213
{"type": "docs", "release": "patch"},
14+
{"type": "style", "release": "patch"},
1315
{"type": "refactor", "release": "patch"},
16+
{"type": "test", "release": "patch"},
1417
{"type": "ci", "release": "patch"},
1518
{"type": "chore", "release": "patch"},
16-
{"breaking": true, "release": "major"}
17-
]
19+
{"type": "build", "release": "patch"},
20+
{"breaking": true, "release": "major"},
21+
{"scope": "no-release", "release": false}
22+
],
23+
"parserOpts": {
24+
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
25+
}
1826
}
1927
],
20-
"@semantic-release/release-notes-generator",
21-
"@semantic-release/github"
28+
[
29+
"@semantic-release/release-notes-generator",
30+
{
31+
"preset": "conventionalcommits",
32+
"presetConfig": {
33+
"types": [
34+
{"type": "feat", "section": "🚀 Features"},
35+
{"type": "fix", "section": "🐛 Bug Fixes"},
36+
{"type": "perf", "section": "⚡ Performance Improvements"},
37+
{"type": "revert", "section": "⏪ Reverts"},
38+
{"type": "docs", "section": "📚 Documentation"},
39+
{"type": "style", "section": "💄 Styles"},
40+
{"type": "refactor", "section": "♻️ Code Refactoring"},
41+
{"type": "test", "section": "✅ Tests"},
42+
{"type": "ci", "section": "🔧 CI/CD"},
43+
{"type": "chore", "section": "🏗️ Chores"},
44+
{"type": "build", "section": "📦 Build System"}
45+
]
46+
},
47+
"writerOpts": {
48+
"commitsSort": ["subject", "scope"]
49+
}
50+
}
51+
],
52+
[
53+
"@semantic-release/changelog",
54+
{
55+
"changelogFile": "CHANGELOG.md"
56+
}
57+
],
58+
[
59+
"@semantic-release/github",
60+
{
61+
"assets": [
62+
{
63+
"path": "CHANGELOG.md",
64+
"label": "Changelog"
65+
}
66+
],
67+
"successComment": false,
68+
"failComment": false,
69+
"releasedLabels": false
70+
}
71+
],
72+
[
73+
"@semantic-release/git",
74+
{
75+
"assets": ["CHANGELOG.md"],
76+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
77+
}
78+
]
2279
]
2380
}

app/core/config.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from functools import lru_cache
32

43
from pydantic_settings import BaseSettings, SettingsConfigDict
@@ -8,16 +7,19 @@
87

98
class Settings(BaseSettings):
109
"""
11-
Конфиг всего приложения.
12-
Все переменные тянутся из .env — легко расширять и объяснять новым людям.
10+
Конфиг приложения. Все переменные из ENV (синхронизировано с Helm values).
1311
"""
14-
openai_api_key: str = os.getenv("OPENAI_API_KEY", "")
15-
llm_api_url: str = "http://localhost:4000"
16-
chat_model: str = "openai/gpt-4.1"
17-
project_name: str = "ChatMicroservice"
18-
notion_token: str = os.getenv("NOTION_TOKEN", "")
19-
notion_page_id: str = os.getenv("NOTION_PAGE_ID", "")
20-
database_url: str = os.getenv("DATABASE_URL", "sqlite:///db.sqlite3")
12+
# OpenRouter LLM
13+
openrouter_api_key: str = ""
14+
openrouter_api_url: str = "https://openrouter.ai/api/v1/chat/completions"
15+
openrouter_model: str = "anthropic/claude-sonnet-4"
16+
17+
# Database
18+
database_url: str = "sqlite:///db.sqlite3"
19+
20+
# Application
21+
environment: str = "development"
22+
log_level: str = "INFO"
2123

2224
model_config = SettingsConfigDict(
2325
env_file=".env",

app/main.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@
55
from fastapi.middleware.cors import CORSMiddleware
66

77
from .api import api_router
8-
from .core.config import get_settings
98
from .core.db import init_db
109
from .core.health import health_router
11-
from .integrations.behavior_manager import BehaviorManager
12-
from .integrations.notion_client import NotionClient
1310
from .logger import enrich_context
1411
from .observability.tracing import setup_tracing
1512

1613

1714
@asynccontextmanager
1815
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
1916
"""Lifespan event handler for startup and shutdown."""
20-
settings = get_settings()
21-
2217
# Startup: init database
2318
enrich_context(event="startup_init_db_start").info("Starting database initialization")
2419
try:
@@ -28,25 +23,6 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
2823
enrich_context(event="startup_init_db_error", error=str(e)).error("Database initialization failed")
2924
raise
3025

31-
# Startup: load behavior from Notion (if configured)
32-
if settings.notion_token and settings.notion_page_id:
33-
enrich_context(event="notion_config_found").info("Notion configuration found")
34-
notion_client = NotionClient(settings.notion_token)
35-
behavior_manager = BehaviorManager(notion_client, settings.notion_page_id)
36-
app.state.behavior_manager = behavior_manager
37-
38-
enrich_context(event="startup_behavior_start").info("Starting behavior loading")
39-
try:
40-
await behavior_manager.refresh()
41-
enrich_context(event="startup_behavior_success").info("Behavior loading completed")
42-
except Exception as e:
43-
enrich_context(event="startup_behavior_error", error=str(e)).error("Behavior loading failed")
44-
# Не падаем на этой ошибке
45-
else:
46-
enrich_context(event="notion_config_missing").info(
47-
"Notion configuration not found, skipping behavior loading"
48-
)
49-
5026
enrich_context(event="startup").info("Application initialized")
5127

5228
yield # Application runs here

tests/test_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
def test_settings_defaults():
77
"""Test Settings has correct defaults."""
88
settings = Settings()
9-
assert settings.llm_api_url == "http://localhost:4000"
10-
assert settings.chat_model == "openai/gpt-4.1"
11-
assert settings.project_name == "ChatMicroservice"
9+
assert settings.openrouter_api_url == "https://openrouter.ai/api/v1/chat/completions"
10+
assert settings.openrouter_model == "anthropic/claude-sonnet-4"
11+
assert settings.environment == "development"
1212

1313

1414
def test_get_settings_cached():

0 commit comments

Comments
 (0)