A REST API for managing gym and fitness-related data, built with Node.js, Express.js, PostgreSQL, and Docker.
The API provides structured endpoints for retrieving and managing fitness data, with support for filtering, sorting, pagination, request validation, database seeding, and consistent error handling.
- RESTful API architecture
- PostgreSQL database integration
- Filtering and search support
- Sorting and pagination
- Request validation
- Structured error responses
- Database schema and seed scripts
- Health-check endpoint
- Docker-based local environment
- Postman collection for API testing
- Node.js
- Express.js
- PostgreSQL
- SQL
- Docker
- Docker Compose
- Zod
- JavaScript
- Postman
Make sure the following tools are installed:
- Node.js
- npm
- Docker
- Docker Compose
- PostgreSQL, when running without Docker
git clone https://github.com/maaz2692/gym-fitness-api.git
cd gym-fitness-apinpm installCreate a local environment file from the example:
Copy-Item .env.example .envcp .env.example .envUpdate the values inside .env according to your local environment.
Example:
PORT=3000
DB_HOST=localhost
DB_PORT=5432
DB_NAME=gym_fitness
DB_USER=your_database_user
DB_PASSWORD=your_database_passwordNever commit the
.envfile or real database credentials to the repository.
Start the API and PostgreSQL services:
docker compose up --buildTo stop the services:
docker compose downTo remove the containers and associated volumes:
docker compose down -vStart the development server:
npm run devWhen a development script is not configured, use:
npm startThe API will run on:
http://localhost:3000
Run the database schema script before starting the application when PostgreSQL is running locally.
Example:
psql -U your_database_user -d gym_fitness -f database/schema.sqlLoad sample data using the seed script:
psql -U your_database_user -d gym_fitness -f database/seed.sqlAdjust the file paths if the database scripts are stored in a different folder.
The API supports:
- Retrieving fitness records
- Filtering results using query parameters
- Sorting results by supported fields
- Paginating large result sets
- Validating incoming request data
- Returning structured success and error responses
Example request:
GET /api/resources?page=1&limit=10&sort=nameReplace /api/resources with the actual route used by the project.
Use the health endpoint to verify that the API is running:
GET /healthExample response:
{
"status": "ok"
}Update this section if your health-check route or response is different.
A Postman collection is included in the repository.
To use it:
- Open Postman.
- Select Import.
- Choose the collection file from the repository.
- Configure the base URL.
- Run the available requests.
Example base URL:
http://localhost:3000
.
├── src/
│ ├── controllers/ # Request and response handling
│ ├── routes/ # API route definitions
│ ├── services/ # Business logic
│ ├── middleware/ # Validation and error handling
│ ├── validators/ # Request validation schemas
│ ├── database/ # Database connection and queries
│ └── app.js # Express application setup
├── database/
│ ├── schema.sql # Database schema
│ └── seed.sql # Sample data
├── postman/ # Postman collection
├── .env.example
├── Dockerfile
├── docker-compose.yml
├── package.json
└── README.md
Change this structure so that it matches the repository exactly.
Incoming requests are validated before being processed.
Example validation error:
{
"error": "Validation failed",
"details": [
{
"field": "name",
"message": "Name is required"
}
]
}The actual error format may differ depending on the project implementation.
- Migrate the codebase to TypeScript
- Add automated unit and integration tests
- Add Swagger or OpenAPI documentation
- Add authentication and role-based authorization
- Add GitHub Actions for continuous integration
- Deploy the API publicly
- Add structured application logging
- Add rate limiting and security headers
Maaz Mustafa Khurshed Qazi
- GitHub: https://github.com/maaz2692
- LinkedIn: https://www.linkedin.com/in/qazi-maaz/
This project is available for educational and portfolio purposes.