Skip to content

Commit 767dab8

Browse files
committed
Updating documentation to new base standard
1 parent bbd0571 commit 767dab8

14 files changed

+2823
-14
lines changed

.claude/app.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

.claude/app.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# App-Specific Context
2+
3+
> **This file IS safe to modify.** Add your app-specific rules, context, and requirements here.
4+
5+
## About This App
6+
7+
<!-- Describe what this application does -->
8+
9+
## App-Specific Rules
10+
11+
<!-- Add rules specific to this application that Claude should follow -->
12+
13+
## Key Files & Locations
14+
15+
<!-- List important files Claude should know about -->
16+
17+
## Domain-Specific Terms
18+
19+
<!-- Define any domain terminology Claude should understand -->
20+
21+
## Integration Notes
22+
23+
<!-- Any app-specific integration details -->
24+
25+
---
26+
27+
*This file is for app-specific context. Do not add general standards here - those belong in the template files.*

.claude/containers.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

.claude/containers.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Container Image Standards
2+
3+
## ⚠️ CRITICAL RULES
4+
5+
1. **Debian 12 (bookworm) ONLY** - all container images must use Debian-based images
6+
2. **NEVER use Alpine** - causes glibc/musl compatibility issues, missing packages, debugging difficulties
7+
3. **Use `-slim` variants** when available for smaller image sizes
8+
4. **PostgreSQL 16.x** standard for all database containers
9+
5. **Multi-arch builds required** - support both amd64 and arm64
10+
11+
---
12+
13+
## Base Image Selection
14+
15+
### Priority Order (MUST follow)
16+
17+
1. **Debian 12 (bookworm)** - PRIMARY, always use if available
18+
2. **Debian 11 (bullseye)** - fallback if bookworm unavailable
19+
3. **Debian 13 (trixie)** - fallback for newer packages
20+
4. **Ubuntu LTS** - ONLY if no Debian option exists
21+
5.**NEVER Alpine** - forbidden, causes too many issues
22+
23+
---
24+
25+
## Standard Images
26+
27+
| Service | Image | Notes |
28+
|---------|-------|-------|
29+
| PostgreSQL | `postgres:16-bookworm` | Primary database |
30+
| MySQL | `mysql:8.0-debian` | Alternative database |
31+
| Redis | `redis:7-bookworm` | Cache/session store |
32+
| Python | `python:3.13-slim-bookworm` | Flask backend |
33+
| Node.js | `node:18-bookworm-slim` | WebUI build |
34+
| Nginx | `nginx:stable-bookworm-slim` | Reverse proxy |
35+
| Go | `golang:1.24-bookworm` | Build stage only |
36+
| Runtime | `debian:bookworm-slim` | Go runtime stage |
37+
38+
---
39+
40+
## Dockerfile Patterns
41+
42+
### Python Service
43+
```dockerfile
44+
FROM python:3.13-slim-bookworm AS builder
45+
WORKDIR /app
46+
COPY requirements.txt .
47+
RUN pip install --no-cache-dir -r requirements.txt
48+
COPY . .
49+
50+
FROM python:3.13-slim-bookworm
51+
WORKDIR /app
52+
COPY --from=builder /app /app
53+
CMD ["gunicorn", "-b", "0.0.0.0:8080", "app:app"]
54+
```
55+
56+
### Go Service
57+
```dockerfile
58+
FROM golang:1.24-bookworm AS builder
59+
WORKDIR /app
60+
COPY go.mod go.sum ./
61+
RUN go mod download
62+
COPY . .
63+
RUN CGO_ENABLED=0 go build -o /app/server
64+
65+
FROM debian:bookworm-slim
66+
COPY --from=builder /app/server /server
67+
CMD ["/server"]
68+
```
69+
70+
### Node.js/React Service
71+
```dockerfile
72+
FROM node:18-bookworm-slim AS builder
73+
WORKDIR /app
74+
COPY package*.json ./
75+
RUN npm ci
76+
COPY . .
77+
RUN npm run build
78+
79+
FROM nginx:stable-bookworm-slim
80+
COPY --from=builder /app/dist /usr/share/nginx/html
81+
```
82+
83+
---
84+
85+
## Why Not Alpine?
86+
87+
**glibc vs musl** - Many Python packages require glibc, Alpine uses musl
88+
**Missing packages** - Common tools often unavailable or different versions
89+
**Debugging harder** - No bash by default, limited tooling
90+
**DNS issues** - Known DNS resolution problems in some scenarios
91+
**Build failures** - C extensions often fail to compile
92+
93+
**Debian-slim** - Only ~30MB larger than Alpine but zero compatibility issues
94+
95+
---
96+
97+
## Docker Compose Example
98+
99+
```yaml
100+
services:
101+
postgres:
102+
image: postgres:16-bookworm
103+
104+
redis:
105+
image: redis:7-bookworm
106+
107+
api:
108+
build:
109+
context: ./services/flask-backend
110+
# Uses python:3.13-slim-bookworm internally
111+
112+
web:
113+
image: nginx:stable-bookworm-slim
114+
```

