# etoosamoe/eto-app architecture

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

- Interactive diagram: https://gitdiagram.com/etoosamoe/eto-app
- Repository: https://github.com/etoosamoe/eto-app

## Overview

##### Project Type and Purpose
- This is a full-stack web application designed as a learning tool to hone programming and DevOps skills. It comprises a Python-based backend API (using FastAPI, SQLAlchemy, and Pydantic), a React-based frontend, and a default local SQLite database (with options to configure alternative databases). The project also includes containerization (via Docker and docker-compose) and Kubernetes manifests, showing a multi-environment, multi-deployment approach.

##### Analyzing the File Structure
- Top-level key directories:
– backend: Contains the API code, models, database connections, environment configurations, and sample dataset files.
– frontend: Contains the React app source code, Docker configuration for a multi-stage build (where Nginx serves the built static files and proxies API calls to the backend), and environment configurations.
– k8s: YAML manifests for Kubernetes deployments, including backend, frontend, Postgres database, namespaces, and secrets.
– Other files such as docker-compose.yml, .env.example files, and CI/CD configurations under .github indicate that container orchestration and continuous integration are also integral parts.

##### Components
a. Main Components:
- Frontend Component:
- Built with NodeJS and React.
- Uses a multi-stage Docker build resulting in an Nginx container that serves static files.
- Proxies API requests (e.g., /api/servers, /api/docs, /api/version) to the backend.
- Backend API Component:
- Written in Python with FastAPI.
- Implements CRUD operations, healthchecks (/healthcheck), and special endpoints (e.g., /flaky).
- Uses SQLAlchemy and Pydantic for data models and schema validation.
- Connects to a database (default SQLite inside the container, configurable via environment variables for other DB options).
- Database:
- Default configuration uses a local SQLite file (ephemeral when using containers), but Kubernetes manifests indicate support for PostgreSQL.
- Container/Orchestration Layer:
- Docker & docker-compose: For running backend and frontend containers locally.
- Kubernetes (and even Helm in progress): For production or scalable deployments (containers for frontend, backend, and a DB service).

b. Relationships and Interactions:

c. Architectural Patterns & Design Principles:
- Separation of concerns: clear delineation between frontend (presentation layer) and backend (API and business logic).
- Containerization: Each component (frontend, backend, and optionally the database) is containerized and independently deployable.
- API Gateway/Reverse Proxy: Nginx in the frontend container is used to help route requests appropriately.
- Environment-based configuration: Use of .env files to manage different configurations for local, Docker, and Kubernetes deployments.

d. Relevant Technologies & Frameworks:
- Backend: Python, FastAPI, SQLAlchemy, Pydantic, Uvicorn.
- Frontend: NodeJS, React, Nginx.
- Database: SQLite (default) and alternatives like PostgreSQL (supported in Kubernetes).
- DevOps/Deployment: Docker, docker-compose, Kubernetes, GitHub Actions for CI.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User/Client Browser
    U["User/Client Browser"]:::client

    %% Frontend Layer
    subgraph "Frontend Layer"
        F["Frontend (React+Nginx)"]:::frontend
        N["Nginx Proxy"]:::nginx
        F -->|"routes"| N
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B["Backend API (FastAPI)"]:::backend
    end

    %% Database Subgraph with two options
    subgraph "Database"
        DB1["SQLite (Default)"]:::database
        DB2["PostgreSQL (K8s)"]:::database
    end

    %% Container Orchestration and Deployment
    subgraph "Container Orchestration"
        DC["Docker Compose"]:::orchestration
        K8S["Kubernetes"]:::orchestration
    end

    %% CI/CD Pipeline
    CICD["CI/CD Pipeline (GitHub Actions)"]:::cicd

    %% Environment Configurations
    subgraph "Environment Config"
        ENV1["Top Level: .env.example"]:::env
        ENV2["Backend: .env.example"]:::env
        ENV3["Frontend: .env.example"]:::env
    end

    %% Data Flow Connections
    U -->|"HTTP request"| F
    N -->|"forwards to API"| B
    B -->|"performs CRUD"| DB1
    B -->|"performs CRUD"| DB2

    %% Deployment/Orchestration Connections
    CICD -->|"triggers"| DC
    CICD -->|"triggers"| K8S
    DC -->|"deploys"| F
    DC -->|"deploys"| B
    DC -->|"deploys"| DB1
    K8S -->|"deploys"| F
    K8S -->|"deploys"| B
    K8S -->|"deploys"| DB2

    %% Environment Configuration to Components
    ENV1 --> F
    ENV2 --> B
    ENV3 --> F

    %% Styling Classes
    classDef client fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef nginx fill:#B0E0E6,stroke:#333,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef database fill:#FFA07A,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef orchestration fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef cicd fill:#FFC0CB,stroke:#333,stroke-width:2px;
    classDef env fill:#E0FFFF,stroke:#333,stroke-width:2px;

    %% Click Events
    click F "https://github.com/etoosamoe/eto-app/tree/master/frontend/"
    click B "https://github.com/etoosamoe/eto-app/tree/master/backend/app/"
    click DB1 "https://github.com/etoosamoe/eto-app/blob/master/backend/dataset.csv"
    click DB2 "https://github.com/etoosamoe/eto-app/blob/master/k8s/db.yml"
    click DC "https://github.com/etoosamoe/eto-app/blob/master/docker-compose.yml"
    click K8S "https://github.com/etoosamoe/eto-app/tree/master/k8s/"
    click CICD "https://github.com/etoosamoe/eto-app/blob/master/.github/workflows/build.yml"
    click ENV1 "https://github.com/etoosamoe/eto-app/blob/master/.env.example"
    click ENV2 "https://github.com/etoosamoe/eto-app/blob/master/backend/.env.example"
    click ENV3 "https://github.com/etoosamoe/eto-app/blob/master/frontend/.env.example"
```
