# mariem-m11/mlops-car-side-recognition-and-data-extraction-app architecture

> Architecture diagram of the GitHub repository mariem-m11/mlops-car-side-recognition-and-data-extraction-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app
- Repository: https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app

## Overview

##### Project Type and Purpose
- This is a full-stack, containerized, machine-learning-driven web application.
- The frontend is a simple static site (HTML/CSS/JS) in the `front/` directory.
- The backend is a FastAPI service in `app/appfast.py` that loads TensorFlow models to do car-pose classification, license-plate OCR, and ID-card recognition.
- The project is orchestrated locally via Docker Compose and in production via Kubernetes.
- It has built-in code quality analysis (SonarQube + PostgreSQL) and a GitLab CI/CD pipeline.

##### File Structure
- Top-level folders:
- `app/` – Python/FastAPI code + Dockerfile + requirements.txt
- `front/` – Static site + Dockerfile
- `docker_compose/` – `docker-compose.yml` and `docker-compose-app.yml` for multi-container setups
- `kubernetes/` – YAML manifests for Deployments, Services, Ingress, and SonarQube components
- `static/` – Images for documentation/UI
- CI/CD: `.gitlab-ci.yml` defines stages for build, test, code-quality, containerize, push, deploy.
- Code scanning: `.scannerwork/` holds SonarQube analysis artifacts.
- Test runner: `test.py` at project root.

##### README for Insights
- Confirms use of FastAPI (with Swagger UI), TensorFlow, Pydantic, python-multipart, Docker (Debian base), pipreqs/pireqs, Docker Compose, Kubernetes, SonarQube, and GitLab CI.
- Shows usage snippets for building, running, converting Compose → Kubernetes, and kubectl commands.

##### Main Components and Their Interactions
a. Client (Browser)
– Interacts over HTTP/HTTPS with the Ingress or LoadBalancer.
b. Ingress / LoadBalancer
– Routes `/` to the Web service and `/api/` to the API service.
c. Web Service (Static Frontend)
– Container built from `front/Dockerfile`, serves `index.html` and assets.
d. API Service (FastAPI + ML)
– Container built from `app/Dockerfile`, endpoint definitions in `appfast.py`.
– Invokes TensorFlow models, performs OCR, returns JSON.
e. Data Store for SonarQube
– PostgreSQL container / pod for code-quality data.
f. SonarQube Service
– Runs alongside the app in Compose and as pods in Kubernetes.
g. GitLab CI/CD Pipeline
– Pulls code, runs tests, triggers SonarQube analysis, builds Docker images, pushes to registry, deploys to Kubernetes.
h. Docker Registry (Docker Hub or private)
– Stores versioned images for frontend and backend.
i. Kubernetes Cluster
– Hosts Deployments, Services, PVCs (for Sonar data), and the nginx-ingress controller.

##### Architectural Patterns and Design Principles
- Microservices: separate web and API containers.
- Twelve-factor app: config via env vars, stateless services, separate build/deploy.
- Infrastructure as Code: all Docker Compose and Kubernetes manifests live in repo.
- CI/CD with code-quality gates (SonarQube).

b. Inside the cluster, place:
– Ingress/LoadBalancer
– Web Deployment + Service
– API Deployment + Service
– SonarQube Deployment + Service + Postgres PVC
c. Outside the cluster, place:
– Developer’s Browser
– Docker Registry
– Browser → Ingress → Web
– Browser → Ingress → API (for `/api` calls)
– GitLab → CI/CD Stages → Docker Registry → Kubernetes Cluster
– CI job → SonarQube analysis (to the SonarQube Service)
e. Component with its primary technology:
– Web: Dockerfile, HTML/CSS/JS
– API: FastAPI, Python, TensorFlow
– CI: GitLab CI, pipreqs/pireqs, pytest/test.py
– Code-Quality: SonarQube, PostgreSQL
– Orchestration: Docker Compose, Kubernetes YAMLs, Helm ingress-nginx

## Diagram (Mermaid)

```mermaid
graph TB
  %% Developer Client
  Browser["Browser"]:::external

  %% CI/CD
  subgraph "CI/CD - GitLab"
    GitLab["GitLab"]:::external
    CICD["CI/CD Pipeline"]:::ci
    TestRunner["Test Runner\n(test.py)"]:::ci
    Registry["Docker Registry"]:::infra
  end

  %% Local Dev
  subgraph "Local Dev - Docker Compose"
    Compose["Docker Compose\n(docker_compose/)"]:::infra
    WebComp["Web Container\n(front/)"]:::app
    APIComp["API Container\n(app/)"]:::app
    SonarComp["SonarQube Container"]:::ci
    PostgresComp["PostgreSQL Container"]:::infra
  end

  %% Production
  subgraph "Production - Kubernetes Cluster"
    Ingress["Ingress / LoadBalancer"]:::infra
    WebDep["Web Deployment + Service"]:::app
    APIDep["API Deployment + Service"]:::app
    SonarDep["SonarQube Deployment + Service"]:::ci
    SonarPVC["SonarQube PVC"]:::infra
    PostgresPVC["PostgreSQL PVC"]:::infra
  end

  %% Interactions
  Browser -->|"HTTP/HTTPS"| Ingress
  Ingress -->|"serves /"| WebDep
  Ingress -->|"serves /api"| APIDep

  GitLab -->|"git push"| CICD
  CICD -->|"run tests"| TestRunner
  CICD -->|"SonarQube analysis"| SonarDep
  CICD -->|"docker build & push"| Registry

  Registry -->|"pull image"| WebDep
  Registry -->|"pull image"| APIDep
  Registry -->|"pull image"| SonarDep

  Compose --> WebComp
  Compose --> APIComp
  Compose --> SonarComp
  Compose --> PostgresComp

  %% Click Events
  click WebComp "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/tree/main/front/"
  click WebComp "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/tree/main/front/Dockerfile"
  click WebComp "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/front/index.html"
  click APIComp "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/tree/main/app/"
  click APIComp "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/tree/main/app/Dockerfile"
  click APIComp "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/app/appfast.py"
  click APIComp "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/app/requirements.txt"
  click Compose "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/docker_compose/docker-compose.yml"
  click Compose "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/docker_compose/docker-compose-app.yml"
  click WebDep "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/kubernetes/web-deployment.yaml"
  click WebDep "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/kubernetes/web-service.yaml"
  click APIDep "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/kubernetes/api-deployment.yaml"
  click APIDep "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/kubernetes/api-service.yaml"
  click SonarDep "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/kubernetes/sonarqube/sonar-deployment.yaml"
  click SonarPVC "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/kubernetes/sonarqube/sonar-pvc.yaml"
  click PostgresPVC "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/kubernetes/sonarqube/postgres-pvc.yaml"
  click CICD "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/.gitlab-ci.yml"
  click TestRunner "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/blob/main/test.py"
  click SonarComp "https://github.com/mariem-m11/mlops-car-side-recognition-and-data-extraction-app/tree/main/.scannerwork/"

  %% Styles
  classDef external fill:#AED6F1,stroke:#1B4F72,color:#1B2631;
  classDef app fill:#A9DFBF,stroke:#196F3D,color:#1D8348;
  classDef ci fill:#F5B041,stroke:#B9770E,color:#7E5109;
  classDef infra fill:#D7DBDD,stroke:#626567,color:#1B2631;
```
