An open API service indexing awesome lists of open source software.

https://github.com/rinminase/anidb-be

💬🐳 Rin Minase's AniDB API Service utilizing the latest version of Laravel and deployed to Heroku
https://github.com/rinminase/anidb-be

anilist-api cloudinary docker functional-testing graphql heroku laravel open-api open-api-v3 php phpunit postgresql restful-api sentry swagger web-scraping

Last synced: 7 months ago
JSON representation

💬🐳 Rin Minase's AniDB API Service utilizing the latest version of Laravel and deployed to Heroku

Awesome Lists containing this project

README

          

Rin Minase's Anime Database
(Back-end API Service)



Laravel


PHP

## Introduction
_Add info here_

## Table Of Contents

- [Getting Started](#getting-started)
- [Environment variables setup](#environment-variables-setup)
- [Running the project](#running-the-project)
- [Running the optional containers](#running-the-optional-containers)
- [Re-running the project](#re-running-the-project)
- [Running scheduled tasks](#running-scheduled-tasks)
- [Running the Swagger Generator / API Documentation Generator](#running-the-swagger-generator--api-documentation-generator)
- [Running the Unit Tests](#running-the-unit-tests)
- [Project shorthands / aliases inside the PHP Docker container](#project-shorthands--aliases-inside-the-php-docker-container)
- [Project Structure](#project-structure)
- [Project Tech Stack](#built-with)

## Getting Started

### Environment variables setup
[Return to the table of contents](#table-of-contents)

1. Database

Definition of terms:
- **DB_HOST** - docker **container name** of the database
- **DB_PORT** - port used by the database
- **DB_DATABASE** - database username
- **DB_PASSWORD** - database password

**Notes :** DB_HOST **should** use docker container name of db, by default this is 'anidb-pgsql', but yours could be different. You can check this by running `docker ps` then check the container name of the `postgres` container.

2. Cloudinary
- Fire up your browser and login your [Cloudinary Account](https://cloudinary.com/users/login). If you have no account yet, you can [create one](https://cloudinary.com/users/register/free) for free.
- After logging in, navigate to the [Cloudinary Console](https://cloudinary.com/console) to retrieve your Cloudinary URL
- Copy the value of `API Environment variable` to `CLOUDINARY_URL` of your ENV file

### Running the project
[Return to the table of contents](#table-of-contents)

1. [Download](https://www.docker.com/products/docker-desktop) and install Docker.

2. Clone the project, then install the dependencies

```bash
git clone https://github.com/RinMinase/anidb-be.git
cd anidb-be
```

3. Run the necessary docker containers

```bash
docker compose up -d
docker compose exec php sh
```

This runs only the necessary containers. As for running the optional containers, please see the section [below](#running-the-optional-containers).

4. Inside the docker image, copy the env file, install the necessary dependencies and generate the necessary key for laravel

```bash
cp .env.example .env
composer install
php artisan key:generate
```

5. Generate the necessary API key and take note of this is as this is REQUIRED to access the API

```bash
php artisan app:generate-api-key
```
or you can generate your own from any application, and add it under `API_KEY` in your `.env` file. Example:
```bash
openssl rand -hex 36
```

6. Generate the necessary root password key and take note of this is as this is REQUIRED to create admin accounts

```bash
php artisan app:generate-root-password
```
or generate your own, and add it under `APP_REGISTRATION_ROOT_PASSWORD` in your `.env` file.

7. Cache the config file, then run the database migrations

```bash
php artisan config:cache
php artisan migrate:fresh --seed
```

7. Fire up your browser and go to `localhost`.

**Note:**
If you need to access the container run, `docker compose exec php sh`

### Running the optional containers
[Return to the table of contents](#table-of-contents)

List of **optional** containers:

| Name | Description |
| ------ | -------------------------------------------------------------------------- |
| dbui | GUI for postgres using [sosedoff/pgweb](https://github.com/sosedoff/pgweb) |

You can run them individually by:

```bash
docker compose up -d
```

Or run all of them by:

```bash
docker compose up -d --profile optional
```

### Re-running the project
[Return to the table of contents](#table-of-contents)

1. Navigate inside the `php` docker container

```bash
docker compose exec php sh
```

2. Run the migrations when necessary, then install the dependencies also when necessary

```bash
php artisan migrate
composer install
```

3. Fire up your browser and go to `localhost`.

### Running scheduled tasks
[Return to the table of contents](#table-of-contents)

1. Navigate inside the `php` docker container [[how]](#re-running-the-project)

2. Run the command to run the scheduled tasks manually

```bash
php artisan schedule:run
```

There are a few commands specific to running tasks:

| Name | Description |
| ----------------- | ------------------------------------------------------------ |
| `schedule:run` | `Runs the scheduled tasks manually` **with respect to cron** |
| `schedule:work` | `Runs the scheduler daemon / worker` |
| `schedule:list` | `Lists the upcoming tasks to be run` |

### Running the Swagger Generator / API Documentation Generator
[Return to the table of contents](#table-of-contents)

1. Navigate inside the `php` docker container [[how]](#re-running-the-project)

2. Run the command to generate the documentations inside the container

```bash
docs
```

3. Fire up your browser and go to `localhost/docs` to open Swagger UI.

### Running the Unit Tests
[Return to the table of contents](#table-of-contents)

1. Navigate inside the `php` docker container [[how]](#re-running-the-project)

2. Run the command below:
```bash
php artisan test
```
or if you want to run a specific test module
```
php artisan test --filter
```
or if you want to run a specific single test
```bash
php artisan test --filter test_function_name tests/Location/of/TestCase.php
```

### Project shorthands / aliases inside the PHP Docker container
[Return to the table of contents](#table-of-contents)

This shortcuts were created to reduce the need to keep typing the same long commands over and over again.

| Shortcut | Long version |
| ----------------- | ----------------------- |
| `pa` or `artisan` | `php artisan` |
| `docs` | `composer docs` |
| `dump` or `da` | `composer dumpautoload` |

## Project Structure
[Return to the table of contents](#table-of-contents)

.
├── app/ # Application source code
│ ├── docs.blade.php # Swagger page template
│ ├── index.blade.php # Landing page template
│ └── ... # Other application-related files
├── bootstrap/ # Project initializers
│ ├── app.php # Framework bootstrapper
│ ├── helpers.php # Helper functions
│ └── routes.php # Route definitions
├── config/ # Laravel configuration files
├── database/ # Database migrations and seeders
├── docker/ # Docker functions
│ ├── php-config/ # PHP settings for docker
│ ├── sites/ # Nginx sites for docker
│ ├── nginx.dockerfile # Nginx container docker file
│ ├── php.dockerfile # PHP container docker file
│ └── ... # Other docker files
├── public/ # Project entry point
├── tests/ # Project test files
├── .czrc # Commitizen configuration file
├── docker-compose.yml # Main docker file
├── phpunit.xml # Unit test configuration file
├── Procfile # Heroku process file
└── ... # Other project files

## Built with
* [Laravel 11](https://laravel.com) - Core Framework
* [PHP 8.4](https://php.net) - Language syntax
* [PostgreSQL](https://www.postgresql.org) - Database
* [Docker](https://www.docker.com) - Container platform
* [Sentry](https://sentry.io/) - Application Monitoring
* [Swagger](https://swagger.io/) - API Documentation
* [Heroku](https://www.heroku.com) - Hosting and Continuous Integration (CI) service
* [PHPUnit](https://phpunit.de/) - Unit Testing
* [RESTful API](https://restfulapi.net) - HTTP Requests Architecture

## Deployed to
* [Heroku](http://rin-anidb.herokuapp.com)