# pelumiade/library-management architecture

> Architecture diagram of the GitHub repository pelumiade/library-management, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pelumiade/library-management
- Repository: https://github.com/pelumiade/library-management

## Overview

##### Main Components
- Admin API Service: This service handles operations such as adding, updating, or removing books, managing users, and tracking book lending.
- Frontend API Service: This service is tailored for end-user interactions including user enrollment, browsing books, borrowing, and returning books.
- Message Broker (RabbitMQ): The intermediary that facilitates asynchronous, event-driven communication between the two services.
- Databases: Each service has its own isolated database (termed “authoritative” for the Admin API and a “mirror” for the Frontend API).
- Containerization: Docker and Docker Compose are used to deploy both services along with the RabbitMQ management interface.
- Deployment Infrastructure: The system is deployed on AWS EC2 with provided endpoints for each service and RabbitMQ.

##### Architectural Relationships
- How the Admin API publishes messages to RabbitMQ whenever there’s a change (for example, when books are added or updated).
- How the Frontend API subscribes to the relevant RabbitMQ queues to consume messages and keep its catalog in sync.
- That both services expose RESTful endpoints (with their FastAPI-driven documentation available at separate URLs) and use separate connection pools to their respective databases.
- Interactions between external clients (users and administrators) and the relevant API endpoints.

##### Architectural Patterns and Design Principles
- Microservices: Emphasize the separation of concerns, with two dedicated services operating independently.
- Event-Driven Communication: Detail the asynchronous message passing using RabbitMQ for data consistency between services.
- Database Isolation: Note that each service uses its own database to maintain integrity and performance.
- Containerization: Include Docker to indicate how services are packaged and deployed, reinforcing scalability and ease of deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Admin Service"
        AC["Admin Client"]:::client
        AA["Admin API Service"]:::service
        ADB["Admin Database"]:::database
        ADF["Dockerfile (Admin)"]:::docker
    end

    subgraph "Frontend Service"
        UC["User Client"]:::client
        FA["Frontend API Service"]:::service
        FDB["Frontend Database"]:::database
        FDF["Dockerfile (Frontend)"]:::docker
    end

    subgraph "Messaging"
        RMQ["RabbitMQ Message Broker"]:::message
        RMQComp["docker-compose.yml"]:::docker
    end

    DEP["AWS EC2 Deployment"]:::deployment

    %% Client interactions
    AC -->|"APIRequest"| AA
    UC -->|"APIRequest"| FA

    %% Asynchronous message communication
    AA -->|"Publish:BookUpdate"| RMQ
    RMQ -->|"Consume:SyncCatalog"| FA

    %% Database connections
    AA -->|"DBConnection"| ADB
    FA -->|"DBConnection"| FDB

    %% Docker containerization details
    AA ---|"Dockerized"| ADF
    FA ---|"Dockerized"| FDF
    RMQ ---|"ContainerConfig"| RMQComp

    %% Deployment association
    AA -->|"DeployedOn"| DEP
    FA -->|"DeployedOn"| DEP
    RMQ -->|"DeployedOn"| DEP

    %% Click events
    click AA "https://github.com/pelumiade/library-management/tree/main/admin_api/"
    click FA "https://github.com/pelumiade/library-management/tree/main/frontend_api/"
    click RMQ "https://github.com/pelumiade/library-management/blob/main/docker-compose.yml"
    click ADB "https://github.com/pelumiade/library-management/blob/main/admin_api/test.db"
    click FDB "https://github.com/pelumiade/library-management/blob/main/frontend_api/test.db"
    click ADF "https://github.com/pelumiade/library-management/tree/main/admin_api/Dockerfile"
    click FDF "https://github.com/pelumiade/library-management/tree/main/frontend_api/Dockerfile"

    %% Class definitions for styling
    classDef service fill:#a3d2ca,stroke:#000,stroke-width:2px;
    classDef client fill:#ffcc5c,stroke:#000,stroke-width:2px;
    classDef database fill:#ff6f69,stroke:#000,stroke-width:2px;
    classDef message fill:#f9d976,stroke:#000,stroke-width:2px;
    classDef docker fill:#d0e1f9,stroke:#000,stroke-width:2px;
    classDef deployment fill:#c1c8e4,stroke:#000,stroke-width:2px;
```
