{"id":23300660,"url":"https://github.com/lukasbecvar/api-base","last_synced_at":"2026-04-27T22:31:07.282Z","repository":{"id":268681309,"uuid":"904737855","full_name":"lukasbecvar/api-base","owner":"lukasbecvar","description":"Base app template for creating REST API in the Symfony framework.","archived":false,"fork":false,"pushed_at":"2025-11-06T17:47:33.000Z","size":413,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-06T19:22:44.741Z","etag":null,"topics":["api","api-base","api-template","base","jwt-auth","php","rest-api","symfony","user-system"],"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/lukasbecvar.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-12-17T13:10:13.000Z","updated_at":"2025-11-06T17:47:37.000Z","dependencies_parsed_at":"2024-12-18T09:38:33.308Z","dependency_job_id":"c1c48bd9-bf49-4fbf-963f-cd888c9c0f24","html_url":"https://github.com/lukasbecvar/api-base","commit_stats":{"total_commits":123,"total_committers":1,"mean_commits":123.0,"dds":0.0,"last_synced_commit":"3ac3a0dc5740f7dd939807adaf5e8091df3974b4"},"previous_names":["lukasbecvar/api-base"],"tags_count":9,"template":true,"template_full_name":null,"purl":"pkg:github/lukasbecvar/api-base","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasbecvar%2Fapi-base","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasbecvar%2Fapi-base/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasbecvar%2Fapi-base/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasbecvar%2Fapi-base/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukasbecvar","download_url":"https://codeload.github.com/lukasbecvar/api-base/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasbecvar%2Fapi-base/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32358509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"ssl_error","status_checked_at":"2026-04-27T20:07:00.910Z","response_time":128,"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","api-base","api-template","base","jwt-auth","php","rest-api","symfony","user-system"],"created_at":"2024-12-20T09:17:30.657Z","updated_at":"2026-04-27T22:31:07.277Z","avatar_url":"https://github.com/lukasbecvar.png","language":"PHP","readme":"# Symfony API Base\nThis is a base application for a REST API in the Symfony framework that I created to speed up backend development.\n\n## Index\n* [Features](#features)\n* [Getting Started](#getting-started)\n* [API Documentation](#api-documentation)\n* [Authentication](#authentication)\n* [Error handling](#error-handling)\n* [Logging system](#logging-system)\n* [User system](#user-system)\n* [CLI commands](#cli-commands)\n* [Environment configuration variables](#environment-configuration-variables)\n* [Request examples](#request-examples)\n* [Dependencies \u0026 requirements](#dependencies--requirements)\n* [License](#license)\n\n## Features\nThe base contains essential utilities and functions for validation, logging, error handling, and the user system.\n\n## Getting Started\n1. Clone the repository:\n```bash\ngit clone https://github.com/your-username/api-base.git\ncd api-base\n```\n3. Build and run containers:\nThis command will build the Docker images and start all services (PHP/Apache, MySQL, Redis).\n```bash\nsh scripts/docker-start-dev.sh\n```\n4. Install dependencies:\nUse Composer inside the PHP container to install all required packages (this makes docker-start automatically).\n```bash\nsh scripts/install.sh\n```\n5. Run database migrations:\nThis will create the database schema based on your entities.\n```bash\nsh scripts/migrate.sh\n```\n6. Generate JWT keys:\nCreate the public and private keys required for signing JWT tokens (this makes docker-start automatically).\n```bash\ndocker-compose exec php php bin/console lexik:jwt:generate-keypair\n```\n7. The API is now running at `http://localhost`\n8. Develop your API\nNow you can rename ```api-base``` to whatever you need, rewrite the configurations, and start developing your API solution.\n\n## API-Documentation\n##### Nelmio UI\nThe documentation for API endpoints can be found at the route `/api/doc`, with Nelmio UI complete documentation and also allows testing requests directly in the web browser. Alternatively, you can find documentation in JSON format at `/api/doc.json` (You can use this JSON response to import the configuration into Postman).\n\n## Authentication \n##### API-Token\nAll API requests must have static X-API-Token header set, which is used for validating the request. The token is set in the .env file.\n##### JWT\nJWT token is used for user authentication.\n\n## Error handling\nError handling is managed by the ```handleError``` function in the ```ErrorManager class```, which triggers an exception that is listened to by the ```ExceptionEventSubscriber```. The subscriber logs the exception into the exception log and displays an error response for the user.\n\n## Logging system\nFor logging, there is the ```LogManager class```, which contains functions for saving and reading logs from the database through the Log entity.\n\n## User system\nThe user system is managed by the ```UserManager class```, and login works using a JWT token in the authorization header, thanks to Symfony Security and Lexik JWT.\n\n## CLI commands\nThe application has CLI commands for the LogManager and UserManager, and overall system management through the CLI.\n\n## Environment configuration variables\n| Variable | Description | Example value |\n| --- | --- | --- |\n| `APP_ENV` | Specific environment name | `dev` |\n| `APP_SECRET` | Session \u0026 token encryption key | `369af56dccfce490cb9325e8b4b59a90` |\n| `API_TOKEN` | API access token for authentication | `1234` |\n| `APP_VERSION` | App version identifier | `1.0` |\n| `TRUSTED_HOSTS` | Trusted domain names | `^.*$` |\n| `ALLOWED_ORIGINS` | Allowed origins (use * for all origins) | `*` |\n| `ALLOWED_IP_ADDRESSES` | Allowed ip addresses (use % for all IP addresses) | `%` |\n| `SSL_ONLY` | Enable only SSL traffic (true/false) | `false` |\n| `MAINTENANCE_MODE` | Enable maintenance mode (true/false) | `false` |\n| `LIMIT_CONTENT_PER_PAGE` | Pagination config (int value) | `10` |\n| `REGISTRATION_WITH_API_ENDPOINT_ENABLED` | Enable registration API endpoint (true/false) | `true` |\n| `DATABASE_LOGGING` | Log manager config | `true` |\n| `LOG_LEVEL` | Log level (1: CRITICAL, 2: WARNING, 3: NOTICE, 4: INFO) | `4` |\n| `RATE_LIMIT_ENABLED` | Enable rate limit (true/false) | `false` |\n| `RATE_LIMIT_INTERVAL` | Rate limit interval (seconds) | `60` |\n| `RATE_LIMIT_LIMIT` | Rate limit limit | `100` |\n| `DATABASE_DRIVER` | Database driver | `pdo_mysql` |\n| `DATABASE_VERSION` | Database version | `8.0.43` |\n| `DATABASE_HOST` | Database host | `127.0.0.1` |\n| `DATABASE_PORT` | Database port | `3306` |\n| `DATABASE_NAME` | Database name | `product_vault` |\n| `DATABASE_USERNAME` | Database username | `root` |\n| `DATABASE_PASSWORD` | Database password | `root` |\n| `REDIS_SCHEME` | Redis scheme | `redis` |\n| `REDIS_HOST` | Redis host | `127.0.0.1` |\n| `REDIS_PORT` | Redis port | `6379` |\n| `REDIS_USER` | Redis user | `default` |\n| `REDIS_PASSWORD` | Redis password | `redis_test_password` |\n| `JWT_TOKEN_TTL` | JWT token TTL (in seconds) | `2629536` (1 month token expiration) |\n| `JWT_SECRET_KEY` | JWT secret key | `%kernel.project_dir%/token-keypair/private.pem` |\n| `JWT_PUBLIC_KEY` | JWT public key | `%kernel.project_dir%/token-keypair/public.pem` |\n| `JWT_PASSPHRASE` | JWT passphrase | `f82fdd5f4644df4ba8fe9df82fdd5f4644df4ba8fe9d` |\n| `MAILER_ENABLED` | Enable mailer | `false` |\n| `MAILER_HOST` | Mailer host | `smtp.seznam.cz` |\n| `MAILER_PORT` | Mailer port | `465` |\n| `MAILER_USERNAME` | Mailer username | `service@becvar.xyz` |\n| `MAILER_PASSWORD` | Mailer password | `password` |\n\n## Request examples\nAll requests accept input data in JSON format and return JSON data back to the client.\n##### register request\n```\ncurl -X POST http://localhost/api/auth/register \\\n    -H \"Content-Type: application/json\" \\\n    -H \"X-API-TOKEN: 1234\" \\\n    -d '{\n        \"email\": \"test@example.com\",\n        \"first-name\": \"John\",\n        \"last-name\": \"Doe\",\n        \"password\": \"securePassword123\"\n    }'\n```\n##### login request\n```\ncurl -X POST http://localhost/api/auth/login \\\n    -H \"Content-Type: application/json\" \\\n    -H \"X-API-TOKEN: 1234\" \\\n    -d '{\n        \"email\": \"test@test.test\",\n        \"password\": \"test\"\n    }'\n```\n##### logout request\n```\ncurl -X POST http://localhost/api/auth/logout \\\n    -H \"Content-Type: application/json\" \\\n    -H \"X-API-TOKEN: 1234\" \\\n    -H \"Authorization: Bearer \u003ctoken\u003e\"\n```\n##### user info request\n```\ncurl -X GET http://localhost/api/user/info \\\n    -H \"Content-Type: application/json\" \\\n    -H \"X-API-TOKEN: 1234\" \\\n    -H \"Authorization: Bearer \u003ctoken\u003e\"\n```\n##### update user password request\n```\ncurl -X PATCH http://localhost/api/user/data/update/password \\\n    -H \"Content-Type: application/json\" \\\n    -H \"X-API-TOKEN: 1234\" \\\n    -H \"Authorization: Bearer \u003ctoken\u003e\" \\\n    -d '{\n        \"new-password\": \"asdfghjkoiuzrewq\"\n    }'\n```\n##### update user role request\n```\ncurl -X PATCH http://localhost/api/user/data/update/role \\\n    -H \"Content-Type: application/json\" \\\n    -H \"X-API-TOKEN: 1234\" \\\n    -H \"Authorization: Bearer \u003ctoken\u003e\" \\\n    -d '{\n        \"user-id\": 1,\n        \"task\": \"add\",\n        \"role\": \"ROLE_TEST\"\n    }'\n```\n##### update user status request\n```\ncurl -X PATCH http://localhost/api/user/data/update/status \\\n    -H \"Content-Type: application/json\" \\\n    -H \"X-API-TOKEN: 1234\" \\\n    -H \"Authorization: Bearer \u003ctoken\u003e\" \\\n    -d '{\n        \"user-id\": 2,\n        \"status\": \"idk\"\n    }'\n```\n##### delete user request\n```\ncurl -X PATCH http://localhost/api/user/delete \\\n    -H \"Content-Type: application/json\" \\\n    -H \"X-API-TOKEN: 1234\" \\\n    -H \"Authorization: Bearer \u003ctoken\u003e\" \\\n    -d '{\n        \"user-id\": 3\n    }'\n```\n##### get users list request\n```\ncurl -X GET http://localhost/api/user/list \\\n    -H \"Content-Type: application/json\" \\\n    -H \"X-API-TOKEN: 1234\" \\\n    -H \"Authorization: Bearer \u003ctoken\u003e\"\n```\n\n## Dependencies \u0026 requirements\n* PHP\n    * [Website](https://php.net)\n* Redis\n    * [Website](https://redis.io)\n* MySQL\n    * [Website](https://www.mysql.com)\n* Symfony framework\n    * [Website](https://symfony.com)\n* Doctrine ORM\n    * [Github](https://github.com/doctrine/orm)\n* Lexik JWT Authentication Bundle\n    * [Github](https://github.com/lexik/LexikJWTAuthenticationBundle)\n* PHPUnit\n    * [Github](https://github.com/sebastianbergmann/phpunit)\n* Better PHPUnit CLI output\n    * [Github](https://github.com/robiningelbrecht/phpunit-pretty-print)\n* PHPStan\n    * [Github](https://github.com/phpstan/phpstan)\n\n## License\nThis software is licensed under the [MIT license](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukasbecvar%2Fapi-base","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukasbecvar%2Fapi-base","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukasbecvar%2Fapi-base/lists"}