# yatharth0045/12-factor-app architecture

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

- Interactive diagram: https://gitdiagram.com/yatharth0045/12-factor-app
- Repository: https://github.com/yatharth0045/12-factor-app

## Overview

##### Project Components
- Main Microservice: Represented by the primary app.py at the project root, built from the Dockerfile in the root directory and launched via docker run on port 8080.
- Admin Microservice: Located under the “admin” directory (with its own Dockerfile and app.py) and deployed separately on port 8081.
- Fluentd Logging Service: Found under the “fluentd” directory (with its Dockerfile and fluent.conf). This service is used to collect logs from the microservices and is connected to external logging systems.
- Redis: A backing service which the applications link to as an external dependency (running on port 6379).
- Elasticsearch and Kibana: Although they are not directly part of the codebase, the README instructs running these services for log searching and visualization (ports 9200 for Elasticsearch and 5601 for Kibana).

##### Component Relationships and Data Flow
- The main microservice and admin service connect to Redis (through the use of --link in docker commands) for caching or session management.
- Both the main service and the admin service are configured to push logs to Fluentd via the log-driver and log-opt parameters.
- Fluentd then aggregates the logs and forwards them to Elasticsearch (and optionally to stdout) for indexing and logstash formatting.
- Kibana is connected to Elasticsearch to provide a user interface for log analysis.

##### Architectural Patterns and Design Principles
- 12 Factor Methodology: Emphasize the stateless, isolated deployment of microservices.
- Containerization: Each major component (main service, admin service, Fluentd) is containerized. Represents the principle of dependencies being isolated within each container.
- Dependency Injection: Configurations are passed in via environment variables (.env files) and external service links, ensuring that the codebase does not hard code configurations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% System Architecture Layers
    subgraph "Application Microservices"
        MainMicroservice("Main Microservice<br/>(app.py, Dockerfile, port 8080)"):::app
        AdminMicroservice("Admin Microservice<br/>(admin/app.py, admin/Dockerfile, port 8081)"):::app
    end

    subgraph "Logging and Monitoring"
        Fluentd("Fluentd Logging Agent<br/>(fluent.conf, Dockerfile, port 24224)"):::log
        Elastic("Elasticsearch<br/>(port 9200)"):::log
        Kibana("Kibana<br/>(port 5601)"):::log
    end

    subgraph "External Dependencies"
        Redis("Redis<br/>(port 6379)"):::dep
    end

    %% Relationships between Components
    MainMicroservice -->|"logs"| Fluentd
    AdminMicroservice -->|"logs"| Fluentd

    MainMicroservice -->|"cache"| Redis
    AdminMicroservice -->|"cache"| Redis

    Fluentd -->|"forwards"| Elastic
    Elastic -->|"UI"| Kibana

    %% Click Events for Component Mappings
    click MainMicroservice "https://github.com/yatharth0045/12-factor-app/blob/main/app.py"
    click MainMicroservice "https://github.com/yatharth0045/12-factor-app/tree/main/Dockerfile"
    click AdminMicroservice "https://github.com/yatharth0045/12-factor-app/blob/main/admin/app.py"
    click AdminMicroservice "https://github.com/yatharth0045/12-factor-app/tree/main/admin/Dockerfile"
    click Fluentd "https://github.com/yatharth0045/12-factor-app/blob/main/fluentd/fluent.conf"
    click Fluentd "https://github.com/yatharth0045/12-factor-app/tree/main/fluentd/Dockerfile"

    %% Styles
    classDef app fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef dep fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef log fill:#ffa07a,stroke:#000,stroke-width:2px;
```
