diff --git a/README.md b/README.md index fc4e5c5..a58521a 100644 --- a/README.md +++ b/README.md @@ -1 +1,142 @@ -# back \ No newline at end of file +# ๐Ÿš‚ Track&Train Backend + +> **A modern, modular, and testable backend for fitness & coaching platforms, built with Python, FastAPI, and a full Hexagonal Architecture.** + +--- + +## ๐Ÿ—๏ธ Project Architecture + +![Project Architecture Diagram](./image.png) + +- **Entrypoints**: FastAPI routers, schemas, and dependencies +- **Domain**: Pure business logic, models, and service orchestration +- **Adapters**: Infrastructure for SQL (Postgres/SQLAlchemy) and in-memory (for tests) +- **Tests**: Full test coverage for all features using in-memory adapters + +--- + +## โœจ Features + +- ๐Ÿง‘โ€๐Ÿ’ผ **User & Coach Management**: Register, login, promote users to coaches, manage roles +- ๐Ÿ‹๏ธ **Group Management**: Create, update, delete, join/leave groups, add/remove members +- ๐Ÿ† **Training & Exercise**: CRUD for trainings and exercises +- ๐Ÿฝ๏ธ **Diet**: CRUD for diets +- ๐Ÿ” **JWT Auth**: Secure endpoints with role-based access +- ๐Ÿงฉ **Hexagonal Architecture**: Clean separation of concerns, easy to test and extend +- ๐Ÿงช **Comprehensive Tests**: All business logic tested with in-memory adapters +- ๐Ÿš€ **Hot Reload**: Fast development with Docker volume binding + +--- + +## โš™๏ธ Installation & Usage + +### 1๏ธโƒฃ Local Development + +```bash +# 1. Copy environment variables +cp .env.example .env +# 2. Edit .env to set your secrets and DB connection + +# 3. Create and activate a virtual environment +uv sync +source .venv/bin/activate + +# 4. Start the API (with hot reload) +uvicorn src.main:app --reload --host 127.0.0.1 --port 8000 +``` + +- The API will be available at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) + +### 2๏ธโƒฃ Docker Compose (API + Postgres) + +```bash +# 1. Copy environment variables +cp .env.example .env +# 2. Edit .env as needed + +# 3. Start everything (API + DB + hot reload) +docker compose up -d +``` + +- The backend is mounted with a volume on `src/` for instant code reload +- Database and backend are both started and networked automatically + +--- + +## ๐Ÿงช Running Tests + +- All tests are designed to run sequentially (not isolated per test) +- You can run all API tests in order with: + +```bash +pytest src/entrypoints/api/tests/profile.py src/entrypoints/api/tests/group.py src/entrypoints/api/tests/exercise.py src/entrypoints/api/tests/training.py src/entrypoints/api/tests/diet.py +``` + +- You can also run a single test file if needed, but tests are designed to be run in sequence for full state setup. + +--- + +## ๐Ÿ“‚ Main Project Structure + +``` +back/ +โ”œโ”€โ”€ src/ +โ”‚ โ”œโ”€โ”€ __init__.py +โ”‚ โ”œโ”€โ”€ main.py # FastAPI app entrypoint +โ”‚ โ”œโ”€โ”€ container.py # Dependency injection container +โ”‚ โ”œโ”€โ”€ domain/ +โ”‚ โ”‚ โ”œโ”€โ”€ model/ # Domain models (Profile, Group, etc.) +โ”‚ โ”‚ โ”œโ”€โ”€ services/ # Business logic (service layer) +โ”‚ โ”‚ โ”œโ”€โ”€ ports/ # Interfaces (repositories, etc.) +โ”‚ โ”‚ โ”œโ”€โ”€ exceptions.py # Domain exceptions +โ”‚ โ”œโ”€โ”€ adapters/ +โ”‚ โ”‚ โ”œโ”€โ”€ sqlalchemy/ # SQLAlchemy (Postgres) implementation +โ”‚ โ”‚ โ”œโ”€โ”€ inmemory/ # In-memory implementation for tests +โ”‚ โ”œโ”€โ”€ entrypoints/ +โ”‚ โ”‚ โ”œโ”€โ”€ api/ # FastAPI routers, schemas, dependencies +โ”‚ โ”‚ โ””โ”€โ”€ tests/ # Pytest test files +โ”‚ โ””โ”€โ”€ ... +โ”œโ”€โ”€ Dockerfile +โ”œโ”€โ”€ docker-compose.yml +โ”œโ”€โ”€ pyproject.toml +โ”œโ”€โ”€ .env.example +โ””โ”€โ”€ README.md +``` + +--- + +## ๐Ÿ“ Example API Endpoints + +- `POST /profiles` โ†’ Register user +- `POST /profiles/login` โ†’ Login +- `PATCH /profiles/{id}/roles`โ†’ Promote user to coach +- `POST /groups` โ†’ Create group (coach/admin) +- `GET /groups` โ†’ List all groups +- `GET /groups/coachs/mine` โ†’ List all coaches for current user +- `POST /groups/{group_id}/members/{user_id}` โ†’ Add member +- `DELETE /groups/{group_id}/leave` โ†’ Leave group +- ...and many more! + +--- + +## ๐Ÿ’ก Why Hexagonal Architecture? + +- **Testability**: Swap adapters (SQL/in-memory) for real DB or fast tests +- **Maintainability**: Business logic is pure and isolated +- **Extensibility**: Add new adapters (e.g., REST, gRPC, CLI) without touching domain +- **Separation of Concerns**: Each layer has a single responsibility + +--- + +## ๐Ÿ› ๏ธ Contributing + +- Fork, branch, and submit PRs! +- All new features should include tests +- Please update the changelog for any user-facing changes + +--- + +## ๐Ÿง‘โ€๐Ÿ’ป Authors & License + +- Made with โค๏ธ by the Track&Train team +- MIT License \ No newline at end of file diff --git a/image.png b/image.png new file mode 100644 index 0000000..2deee48 Binary files /dev/null and b/image.png differ