# variaxxx/credit-ruiner architecture

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

- Interactive diagram: https://gitdiagram.com/variaxxx/credit-ruiner
- Repository: https://github.com/variaxxx/credit-ruiner

## Overview

##### Project Overview
- The project is a full-stack web application composed of a Python-based backend and an Angular-based frontend.
- It uses a pre-trained model (model.pkl) to analyze data about a borrower and determine their payment capacity.
- Containerization is supported via Docker (Dockerfiles for both backend and frontend, plus a docker-compose.yml) and NGINX configurations (for serving the frontend and/or API gateway).

##### Main Components
a. Frontend Application:
- Built with Angular.
- Contains several modules for pages (e.g., login, registration, analysis page, history page, profile, welcome page) and shared UI components (headers, sidebars, buttons, and other UI kit elements).
- Managed with its own build configurations, and served possibly via an NGINX container (note the nginx.conf in both frontend and project root).

b. Backend Service:
- A Python-based web service (likely using Flask given the file names like __init__.py, routes, models, etc.).
- Contains modules for configuration, command-line utilities, and routing (account, analysis, auth).
- Integrates a pre-trained model (“model.pkl” in the backend/instance directory) which is used for evaluating creditworthiness.
- Has dedicated Docker configuration and WSGI entry point for production use.

c. Data Processing / Model Component:
- The "analysis" model located under backend/app/models and the instance/model.pkl file indicate that the core predictive logic (credit analysis) relies on a trained machine learning model.
- How the backend loads and utilizes this model to process user data coming from the frontend.

d. Containerization & Deployment:
- Dockerfiles for both the backend and frontend suggest that each component can be containerized.
- The docker-compose.yml file likely coordinates these containers and possibly ties in additional services like a reverse proxy or load balancer.

##### Relationships and Data Flow
- Users interact with the Angular frontend (UI components, pages).
- The frontend makes HTTP (or REST API) calls to the Python backend.
- The backend processes authentication, account management, and credit analysis requests; during analysis it invokes the pre-trained model to determine creditworthiness.
- Responses (analysis results, user data, etc.) are then sent back from the backend to the frontend.
- Optionally, separate the “Public” Internet/Browser layer from the internal Docker network, showing that requests first hit the NGINX layer if applicable.

