Skip to content

Commit b175c73

Browse files
committed
feat: add AGENTS.md
1 parent 50cf301 commit b175c73

File tree

3 files changed

+172
-2
lines changed

3 files changed

+172
-2
lines changed

AGENTS.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# AGENTS.md
2+
3+
Agent guidance for working in `full-stack-fastapi-template`.
4+
5+
## Purpose
6+
7+
- Prefer small, targeted changes that fit the existing backend/frontend split.
8+
- Verify with the narrowest useful command before running broader checks.
9+
- Preserve existing architecture and generated-code boundaries.
10+
11+
## Repository Layout
12+
13+
- `backend/`: FastAPI app, SQLModel models, services, repositories, middleware, pytest suite.
14+
- `frontend/`: React 19 + TypeScript + Vite app with TanStack Router/Query and Playwright tests.
15+
- `scripts/`: top-level Docker-backed helpers and frontend client generation.
16+
- `backend/scripts/`: backend-local lint, format, and test helpers.
17+
- `frontend/src/client/`: generated OpenAPI client. Do not hand-edit.
18+
- `frontend/src/routeTree.gen.ts`: generated TanStack route tree. Do not hand-edit.
19+
20+
## Rule Files
21+
22+
- No `.cursor/rules/` directory was found.
23+
- No `.cursorrules` file was found.
24+
- No `.github/copilot-instructions.md` file was found.
25+
- If any of those files are added later, merge their repo-specific rules into this file.
26+
27+
## Tooling
28+
29+
- Python package management: `uv`
30+
- Python version: `>=3.10,<4.0`
31+
- Backend linting/formatting: `ruff`
32+
- Backend type checking: `mypy --strict`
33+
- Backend testing: `pytest` with `coverage`
34+
- Frontend package manager/runtime: `bun`
35+
- Frontend formatting/linting: `biome`
36+
- Frontend build: `tsc -p tsconfig.build.json && vite build`
37+
- Frontend E2E testing: `playwright`
38+
- Full-stack local environment: `docker compose`
39+
40+
## Setup
41+
42+
### Root
43+
44+
- Install frontend dependencies: `bun install`
45+
- Root scripts proxy to the frontend workspace.
46+
47+
### Backend
48+
49+
- Install dependencies: `cd backend && uv sync`
50+
- Activate virtualenv if needed: `cd backend && source .venv/bin/activate`
51+
- Use `backend/.venv/bin/python` as the interpreter.
52+
53+
### Frontend
54+
55+
- Start local dev server: `cd frontend && bun run dev`
56+
- Set `VITE_API_URL` when pointing the frontend at a non-default API.
57+
58+
## Development Commands
59+
60+
### Docker Compose
61+
62+
- Start full stack: `docker compose up -d`
63+
- Start with live reload workflow: `docker compose watch`
64+
- Start backend dependency stack for Playwright: `docker compose up -d --wait backend`
65+
- Stop and remove volumes: `docker compose down -v`
66+
- View logs: `docker compose logs` or `docker compose logs backend`
67+
68+
### Backend Validation
69+
70+
- Lint/type/format-check bundle: `cd backend && bash scripts/lint.sh`
71+
- Auto-fix backend style: `cd backend && bash scripts/format.sh`
72+
- Full backend suite: `cd backend && bash scripts/test.sh`
73+
- Full Docker-backed suite from repo root: `bash ./scripts/test.sh`
74+
75+
### Backend Single Test
76+
77+
- One test file locally: `cd backend && coverage run -m pytest tests/api/routes/test_users.py`
78+
- One test function locally: `cd backend && coverage run -m pytest tests/api/routes/test_users.py::test_get_users_superuser_me`
79+
- One test file in running container: `docker compose exec backend bash scripts/tests-start.sh tests/api/routes/test_users.py`
80+
- One test function in running container: `docker compose exec backend bash scripts/tests-start.sh tests/api/routes/test_users.py::test_get_users_superuser_me`
81+
- Stop on first backend failure in container: `docker compose exec backend bash scripts/tests-start.sh -x`
82+
83+
### Frontend Validation
84+
85+
- Lint/format frontend from root: `bun run lint`
86+
- Lint/format frontend from workspace: `cd frontend && bun run lint`
87+
- Frontend build: `cd frontend && bun run build`
88+
- Full Playwright suite from root: `bun run test`
89+
- Full Playwright suite from workspace: `cd frontend && bun run test`
90+
91+
### Frontend Single Test
92+
93+
- One Playwright file: `cd frontend && bunx playwright test tests/example.spec.ts`
94+
- One Playwright test by name: `cd frontend && bunx playwright test -g "login"`
95+
- Playwright UI mode: `cd frontend && bunx playwright test --ui`
96+
97+
### Client Generation
98+
99+
- Preferred: `bash ./scripts/generate-client.sh`
100+
- Frontend-only form: `cd frontend && bun run generate-client`
101+
- Regenerate after backend OpenAPI changes.
102+
103+
## Architecture Notes
104+
105+
- Backend generally follows `router -> service -> repository` by feature.
106+
- Keep route handlers thin; move business logic out of routers.
107+
- Frontend uses file-based TanStack Router routes under `frontend/src/routes/`.
108+
- API interaction should stay in generated client calls and React Query hooks/mutations.
109+
- Reuse shared UI primitives before creating new abstractions.
110+
111+
## Backend Style Guidelines
112+
113+
- Use explicit type annotations throughout; `mypy` is strict.
114+
- Prefer `uuid.UUID`, SQLModel models, and existing schema classes already used nearby.
115+
- Keep imports grouped and sorted by Ruff/isort defaults.
116+
- Use concise docstrings only when they add real information.
117+
- Prefer `HTTPException` for expected request/domain failures with stable status codes and clear `detail` values.
118+
- Let middleware handle unexpected server errors instead of broad ad hoc catches.
119+
- Avoid `print`; Ruff forbids it.
120+
- Reuse shared primitives such as `Message`, `PaginatedResponse`, `SessionDep`, and current-user deps.
121+
- When mutating SQLModel instances, `commit()` and `refresh()` when the caller needs the updated object.
122+
- Keep authorization checks aligned with nearby routes, especially around sensitive resources.
123+
- Do not make Alembic changes unless the task really requires a schema change.
124+
125+
## Frontend Style Guidelines
126+
127+
- Keep code compatible with TypeScript `strict` mode.
128+
- Prefer `@/` path aliases for app code imports.
129+
- Follow Biome defaults in this repo: spaces, double quotes, minimal semicolons.
130+
- Let Biome organize imports rather than hand-tuning ordering.
131+
- Prefer functional React components and existing hook patterns.
132+
- Use `zod` and `react-hook-form` for forms when matching current flows.
133+
- Handle async failures through existing helpers such as `handleError` and toast utilities.
134+
- Avoid parameter reassignment; Biome treats it as an error.
135+
- Use self-closing JSX elements where applicable.
136+
- Avoid broad rewrites of `frontend/src/components/ui/`; it is mostly library-style code.
137+
- Avoid `any` unless truly necessary, even though Biome permits it.
138+
139+
## Naming Conventions
140+
141+
- Python classes: `PascalCase`
142+
- Python functions, variables, and modules: `snake_case`
143+
- React components: `PascalCase`
144+
- Hooks: `useX`
145+
- Keep route file names aligned with current TanStack Router naming patterns, including `_layout` segments.
146+
- Match nearby naming instead of renaming for personal preference.
147+
148+
## Error Handling
149+
150+
- Backend: raise `HTTPException` for expected failures and return typed response models when schemas already exist.
151+
- Backend: preserve middleware-based logging and 500 shaping for unexpected exceptions.
152+
- Frontend: preserve existing auth failure behavior that clears tokens and redirects on `401/403`.
153+
- Frontend: show API failures through shared toast/error helpers where possible.
154+
155+
## Testing Expectations
156+
157+
- Run the smallest relevant test first.
158+
- For backend logic changes, start with a targeted pytest invocation before the full suite.
159+
- For frontend UI changes, start with the narrowest Playwright file or `-g` match.
160+
- If API contracts change, run both backend and frontend checks that cover that contract.
161+
- If you regenerate the frontend client, review generated diffs separately from handwritten changes.
162+
163+
## Change Safety
164+
165+
- Do not hand-edit generated files unless the task explicitly requires it.
166+
- Do not silently change tooling or scripts unless the task is about build/dev workflow.
167+
- Never commit real secrets; `.env` values in docs are placeholders.
168+
- If models or schema change, generate and commit the matching Alembic revision.
169+
- Prefer minimal diffs that preserve current architecture and conventions.

CLAUDE.md

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

backend/tests/api/routes/test_users.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ def test_get_non_existing_user_permissions_error(
140140
f"{settings.API_V1_STR}/users/{user_id}",
141141
headers=normal_user_token_headers,
142142
)
143-
assert r.status_code == 404
144-
assert r.json() == {"detail": "User not found"}
143+
assert r.status_code == 403
144+
assert r.json() == {"detail": "The user doesn't have enough privileges"}
145145

146146

147147
def test_create_user_existing_username(

0 commit comments

Comments
 (0)