.claude/database.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

.claude/database.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# Database Standards Quick Reference
2+
3+
## ⚠️ CRITICAL RULES
4+
5+
1. **PyDAL MANDATORY for ALL runtime operations** - no exceptions
6+
2. **SQLAlchemy + Alembic for schema/migrations only** - never for runtime queries
7+
3. **Support ALL databases by default**: PostgreSQL, MySQL, MariaDB Galera, SQLite
8+
4. **DB_TYPE environment variable required** - maps to connection string prefix
9+
5. **Connection pooling REQUIRED** - use PyDAL built-in pool_size configuration
10+
6. **Thread-safe connections MANDATORY** - thread-local storage for multi-threaded apps
11+
7. **Retry logic with exponential backoff** - handle database initialization delays
12+
8. **MariaDB Galera special handling** - WSREP checks, short transactions, charset utf8mb4
13+
14+
---
15+
16+
## Database Support Matrix
17+
18+
| Database | DB_TYPE | Version | Default Port | Use Case |
19+
|----------|---------|---------|--------------|----------|
20+
| PostgreSQL | `postgresql` | **16.x** | 5432 | Production (primary) |
21+
| MySQL | `mysql` | 8.0+ | 3306 | Production alternative |
22+
| MariaDB Galera | `mysql` | 10.11+ | 3306 | HA clusters (special config) |
23+
| SQLite | `sqlite` | 3.x | N/A | Development/lightweight |
24+
25+
---
26+
27+
## Dual-Library Architecture (Python)
28+
29+
### SQLAlchemy + Alembic
30+
- **Purpose**: Schema definition and version-controlled migrations ONLY
31+
- **When**: Application first-time setup
32+
- **What**: Define tables, columns, relationships
33+
- **Not for**: Runtime queries, data operations
34+
35+
### PyDAL
36+
- **Purpose**: ALL runtime database operations
37+
- **When**: Every request, transaction, query
38+
- **What**: Queries, inserts, updates, deletes, transactions
39+
- **Built-in**: Connection pooling, thread safety, retry logic
40+
41+
---
42+
43+
## Environment Variables
44+
45+
```bash
46+
DB_TYPE=postgresql # Database type
47+
DB_HOST=localhost # Database host
48+
DB_PORT=5432 # Database port
49+
DB_NAME=app_db # Database name
50+
DB_USER=app_user # Database username
51+
DB_PASS=app_pass # Database password
52+
DB_POOL_SIZE=10 # Connection pool size (default: 10)
53+
DB_MAX_RETRIES=5 # Maximum connection retries (default: 5)
54+
DB_RETRY_DELAY=5 # Retry delay in seconds (default: 5)
55+
```
56+
57+
---
58+
59+
## PyDAL Connection Pattern
60+
61+
```python
62+
from pydal import DAL
63+
64+
def get_db():
65+
db_type = os.getenv('DB_TYPE', 'postgresql')
66+
db_uri = f"{db_type}://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
67+
68+
db = DAL(
69+
db_uri,
70+
pool_size=int(os.getenv('DB_POOL_SIZE', '10')),
71+
migrate=True,
72+
check_reserved=['all'],
73+
lazy_tables=True
74+
)
75+
return db
76+
```
77+
78+
---
79+
80+
## Thread-Safe Usage Pattern
81+
82+
**NEVER share DAL instance across threads. Use thread-local storage:**
83+
84+
```python
85+
import threading
86+
87+
thread_local = threading.local()
88+
89+
def get_thread_db():
90+
if not hasattr(thread_local, 'db'):
91+
thread_local.db = DAL(db_uri, pool_size=10, migrate=False)
92+
return thread_local.db
93+
```
94+
95+
**Flask pattern (automatic via g context):**
96+
97+
```python
98+
from flask import g
99+
100+
def get_db():
101+
if 'db' not in g:
102+
g.db = DAL(db_uri, pool_size=10)
103+
return g.db
104+
105+
@app.teardown_appcontext
106+
def close_db(error):
107+
db = g.pop('db', None)
108+
if db: db.close()
109+
```
110+
111+
---
112+
113+
## MariaDB Galera Special Requirements
114+
115+
1. **Connection String**: Use `mysql://` (same as MySQL)
116+
2. **Driver Args**: Set charset to utf8mb4
117+
3. **WSREP Checks**: Verify `wsrep_ready` before critical writes
118+
4. **Auto-Increment**: Configure `innodb_autoinc_lock_mode=2` for interleaved mode
119+
5. **Transactions**: Keep short to avoid certification conflicts
120+
6. **DDL Operations**: Plan during low-traffic periods (uses Total Order Isolation)
121+
122+
```python
123+
# Galera-specific configuration
124+
db = DAL(
125+
f"mysql://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}",
126+
pool_size=10,
127+
driver_args={'charset': 'utf8mb4'}
128+
)
129+
```
130+
131+
---
132+
133+
## Connection Pooling & Retry Logic
134+
135+
```python
136+
import time
137+
138+
def wait_for_database(max_retries=5, retry_delay=5):
139+
"""Wait for DB with retry logic"""
140+
for attempt in range(max_retries):
141+
try:
142+
db = get_db()
143+
db.close()
144+
return True
145+
except Exception as e:
146+
print(f"Attempt {attempt+1}/{max_retries} failed: {e}")
147+
if attempt < max_retries - 1:
148+
time.sleep(retry_delay)
149+
return False
150+
151+
# Application startup
152+
if not wait_for_database():
153+
sys.exit(1)
154+
db = get_db()
155+
```
156+
157+
---
158+
159+
## Concurrency Selection
160+
161+
| Workload | Approach | Libraries | Pool Size Formula |
162+
|----------|----------|-----------|-------------------|
163+
| I/O-bound (>100 concurrent) | Async | `asyncio`, `databases` | pool = concurrent / 2 |
164+
| CPU-bound | Multi-processing | `multiprocessing` | pool = CPU cores |
165+
| Mixed/Blocking I/O | Multi-threading | `threading`, `ThreadPoolExecutor` | pool = (2 × cores) + spindles |
166+
167+
---
168+
169+
## Go Database Requirements
170+
171+
When using Go for high-performance apps:
172+
- **GORM** (preferred): Full ORM with PostgreSQL/MySQL support
173+
- **sqlx** (alternative): Lightweight, more control
174+
- Must support PostgreSQL, MySQL, SQLite
175+
- Active maintenance required
176+
177+
```go
178+
import (
179+
"gorm.io/driver/postgres"
180+
"gorm.io/driver/mysql"
181+
"gorm.io/gorm"
182+
)
183+
184+
func initDB() (*gorm.DB, error) {
185+
dbType := os.Getenv("DB_TYPE")
186+
dsn := os.Getenv("DATABASE_URL")
187+
188+
var dialector gorm.Dialector
189+
switch dbType {
190+
case "mysql":
191+
dialector = mysql.Open(dsn)
192+
default:
193+
dialector = postgres.Open(dsn)
194+
}
195+
196+
return gorm.Open(dialector, &gorm.Config{})
197+
}
198+
```
199+
200+
---
201+
202+
## See Also
203+
204+
- `/home/penguin/code/project-template/docs/standards/DATABASE.md` - Full documentation
205+
- Alembic migrations: https://alembic.sqlalchemy.org/
206+
- PyDAL docs: https://py4web.io/en_US/chapter-12.html

.claude/flask-backend.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)