{"id":29271987,"url":"https://github.com/jrjoacir/template-ruby-grape-api","last_synced_at":"2025-07-05T00:10:20.261Z","repository":{"id":36297012,"uuid":"157093672","full_name":"jrjoacir/template-ruby-grape-api","owner":"jrjoacir","description":"Purpose of this project is to offer a template for create an API in Ruby language using Grape API framework inside docker container and propose a development architecture for APIs","archived":false,"fork":false,"pushed_at":"2023-01-18T18:26:34.000Z","size":191,"stargazers_count":5,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-03T12:35:51.465Z","etag":null,"topics":["api","api-blueprint","backend","container-docker","database-container","development-architecture","docker","docker-compose","grape","healthcheck","orm","postgresql","puma","rspec","rubocop","ruby","ruby-language","sequel","template"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/jrjoacir.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-11T15:35:01.000Z","updated_at":"2022-12-04T16:32:19.000Z","dependencies_parsed_at":"2023-02-10T16:45:47.057Z","dependency_job_id":null,"html_url":"https://github.com/jrjoacir/template-ruby-grape-api","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/jrjoacir/template-ruby-grape-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrjoacir%2Ftemplate-ruby-grape-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrjoacir%2Ftemplate-ruby-grape-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrjoacir%2Ftemplate-ruby-grape-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrjoacir%2Ftemplate-ruby-grape-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jrjoacir","download_url":"https://codeload.github.com/jrjoacir/template-ruby-grape-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrjoacir%2Ftemplate-ruby-grape-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263636825,"owners_count":23492312,"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","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-blueprint","backend","container-docker","database-container","development-architecture","docker","docker-compose","grape","healthcheck","orm","postgresql","puma","rspec","rubocop","ruby","ruby-language","sequel","template"],"created_at":"2025-07-05T00:10:19.489Z","updated_at":"2025-07-05T00:10:20.254Z","avatar_url":"https://github.com/jrjoacir.png","language":"Ruby","readme":"# template-ruby-grape-api\n\n|          |Master   |Develop|\n|----------|---------|-------|\n|**Status**|[![Build Status](https://travis-ci.com/jrjoacir/template-ruby-grape-api.svg?branch=master)](https://travis-ci.com/jrjoacir/template-ruby-grape-api)|[![Build Status](https://travis-ci.com/jrjoacir/template-ruby-grape-api.svg?branch=develop)](https://travis-ci.com/jrjoacir/template-ruby-grape-api)|\n\nEstá documentação também está disponível em [Português do Brasil](README_pt-br.md).\n\nPurpose of this project is to offer a template for create an API in [Ruby language](https://www.ruby-lang.org) using [Grape API framework](http://www.ruby-grape.org/) inside docker container and propose a development architecture for APIs. This template has:\n\n- An application docker container with Ruby language and their gems like Grape API Framework\n- A database docker container with Postgresql 12\n- A suggestion of directory structure for construct the application and their layers\n\nIn this project exist endpoint examples for **Project** and **Healthcheck** resources. We believe with these examples the developer can develop his/her application.\n\nWe will continue to improve this project according new ideas and suggestions appear, or according bugs are found.\n\n## Dependencies\n\n- [Docker](https://docs.docker.com/install/)\n- [Docker Compose](https://docs.docker.com/compose/install/)\n\n## Stack\n\n- Database -\u003e [Postgresql 12](https://www.postgresql.org/)\n- Language -\u003e [Ruby 2.6.4](http://ruby-doc.org/core-2.6.4/)\n  - API Framework -\u003e [Grape](https://github.com/ruby-grape/grape)\n  - Web Server -\u003e [Puma](http://puma.io/)\n  - Database ORM -\u003e [Sequel](https://github.com/jeremyevans/sequel)\n\n## Quick start - *See the application working*\n\n1. Build all containers:\n\n    ```bash\n    docker-compose build\n    ```\n\n2. Start container **development**:\n\n    ```bash\n    docker-compose up development\n    ```\n\n3. **Done!**\n\n    You are able to use your API acessing http://localhost:3000. Try to check healthcheck endpoint: http://localhost:3000/healthcheck.\n\n## Development Usage\n\n### The Containers\n\nThis project uses four docker containers:\n- **database**: Container that provides a Postgres database with two instances: *postgres_dev* and *postgres_test*.\n- **development**: Container that executes the application. Depends on container *database*.\n- **test**: Container that executes tests and linter. Depends on container *database*.\n- **apiblueprint**: Container that executes API documentation server.\n\n| Services         | Depends on | Objectives                                                                            |\n|------------------|------------|---------------------------------------------------------------------------------------|\n| **database**     |            | Creates Database Postgres container / Creates postgres_dev and postgres_test databases|\n| **development**  | database   | Creates and executes application container                                            |\n| **test**         | database   | Creates application test container                                                    |\n| **apiblueprint** |            | Creates a API documentation server                                                    |\n\n### Building Containers\n\nTo build all containers just execute following command:\n\n```bash\ndocker-compose build\n```\n\nTo build a only one container, execute:\n\n```bash\ndocker-compose build \u003ccontainer-name\u003e\n```\n\n### Starting application\n\nThe application container (**development**) connects in database container (**database**), this means that development container depends on database container. For start both containers you have to execute following command:\n\n```bash\ndocker-compose up development\n```\n\nIn case you want to hide output docker information, you need to add *-d* parameter: ```docker-compose up -d development```.\n\n**Note:** in a first execution will be created database and its structure.\n\n**Done!**\n\nYou are able to use your API acessing http://localhost:3000. Try to check healthcheck endpoint: http://localhost:3000/healthcheck.\n\n### Create data examples\n\nIf you need to insert some data in development database, you can use the rake task *seeds* with the following command.\n\n```bash\ndocker-compose run --rm development rake db:seeds\n```\n\n**Notes:**\n- Rake command clear all database tables before populate\n\nSome information about containers:\n- **database**\n  - **Port**: 5432\n  - Databases created with ```docker/database/create-multiple-postgresql-databases.sh``` file: ```postgres_test``` and ```postgres_dev```\n\n- **development**\n  - **Port**: 3000\n\nMore information about *stop*, *start*, *restart*, *run* containers and so on, read [Docker Compose Documentation](https://docs.docker.com/compose/) and [Docker Documentation](https://docs.docker.com/).\n\n### Execute tests\n\nThis project uses one more container only to executing tests. This container calls **test**. Create infrastructure for **test** container:\n\n```bash\ndocker-compose up test\n```\n\nExecute all tests with following command:\n\n\n```bash\ndocker-compose run --rm test rspec\n```\n\nFor execute just one file test, you can inform a file in end of command.\n\n```bash\ndocker-compose run --rm test rspec spec/services/healthcheck/get_service_spec.rb\n```\n\nThis project uses [Rspec](https://relishapp.com/rspec/) Ruby gem as a test tool.\n\n### Execute code analizer\n\nCreate infrastructure for **test** container:\n\n```bash\ndocker-compose up test\n```\n\nThis project uses [Rubocop](https://www.rubocop.org) Ruby gem as a Code Analizer tool, so analize all code with following command.\n\n```bash\ndocker-compose run --rm test rubocop\n```\n\nFor analize just one file, you can inform a file in end of command.\n\n```bash\ndocker-compose run --rm test rubocop app/services/healthcheck/get_service.rb\n```\n\n### Code coverage\n\nThis project uses [Simplecov](https://github.com/colszowka/simplecov) Ruby gem as Code Coverage tool, so know about this project code coverage opening file [./coverage/index.html](./coverage/index.html) after execute all tests with *Rspec* command.\n\n\n### Database Migrations\n\nFor execute database migrations:\n\n```bash\ndocker-compose run --rm \u003ccontainer\u003e rake db:migrate\n```\n\nThis command removes container.\n\n## API Blueprint Documentation\n\nThis project uses [API Blueprint](https://apiblueprint.org) as API Documentation, so you can edit file `doc.apib` with all documentation you need. To generate HTML file for this documentation and access it by Snowboard, you can use a simple docker-compose command:\n\n```bash\ndocker-compose up apiblueprint\n```\n\nor use the following docker command:\n\n```bash\ndocker run -it --rm -p 127.0.0.1:8088:8088/tcp -v $PWD:/doc quay.io/bukalapak/snowboard http -b 0.0.0.0:8088 --playground -c config/snowboard.yml doc.apib\n```\n\nTo access API Blueprint local server documentation page, visit [http://localhost:8088](http://localhost:8088).\n\nThe `config/snowboard.yml` configuration file was created to enable interative API documentation. So, its possible to simulate an API.\n\n### More information about documentation\n- [API Blueprint](https://apiblueprint.org)\n\n## Directory Structure\n\n- **app** -\u003e Main API Directory. Where is contained all API logic.\n  - **endpoints** -\u003e Endpoints logical construction and endpoint mounts, divided by versions (v1, v2, v3 ...). Each resource has a directory and each http method (get, post, put, delete, etc) has a file.\n  - **entities** -\u003e Presentation logic of Endpoints data result, divided by versions (v1, v2, v3 ...). Each resource has an Entity representation.\n  - **errors** -\u003e Has error classes customized.\n  - **helpers** -\u003e Helper classes or modules for use in API\n  - **models** -\u003e Keeps model classes bound or not with database tables.\n  - **services** -\u003e Contains every business logic for each operation. Each resource has a directory and each operation (get, create, update, delete) has a file.\n  - **validators** -\u003e Contains validators classes or modules used to services. Each resource has a directory and each operation has a file.\n- **config** -\u003e Contains application configuration files.\n  - **environments** -\u003e Each environment (test, development, production) is represented by a configuration file. Each file contains specific configuration for each environment.\n  - **initializers** -\u003e Has files that need to be load in the application initialization.\n- **db** -\u003e Contains files associated to database execution using or not an ORM.\n  - **migrations** -\u003e Contains Sequel ORM migrations files.\n  - **seeds** -\u003e Contains classes that create data examples in database.\n- **docker** -\u003e Has docker configuration files.\n  - **app** -\u003e Contains docker configuration files for application container.\n  - **database** -\u003e Contains docker configuration files for database container.\n- **spec** -\u003e Has all tests, classes and modules for support tests, factories, everything about tests. Each written test has to follow their directory structure.\n  - **factories** -\u003e Keeps every factories class (we are using [FactoryBot](https://github.com/thoughtbot/factory_bot)).\n  - **endpoints** -\u003e Contains tests for Endpoints.\n  - **models** -\u003e Contains tests for Models.\n  - **services** -\u003e Contains tests for Services.\n  - **commands** -\u003e Contains tests for Commands.\n\n## Additional information\n\n- Dockerfile for Postgresql 12 (Container Docker) got on official [Postgresql Dockerfile](https://hub.docker.com/_/postgres/)\n\n- Dockerfile for Ruby (Container Docker) got on official [Ruby Dockerfile](https://hub.docker.com/_/ruby/)\n\n- [Design Patterns in Ruby](https://github.com/davidgf/design-patterns-in-ruby)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjrjoacir%2Ftemplate-ruby-grape-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjrjoacir%2Ftemplate-ruby-grape-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjrjoacir%2Ftemplate-ruby-grape-api/lists"}