Fittlr is a comprehensive fitness application that provides users with a platform to manage their fitness activities, track their progress, and engage with a community of fitness enthusiasts. The backend of Fittlr is built using Node.js, Express, and Prisma, and it provides a robust API for managing user authentication, fitness data, gym bookings, and more.
Before running the app, ensure you have the following installed:
- Node.js (v14 or higher)
- PostgreSQL (v12 or higher)
- Google Cloud account for OAuth 2.0 credentials
The project directory structure is organized as follows:
Fittlr-Backend/
├── controllers/
│ ├── auth/
│ │ └── User.js
│ ├── challenges/
│ │ └── challengeController.js
│ ├── community/
│ │ ├── commentController.js
│ │ ├── followController.js
│ │ ├── likeController.js
│ │ └── postController.js
│ ├── fallback/
│ │ ├── login.js
│ │ ├── logout.js
│ │ └── register.js
│ ├── Gym_Schedule/
│ │ ├── bookingFlow.controller.js
│ │ ├── bookingsummry.js
│ │ ├── createBooking.js
│ │ ├── gymSchedule.controller.js
│ │ ├── machineService.controller.js
│ │ └── machineTracking.js
│ ├── Home/
│ │ ├── googleFit.controller.js
│ │ └── googleFitfallback.js
│ ├── Profile/
│ │ └── profile.js
│ └── tickets/
│ └── tickets.js
├── db/
│ └── connect.js
├── errors/
│ ├── bad-request.js
│ ├── custom-api.js
│ ├── index.js
│ ├── not-found.js
│ └── unauthenticated.js
├── middleware/
│ ├── authentication.js
│ ├── error-handler.js
│ ├── logger.js
│ ├── not-found.js
│ └── upload.js
├── prisma/
│ ├── migrations/
│ │ ├── 20250320053553_init/
│ │ │ └── migration.sql
│ │ ├── 20250321183015_init_models/
│ │ │ └── migration.sql
│ │ ├── 20250321190437_init_models/
│ │ │ └── migration.sql
│ │ ├── 20250321192113_init_models/
│ │ │ └── migration.sql
│ │ ├── 20250322064642_init_models/
│ │ │ └── migration.sql
│ │ ├── 20250322071616_add_password_field/
│ │ │ └── migration.sql
│ │ ├── 20250322095847_add_machine_status_tickets_update/
│ │ │ └── migration.sql
│ │ └── migration_lock.toml
│ └── schema.prisma
├── routes/
│ ├── booking.js
│ ├── challengeRoutes.js
│ ├── community/
│ │ ├── commentRoutes.js
│ │ ├── followRoutes.js
│ │ ├── likeRoutes.js
│ │ └── postRoutes.js
│ ├── fallback.js
│ ├── googleAuth.js
│ ├── googlefit.js
│ ├── profile.js
│ └── ticket.js
├── scripts/
│ └── setup-db.js
├── services/
│ ├── authConfig.service.js
│ ├── cache.js
│ ├── cachePreloader.js
│ ├── cloudflare.js
│ ├── googleAuth.service.js
│ ├── googleFit.service.js
│ ├── jwt_create.js
│ ├── passport.js
│ ├── passport.service.js
│ ├── password_auth.js
│ ├── token.service.js
│ └── user.service.js
├── utils/
│ ├── configValidator.js
│ ├── cookie.utils.js
│ ├── tokenRefresh.js
├── .env.example
├── .gitignore
├── app.js
├── howto.txt
├── package.json
├── user_jouney.txt
└── README.md
-
Google OAuth Login
- Endpoint:
/api/v1/user/auth/google - Method:
GET - Description: Initiates Google OAuth login process.
- Endpoint:
-
Google OAuth Callback
- Endpoint:
/api/v1/user/auth/google/callback - Method:
GET - Description: Handles Google OAuth callback and user authentication.
- Endpoint:
-
Fallback Login
- Endpoint:
/api/v1/user/auth/fallback/login - Method:
POST - Description: Handles fallback login with email and password.
- Request Body:
{ "email": "user@example.com", "password": "password123" }
- Endpoint:
-
Fallback Register
- Endpoint:
/api/v1/user/auth/fallback/register - Method:
POST - Description: Handles fallback user registration.
- Request Body:
{ "email": "user@example.com", "password": "password123", "name": "John Doe" }
- Endpoint:
-
Get User Profile
- Endpoint:
/api/v1/user/profile - Method:
GET - Description: Retrieves the authenticated user's profile.
- Endpoint:
-
Update User Profile
- Endpoint:
/api/v1/user/profile - Method:
PUT - Description: Updates the authenticated user's profile.
- Request Body:
{ "name": "John Doe" }
- Endpoint:
-
Get Gym Availability
- Endpoint:
/api/v1/user/booking/availability - Method:
GET - Description: Retrieves gym availability for booking.
- Query Parameters:
gymId(required): ID of the gym.date(optional): Date for availability check (YYYY-MM-DD).startTime(optional): Start time for availability check (HH:MM).duration(optional): Duration for availability check (minutes).
- Endpoint:
-
Create Booking
- Endpoint:
/api/v1/user/booking/create - Method:
POST - Description: Creates a new gym booking.
- Request Body:
{ "userId": "user123", "gymId": "gym123", "startTime": "2023-10-01T10:00:00Z", "duration": 60, "selectedMachines": [ { "id": "machine123", "name": "Treadmill" } ] }
- Endpoint:
-
Get Booking Summary
- Endpoint:
/api/v1/user/booking/booksummary - Method:
GET - Description: Retrieves the summary of a specific booking.
- Query Parameters:
bookingId(required): ID of the booking.userId(required): ID of the user.
- Endpoint:
-
Create Post
- Endpoint:
/api/v1/user/community/posts - Method:
POST - Description: Creates a new post in the community.
- Request Body:
{ "content": "This is a new post", "imageUrl": "https://example.com/image.jpg" }
- Endpoint:
-
Get Posts
- Endpoint:
/api/v1/user/community/posts - Method:
GET - Description: Retrieves all posts in the community.
- Query Parameters:
page(optional): Page number for pagination.limit(optional): Number of posts per page.
- Endpoint:
-
Create Comment
- Endpoint:
/api/v1/user/community/comments/:postId - Method:
POST - Description: Creates a new comment on a post.
- Request Body:
{ "content": "This is a comment" }
- Endpoint:
-
Get Comments
- Endpoint:
/api/v1/user/community/comments/:postId - Method:
GET - Description: Retrieves comments for a specific post.
- Query Parameters:
page(optional): Page number for pagination.limit(optional): Number of comments per page.
- Endpoint:
-
Like Post
- Endpoint:
/api/v1/user/community/likes/:postId - Method:
POST - Description: Likes or unlikes a post.
- Endpoint:
-
Follow User
- Endpoint:
/api/v1/user/community/follow/:userIdToFollow - Method:
POST - Description: Follows a user.
- Endpoint:
-
Unfollow User
- Endpoint:
/api/v1/user/community/unfollow/:userIdToUnfollow - Method:
POST - Description: Unfollows a user.
- Endpoint:
-
Send Challenge
- Endpoint:
/api/v1/user/challenges/send/:receiverId - Method:
POST - Description: Sends a new challenge to a user.
- Request Body:
{ "type": "COUNT_BASED", "description": "50 Push-ups", "count": 50 }
- Endpoint:
-
Get Received Challenges
- Endpoint:
/api/v1/user/challenges/received - Method:
GET - Description: Retrieves challenges received by the authenticated user.
- Query Parameters:
status(optional): Filter by challenge status (PENDING, ACCEPTED, COMPLETED, REJECTED).page(optional): Page number for pagination.limit(optional): Number of challenges per page.
- Endpoint:
-
Get Sent Challenges
- Endpoint:
/api/v1/user/challenges/sent - Method:
GET - Description: Retrieves challenges sent by the authenticated user.
- Query Parameters:
status(optional): Filter by challenge status (PENDING, ACCEPTED, COMPLETED, REJECTED).page(optional): Page number for pagination.limit(optional): Number of challenges per page.
- Endpoint:
-
Update Challenge Status
- Endpoint:
/api/v1/user/challenges/:id/status - Method:
PUT - Description: Updates the status of a challenge.
- Request Body:
{ "status": "ACCEPTED" }
- Endpoint:
-
Delete Challenge
- Endpoint:
/api/v1/user/challenges/:id - Method:
DELETE - Description: Deletes a challenge.
- Endpoint:
-
Get Fitness Summary
- Endpoint:
/api/v1/user/auth/google/fit/summary - Method:
GET - Description: Retrieves fitness data summary for the authenticated user.
- Query Parameters:
days(optional): Number of days to fetch data for (default: 7).
- Endpoint:
-
Get Step Count
- Endpoint:
/api/v1/user/auth/google/fit/steps - Method:
GET - Description: Retrieves step count data for the authenticated user.
- Query Parameters:
days(optional): Number of days to fetch data for (default: 7).
- Endpoint:
-
Get Calories Burned
- Endpoint:
/api/v1/user/auth/google/fit/calories - Method:
GET - Description: Retrieves calories burned data for the authenticated user.
- Query Parameters:
days(optional): Number of days to fetch data for (default: 7).
- Endpoint:
-
Get Distance Walked
- Endpoint:
/api/v1/user/auth/google/fit/distance - Method:
GET - Description: Retrieves distance walked data for the authenticated user.
- Query Parameters:
days(optional): Number of days to fetch data for (default: 7).
- Endpoint:
-
Clone the repository:
git clone https://github.com/srijan2607/Fittlr-Backend.git cd Fittlr-Backend -
Install dependencies:
npm install
-
Set up the environment variables:
- Create a
.envfile in the root directory. - Copy the contents of
.env.exampleinto.env. - Update the values in
.envwith your configuration.
- Create a
-
Set up the database:
npm run db:setup
-
Start the server:
npm start
-
The server should now be running at
http://localhost:7900.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License.