# Repository Guidelines ## Structure - `backend/app/` — FastAPI entrypoint (`main.py`), Pydantic schemas, `services/data_service.py` (yfinance + TTL cache), `db/watchlist.py` (SQLite). - `backend/tests/` — pytest. `pytest.ini` puts `backend/` on `pythonpath`. - `frontend/app/` — Next.js App Router. `frontend/components/`, `frontend/lib/`, `frontend/types/api.ts` (shared types — keep in sync with `backend/app/schemas.py`). - `systemd/`, `nginx/` — production deployment templates. - `design-system/` — brand tokens (`colors_and_type.css`) and Prism UI kit. Mirrored into `frontend/public/design-system/`. ## Development ```bash # Backend (port 8001) cd backend && python -m venv .venv && source .venv/bin/activate pip install -r requirements.txt uvicorn app.main:app --reload --host 127.0.0.1 --port 8001 # Frontend (port 3001) cd frontend && npm install NEXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8001 npm run dev -- --hostname 127.0.0.1 --port 3001 # Tests + lint backend/.venv/bin/pytest cd frontend && npm run lint && npm run build ``` ## Running And Deployment Local runtime: uvicorn on `127.0.0.1:8001`, Next.js on `127.0.0.1:3001`. See `README.md` for clone-to-run instructions. `scripts/deploy.sh` is only a build/setup helper. It creates `backend/.venv` if needed, installs backend requirements, runs `npm ci`, and builds the frontend. It does not install `systemd`, configure `nginx`, restart services, or manage git hooks. `systemd/` and `nginx/` are optional reference templates for users who want to wire Prism into their own server setup. ## Coding Style - Python: type hints, snake_case, small route functions. Service logic under `backend/app/services/`, persistence under `backend/app/db/`. - TypeScript: React function components, PascalCase components, camelCase values, `@/` alias. Shared API shapes in `frontend/types/api.ts`; formatters in `frontend/lib/format.ts`. ## Testing Backend tests are `test_*.py` under `backend/tests/`. Run them with `backend/.venv/bin/pytest` unless you have already activated the backend virtualenv. Stub `data_service` with `monkeypatch` — never hit live yfinance. Use `tmp_path` for any test that touches SQLite. No frontend test runner; rely on `npm run lint` and `npm run build`. ## Commits & PRs Concise imperative subjects (`Add watchlist tests`, `Fix history error handling`). PRs include: short summary, `pytest`/`npm run lint`/`npm run build` results, UI screenshots when relevant, and any env vars touched. ## Design System All frontend work must follow `design-system/`. Import `design-system/colors_and_type.css` (CSS custom properties for ink/fg/champagne/semantic colors, spacing, radii, fonts). Hard rules: - Background `#0B0E13`, text `#F2ECDC` — never pure black/white. - Champagne `#C2AA7A` for links/focus/eyebrows/buttons; never a large background. - Semantic: gain `#4F8C5E`, loss `#B5494B`, caution `#C49545`, info `#4A78B5`. - Card radius 6px, button radius 2px, capsule chips 999px. Nothing else rounded. - Hairline `1px` borders only (`#232934`). No gradients except chart fill. No glass effects. - Fonts: `--font-serif` EB Garamond (display/body), `--font-sans` IBM Plex Sans (UI), `--font-mono` IBM Plex Mono (all numerics, with `font-variant-numeric: tabular-nums`). - 150ms ease transitions. No bounces. No emoji — use SVGs in `design-system/assets/icons/` or unicode geometrics (`▲ ▼ ◈ ✦ ↗ ·`). Read `design-system/ui_kits/prism/parts{1,2,3}.jsx` and `prism.css` before building new dashboard surfaces. ## Reference: Prism v1 (`../prism`) Read-only reference for finance logic — do not import at runtime. Key files: `services/data_service.py` (TTM ratios, options, filings), `services/valuation_service.py` (`run_dcf`, `run_ev_ebitda`, `run_ev_revenue`, `run_price_to_book`), `services/fmp_service.py`, `services/news_service.py`, `components/overview.py` (signal badges, 52w range, short interest), `utils/formatters.py`. v1 caching TTLs to mirror: financials 1 h, indices 5 min, search 60 s. Data hierarchy: yfinance → FMP fallback → Finnhub for sentiment. ## Security Never commit API keys, `.env`, `node_modules/`, `backend/.venv/`, or `backend/data/prism.db`. Optional keys (`FMP_API_KEY`, `FINNHUB_API_KEY`) come from `.env` or the environment. ## graphify This project has a knowledge graph at graphify-out/ with god nodes, community structure, and cross-file relationships. When the user types `/graphify`, invoke the `skill` tool with `skill: "graphify"` before doing anything else. Rules: - For codebase questions, first run `graphify query ""` when graphify-out/graph.json exists. Use `graphify path "" ""` for relationships and `graphify explain ""` for focused concepts. These return a scoped subgraph, usually much smaller than GRAPH_REPORT.md or raw grep output. - Dirty graphify-out/ files are expected after hooks or incremental updates; dirty graph files are not a reason to skip graphify. Only skip graphify if the task is about stale or incorrect graph output, or the user explicitly says not to use it. - If graphify-out/wiki/index.md exists, use it for broad navigation instead of raw source browsing. - Read graphify-out/GRAPH_REPORT.md only for broad architecture review or when query/path/explain do not surface enough context. - After modifying code, run `graphify update .` to keep the graph current (AST-only, no API cost).