Skip to content

Commit eafa968

Browse files
docs: add CLAUDE.md and update README
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4984dbb commit eafa968

File tree

2 files changed

+83
-4
lines changed

2 files changed

+83
-4
lines changed

CLAUDE.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Commands
6+
7+
```bash
8+
# Run locally
9+
python main.py
10+
# Or
11+
uvicorn main:app --host 0.0.0.0 --port 8000
12+
13+
# Lint
14+
flake8 . # max-line-length=120
15+
16+
# Docker
17+
docker build -f docker/dockerfile -t awsl-fastapi .
18+
docker compose -f docker/docker-compose.yml up
19+
```
20+
21+
No test suite exists in this project.
22+
23+
## Architecture
24+
25+
FastAPI REST API for Weibo content aggregation. Collects producer (Weibo user) profiles and serves their image content.
26+
27+
### Key Patterns
28+
29+
- **DB abstraction**: `src/db/base.py` defines `DBClientBase` with metaclass auto-registration. Providers (`mysql_provider.py`, `tidb_http_provider.py`) register via `_type` class attribute. Selected at runtime by `settings.db_client_type`.
30+
- **Models submodule**: `src/models/` is a **git submodule** (separate repo). ORM models live there. Commit model changes in the submodule first, then update the ref in this repo.
31+
- **Admin auth**: All admin endpoints under `/admin` prefix use Bearer Token via `HTTPBearer` + `hmac.compare_digest`. Token value from `settings.token`.
32+
- **WeiboHeaders**: Thread-safe singleton in `config.py` (`wb_headers`). Loaded from DB on startup, persisted on update. DB writes happen outside the lock.
33+
- **Config**: Pydantic `BaseSettings` in `config.py`, loaded from `.env`. Sensitive fields (`token`, `db_url`) have `exclude=True`.
34+
35+
### Deployment
36+
37+
- **Vercel**: Serverless Python, configured in `vercel.json`. CI deploys two projects in parallel (`.github/workflows/main.yml`).
38+
- **Docker**: Released to `ghcr.io` on git tags (`.github/workflows/release.yml`).
39+
40+
### Constants
41+
42+
Weibo API URLs and `WB_HEADERS_KEY` are centralized in `config.py`.

README.MD

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
1-
# Awsl Fastapi
1+
# AWSL FastAPI
22

3-
```env
4-
cookie_sub=xxx
5-
db_url=mysql+mysqlconnector://xxx:xxx/xxx(数据库地址)
3+
Weibo content aggregation API. Manages producers (Weibo users) and serves their image content.
4+
5+
## Quick Start
6+
7+
```bash
8+
cp .env.example .env
9+
# Edit .env with your config
10+
pip install -r requirements.txt
11+
python main.py
612
```
13+
14+
API docs at `http://localhost:8000/docs`
15+
16+
## Environment Variables
17+
18+
| Variable | Required | Description |
19+
|---|---|---|
20+
| `db_url` | Yes | Database connection string, e.g. `mysql+mysqlconnector://user:pass@host/db` |
21+
| `token` | Yes | Admin API Bearer Token |
22+
| `cookie_sub` | No | Weibo SUB cookie (fallback, prefer `/admin/wb_headers` API) |
23+
| `db_client_type` | No | `mysql` (default) or `tidb_http` |
24+
| `use_db_pool` | No | Enable connection pooling (default: `true`) |
25+
| `db_pool_size` | No | Pool size (default: `20`) |
26+
| `origin` | No | Original image domain for CDN replacement |
27+
| `cdn` | No | CDN domain to replace origin |
28+
| `CORS` | No | Set to any value to enable CORS |
29+
| `ENV_FILE` | No | Path to env file (default: `.env`) |
30+
31+
## Docker
32+
33+
```bash
34+
docker build -f docker/dockerfile -t awsl-fastapi .
35+
docker compose -f docker/docker-compose.yml up
36+
```
37+
38+
Docker Compose includes MySQL, Prometheus, Pushgateway, and Grafana.
39+
40+
## Deployment
41+
42+
- **Vercel**: Auto-deploys on push to `main`
43+
- **Docker**: Pushes to `ghcr.io` on git tag (`*.*.*`)

0 commit comments

Comments
 (0)