Imported from SM23001/Gym1 (
AGENTS.md). Install upstream withnpx skills add SM23001/Gym1. Copyright stays with the author.
Agent guide — Gym1
Command-line gym management in Python with PostgreSQL. Entry point: python cli.py.
Database (required)
PostgreSQL runs on 192.168.1.34:5432 (LAN). The app and tests need network access to that host.
- Copy env template:
cp .env.example .env - Use
gymdb_testfor pytest (tests TRUNCATE all tables on every case) - Never point pytest at a production database
Create the test database once on the server if needed:
CREATE DATABASE gymdb_test OWNER gymuser;
Setup
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
Or: make setup
Verify changes
Always run after code changes:
make test
# or: .venv/bin/python -m pytest -q
Quick connectivity check:
make check-db
Run the app
make run
# or: .venv/bin/python cli.py
Seed demo data
Load sample trainers, members, classes, enrollments, and attendance via the service layer:
make seed
# or: .venv/bin/python seed.py --reset
Use GYM_DB_NAME=gymdb in .env (not gymdb_test). The script refuses to seed the test database. Without --reset, seeding is skipped if trainers already exist.
Architecture (do not violate)
| Layer | Modules | Responsibility |
|---|---|---|
| Presentation | cli.py, ui.py, colors.py |
Menu, input, output. No business logic. |
| Service | service.py |
Use cases, rules, BusinessError. No SQL. |
| Domain | models.py |
Dataclasses only. |
| Repository | repository.py |
SQL and persistence. No business rules. |
| Infrastructure | db.py, config.py |
Connection, schema, settings. |
Dependency flow: CLI → service → repository → db. Never put SQL in service.py or business rules in repository.py.
Adding a feature
Follow this order and match existing patterns:
models.py— entity if neededrepository.py— SQL functionsservice.py— validation and business rulescli.py/ui.py— menu and user messagestests/test_*_crud.pyortests/test_service.py— copy fixture style fromtest_trainer_crud.py
Team ownership
| Focus | Primary files |
|---|---|
| Core (business + data) | service.py, repository.py, db.py, config.py, models.py |
| UI/CLI | cli.py, ui.py, colors.py |
| Quality + docs | tests/, conftest.py, README.md, AGENTS.md |
MCP (Cursor)
Project MCP config: .cursor/mcp.json — gym-postgres server for schema inspection and read queries during development.
Requirements: Node.js (npx) and a reachable PostgreSQL test database (gymdb_test).
- Copy
.env.exampleto.env(sameGYM_DB_*vars as the app). - Restart Cursor or toggle the server in Settings → MCP.
- The wrapper
scripts/run-mcp-postgres.shloads.envand always connects togymdb_test, not productiongymdb.
Use MCP for debugging and exploration only. Business rules live in service.py; prefer make test to verify behavior.
Constraints
- Never commit
.env(secrets stay local) - Tests use real PostgreSQL — no mocks for persistence
- Keep CLI thin: catch
BusinessErrorandValueError, delegate to service - Minimize scope: match existing naming, types, and patterns in each layer