# garonmain/backend-for-gamelibrary architecture

> Architecture diagram of the GitHub repository garonmain/backend-for-gamelibrary, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/garonmain/backend-for-gamelibrary
- Repository: https://github.com/garonmain/backend-for-gamelibrary

## Overview

1. **What this backend is**
   - A Laravel API for a game library domain.
   - Core concepts are **users**, **games**, **publishers**, **collectibles**, and **favorites**.
   - The codebase is organized around CRUD-style REST endpoints plus token-based authentication.

2. **HTTP/API entry points**
   - `routes/api.php` is the main integration boundary for clients.
   - `routes/web.php` is present but the repository is clearly API-first.
   - Requests enter Laravel, hit a controller, then flow through validation, authorization, model persistence, and finally a resource serializer back to JSON.

3. **Authentication subsystem**
   - `AuthController` handles registration and login.
   - `LoginUserRequest` and `RegisterUserRequest` validate credentials and registration payloads.
   - The `User` model uses `HasApiTokens`, and the repo includes the `personal_access_tokens` migration, so authentication is built on **Laravel Sanctum**.
   - The `users` table is custom: it stores `name`, `registered_at`, and `password`, not the usual email-based schema.

4. **Domain API subsystems**
   - `GameController`, `PublisherController`, `CollectibleController`, and `FavoriteController` each own one part of the domain.
   - This suggests a clean separation of concerns:
     - **Publishers** manage publisher records.
     - **Games** belong to publishers.
     - **Collectibles** belong to games.
     - **Favorites** connect users to games.

5. **Data model and relationships**
   - `publishers` is a parent entity for `games`.
   - `games` has a foreign key `publisher_id`.
   - `collectibles` has a foreign key `game_id`.
   - `favorites` is a many-to-many join table between `users` and `games`, with a composite primary key.
   - The database schema uses JSON-capable columns for arrays like `platforms` and `images`, which matters for serialization and validation.

6. **Validation layer**
   - Each write path has a dedicated Form Request class:
     - `StoreGameRequest`, `UpdateGameRequest`
     - `StorePublisherRequest`, `UpdatePublisherRequest`
     - `StoreCollectibleRequest`, `UpdateCollectibleRequest`
     - `StoreFavoriteRequest`
   - This keeps input validation out of controllers and makes the API boundary explicit.

7. **Authorization layer**
   - Policies exist for all major domain entities: `GamePolicy`, `PublisherPolicy`, `CollectiblePolicy`, `FavoritePolicy`.
   - That means the app does not rely only on authentication; it also applies per-resource permission checks before allowing changes.

8. **Response shaping**
   - Resources normalize outgoing JSON:
     - `GameResource`
     - `PublisherResource`
     - `CollectibleResource`
     - `FavoriteResource`
   - This is the main presentation boundary of the API, so clients receive a consistent contract regardless of how the models are stored.

9. **Persistence and lifecycle**
   - Laravel migrations define the schema, factories create test data, and seeders populate initial content.
   - The repository includes both migration-based schema definitions and sample SQL data in the README, which helps mirror the same domain in local setup.
   - `DatabaseSeeder` coordinates the seeded dataset for publishers, games, collectibles, favorites, and users.

10. **Operational and deployment boundaries**
   - A `Dockerfile` and `docker-compose.yml` indicate containerized development or deployment.
   - Standard Laravel config files are present for database, auth, cache, queue, mail, session, filesystem, and Sanctum.
   - `public/index.php` is the framework entry point, with Laravel serving as the application runtime.

11. **Documentation and API discovery**
   - `.scribe/` and `resources/views/scribe/` show the API is documented with **Scribe**.
   - `mestermunka_postman_test.postman_collection.json` provides a runnable API test/inspection collection.
   - These are sidecar artifacts around the API, not core runtime logic, but they are important for understanding how the endpoints are consumed.

