Skip to content

Commit 2467e09

Browse files
committed
init commit
0 parents  commit 2467e09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+5740
-0
lines changed

.dockerignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Version control
2+
.git
3+
.gitignore
4+
.github
5+
6+
# Environment files - these will be passed as build args
7+
.env*
8+
.env.example
9+
10+
# Python
11+
__pycache__/
12+
*.py[cod]
13+
*$py.class
14+
*.so
15+
.Python
16+
.pytest_cache/
17+
.coverage
18+
htmlcov/
19+
.tox/
20+
.nox/
21+
.hypothesis/
22+
pytestdebug.log
23+
*.egg-info/
24+
*.ipynb
25+
26+
# Virtual environments
27+
.venv
28+
venv
29+
ENV/
30+
env/
31+
32+
# Development tools
33+
.idea
34+
.vscode
35+
*.swp
36+
*.swo
37+
.DS_Store
38+
39+
# Logs
40+
logs/
41+
*.log
42+
43+
# Docker
44+
Dockerfile
45+
.dockerignore
46+
docker-compose.yml
47+
48+
# Documentation
49+
docs/
50+
README.md
51+
*.md
52+
53+
# Build artifacts
54+
*.pyc
55+
*.pyo
56+
*.egg-info
57+
dist/
58+
build/
59+
60+
# other
61+
schema.sql

.env.example

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Environment Configuration Example
2+
3+
# Application Settings
4+
APP_ENV=development
5+
PROJECT_NAME="Web Assistant"
6+
VERSION=1.0.0
7+
DEBUG=true
8+
9+
# API Settings
10+
API_V1_STR=/api/v1
11+
12+
# CORS Settings
13+
ALLOWED_ORIGINS="http://localhost:3000,http://localhost:8000"
14+
15+
# Langfuse Settings
16+
LANGFUSE_PUBLIC_KEY="your-langfuse-public-key"
17+
LANGFUSE_SECRET_KEY="your-langfuse-secret-key"
18+
LANGFUSE_HOST=https://cloud.langfuse.com
19+
20+
# LLM Settings
21+
LLM_API_KEY="your-llm-api-key" # e.g. OpenAI API key
22+
LLM_MODEL=gpt-4o-mini
23+
DEFAULT_LLM_TEMPERATURE=0.2
24+
25+
# JWT Settings
26+
JWT_SECRET_KEY="your-jwt-secret-key"
27+
JWT_ALGORITHM=HS256
28+
JWT_ACCESS_TOKEN_EXPIRE_DAYS=30
29+
30+
# Database Settings
31+
POSTGRES_URL="postgresql://:your-db-password@POSTGRES_HOST:POSTGRES_PORT/POSTGRES_DB"
32+
POSTGRES_POOL_SIZE=5
33+
POSTGRES_MAX_OVERFLOW=10
34+
35+
# Rate Limiting Settings
36+
RATE_LIMIT_DEFAULT="1000 per day,200 per hour"
37+
RATE_LIMIT_CHAT="100 per minute"
38+
RATE_LIMIT_CHAT_STREAM="100 per minute"
39+
RATE_LIMIT_MESSAGES="200 per minute"
40+
RATE_LIMIT_LOGIN="100 per minute"
41+
42+
# Logging
43+
LOG_LEVEL=DEBUG
44+
LOG_FORMAT=console

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Python-generated files
2+
__pycache__/
3+
*.py[oc]
4+
build/
5+
dist/
6+
wheels/
7+
*.egg-info
8+
*.jsonl
9+
10+
# Virtual environments
11+
.venv
12+
13+
# Environment variables
14+
.env
15+
.env.development
16+
.env.staging
17+
.env.production
18+
19+
# Misc
20+
*.ipynb

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

