{"id":28175501,"url":"https://github.com/mthszr/gym-api","last_synced_at":"2025-07-24T14:34:15.868Z","repository":{"id":279222489,"uuid":"937647402","full_name":"mthszr/gym-api","owner":"mthszr","description":"A Gym API built with Node.js, TypeScript, and Fastify. It manages user authentication, gym discovery, and check-in tracking with proximity validation. Emphasizing Clean Architecture and SOLID principles for scalability and maintainability, it leverages PostgreSQL, Prisma ORM, and Docker, with comprehensive testing using Vitest and Supertest.","archived":false,"fork":false,"pushed_at":"2025-03-04T14:39:52.000Z","size":132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-15T23:14:30.349Z","etag":null,"topics":["backend","clean-architecture","fastify","javascript","nodejs","postgresql","prisma","rest-api","solid","typescript","vitest","zod"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mthszr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-23T15:21:56.000Z","updated_at":"2025-03-04T15:04:37.000Z","dependencies_parsed_at":"2025-03-03T17:27:16.263Z","dependency_job_id":null,"html_url":"https://github.com/mthszr/gym-api","commit_stats":null,"previous_names":["mthszr/api_solid","mthszr/gym-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mthszr/gym-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mthszr%2Fgym-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mthszr%2Fgym-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mthszr%2Fgym-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mthszr%2Fgym-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mthszr","download_url":"https://codeload.github.com/mthszr/gym-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mthszr%2Fgym-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266856183,"owners_count":23995645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","clean-architecture","fastify","javascript","nodejs","postgresql","prisma","rest-api","solid","typescript","vitest","zod"],"created_at":"2025-05-15T23:14:22.491Z","updated_at":"2025-07-24T14:34:15.852Z","avatar_url":"https://github.com/mthszr.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 🚀 Project Overview\n\nA gym API for a comprehensive fitness facility check-in management system built with modern backend technologies. This application demonstrates implementation of SOLID principles and Clean Architecture in a real-world TypeScript application.\n\nKey Features\n- User Management: Complete authentication flow with JWT and refresh tokens\n- Gym Discovery: Find gyms by location or search by name\n- Check-in System: Track gym attendance with location validation (within 100m)\n- Admin Portal: Special permissions for gym registration and check-in validation\n- Metrics Dashboard: View historical check-ins and user statistics\n\nThe system enforces business rules like daily check-in limits, proximity validation, and time-limited check-in verification, all while maintaining high security standards with password hashing and role-based access control.\n\nBuilt with scalability in mind, the application uses PostgreSQL for data persistence and follows a strict repository pattern to ensure clean separation between business logic and data access. All API endpoints are fully tested with comprehensive unit, and E2E tests.\n\n## 🔧 Getting Started\n\n### Prerequisites\n- Node.js 18+\n- PostgreSQL\n\n### Installation\n```bash\n# Clone the repository\ngit clone https://github.com/mthszr/gym-api.git\n\n# Install dependencies\nnpm install\n\n# Set up environment variables\ncp .env.example .env\n# Edit .env with your database credentials\n\n# Run migrations\nnpx prisma migrate dev\n\n# Start development server\nnpm run start:dev\n```\n\n### Testing\n\n```bash\n# Run unit tests\nnpm test\n\n# Run e2e tests\nnpm run test:e2e\n\n# Run test coverage\nnpm run test:coverage\n```\n\n## 🚦 API Routes\n\n### Authentication\n- `POST /sessions` - User login\n- `PATCH /token/refresh` - Refresh access token\n\n### Users\n- `POST /users` - Register new user\n- `GET /me` - Get authenticated user profile\n\n### Gyms\n- `POST /gyms` - Register new gym (admin only)\n- `GET /gyms/search` - Search gyms by name\n- `GET /gyms/nearby` - Find nearby gyms\n\n### Check-ins\n- `POST /gyms/:gymId/check-ins` - Create check-in\n- `PATCH /check-ins/:checkInId/validate` - Validate check-in (admin only)\n- `GET /check-ins/history` - Get user check-in history\n- `GET /check-ins/metrics` - Get user check-in count\n\n## 🛠 Technologies\n- Node.js\n- TypeScript\n- Fastify\n- Prisma ORM\n- PostgreSQL\n- Vitest\n- Supertest\n- Docker\n- JWT Authentication\n- Zod\n- Biome\n\n## 🏛️ Architecture\nThis project implements:\n\n- SOLID Principles\n  - Single Responsibility\n  - Open/Closed\n  - Liskov Substitution\n  - Interface Segregation\n  - Dependency Inversion\n\n- Clean Architecture\n  - Use Cases\n  - Controllers\n  - Repositories\n  - Entities\n\n- Design Patterns\n  - Repository Pattern\n  - Factory Pattern\n  - Dependency Injection\n\n## 🔐 Security Features\n- Password Hashing\n- JWT Authentication\n- Role-Based Access Control\n- Input Validation\n- Cookie Security\n\n## 📊 Test Coverage\n- Unit Tests\n- End-to-End Tests\n- In-Memory Test Database\n- Custom Test Environment\n\n## ✅ Functional Requirements (FR)\n- (✓) **User Registration:** The system must allow users to register.\n\n- (✓) **Authentication:** The system must enable user authentication.\n\n- (✓) **Profile Retrieval:** The system must allow logged-in users to retrieve their profiles.\n\n- (✓) **Check-in Count:** The system must display the total number of check-ins performed by the authenticated user.\n\n- (✓) **Check-in History:** Users must be able to access their check-in history.\n\n- (✓) **Search for Nearby Gyms:** The system must allow users to locate gyms near their location within 100 kilometers.\n\n- (✓) **Search for Gyms by Name:** The system must enable users to search for gyms using their name as a criterion.\n\n- (✓) **Perform Check-in:** The system must allow users to check in at a gym.\n\n- (✓) **Check-in Validation:** The system must enable validation of a user's check-in.\n\n- (✓) **Gym Registration:** The system must allow the registration of new gyms.\n\n\n## 📋 Business Rules (BR)\n- (✓) **Unique Email:** The system must not allow the registration of users with duplicate emails.\n\n- (✓) **Daily Check-in Limit:** Users cannot perform more than one check-in per day.\n\n- (✓) **Check-in Proximity:** Users can only check in if they are within a maximum distance of 100 meters from the gym.\n\n- (✓) **Check-in Time Validation:** Check-in validation must occur within 20 minutes of its creation.\n\n- (✓) **Admin Validation:** Only administrators can validate check-ins.\n\n- (✓) **Restricted Gym Registration:** Gym registration must be performed exclusively by administrators.\n\n\n## ⚙️ Non-Functional Requirements (NFR)\n- (✓) **Password Encryption:** User passwords must be stored in an encrypted format.\n\n- (✓) **Data Persistence:** Application data must be stored in a PostgreSQL database.\n\n- (✓) **Data Pagination:** All data lists must be paginated, displaying 20 items per page.\n\n- (✓) **Authentication with JWT:** User identification and authentication must be performed using JSON Web Tokens (JWT).\n\n## 📝 What I Learned\n\n### 1. Architecture \u0026 Design\n- Implementing SOLID principles in a real-world TypeScript application\n- Structuring a clean architecture with clear separation of concerns\n- Using the repository pattern to abstract data access\n- Implementing factory patterns for dependency injection\n- Building a scalable folder structure for enterprise applications\n\n### 2. Technical Skills\n- Creating a RESTful API with Fastify\n- Database modeling and querying with Prisma ORM\n- Working with PostgreSQL for production data\n- JWT authentication and refresh token flows\n- Role-based access control implementation\n- Geographic distance calculations for nearby gym features\n\n### 3. Testing Strategies\n- Test-Driven Development (TDD) approach\n- Creating in-memory repositories for unit testing\n- Building a custom Prisma test environment\n- E2E testing with Supertest\n- Integration testing for complex use cases\n- Setting up proper test isolation and database seeding\n\n### 4. Development Tools\n- Code quality enforcement with Biome\n- Docker containerization for development consistency\n- Environment configuration and security practices\n- Input validation with Zod\n- TypeScript configuration for strict type safety\n- Git workflow and project organization\n\n### 5. Performance \u0026 Security\n- Database query optimization strategies\n- Password hashing and secure authentication\n- Cookie-based security for refresh tokens\n- Rate limiting and input sanitization\n- Efficient pagination implementation","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmthszr%2Fgym-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmthszr%2Fgym-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmthszr%2Fgym-api/lists"}