{"id":27137940,"url":"https://github.com/adarshkr357/recipes-api","last_synced_at":"2026-05-02T20:40:51.230Z","repository":{"id":286465488,"uuid":"961478498","full_name":"adarshkr357/recipes-api","owner":"adarshkr357","description":"A RESTful API built in PHP that manages recipes, including CRUD operations, search, and rating functionality. The API uses PostgreSQL for persistence, JWT for authentication, and auto-loads initial recipe data from TheMealDB. It is fully containerized using Docker, follows REST best practices, and includes unit tests with PHPUnit.","archived":false,"fork":false,"pushed_at":"2025-04-06T16:14:19.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-29T08:55:40.282Z","etag":null,"topics":["api-design","docker","jwt","pdo","php","postgresql","production-ready","recipes","rest-api","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adarshkr357.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2025-04-06T15:55:31.000Z","updated_at":"2025-04-06T16:22:52.000Z","dependencies_parsed_at":"2025-04-06T17:35:14.534Z","dependency_job_id":null,"html_url":"https://github.com/adarshkr357/recipes-api","commit_stats":null,"previous_names":["adarshkr357/recipes-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/adarshkr357/recipes-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adarshkr357%2Frecipes-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adarshkr357%2Frecipes-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adarshkr357%2Frecipes-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adarshkr357%2Frecipes-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adarshkr357","download_url":"https://codeload.github.com/adarshkr357/recipes-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adarshkr357%2Frecipes-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32549387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T19:18:06.202Z","status":"ssl_error","status_checked_at":"2026-05-02T19:16:21.335Z","response_time":132,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["api-design","docker","jwt","pdo","php","postgresql","production-ready","recipes","rest-api","unit-testing"],"created_at":"2025-04-08T04:37:20.745Z","updated_at":"2026-05-02T20:40:46.204Z","avatar_url":"https://github.com/adarshkr357.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Production-Ready Recipes API\n\n## Overview\n\nThis project is a production-ready PHP API for managing recipes and user authentication. It demonstrates a complete modern API built using:\n\n- **PHP 8.2+**  \n- **PostgreSQL** for persistent storage  \n- **PDO** with PostgreSQL driver  \n- **JWT** for authentication  \n- **Docker \u0026 Docker Compose** (optional) for containerized deployment  \n- **Composer** for dependency management  \n- **PHPUnit** for testing\n\nKey features include:\n\n- **CRUD Endpoints for Recipes:**  \n  Create, read, update, delete, and search recipes; also, rate recipes with calculated averages.\n  \n- **User Authentication:**  \n  Simple registration and login endpoints (implemented as GET endpoints for demo purposes) that generate JWT tokens after verifying credentials.\n  \n- **Automatic Initial Data Load:**  \n  If the recipes table is empty on startup, the API auto-loads recipe data from [TheMealDB](https://www.themealdb.com).\n\n- **Database Schema Initialization:**  \n  The application auto-creates required tables (`users`, `recipes`, and `ratings`) if they do not exist. Foreign key constraints (including `ON DELETE CASCADE` on ratings) are applied for data integrity.\n\n## Requirements\n\n- **PHP 8.2+** with these extensions enabled:\n  - `pdo`\n  - `pdo_pgsql`\n  - `pgsql`\n- **PostgreSQL** 9.5+\n- **Composer**\n- **Docker \u0026 Docker Compose** (optional)\n- **PHPUnit 9+** for testing\n\n## Setup \u0026 Installation\n\n### 1. Clone the Repository\n\n```bash\ngit clone https://github.com/adarshkr357/recipes-api.git\ncd recipes-api\n```\n\n### 2. Install Dependencies\n\nRun the following command to install PHP dependencies:\n\n```bash\ncomposer install\n```\n\n### 3. Configure Environment Variables\n\nCreate a `.env` file in the project root with your environment-specific settings. For example:\n\n```dotenv\n# Database configuration\nDB_HOST=postgres\nDB_PORT=5432\nDB_NAME=hellofresh\nDB_USER=hellofresh\nDB_PASS=hellofresh\n\n# JWT configuration\nJWT_SECRET=\u003cYour JWT Secret Key\u003e\nJWT_ISSUER=http://localhost\nJWT_AUDIENCE=http://localhost\nJWT_EXPIRATION=3600\n```\n\n#### Generating Your JWT Secret Key\n\nUse this PHP command to generate a secure key:\n\n```bash\nphp -r \"echo bin2hex(random_bytes(32));\"\n```\n\nCopy the output (a 64-character hexadecimal string) into your `.env` under `JWT_SECRET`.\n\n### 4. Database Setup\n\nWhen the application starts, it automatically initializes the database:\n- It creates the required tables (`users`, `recipes`, and `ratings`) if they do not exist.\n- It seeds recipe data from TheMealDB if the `recipes` table is empty.\n\n**To manually truncate (empty) all tables:**\n\n```bash\ndocker exec -it \u003ccontainer\u003e psql -h localhost -p 5432 -U hellofresh -d hellofresh -c \"TRUNCATE TABLE users, recipes, ratings RESTART IDENTITY CASCADE;\"\n```\n\nMake sure to adjust the host, port, user, and database name as needed.\n\n### 5. Running the Application\n\n#### Using Docker\n\nBuild and start containers using Docker Compose:\n\n```bash\ndocker-compose build\ndocker-compose up -d\n```\n\nThen, open your browser at `http://localhost:8080` (or your configured port).\n\n#### Without Docker\n\nYou can start a local PHP server from the project root:\n\n```bash\nphp -S localhost:8080 -t web\n```\n\nThen open [http://localhost:8080](http://localhost:8080) in your browser.\n\n## API Endpoints\n\n### Public (Unauthenticated) Endpoints\n\n- **GET /**  \n  Returns API documentation (an overview of all endpoints).\n\n- **GET /recipes**  \n  List all recipes from the database.\n\n- **GET /recipes/{id}**  \n  Retrieve details for a specific recipe.\n\n- **GET /recipes/search?q=QUERY**  \n  Search for recipes by name.\n\n### Protected Endpoints  \n*(These endpoints are intended to be protected by JWT-based authentication using AuthMiddleware. They are demonstrated here but are not enforced by default in this example.)*\n\n- **POST /recipes** – Create a new recipe.\n- **PUT/PATCH /recipes/{id}** – Update an existing recipe.\n- **DELETE /recipes/{id}** – Delete a recipe.\n- **POST /recipes/{id}/rating** – Submit a recipe rating.\n\n### Authentication Endpoints (Implemented as GET for Demo)\n\n- **GET /auth/register?username=...\u0026password=[...]**  \n  Registers a new user using the provided username and password. An email is optional; if omitted, a default email value (`username@example.com`) is used.\n\n- **GET /auth/login?username=...\u0026password=...**  \n  Logs in a user and returns a JWT token upon successful authentication.\n\n## Testing\n\nTo run the tests, simply execute:\n\n```bash\nvendor/bin/phpunit tests\n```\n\n*Note:*  \nEnsure your test environment is configured (for example, using `DB_HOST=localhost` if running locally).\n\n## Deployment Considerations\n\n- **JWT Secret Management:**  \n  Keep your `JWT_SECRET` secure and do not commit it to source control.\n- **Database Migrations:**  \n  Although this project auto-creates and seeds the database, for production you should use a tool or strategy to manage database migrations.\n- **Security \u0026 Error Handling:**  \n  Enhance authentication middleware, input validation, and error logging as needed for production.\n\n## Contributing\n\nContributions, issues, and feature requests are welcome!  \nPlease open an [issue](https://github.com/adarshkr357/recipes-api/issues) or submit a [pull request](https://github.com/adarshkr357/recipes-api/pulls).\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadarshkr357%2Frecipes-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadarshkr357%2Frecipes-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadarshkr357%2Frecipes-api/lists"}