##### Architectural Patterns and Technologies
- For the full-stack application, emphasize the separation of concerns:
- Frontend: a client-side, component-based Angular application with routing, services (for API communication), guards (for authentication), and UI kit components.
- Backend: a RESTful API built in Python, handling routes and models, and utilizing a pre-trained machine learning model.
- That the system follows containerization principles via Docker and orchestrates multiple services via docker-compose.
- Use of the WSGI server (likely through a production server like Gunicorn behind NGINX) to run the Python application.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    subgraph "User Layer"
        Browser["User Browser"]:::external
    end

    %% Edge Layer
    subgraph "Edge Layer"
        NginxProxy["NGINX Reverse Proxy"]:::infra
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        FrontendApp["Angular App"]:::frontend
        AngularConfig["Angular Config (angular.json)"]:::frontend
        PackageJson["Package.json"]:::frontend
        FrontendComponents["Angular Components (src/app)"]:::frontend
        FrontendUI["UI Kit Components (src/ui-kit)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BackendAPI["Python Flask API"]:::backend
        BackendApp["Backend App (Flask - app)"]:::backend
        WSGIEntry["WSGI Entry Point (wsgi.py)"]:::backend
        CLICommands["CLI Commands (cli_commands.py)"]:::backend
        ConfigSettings["Config Settings (config.py)"]:::backend
        Routes["API Routes (routes/)"]:::backend
        AnalysisModule["Analysis Model Module"]:::model
        ModelFile["Pre-trained Model (model.pkl)"]:::model
    end

    %% Deployment & Infrastructure
    subgraph "Deployment & Infrastructure"
        DockerCompose["Docker Compose"]:::deploy
        BackendDockerfile["Backend Dockerfile"]:::deploy
        FrontendDockerfile["Frontend Dockerfile"]:::deploy
        FrontendNginx["Frontend NGINX Config"]:::deploy
        RootNginx["Root NGINX Config"]:::deploy
    end

    %% Main Flow of Requests
    Browser -->|"HTTP_Request"| NginxProxy
    NginxProxy -->|"Routes_to_Frontend"| FrontendApp

    %% Frontend Details Composition
    FrontendApp -->|"Includes"| AngularConfig
    FrontendApp -->|"Includes"| PackageJson
    FrontendApp -->|"Includes"| FrontendComponents
    FrontendApp -->|"Includes"| FrontendUI

    %% Interaction between Frontend and Backend
    FrontendApp -->|"API_Call"| BackendAPI
    BackendAPI -->|"Delegates_to"| BackendApp
    BackendAPI -->|"Handles_Routes"| Routes
    BackendAPI -->|"Uses"| WSGIEntry

    %% Backend Internal Components
    BackendApp -->|"Executes"| CLICommands
    BackendApp -->|"Uses_Config"| ConfigSettings
    BackendApp -->|"Loads_Model"| AnalysisModule
    AnalysisModule -->|"Predicts_with"| ModelFile
    BackendAPI -->|"Returns_Response"| FrontendApp
    FrontendApp -->|"Renders"| Browser

    %% Deployment Connections
    DockerCompose -->|"Orchestrates"| FrontendApp
    DockerCompose -->|"Orchestrates"| BackendAPI
    DockerCompose -->|"Orchestrates"| NginxProxy

    BackendDockerfile -->|"Builds"| BackendAPI
    FrontendDockerfile -->|"Builds"| FrontendApp
    FrontendNginx -->|"Configures"| NginxProxy
    RootNginx -->|"Configures"| NginxProxy

    %% Click Events for Frontend
    click FrontendApp "https://github.com/variaxxx/credit-ruiner/tree/main/frontend/"
    click AngularConfig "https://github.com/variaxxx/credit-ruiner/blob/main/frontend/angular.json"
    click PackageJson "https://github.com/variaxxx/credit-ruiner/blob/main/frontend/package.json"
    click FrontendComponents "https://github.com/variaxxx/credit-ruiner/tree/main/frontend/src/app"
    click FrontendUI "https://github.com/variaxxx/credit-ruiner/tree/main/frontend/src/ui-kit"

    %% Click Events for Backend
    click BackendAPI "https://github.com/variaxxx/credit-ruiner/tree/main/backend/"
    click BackendApp "https://github.com/variaxxx/credit-ruiner/tree/main/backend/app"
    click WSGIEntry "https://github.com/variaxxx/credit-ruiner/blob/main/backend/wsgi.py"
    click CLICommands "https://github.com/variaxxx/credit-ruiner/blob/main/backend/cli_commands.py"
    click ConfigSettings "https://github.com/variaxxx/credit-ruiner/blob/main/backend/config.py"
    
    %% Click Events for Data Processing / Model Component
    click AnalysisModule "https://github.com/variaxxx/credit-ruiner/blob/main/backend/app/models/analysis.py"
    click ModelFile "https://github.com/variaxxx/credit-ruiner/blob/main/backend/instance/model.pkl"

    %% Click Events for Containerization & Deployment
    click BackendDockerfile "https://github.com/variaxxx/credit-ruiner/tree/main/backend/Dockerfile"
    click FrontendDockerfile "https://github.com/variaxxx/credit-ruiner/tree/main/frontend/Dockerfile"
    click DockerCompose "https://github.com/variaxxx/credit-ruiner/blob/main/docker-compose.yml"
    click FrontendNginx "https://github.com/variaxxx/credit-ruiner/blob/main/frontend/nginx.conf"
    click RootNginx "https://github.com/variaxxx/credit-ruiner/blob/main/nginx.conf"

    %% Styles
    classDef external fill:#ffd1dc,stroke:#ff007f,stroke-width:2px;
    classDef infra fill:#cce5ff,stroke:#3399ff,stroke-width:2px;
    classDef frontend fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef backend fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef model fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef deploy fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
```
