# thethanghn/trinity-appravel-api architecture

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

- Interactive diagram: https://gitdiagram.com/thethanghn/trinity-appravel-api
- Repository: https://github.com/thethanghn/trinity-appravel-api

## Overview

##### Project Type Analysis
This is a REST API banking application that handles account management and transactions. It's built as a Rails API-only application, focusing on backend operations without frontend components.

##### Main Components

A. API Layer (Controllers)
- API/V1 namespace containing the four main controllers
- Accounts, Banks, Customers, and Transactions controllers

B. Service Layer
- AccountService
- TransactionService
- How they handle business logic between controllers and models

C. Data Layer
- Four main models: Account, Bank, Customer, and Transaction
- Their relationships

D. Documentation Layer
- Swagger/OpenAPI integration

##### Use a top-down approach with these levels

**┌─────────────────────────────────────────────────┐**
- API Layer (REST)               │
- [Swagger UI/Documentation]                     │
- ┘
- ↓
**┌─────────────────────────────────────────────────┐**
- Controllers Layer                  │
- ┌─────────┐ ┌────────┐ ┌─────────┐ ┌─────────┐ │
- Accounts │ │ Banks  │ │Customers│ │Transact.│ │
- ┘ └────────┘ └─────────┘ └─────────┘ │
- ┘
- ↓
**┌─────────────────────────────────────────────────┐**
- Service Layer                      │
- ┌───────────────┐    ┌─────────────────┐    │
- AccountService │    │TransactionService│    │
- ┘    └─────────────────┘    │
- ┘
- ↓
**┌─────────────────────────────────────────────────┐**
- Model Layer                        │
- ┌─────────┐ ┌────────┐ ┌─────────┐ ┌─────────┐ │
- Customer │─│Account │─│Transfer │ │  Bank   │ │
- ┘ └────────┘ └─────────┘ └─────────┘ │
- ┘
- ↓
**┌─────────────────────────────────────────────────┐**
- Database Layer                     │
- [SQLite Database]                  │
- ┘

- → for one-to-many relationships
- ↔ for many-to-many relationships
- ⇢ for service calls

##### Additional Elements

**Customer --1:N--> Account**
**Bank --1:N--> Account**
**Account --1:N--> Transaction**

- POST /api/v1/accounts (create account)
- POST /api/v1/transactions (transfer)
- GET /api/v1/accounts/:id/balance
- GET /api/v1/accounts/:id/transactions

##### Important Notes
- Notes about the Swagger documentation integration
- API versioning (v1) structure
- Test coverage (RSpec) scope

##### Technical Details to Highlight
- Rails API-only application
- RESTful architecture
- Service-oriented design pattern
- Active Record ORM usage
- RSpec test suite
- Swagger API documentation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph API
        SwaggerUI["Swagger UI/Documentation"]:::documentation
        click SwaggerUI "https://github.com/thethanghn/trinity-appravel-api/blob/main/swagger/v1/swagger.yaml"
        SwaggerConfig["Swagger Config"]:::documentation
        click SwaggerConfig "https://github.com/thethanghn/trinity-appravel-api/blob/main/config/initializers/rswag_api.rb"
    end

    subgraph Controllers
        AC["Accounts Controller"]:::controller
        click AC "https://github.com/thethanghn/trinity-appravel-api/blob/main/app/controllers/api/v1/accounts_controller.rb"
        BC["Banks Controller"]:::controller
        click BC "https://github.com/thethanghn/trinity-appravel-api/blob/main/app/controllers/api/v1/banks_controller.rb"
        CC["Customers Controller"]:::controller
        click CC "https://github.com/thethanghn/trinity-appravel-api/blob/main/app/controllers/api/v1/customers_controller.rb"
        TC["Transactions Controller"]:::controller
        click TC "https://github.com/thethanghn/trinity-appravel-api/blob/main/app/controllers/api/v1/transactions_controller.rb"
    end

    subgraph Services
        AS["Account Service"]:::service
        click AS "https://github.com/thethanghn/trinity-appravel-api/blob/main/app/services/account_service.rb"
        TS["Transaction Service"]:::service
        click TS "https://github.com/thethanghn/trinity-appravel-api/blob/main/app/services/transaction_service.rb"
        BS["Base Service"]:::service
        click BS "https://github.com/thethanghn/trinity-appravel-api/blob/main/app/services/application_service.rb"
    end

    subgraph Models
        Account["Account Model"]:::model
        click Account "https://github.com/thethanghn/trinity-appravel-api/blob/main/app/models/account.rb"
        Bank["Bank Model"]:::model
        click Bank "https://github.com/thethanghn/trinity-appravel-api/blob/main/app/models/bank.rb"
        Customer["Customer Model"]:::model
        click Customer "https://github.com/thethanghn/trinity-appravel-api/blob/main/app/models/customer.rb"
        Transaction["Transaction Model"]:::model
        click Transaction "https://github.com/thethanghn/trinity-appravel-api/blob/main/app/models/transaction.rb"
    end

    subgraph Database
        DB[(SQLite Database)]:::database
    end

    subgraph Tests
        APITests["API Tests"]:::test
        click APITests "https://github.com/thethanghn/trinity-appravel-api/tree/main/spec/requests/api/v1"
        ServiceTests["Service Tests"]:::test
        click ServiceTests "https://github.com/thethanghn/trinity-appravel-api/tree/main/spec/services"
    end

    SwaggerUI --> AC & BC & CC & TC
    SwaggerConfig --> SwaggerUI

    AC & BC & CC & TC --> AS & TS
    BS --> AS & TS

    AS --> Account & Bank & Customer
    TS --> Transaction & Account

    Account & Bank & Customer & Transaction --> DB

    APITests -.-> AC & BC & CC & TC
    ServiceTests -.-> AS & TS

    %% Relationships
    Customer --"1:N"--> Account
    Bank --"1:N"--> Account
    Account --"1:N"--> Transaction

    %% Styling
    classDef controller fill:#3498db,stroke:#2980b9,color:white
    classDef service fill:#2ecc71,stroke:#27ae60,color:white
    classDef model fill:#e67e22,stroke:#d35400,color:white
    classDef database fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef documentation fill:#9b59b6,stroke:#8e44ad,color:white
    classDef test fill:#f1c40f,stroke:#f39c12,color:black

    %% Legend
    subgraph Legend
        C1[Controller]:::controller
        S1[Service]:::service
        M1[Model]:::model
        D1[Database]:::database
        Doc1[Documentation]:::documentation
        T1[Test]:::test
    end
```
