2.6 KiB
2.6 KiB
AGENTS.md — IDRS API server
Project conventions and operational gotchas for agents working in this repo.
Layout
app/main.py— FastAPI app: public endpointsGET /api/getTokenInfo,GET /api/version/android,GET /img/token/<filename>; mounts/static; startup callsdb.init_db().app/admin.py— sqladmin panel:TokenAdmin(custom WTForms form,on_model_change),VersionAdmin,create_admin(app). Upload icons saved underapp/static/icons/token/withiconUrl = {IDRS_PUBLIC_URL}/img/token/<filename>.app/models.py— SQLAlchemyToken/Version, engine,SessionLocal,ICON_DIR,DB_PATH(envIDRS_DB_PATH).app/db.py— seed fromtokenList.json/versionAndroid.json(once, empty DB only).app/auth.py—AdminAuthBackend, fail-closed creds.tokenList.json/versionAndroid.json— seed source (read-only after seed).
Environment / secrets
.env(gitignored) →ADMIN_USERNAME,ADMIN_PASSWORD,IDRS_PUBLIC_URL(defaulthttps://idrs.databisnis.id). Test credsadmin/testpass123— change before exposure..session_secret(gitignored, auto-generated 0600) ifIDRS_SESSION_SECRETunset.- NEVER bake
.envinto the Docker image; pass via--env-file/-e. - Untracked, never commit:
.env,.session_secret,idrs.db*,venv/,app/static/icons/*.
Run (local)
./run.shloads.envthenuvicorn app.main:app --host 127.0.0.1 --port 8000.- Start detached:
setsid nohup ./run.sh < /dev/null > /tmp/opencode/idrs.log 2>&1 & disown(plain&hangs). - Sanity-import:
./venv/bin/python -c "from app import main; print('IMPORT_OK')".
Docker
docker build -t idrs-api .- Run with volumes:
-v idrs-data:/app/data -v idrs-icons:/app/app/static/icons, env via--env-file .env. - MUST use a single uvicorn worker (in-memory starlette sessions →
--workers >1breaks login). - DB + uploaded icons persist in the volumes across container recreate; code changes need an image rebuild.
Verification
- curl login:
POST /admin/loginwith-c/-bcookie jar; then curl admin endpoints / uploads with the jar. - Assert
/img/token/<f>returnsimage/png; HTML/oversize uploads rejected (400).
Operation gotchas
- NEVER
pkill -f uvicornbroadly — a separate user process runs uvicorn on port 7000. Kill only the port-8000 PID (ps -ef | grep "uvicorn app.main:app --host 127.0.0.1 --port 8000"). - Local server binds 127.0.0.1:8000. Host ports 8080/8100 are taken by other services.
Spec
- Canonical invariants and task status live in
SPEC.md(§V invariants, §T tasks, §B bug log). Keep it updated when behavior changes; check §V before modifying.