# darylfernandes99/healthcare-plan-management-api architecture

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

- Interactive diagram: https://gitdiagram.com/darylfernandes99/healthcare-plan-management-api
- Repository: https://github.com/darylfernandes99/healthcare-plan-management-api

## Overview

##### Main components
- API Server: The primary application entry point is app.py, which wires up routes (defined in src/routes.py) and ties in controllers (located in src/controllers) to handle business logic.
- Controllers & Middlewares: Controllers (e.g., plans_controller.py) process requests, while middlewares (e.g., auth_middleware.py) handle tasks such as authentication.
- Data Models: Under src/models, there are several modules representing integration points with external systems (e.g., elastic_search_model.py for Elasticsearch, redis_model.py for Redis, and etag_model.py).
- Queue Consumer: The src/consumer.py likely listens to RabbitMQ queues to handle asynchronous processing (for operations like create, update, or delete) without blocking the main thread.
- Configurations: The src/config directory contains configurations and environment-specific setups (development vs. production) along with log formatting and other settings.
- Static Assets: Contains swagger.json files which can provide API documentation and possibly aid in understanding the API’s interactions.

##### External systems and their roles
- Redis: Serves as the quick key-value store for caching or transient storage of healthcare plans.
- Elasticsearch: Provides indexing and full-text search for healthcare plans and related data.
- RabbitMQ: Manages asynchronous task queues to handle background processing (ensuring that operations like plan creation, updating, and deletion don’t block API responses).

##### Relationships and interactions
- The API server handles incoming HTTP requests which are passed through the authentication middleware.
- The controllers interpret the requests and hand off operations to the appropriate data models.
- For synchronization, data is written to both Redis and Elasticsearch or read from them as needed.
- For asynchronous processing, operations (create, update, delete) are queued in RabbitMQ and later processed by the consumer.
- Utilize configuration files to adjust behavior between development and production environments.

##### Architectural patterns and design principles
- The project follows a separation of concerns where each module (controllers, models, middlewares) has a specific role.
- MVC-like pattern emerges as routes in app.py delegate to controllers, which in turn interact with models.
- There’s an emphasis on asynchronous processing via RabbitMQ to keep the API responsive.
- External services (Redis, Elasticsearch) are abstracted in separate model modules, promoting modularity and easier maintenance.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Client("Client"):::presentation
        APIServer("API Server (app.py)"):::presentation
        Routes("Routes (src/routes.py)"):::presentation
        Config("Configurations (src/config)"):::presentation
    end

    %% Business Layer
    subgraph "Business Layer"
        Auth("Auth Middleware (src/middlewares/auth_middleware.py)"):::business
        Controller("Plans Controller (src/controllers/plans_controller.py)"):::business
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        RedisModel("Redis Model (src/models/redis_model.py)"):::data
        ElasticModel("Elasticsearch Model (src/models/elastic_search_model.py)"):::data
        EtagModel("ETag Model (src/models/etag_model.py)"):::data
        PlansModel("Plans Model (src/models/plans_model.py)"):::data
    end

    %% Asynchronous Processing
    subgraph "Asynchronous Processing"
        RabbitMQ("RabbitMQ"):::async
        Consumer("Queue Consumer (src/consumer.py)"):::async
    end

    %% External Services
    subgraph "External Services"
        RedisService("Redis"):::external
        EsService("Elasticsearch"):::external
    end

    %% Documentation
    subgraph "Documentation"
        Swagger("Swagger Documentation (static/swagger.json)"):::documentation
        SwaggerCopy("Swagger Copy (static/swagger copy.json)"):::documentation
    end

    %% Relationships
    Client -->|"sends request"| APIServer
    APIServer -->|"handles routing"| Routes
    APIServer -.->|"uses"| Config
    Routes -->|"applies"| Auth
    Auth -->|"delegates to"| Controller

    Controller -->|"CRUD operations"| RedisModel
    Controller -->|"CRUD operations"| ElasticModel
    Controller -->|"CRUD operations"| EtagModel
    Controller -->|"CRUD operations"| PlansModel

    RedisModel -->|"reads/writes"| RedisService
    ElasticModel -->|"queries"| EsService

    %% Asynchronous flow
    Controller -.->|"enqueue task"| RabbitMQ
    RabbitMQ -->|"processes task"| Consumer

    %% Documentation flow (Client can fetch API docs)
    Client -->|"views"| Swagger
    Client -->|"views"| SwaggerCopy

    %% Click Events
    click APIServer "https://github.com/darylfernandes99/healthcare-plan-management-api/blob/main/app.py"
    click Routes "https://github.com/darylfernandes99/healthcare-plan-management-api/blob/main/src/routes.py"
    click Config "https://github.com/darylfernandes99/healthcare-plan-management-api/tree/main/src/config/"
    click Auth "https://github.com/darylfernandes99/healthcare-plan-management-api/blob/main/src/middlewares/auth_middleware.py"
    click Controller "https://github.com/darylfernandes99/healthcare-plan-management-api/blob/main/src/controllers/plans_controller.py"
    click RedisModel "https://github.com/darylfernandes99/healthcare-plan-management-api/blob/main/src/models/redis_model.py"
    click ElasticModel "https://github.com/darylfernandes99/healthcare-plan-management-api/blob/main/src/models/elastic_search_model.py"
    click EtagModel "https://github.com/darylfernandes99/healthcare-plan-management-api/blob/main/src/models/etag_model.py"
    click PlansModel "https://github.com/darylfernandes99/healthcare-plan-management-api/blob/main/src/models/plans_model.py"
    click Consumer "https://github.com/darylfernandes99/healthcare-plan-management-api/blob/main/src/consumer.py"
    click Swagger "https://github.com/darylfernandes99/healthcare-plan-management-api/blob/main/static/swagger.json"
    click SwaggerCopy "https://github.com/darylfernandes99/healthcare-plan-management-api/blob/main/static/swagger copy.json"

    %% Styles
    classDef presentation fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef business fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef data fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef async fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#d6d8db,stroke-width:2px;
    classDef documentation fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