.vscode/settings.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"python.defaultInterpreterPath": "${workspaceFolder}/venv/bin/python",
4+
"isort.args": [
5+
"--settings-path=${workspaceFolder}/pyproject.toml"
6+
],
7+
"black-formatter.args": [
8+
"--config=${workspaceFolder}/pyproject.toml"
9+
],
10+
"flake8.args": [
11+
"--config=${workspaceFolder}/pyproject.toml"
12+
],
13+
"mypy-type-checker.args": [
14+
"--config-file=${workspaceFolder}/pyproject.toml"
15+
],
16+
"pylint.args": [
17+
"--rcfile=${workspaceFolder}/pyproject.toml"
18+
],
19+
"[python]": {
20+
"editor.codeActionsOnSave": {
21+
"source.organizeImports": "explicit"
22+
},
23+
"editor.formatOnSave": true,
24+
},
25+
"python.analysis.autoImportCompletions": true,
26+
"python.analysis.indexing": true,
27+
"python.languageServer": "Pylance",
28+
"python.analysis.completeFunctionParens": true,
29+
"editor.rulers": [
30+
{
31+
"column": 99,
32+
"color": "#FFFFFF"
33+
},
34+
{
35+
"column": 119,
36+
"color": "#90EE90"
37+
}
38+
],
39+
"python.testing.pytestArgs": [
40+
"tests"
41+
],
42+
"python.testing.unittestEnabled": false,
43+
"python.testing.pytestEnabled": true,
44+
}

Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM python:3.13.2-slim
2+
3+
# Set working directory
4+
WORKDIR /app
5+
6+
# Set non-sensitive environment variables
7+
ARG APP_ENV=production
8+
ARG POSTGRES_URL
9+
10+
ENV APP_ENV=${APP_ENV} \
11+
PYTHONFAULTHANDLER=1 \
12+
PYTHONUNBUFFERED=1 \
13+
PYTHONHASHSEED=random \
14+
PIP_NO_CACHE_DIR=1 \
15+
PIP_DISABLE_PIP_VERSION_CHECK=on \
16+
PIP_DEFAULT_TIMEOUT=100 \
17+
POSTGRES_URL=${POSTGRES_URL}
18+
19+
# Install system dependencies
20+
RUN apt-get update && apt-get install -y \
21+
build-essential \
22+
libpq-dev \
23+
&& pip install --upgrade pip \
24+
&& pip install uv \
25+
&& rm -rf /var/lib/apt/lists/*
26+
27+
# Copy pyproject.toml first to leverage Docker cache
28+
COPY pyproject.toml .
29+
RUN uv venv && . .venv/bin/activate && uv pip install -e .
30+
31+
# Copy the application
32+
COPY . .
33+
34+
# Make entrypoint script executable - do this before changing user
35+
RUN chmod +x /app/scripts/docker-entrypoint.sh
36+
37+
# Create a non-root user
38+
RUN useradd -m appuser && chown -R appuser:appuser /app
39+
USER appuser
40+
41+
# Create log directory
42+
RUN mkdir -p /app/logs
43+
44+
# Default port
45+
EXPOSE 8000
46+
47+
# Log the environment we're using
48+
RUN echo "Using ${APP_ENV} environment"
49+
50+
# Command to run the application
51+
ENTRYPOINT ["/app/scripts/docker-entrypoint.sh"]
52+
CMD ["/app/.venv/bin/uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

Makefile

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
install:
2+
pip install uv
3+
uv sync
4+
5+
set-env:
6+
@if [ -z "$(ENV)" ]; then \
7+
echo "ENV is not set. Usage: make set-env ENV=development|staging|production"; \
8+
exit 1; \
9+
fi
10+
@if [ "$(ENV)" != "development" ] && [ "$(ENV)" != "staging" ] && [ "$(ENV)" != "production" ] && [ "$(ENV)" != "test" ]; then \
11+
echo "ENV is not valid. Must be one of: development, staging, production, test"; \
12+
exit 1; \
13+
fi
14+
@echo "Setting environment to $(ENV)"
15+
@bash -c "source scripts/set_env.sh $(ENV)"
16+
17+
prod:
18+
@echo "Starting server in production environment"
19+
@bash -c "source scripts/set_env.sh production && ./.venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port 8000"
20+
21+
staging:
22+
@echo "Starting server in staging environment"
23+
@bash -c "source scripts/set_env.sh staging && ./.venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port 8000"
24+
25+
dev:
26+
@echo "Starting server in development environment"
27+
@bash -c "source scripts/set_env.sh development && uv run uvicorn app.main:app --reload --port 8000"
28+
29+
lint:
30+
ruff check .
31+
32+
format:
33+
ruff format .
34+
35+
clean:
36+
rm -rf .venv
37+
rm -rf __pycache__
38+
rm -rf .pytest_cache
39+
40+
docker-build:
41+
docker build -t fastapi-langgraph-template .
42+
43+
docker-build-env:
44+
@if [ -z "$(ENV)" ]; then \
45+
echo "ENV is not set. Usage: make docker-build-env ENV=development|staging|production"; \
46+
exit 1; \
47+
fi
48+
@if [ "$(ENV)" != "development" ] && [ "$(ENV)" != "staging" ] && [ "$(ENV)" != "production" ]; then \
49+
echo "ENV is not valid. Must be one of: development, staging, production"; \
50+
exit 1; \
51+
fi
52+
@./scripts/build-docker.sh $(ENV)
53+
54+
docker-run:
55+
docker run -p 8000:8000 fastapi-langgraph-template
56+
57+
docker-run-env:
58+
@if [ -z "$(ENV)" ]; then \
59+
echo "ENV is not set. Usage: make docker-run-env ENV=development|staging|production"; \
60+
exit 1; \
61+
fi
62+
@if [ "$(ENV)" != "development" ] && [ "$(ENV)" != "staging" ] && [ "$(ENV)" != "production" ]; then \
63+
echo "ENV is not valid. Must be one of: development, staging, production"; \
64+
exit 1; \
65+
fi
66+
@./scripts/run-docker.sh $(ENV)
67+
68+
docker-logs:
69+
@if [ -z "$(ENV)" ]; then \
70+
echo "ENV is not set. Usage: make docker-logs ENV=development|staging|production"; \
71+
exit 1; \
72+
fi
73+
@if [ "$(ENV)" != "development" ] && [ "$(ENV)" != "staging" ] && [ "$(ENV)" != "production" ]; then \
74+
echo "ENV is not valid. Must be one of: development, staging, production"; \
75+
exit 1; \
76+
fi
77+
@./scripts/logs-docker.sh $(ENV)
78+
79+
docker-stop:
80+
@if [ -z "$(ENV)" ]; then \
81+
echo "ENV is not set. Usage: make docker-stop ENV=development|staging|production"; \
82+
exit 1; \
83+
fi
84+
@if [ "$(ENV)" != "development" ] && [ "$(ENV)" != "staging" ] && [ "$(ENV)" != "production" ]; then \
85+
echo "ENV is not valid. Must be one of: development, staging, production"; \
86+
exit 1; \
87+
fi
88+
@./scripts/stop-docker.sh $(ENV)
89+
90+
# Docker Compose commands for the entire stack
91+
docker-compose-up:
92+
@if [ -z "$(ENV)" ]; then \
93+
echo "ENV is not set. Usage: make docker-compose-up ENV=development|staging|production"; \
94+
exit 1; \
95+
fi
96+
@if [ "$(ENV)" != "development" ] && [ "$(ENV)" != "staging" ] && [ "$(ENV)" != "production" ]; then \
97+
echo "ENV is not valid. Must be one of: development, staging, production"; \
98+
exit 1; \
99+
fi
100+
APP_ENV=$(ENV) docker-compose up -d
101+
102+
docker-compose-down:
103+
@if [ -z "$(ENV)" ]; then \
104+
echo "ENV is not set. Usage: make docker-compose-down ENV=development|staging|production"; \
105+
exit 1; \
106+
fi
107+
APP_ENV=$(ENV) docker-compose down
108+
109+
docker-compose-logs:
110+
@if [ -z "$(ENV)" ]; then \
111+
echo "ENV is not set. Usage: make docker-compose-logs ENV=development|staging|production"; \
112+
exit 1; \
113+
fi
114+
APP_ENV=$(ENV) docker-compose logs -f
115+
116+
# Help
117+
help:
118+
@echo "Usage: make <target>"
119+
@echo "Targets:"
120+
@echo " install: Install dependencies"
121+
@echo " set-env ENV=<environment>: Set environment variables (development, staging, production, test)"
122+
@echo " run ENV=<environment>: Set environment and run server"
123+
@echo " prod: Run server in production environment"
124+
@echo " staging: Run server in staging environment"
125+
@echo " dev: Run server in development environment"
126+
@echo " test: Run tests"
127+
@echo " clean: Clean up"
128+
@echo " docker-build: Build default Docker image"
129+
@echo " docker-build-env ENV=<environment>: Build Docker image for specific environment"
130+
@echo " docker-run: Run default Docker container"
131+
@echo " docker-run-env ENV=<environment>: Run Docker container for specific environment"
132+
@echo " docker-logs ENV=<environment>: View logs from running container"
133+
@echo " docker-stop ENV=<environment>: Stop and remove container"
134+
@echo " docker-compose-up: Start the entire stack (API, Prometheus, Grafana)"
135+
@echo " docker-compose-down: Stop the entire stack"
136+
@echo " docker-compose-logs: View logs from all services"

0 commit comments

Comments
 (0)