12. **Testing**
   - The repo uses **Pest** for automated tests, with unit tests already present for auth, favorites, and games.
   - This suggests the main behavioral risk areas are authentication and relationship handling.

13. **What to draw in an architecture diagram**
   - Put **API clients** on the left, then **Laravel controllers** as the request layer.
   - Behind controllers, show **Form Requests** and **Policies** as guard rails.
   - Then show **Models / Eloquent** talking to the **MySQL database**.
   - Include **Sanctum token auth** as the authentication boundary.
   - Add **Resources** as the response formatting layer.
   - Optionally show **Scribe/Postman** as documentation/testing consumers of the API contract.

Main entry points: [`routes/api.php`](https://github.com/garonmain/backend-for-gamelibrary/blob/main/routes/api.php) (API Routes), [`database/migrations`](https://github.com/garonmain/backend-for-gamelibrary/tree/main/database/migrations) (MySQL Schema), [`app/Http/Controllers/GameController.php`](https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Http/Controllers/GameController.php) (Game Controller), [`app/Http/Controllers/PublisherController.php`](https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Http/Controllers/PublisherController.php) (Publisher Controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API Layer"]
  node_clients(("API Clients<br/>consumer"))
  node_routes_api["API Routes<br/>routing<br/>[api.php]"]
end

subgraph group_domain["Domain Layer"]
  node_auth_controller["Auth Controller<br/>[AuthController.php]"]
  node_game_controller["Game Controller<br/>[GameController.php]"]
  node_publisher_controller["Publisher Controller"]
  node_collectible_controller["Collectible Controller"]
  node_favorite_controller["Favorite Controller"]
  node_form_requests["Form Requests<br/>validation"]
  node_policies["Policies<br/>authorization"]
  node_resources["API Resources<br/>serialization"]
end

subgraph group_data["Data Layer"]
  node_user_model[("User<br/>model<br/>[User.php]")]
  node_game_model[("Game<br/>model<br/>[Game.php]")]
  node_publisher_model[("Publisher<br/>model<br/>[Publisher.php]")]
  node_collectible_model[("Collectible<br/>model<br/>[Collectible.php]")]
  node_favorite_model[("Favorite<br/>model<br/>[Favorite.php]")]
  node_database[("MySQL Schema<br/>relational-db")]
  node_seeders_factories["Seeders & Factories<br/>data-loading"]
end

subgraph group_ops["Ops & Docs"]
  node_sanctum_tokens[("Sanctum Tokens<br/>auth")]
  node_public_entry["Laravel Runtime<br/>entrypoint<br/>[index.php]"]
  node_scribe_postman["Docs & Postman<br/>[.scribe]"]
end

node_clients -->|"HTTP requests"| node_routes_api
node_routes_api -->|"auth"| node_auth_controller
node_routes_api -->|"games"| node_game_controller
node_routes_api -->|"publishers"| node_publisher_controller
node_routes_api -->|"collectibles"| node_collectible_controller
node_routes_api -->|"favorites"| node_favorite_controller
node_auth_controller -->|"validate"| node_form_requests
node_game_controller -->|"validate"| node_form_requests
node_publisher_controller -->|"validate"| node_form_requests
node_collectible_controller -->|"validate"| node_form_requests
node_favorite_controller -->|"validate"| node_form_requests
node_game_controller -->|"authorize"| node_policies
node_publisher_controller -->|"authorize"| node_policies
node_collectible_controller -->|"authorize"| node_policies
node_favorite_controller -->|"authorize"| node_policies
node_auth_controller -->|"users"| node_user_model
node_game_controller -->|"persist"| node_game_model
node_publisher_controller -->|"persist"| node_publisher_model
node_collectible_controller -->|"persist"| node_collectible_model
node_favorite_controller -->|"persist"| node_favorite_model
node_game_model -->|"table"| node_database
node_publisher_model -->|"table"| node_database
node_collectible_model -->|"table"| node_database
node_favorite_model -->|"table"| node_database
node_user_model -->|"tokens"| node_sanctum_tokens
node_game_model -->|"serialize"| node_resources
node_publisher_model -->|"serialize"| node_resources
node_collectible_model -->|"serialize"| node_resources
node_favorite_model -->|"serialize"| node_resources
node_seeders_factories -->|"seed"| node_database
node_public_entry -->|"bootstrap"| node_routes_api
node_scribe_postman -.->|"documents"| node_routes_api

click node_routes_api "https://github.com/garonmain/backend-for-gamelibrary/blob/main/routes/api.php"
click node_auth_controller "https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Http/Controllers/AuthController.php"
click node_game_controller "https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Http/Controllers/GameController.php"
click node_publisher_controller "https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Http/Controllers/PublisherController.php"
click node_collectible_controller "https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Http/Controllers/CollectibleController.php"
click node_favorite_controller "https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Http/Controllers/FavoriteController.php"
click node_user_model "https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Models/User.php"
click node_game_model "https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Models/Game.php"
click node_publisher_model "https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Models/Publisher.php"
click node_collectible_model "https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Models/Collectible.php"
click node_favorite_model "https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Models/Favorite.php"
click node_database "https://github.com/garonmain/backend-for-gamelibrary/tree/main/database/migrations"
click node_seeders_factories "https://github.com/garonmain/backend-for-gamelibrary/tree/main/database/seeders"
click node_sanctum_tokens "https://github.com/garonmain/backend-for-gamelibrary/blob/main/database/migrations/2026_02_17_171056_create_personal_access_tokens_table.php"
click node_public_entry "https://github.com/garonmain/backend-for-gamelibrary/blob/main/public/index.php"
click node_scribe_postman "https://github.com/garonmain/backend-for-gamelibrary/blob/main/.scribe"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_clients,node_routes_api toneBlue
class node_auth_controller,node_game_controller,node_publisher_controller,node_collectible_controller,node_favorite_controller,node_form_requests,node_policies,node_resources toneAmber
class node_user_model,node_game_model,node_publisher_model,node_collectible_model,node_favorite_model,node_database,node_seeders_factories toneMint
class node_sanctum_tokens,node_public_entry,node_scribe_postman toneRose
```

## Components

### API Layer

HTTP entry points and request handling

- **API Clients**: consumer · External consumers of the REST API
- [API Routes](https://github.com/garonmain/backend-for-gamelibrary/blob/main/routes/api.php): routing · Main HTTP integration boundary for clients · `routes/api.php`

### Domain Layer

Controllers, validation, authorization, and serialization

- [Auth Controller](https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Http/Controllers/AuthController.php): controller · Handles registration and login · `app/Http/Controllers/AuthController.php`
- [Game Controller](https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Http/Controllers/GameController.php): controller · CRUD entry for games · `app/Http/Controllers/GameController.php`
- [Publisher Controller](https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Http/Controllers/PublisherController.php): controller · CRUD entry for publishers · `app/Http/Controllers/PublisherController.php`
- [Collectible Controller](https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Http/Controllers/CollectibleController.php): controller · CRUD entry for collectibles · `app/Http/Controllers/CollectibleController.php`
- [Favorite Controller](https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Http/Controllers/FavoriteController.php): controller · Manages user-game favorites · `app/Http/Controllers/FavoriteController.php`
- **Form Requests**: validation · Dedicated request validation for auth and write operations
- **Policies**: authorization · Per-resource authorization checks
- **API Resources**: serialization · Shapes outbound JSON responses

### Data Layer

Models, schema, and seeded content

- [User](https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Models/User.php): model · Custom user model using Sanctum tokens · `app/Models/User.php`
- [Game](https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Models/Game.php): model · Games domain model · `app/Models/Game.php`
- [Publisher](https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Models/Publisher.php): model · Publishers domain model · `app/Models/Publisher.php`
- [Collectible](https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Models/Collectible.php): model · Collectibles domain model · `app/Models/Collectible.php`
- [Favorite](https://github.com/garonmain/backend-for-gamelibrary/blob/main/app/Models/Favorite.php): model · Join model between users and games · `app/Models/Favorite.php`
- [MySQL Schema](https://github.com/garonmain/backend-for-gamelibrary/tree/main/database/migrations): relational-db · Migrations define users, games, publishers, collectibles, favorites, and tokens · `database/migrations`
- [Seeders & Factories](https://github.com/garonmain/backend-for-gamelibrary/tree/main/database/seeders): data-loading · Creates sample and repeatable domain data · `database/seeders`

### Ops & Docs

Runtime entry, deployment, and API documentation

- [Sanctum Tokens](https://github.com/garonmain/backend-for-gamelibrary/blob/main/database/migrations/2026_02_17_171056_create_personal_access_tokens_table.php): auth · Token-based authentication boundary · `database/migrations/2026_02_17_171056_create_personal_access_tokens_table.php`
- [Laravel Runtime](https://github.com/garonmain/backend-for-gamelibrary/blob/main/public/index.php): entrypoint · Framework entry via public/index.php · `public/index.php`
- [Docs & Postman](https://github.com/garonmain/backend-for-gamelibrary/blob/main/.scribe): docs · Scribe docs and runnable API collection · `.scribe`

## Connections

- API Clients → API Routes: HTTP requests · Clients call the REST API through Laravel routes
- API Routes → Auth Controller: auth · Routes dispatch to authentication actions
- API Routes → Game Controller: games · Routes dispatch to game CRUD actions
- API Routes → Publisher Controller: publishers · Routes dispatch to publisher CRUD actions
- API Routes → Collectible Controller: collectibles · Routes dispatch to collectible CRUD actions
- API Routes → Favorite Controller: favorites · Routes dispatch to favorite actions
- Auth Controller → Form Requests: validate · Auth inputs are validated before execution
- Game Controller → Form Requests: validate · Game writes use dedicated request objects
- Publisher Controller → Form Requests: validate · Publisher writes use dedicated request objects
- Collectible Controller → Form Requests: validate · Collectible writes use dedicated request objects
- Favorite Controller → Form Requests: validate · Favorite writes use dedicated request objects
- Game Controller → Policies: authorize · Game mutations are gated by policy checks
- Publisher Controller → Policies: authorize · Publisher mutations are gated by policy checks
- Collectible Controller → Policies: authorize · Collectible mutations are gated by policy checks
- Favorite Controller → Policies: authorize · Favorite mutations are gated by policy checks
- Auth Controller → User: users · Registration and login operate on the user model
- Game Controller → Game: persist · Games are loaded and saved through Eloquent
- Publisher Controller → Publisher: persist · Publishers are loaded and saved through Eloquent
- Collectible Controller → Collectible: persist · Collectibles are loaded and saved through Eloquent
- Favorite Controller → Favorite: persist · Favorites are managed through the join model
- Game → MySQL Schema: table · Games map to the relational schema
- Publisher → MySQL Schema: table · Publishers map to the relational schema
- Collectible → MySQL Schema: table · Collectibles map to the relational schema
- Favorite → MySQL Schema: table · Favorites map to the relational schema
- User → Sanctum Tokens: tokens · Users authenticate with API tokens
- Game → API Resources: serialize · Game responses are normalized before returning JSON
- Publisher → API Resources: serialize · Publisher responses are normalized before returning JSON
- Collectible → API Resources: serialize · Collectible responses are normalized before returning JSON
- Favorite → API Resources: serialize · Favorite responses are normalized before returning JSON
- Seeders & Factories → MySQL Schema: seed · Seeders and factories populate schema data
- Laravel Runtime → API Routes: bootstrap · Laravel runtime bootstraps the API route layer
- Docs & Postman → API Routes: documents · Docs and collections mirror the API contract
