Fitness Friends is a virtual pet application designed to make fitness tracking fun and engaging. By integrating with the Strava API, the app allows users to track their fitness activities, set goals, and care for a virtual pet whose health and behavior are influenced by the user's progress. Whether you're using a Garmin device, another fitness tracker, or no tracker at all, Fitness Friends provides a unique way to stay motivated on your fitness journey.
- Virtual Pet Interaction: Create and care for a virtual pet (e.g., Parrot, Turtle) whose health and behavior change based on your fitness progress.
- Fitness Goal Tracking: Set weekly goals for distance, duration, or frequency across various sports (e.g., running, cycling, swimming).
- Strava Integration: Connect your Strava account to sync fitness activities from multiple trackers.
- Dynamic Pet Behavior: Pets respond to your progress with different states (e.g., Healthy, Sick, Dead).
- User-Friendly Interface: Register, log in, and interact with your pet through a simple console-based interface.
- Java: Core application logic and object-oriented design.
- H2 Database: Database for storing user data, fitness goals, and pet details.
- Hibernate: Manage database interactions
- SpringBoot: Build and run the application
- JPA: Object-relational mapping to map Java classes to database tables.
- Spring Data: Simplifies database operations using repository interfaces.
- Spring Controllers: Implements RESTful APIs
- Strava API: Sync fitness data from multiple trackers.
- PlantUML: UML diagrams for design documentation.
- Maven: Build and dependency management.
This project leverages several software design patterns to ensure a robust, maintainable, and scalable architecture:
The Challenge: Fitness Friends allows users to create weekly goals for multiple sports, including running, cycling, and swimming. Each sport supports different goal types, such as distance, duration, and frequency. Creating these goal objects directly within the service layer would have tightly coupled the application to concrete implementations. Every time a new sport or goal type was introduced, existing code would need to be modified, making the application harder to maintain.
Design Decision: To separate object creation from business logic, I implemented the Abstract Factory pattern. Each factory is responsible for producing a family of related goal objects for a particular sport, while the rest of the application depends only on shared interfaces rather than concrete classes. This approach keeps the goal creation process consistent across sports and allows additional sports or goal types to be introduced with minimal changes to the existing codebase.
The Challenge: A pet's behaviour depends entirely on its current health state. A healthy pet can move, eat, and play, whereas a sick pet has limited interactions, and a dead pet cannot interact at all. Implementing this behaviour using conditional statements throughout the application would have scattered state-specific logic across multiple classes, making it increasingly difficult to maintain as additional states or behaviours were introduced.
Design Decision: To encapsulate state-dependent behaviour, I implemented the State pattern. Each health state is represented by its own class implementing a common interface. The pet delegates behaviour to its current state rather than determining actions through conditional logic. This keeps behaviour isolated, reduces complexity within the pet class, and makes introducing new states possible without modifying existing implementations
- Clone the Repository:
git clone https://github.com/emma-horton/FitnessFriendsSpringBoot.git cd FitnessFriendsSpringBoot - Build the Project:
mvn clean install
- Run the Application:
./mvnw spring-boot:run
- Register:
- Register a new account and connect your strava
POST /api/users/register
- Login:
- Login to account
POST /api/users/login
- Create a Pet:
- Choose a pet type (e.g., Parrot, Turtle) and name your pet.
POST /api/pets
- Set Fitness Goals:
- Define weekly goals for distance, duration, or frequency in your preferred sport (run, ride or swim).
POST /api/goals
- Interact with Your Pet:
- View your pet's status, play with it, and ensure its health by meeting your fitness goals.
GET /api/pets/{userId} GET /api/pets/{userId}/move GET /api/pets/{userId}/eat GET /api/pets/{userId}/play
- Add more pet types (e.g., Dog, Cat) with unique behaviors.
- Introduce new fitness goal categories (e.g., calories burned).
- Implement a graphical user interface (GUI) for a more interactive experience.
- Add real-time notifications for pet health updates.
- Explore additional design patterns, such as the Observer Pattern for real-time updates.
Contributions are welcome! If you’d like to contribute, please fork the repository and submit a pull request.
Details
To access database: http://localhost:8080/h2-console, JDBC URL: jdbc:h2:file:./data/fitness-friends, username: saFitnessFriendsSpringBoot/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ ├── com/
│ │ │ │ ├── fitnessfriends/
│ │ │ │ │ ├── controller/ # REST API controllers
│ │ │ │ │ ├── dto/ # Data Transfer Objects (DTOs)
│ │ │ │ │ ├── entity/ # JPA entities for database mapping
│ │ │ │ │ ├── repository/ # Spring Data JPA repositories
│ │ │ │ │ ├── service/ # Business logic and services
│ │ │ │ │ │ ├── pet/ # Pet-related logic
│ │ │ │ │ │ ├── goal/ # Goal evaluation strategies
│ │ │ │ │ ├── config/ # Application configuration
│ │ │ │ │ ├── utils/ # Utility classes
│ │ │ │ │ ├── FitnessFriendsApplication.java # Main application entry point
│ │ ├── resources/
│ ├── test/
│ │ ├── java/
│ │ │ ├── com/
│ │ │ │ ├── fitnessfriends/
│ │ │ │ │ ├── controller/ # Controller tests
│ │ │ │ │ ├── service/ # Service tests
│ │ │ │ │ ├── repository/ # Repository tests
│ │ │ │ │ ├── entity/ # Entity tests
├── pom.xml # Maven configuration file
├── README.md # Project documentation
├── mvnw # Maven wrapper script (Linux/Mac)
├── mvnw.cmd # Maven wrapper script (Windows)
