This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a full-stack ecommerce application with a FastAPI backend implementing hexagonal architecture and a React TypeScript frontend. The project manages products, users, and orders with OAuth2 authentication.
- Backend: FastAPI, Motor (MongoDB), OAuth2, Pydantic
- Frontend: React 19, TypeScript, Vite, TailwindCSS, Radix UI, React Query, React Router
- Database: MongoDB (with Docker setup available)
- Architecture: Hexagonal Architecture (Ports & Adapters) for backend, Feature-based architecture for frontend
# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -
# Install dependencies
poetry install
# Activate virtual environment
poetry shell
# Run development server
poetry run uvicorn src.main:app --reload
# Run tests with coverage
poetry run pytest --cov=src --cov-report=term-missing --cov-report=html
# Run specific test types
poetry run pytest -m unit # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m "not slow" # Skip slow tests
# Run specific test file
poetry run pytest tests/test_domain_entities.py
# Run tests matching pattern
poetry run pytest -k "test_user"
# Add a new dependency
poetry add package-name
# Add a development dependency
poetry add --group dev package-name
# Update dependencies
poetry update
# Show installed packages
poetry show
# Export to requirements.txt (if needed for compatibility)
poetry export -f requirements.txt --output requirements.txt# Install dependencies
npm install
# Run development server
npm run dev
# Build for production
npm run build
# Lint code
npm run lint
# Preview production build
npm run preview# Start MongoDB with Docker
docker compose up -dThe backend follows hexagonal architecture with clear separation of concerns:
- Entities (
entities/): Core business objects using@dataclasswith validation in__post_init__ - Exceptions (
exceptions/): Domain-specific exceptions for business rule violations
- Ports (
ports/): Repository interfaces (abstract contracts) - Use Cases (
use_cases/): Business logic orchestration, one publicexecutemethod per use case
- Adapters (
adapters/repositories/): MongoDB repository implementations - Web (
web/): FastAPI routers, DTOs, mappers, dependencies- Routers: Thin controllers delegating to use cases
- DTOs: Pydantic models for request/response validation
- Mappers: Clean conversion between DTOs and domain entities
- Dependencies: Dependency injection with
@lru_cache()for repositories
The frontend is organized by features with each feature containing:
- Components (
components/): React components using feature context - Data (
data/): Schemas (Zod), services (API calls) - Hooks (
hooks/):- Context Hook (
use{Feature}Context.tsx): Feature state management and operations using context - Business Hook (
use{Feature}.tsx): Feature state management and operations - Mutations (
mutations/): React Query mutations for data modification - Queries (
queries/): React Query queries for data fetching
- Context Hook (
- Data (
data/): API client, app storage, query client setup - Hooks (
hooks/): Shared hooks across features
- Radix UI-based reusable components with TailwindCSS styling
- Use dependency injection throughout the web layer
- All use cases follow the pattern: constructor injection → single
executemethod - Domain entities validate in
__post_init__and business methods - Repository implementations use MongoDB with Motor async driver
- DTOs use Pydantic with comprehensive validation
- Map domain exceptions to appropriate HTTP status codes
- Each feature exports a context provider and custom hook
- Components import UI components from
@/components/ui/ - Use
use{Feature}Contextfor accessing feature state and operations for context states - Use
use{Feature}for accessing feature state and operations - Mutations return:
{action, isLoading, error, isSuccess} - Services use axios for API communication
- Type safety with TypeScript and Zod schemas
- Backend uses pytest with comprehensive test configuration
- Tests organized by layers: domain, service, repository, API, integration
- Coverage requirement: 80%
- Use markers for test categorization:
unit,integration,slow,auth,api
- OAuth2 authentication with JWT tokens
- Password hashing with bcrypt
- Protected routes on both backend and frontend
- Environment-based configuration for sensitive data
backend/src/app.py: FastAPI application factorybackend/src/main.py: Application entry pointfrontend/src/main.tsx: React application entry pointbackend/pytest.ini: Test configurationbackend/run_tests.py: Comprehensive test runner with multiple options
- At the starting point of a feature on plan mode phase you MUST ALWAYS init a
.claude/sessions/context_session_{feature_name}.mdwith yor first analisis - You MUST ask to the subagents that you considered that have to be involved about the implementation and check their opinions, try always to run them on parallel if is posible
- After a plan mode phase you ALWAYS update the
.claude/sessions/context_session_{feature_name}.mdwith the definition of the plan and the recomentations of the subagents
- Before you do any work, MUST view files in
.claude/sessions/context_session_{feature_name}.mdfile to get the full context (x being the id of the session we are operate) .claude/sessions/context_session_{feature_name}.mdshould contain most of context of what we did, overall plan, and sub agents will continusly add context to the file- After you finish the each phase, MUST update the
.claude/sessions/context_session_{feature_name}.mdfile to make sure others can get full context of what you did - After you finish the work, MUST update the
.claude/sessions/context_session_{feature_name}.mdfile to make sure others can get full context of what you did
- After finish the final implementation MUST use qa-criteria-validator subagent to provide a report feedback an iterate over this feedback until acceptance criterias are passed
- After qa-criteria-validator finish, you MUST review their report and implement the feedback related with the feature
You have access to 8 subagents:
- shadcn-ui-architect: all task related to UI building & tweaking HAVE TO consult this agent
- qa-criteria-validator: all final client UI/UX implementations has to be validated by this subagent to provide feedback an iterate.
- ui-ux-analyzer: all the task related with UI review, improvements & tweaking HAVE TO consult this agent
- pydantic-ai-architect: all task related to ai agents using pydantic-ai framework & tweaking HAVE TO consult this agent
- frontend-developer: all task related to business logic in the client side before create the UI building & tweaking HAVE TO consult this agent
- frontend-test-engineer: all task related to business logic in the client side after implementation has to consult this agent to get the necesary test cases definitions
- backend-developer: all task related to business logic in the backend side HAVE TO consult this agent
- backend-test-engineer: all task related to business logic in the backned side after implementation has to consult this agent to get the necesary test cases definitions
Subagents will do research about the implementation and report feedback, but you will do the actual implementation;
When passing task to sub agent, make sure you pass the context file, e.g. .claude/sessions/context_session_{feature_name}.md.
After each sub agent finish the work, make sure you read the related documentation they created to get full context of the plan before you start executing