# claudioemmanuel/banking-api architecture

> Architecture diagram of the GitHub repository claudioemmanuel/banking-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/claudioemmanuel/banking-api
- Repository: https://github.com/claudioemmanuel/banking-api

## Overview

##### Project type and purpose
- This is a backend-only, RESTful Banking API built with the Laravel PHP framework.
- It implements core banking operations: deposit, withdrawal, transfer, and balance inquiry.
- It follows a layered architecture with Controllers → Services → Repositories, plus DTOs and Laravel’s ORM.

##### File structure
- Top-level Laravel conventions:
- public/ (HTTP entry point → index.php)
- routes/ (api.php, web.php, console.php)
- app/Http/Controllers (ApiController, base Controller)
- app/Services & app/Repositories (business logic & data access)
- app/Contracts (interfaces for DI)
- app/Dtos (AccountDTO, TransferDTO)
- app/Models (User, Account if present)
- config/, bootstrap/, storage/, tests/, database/ (migrations, seeders)
- Key patterns:
- Dependency Injection (Contracts → Services → Repositories)
- MVC at high level (Controllers use Services)
- DTO layer isolates payload from domain objects
- Repository abstracts Eloquent queries

##### README
- Confirms Laravel Sail/Docker usage
- Describes available endpoints (via API routes)
- Highlights test suite structure under tests/Feature

##### Main components
a. API Gateway / HTTP Server
- Nginx or Apache in the Docker container exposes port 80/443
- Passes requests to Laravel’s public/index.php
b. Laravel Application
- Router (routes/api.php)
- Controllers (app/Http/Controllers/Api/ApiController)
- Middleware (app/Http/Middleware/SkipVerifyCsrfToken for API routes)
- Service Layer (app/Services/AccountService implementing AccountServiceInterface)
- Repository Layer (app/Repositories/AccountRepository implementing AccountRepositoryInterface)
- DTOs for incoming/outgoing payloads (AccountDTO, TransferDTO)
- Eloquent Models (app/Models/User, app/Models/Account if present)
c. Database
- MySQL (via Docker Compose)
- Tables: users, accounts, personal_access_tokens, cache, jobs, etc.
d. External/Supporting Services
- Queue (Laravel queue driver)
- Cache store (Redis or DB)
- Mail service (via config/services.php)
- Authentication (Laravel Sanctum for token-based auth)
e. Test suite
- PHPUnit tests under tests/Feature (ApiControllerTest)

##### Relationships & interactions
- Client → HTTP Server → Laravel Router → Middleware → Controller
- Controller → Service (injected) → Repository → Database
- Service may use multiple Repositories or integrate external services (Mail, Queue)
- Responses: Service returns DTO → Controller returns JSON response
- Tests: Hit API endpoints, mock Services/Repositories if needed

##### Architectural patterns & design principles
- Layered Architecture (Presentation → Application → Domain → Infrastructure)
- Dependency Inversion (Contracts/Interfaces)
- Single Responsibility (Controllers orchestrate, Services contain use-case logic, Repositories handle persistence)
- DTOs decouple domain models from API payloads
- Laravel conventions for config, environment, and bootstrapping

- Clear labels on each component and interface
- Notes on frameworks: Laravel, Eloquent ORM, Sanctum, Sail
- Environment isolation: Docker Compose services

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Docker Compose network
    subgraph "Docker Compose Network"
        direction TB
        HTTP["HTTP Server\n(Nginx/Apache)"]:::presentation
        LaravelApp["Laravel Application\n(Sail Container)"]:::presentation
        MySQL[(MySQL Database)]:::persistence
        Redis[(Cache Store)]:::external
        Queue[(Queue Service)]:::external
        Mail[(Mail Service)]:::external
    end

    %% Laravel Application components
    subgraph "Laravel Application"
        direction TB
        Router["Router\n(routes/api.php)"]:::presentation
        Middleware["Middleware\n(SkipVerifyCsrfToken)"]:::presentation
        Controller["ApiController\n(app/Http/Controllers/Api/ApiController.php)"]:::presentation
        ServiceInterface["AccountServiceInterface\n(app/Contracts/Services/AccountServiceInterface.php)"]:::app_logic
        ServiceImpl["AccountService\n(app/Services/AccountService.php)"]:::app_logic
        RepositoryInterface["AccountRepositoryInterface\n(app/Contracts/Repositories/AccountRepositoryInterface.php)"]:::data_access
        RepositoryImpl["AccountRepository\n(app/Repositories/AccountRepository.php)"]:::data_access
        DTOs["DTOs\nAccountDTO & TransferDTO"]:::dto
        Models["Models\nUser & Account"]:::model
        Migrations["Migrations\n(database/migrations)"]:::persistence
        AuthConfig["Sanctum Auth\n(config/sanctum.php)"]:::external
        Bootstrap["Bootstrap\n(bootstrap/app.php)"]:::external
        Provider["AppServiceProvider\n(app/Providers/AppServiceProvider.php)"]:::external
    end

    %% Test Suite
    TestSuite["Feature Tests\n(tests/Feature/ApiControllerTest.php)"]:::external

    %% Connections
    HTTP -->|"HTTP Request"| Router
    Router -->|"passes through"| Middleware
    Middleware -->|"invokes"| Controller
    Controller -->|"uses"| ServiceInterface
    ServiceInterface -.-> ServiceImpl
    ServiceImpl -->|"calls"| RepositoryInterface
    RepositoryInterface -.-> RepositoryImpl
    RepositoryImpl -->|"queries"| MySQL
    ServiceImpl -->|"dispatches"| Queue
    ServiceImpl -->|"caches via"| Redis
    ServiceImpl -->|"sends email via"| Mail
    ServiceImpl -->|"returns"| DTOs
    DTOs -->|"mapped to"| Models
    Controller -->|"returns JSON"| HTTP
    Bootstrap --> LaravelApp
    Provider --> LaravelApp
    AuthConfig --> LaravelApp
    Migrations --> MySQL
    TestSuite -->|"tests endpoints"| HTTP

    %% Click Events
    click HTTP "https://github.com/claudioemmanuel/banking-api/blob/master/public/index.php"
    click Router "https://github.com/claudioemmanuel/banking-api/blob/master/routes/api.php"
    click Controller "https://github.com/claudioemmanuel/banking-api/blob/master/app/Http/Controllers/Api/ApiController.php"
    click Middleware "https://github.com/claudioemmanuel/banking-api/blob/master/app/Http/Middleware/SkipVerifyCsrfToken.php"
    click ServiceInterface "https://github.com/claudioemmanuel/banking-api/blob/master/app/Contracts/Services/AccountServiceInterface.php"
    click ServiceImpl "https://github.com/claudioemmanuel/banking-api/blob/master/app/Services/AccountService.php"
    click RepositoryInterface "https://github.com/claudioemmanuel/banking-api/blob/master/app/Contracts/Repositories/AccountRepositoryInterface.php"
    click RepositoryImpl "https://github.com/claudioemmanuel/banking-api/blob/master/app/Repositories/AccountRepository.php"
    click DTOs "https://github.com/claudioemmanuel/banking-api/blob/master/app/Dtos/AccountDTO.php"
    click DTOs "https://github.com/claudioemmanuel/banking-api/blob/master/app/Dtos/TransferDTO.php"
    click Models "https://github.com/claudioemmanuel/banking-api/blob/master/app/Models/User.php"
    click AuthConfig "https://github.com/claudioemmanuel/banking-api/blob/master/config/sanctum.php"
    click Bootstrap "https://github.com/claudioemmanuel/banking-api/blob/master/bootstrap/app.php"
    click Provider "https://github.com/claudioemmanuel/banking-api/blob/master/app/Providers/AppServiceProvider.php"
    click Migrations "https://github.com/claudioemmanuel/banking-api/blob/master/database/migrations/0001_01_01_000000_create_users_table.php"
    click Migrations "https://github.com/claudioemmanuel/banking-api/blob/master/database/migrations/0001_01_01_000001_create_cache_table.php"
    click Migrations "https://github.com/claudioemmanuel/banking-api/blob/master/database/migrations/0001_01_01_000002_create_jobs_table.php"
    click Migrations "https://github.com/claudioemmanuel/banking-api/blob/master/database/migrations/2024_09_24_013417_create_personal_access_tokens_table.php"
    click TestSuite "https://github.com/claudioemmanuel/banking-api/blob/master/tests/Feature/ApiControllerTest.php"
    click MySQL "https://github.com/claudioemmanuel/banking-api/blob/master/docker-compose.yml"
    click Redis "https://github.com/claudioemmanuel/banking-api/blob/master/config/cache.php"
    click Queue "https://github.com/claudioemmanuel/banking-api/blob/master/config/queue.php"
    click Mail "https://github.com/claudioemmanuel/banking-api/blob/master/config/services.php"

    %% Styles
    classDef presentation fill:#daf7dc,stroke:#2e8b57,color:#000;
    classDef app_logic fill:#d0e1f9,stroke:#1f618d,color:#000;
    classDef data_access fill:#e3d0f9,stroke:#6c3483,color:#000;
    classDef dto fill:#f0f0f0,stroke:#7f8c8d,color:#000;
    classDef model fill:#fcf3cf,stroke:#b7950b,color:#000;
    classDef persistence fill:#f9d0d0,stroke:#c0392b,color:#000;
    classDef external fill:#d0f9f0,stroke:#117a65,color:#000;
```
