# dhruv2541/credit_compass architecture

> Architecture diagram of the GitHub repository dhruv2541/credit_compass, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dhruv2541/credit_compass
- Repository: https://github.com/dhruv2541/credit_compass

## Overview

#### Purpose and Runtime Entry Points
Credit Compass is a local, educational FinTech SPA for alternative credit scoring and guided micro-investment advice. The React/Vite client starts at `frontend/src/main.jsx` and composes the application in `frontend/src/App.jsx`. The FastAPI API starts through `backend/app/main.py` (`uvicorn app.main:app`) and exposes interactive OpenAPI docs.

#### Client Application and Navigation
The browser client owns presentation, route-level workflows, and chart/simulation interaction. Core screens are login/signup, the credit dashboard, and investment advisor:
- `frontend/src/pages/Login.jsx`
- `frontend/src/pages/Dashboard.jsx`
- `frontend/src/pages/Advisor.jsx`

`frontend/src/context/AuthContext.jsx` provides session/authentication state across the SPA. `frontend/src/hooks/useAxios.js` is the API-client boundary, expected to attach/use JWT-backed requests rather than embedding backend access in pages.

#### Authentication and Request Protection
The backend separates auth endpoints, token/password security, and dependency-based authorization:
- `backend/app/api/auth.py`
- `backend/app/core/security.py`
- `backend/app/api/deps.py`

The intended flow is signup/login → bcrypt password handling → JWT issuance → frontend auth context and Axios client → protected API requests resolved through FastAPI dependencies. This is the primary security boundary between public access and user-specific credit/investment operations.

#### API Composition Layer
FastAPI route modules expose the product capabilities and delegate business/ML work to services:
- `backend/app/main.py`
- `backend/app/api/credit.py`
- `backend/app/api/invest.py`

Credit APIs supply scoring and explainability-oriented output for the dashboard. Investment APIs accept the conversational risk-profile inputs and return advisory/projection-oriented results. `backend/app/api/deps.py` centralizes shared request concerns such as authenticated-user/database dependency resolution.

#### Domain Persistence and Contracts
SQLAlchemy models and sessions form the persistent boundary; Pydantic schemas define API input/output contracts:
- `backend/app/models/models.py`
- `backend/app/db/session.py`
- `backend/app/schemas/schemas.py`

SQLite is the declared datastore. Route handlers should exchange schema objects at the API boundary and use ORM models only inside backend persistence/service flows, limiting database representation leakage to the frontend.

#### Credit ML and Explainability Pipeline
Offline scripts produce the deployed ML artifact:
- `scripts/generate_data.py`
- `scripts/train_model.py`
- `backend/models/model.pkl`

Training uses synthetic credit signals and a scikit-learn LogisticRegression pipeline. At runtime, `backend/app/services/credit_service.py` loads/applies the persisted model to calculate credit likelihood/score and localized SHAP-equivalent feature contributions. The service boundary keeps model mechanics out of HTTP routing and lets the dashboard render both score and positive/negative explanations.

#### Investment Advisory and Presentation Effects
`backend/app/services/invest_service.py` encapsulates risk-profile interpretation and investment-growth calculations consumed by the advisor screen. The client renders the guided interaction and projections, while the backend remains the decision/calculation boundary. Separately, the one-session visual entrance is isolated from financial workflows:
- `frontend/src/components/IntroAnimation/IntroAnimation.jsx`
- `frontend/src/components/IntroAnimation/useIntroSession.js`

#### Infrastructure and External Dependencies
The system is a two-process local deployment: Node.js 18+ runs Vite; Python 3.10+ runs FastAPI/Uvicorn. Material libraries include React, Axios, Tailwind, Recharts, FastAPI, SQLAlchemy, SQLite, bcrypt, PyJWT, scikit-learn, pandas/numpy, and SHAP-related explainability support. No remote financial data provider or third-party AI service is identified; data and predictions are synthetic.

Main entry points: [`frontend/src/hooks/useAxios.js`](https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/hooks/useAxios.js) (API client), [`frontend/src/App.jsx`](https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/App.jsx) (SPA composition), [`backend/app/api/auth.py`](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/api/auth.py) (Auth endpoints), [`backend/app/api/credit.py`](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/api/credit.py) (Credit API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React/Vite Client"]
  node_client_main["Vite entry<br/>React entry<br/>[main.jsx]"]
  node_client_app["SPA composition<br/>React app<br/>[App.jsx]"]
  node_auth_context["Auth state<br/>React context<br/>[AuthContext.jsx]"]
  node_axios_client["API client<br/>Axios hook<br/>[useAxios.js]"]
  node_dashboard["Credit dashboard<br/>screen<br/>[Dashboard.jsx]"]
  node_advisor["Investment advisor<br/>screen<br/>[Advisor.jsx]"]
  node_intro["Intro animation<br/>UI effect<br/>[IntroAnimation.jsx]"]
end

subgraph group_api["FastAPI Backend"]
  node_api_main["FastAPI app<br/>API entry<br/>[main.py]"]
  node_auth_api["Auth endpoints<br/>route module<br/>[auth.py]"]
  node_security["JWT and passwords<br/>security service<br/>[security.py]"]
  node_dependencies["Request dependencies<br/>FastAPI dependencies<br/>[deps.py]"]
  node_credit_api["Credit API<br/>route module<br/>[credit.py]"]
  node_invest_api["Investment API<br/>route module<br/>[invest.py]"]
  node_schemas["API contracts<br/>Pydantic schemas<br/>[schemas.py]"]
  node_credit_service["Credit scoring service<br/>ML service<br/>[credit_service.py]"]
  node_invest_service["Investment service<br/>domain service<br/>[invest_service.py]"]
end

subgraph group_data["Persistence"]
  node_orm_models["Domain models<br/>SQLAlchemy models<br/>[models.py]"]
  node_db_session["Database session<br/>SQLAlchemy session<br/>[session.py]"]
  node_sqlite[("SQLite datastore<br/>database")]
end

subgraph group_ml["Credit ML Pipeline"]
  node_synthetic_data["Synthetic data generator<br/>offline script<br/>[generate_data.py]"]
  node_model_training["Model training<br/>offline script<br/>[train_model.py]"]
  node_credit_model["Deployed credit model<br/>pickle artifact<br/>[model.pkl]"]
end

node_client_main -->|"mounts"| node_client_app
node_client_app -->|"uses"| node_auth_context
node_client_app -->|"routes to"| node_dashboard
node_client_app -->|"routes to"| node_advisor
node_client_app -->|"shows"| node_intro
node_auth_context -->|"provides JWT"| node_axios_client
node_dashboard -->|"calls"| node_axios_client
node_advisor -->|"calls"| node_axios_client
node_axios_client -->|"signup/login"| node_auth_api
node_axios_client -->|"protected requests"| node_credit_api
node_axios_client -->|"protected requests"| node_invest_api
node_api_main -->|"registers"| node_auth_api
node_api_main -->|"registers"| node_credit_api
node_api_main -->|"registers"| node_invest_api
node_auth_api -->|"hashes and issues tokens"| node_security
node_auth_api -->|"uses"| node_schemas
node_credit_api -->|"authorizes"| node_dependencies
node_invest_api -->|"authorizes"| node_dependencies
node_dependencies -->|"verifies JWT"| node_security
node_dependencies -->|"resolves session"| node_db_session
node_credit_api -->|"uses"| node_schemas
node_credit_api -->|"delegates scoring"| node_credit_service
node_invest_api -->|"uses"| node_schemas
node_invest_api -->|"delegates advice"| node_invest_service
node_credit_service -->|"loads"| node_credit_model
node_db_session -->|"connects"| node_sqlite
node_orm_models -->|"persisted through"| node_db_session
node_auth_api -->|"creates users"| node_orm_models
node_synthetic_data -->|"produces training data"| node_model_training
node_model_training -->|"writes artifact"| node_credit_model

click node_client_main "https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/main.jsx"
click node_client_app "https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/App.jsx"
click node_auth_context "https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/context/AuthContext.jsx"
click node_axios_client "https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/hooks/useAxios.js"
click node_dashboard "https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/pages/Dashboard.jsx"
click node_advisor "https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/pages/Advisor.jsx"
click node_intro "https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/components/IntroAnimation/IntroAnimation.jsx"
click node_api_main "https://github.com/dhruv2541/credit_compass/blob/main/backend/app/main.py"
click node_auth_api "https://github.com/dhruv2541/credit_compass/blob/main/backend/app/api/auth.py"
click node_security "https://github.com/dhruv2541/credit_compass/blob/main/backend/app/core/security.py"
click node_dependencies "https://github.com/dhruv2541/credit_compass/blob/main/backend/app/api/deps.py"
click node_credit_api "https://github.com/dhruv2541/credit_compass/blob/main/backend/app/api/credit.py"
click node_invest_api "https://github.com/dhruv2541/credit_compass/blob/main/backend/app/api/invest.py"
click node_schemas "https://github.com/dhruv2541/credit_compass/blob/main/backend/app/schemas/schemas.py"
click node_credit_service "https://github.com/dhruv2541/credit_compass/blob/main/backend/app/services/credit_service.py"
click node_invest_service "https://github.com/dhruv2541/credit_compass/blob/main/backend/app/services/invest_service.py"
click node_orm_models "https://github.com/dhruv2541/credit_compass/blob/main/backend/app/models/models.py"
click node_db_session "https://github.com/dhruv2541/credit_compass/blob/main/backend/app/db/session.py"
click node_synthetic_data "https://github.com/dhruv2541/credit_compass/blob/main/scripts/generate_data.py"
click node_model_training "https://github.com/dhruv2541/credit_compass/blob/main/scripts/train_model.py"
click node_credit_model "https://github.com/dhruv2541/credit_compass/blob/main/backend/models/model.pkl"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_main,node_client_app,node_auth_context,node_axios_client,node_dashboard,node_advisor,node_intro toneBlue
class node_api_main,node_auth_api,node_security,node_dependencies,node_credit_api,node_invest_api,node_schemas,node_credit_service,node_invest_service toneAmber
class node_orm_models,node_db_session,node_sqlite toneMint
class node_synthetic_data,node_model_training,node_credit_model toneRose
```

## Components

### React/Vite Client

- [Vite entry](https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/main.jsx): React entry · `frontend/src/main.jsx`
- [SPA composition](https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/App.jsx): React app · `frontend/src/App.jsx`
- [Auth state](https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/context/AuthContext.jsx): React context · Shares JWT-backed session state across the SPA. · `frontend/src/context/AuthContext.jsx`
- [API client](https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/hooks/useAxios.js): Axios hook · Client boundary for authenticated API requests. · `frontend/src/hooks/useAxios.js`
- [Credit dashboard](https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/pages/Dashboard.jsx): screen · Renders credit score and feature explanations. · `frontend/src/pages/Dashboard.jsx`
- [Investment advisor](https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/pages/Advisor.jsx): screen · Guides risk inputs and displays projections. · `frontend/src/pages/Advisor.jsx`
- [Intro animation](https://github.com/dhruv2541/credit_compass/blob/main/frontend/src/components/IntroAnimation/IntroAnimation.jsx): UI effect · One-session visual entrance isolated from financial flows. · `frontend/src/components/IntroAnimation/IntroAnimation.jsx`

### FastAPI Backend

- [FastAPI app](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/main.py): API entry · Uvicorn entry point and route composition. · `backend/app/main.py`
- [Auth endpoints](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/api/auth.py): route module · Signup and login endpoints. · `backend/app/api/auth.py`
- [JWT and passwords](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/core/security.py): security service · Hashes passwords and issues or verifies JWTs. · `backend/app/core/security.py`
- [Request dependencies](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/api/deps.py): FastAPI dependencies · Resolves authenticated users and database access. · `backend/app/api/deps.py`
- [Credit API](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/api/credit.py): route module · Exposes scoring and explainability results. · `backend/app/api/credit.py`
- [Investment API](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/api/invest.py): route module · Exposes risk-profile advisory and projections. · `backend/app/api/invest.py`
- [API contracts](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/schemas/schemas.py): Pydantic schemas · Defines request and response representations. · `backend/app/schemas/schemas.py`
- [Credit scoring service](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/services/credit_service.py): ML service · Calculates score and localized feature contributions. · `backend/app/services/credit_service.py`
- [Investment service](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/services/invest_service.py): domain service · Interprets risk profiles and calculates growth. · `backend/app/services/invest_service.py`

### Persistence

- [Domain models](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/models/models.py): SQLAlchemy models · `backend/app/models/models.py`
- [Database session](https://github.com/dhruv2541/credit_compass/blob/main/backend/app/db/session.py): SQLAlchemy session · `backend/app/db/session.py`
- **SQLite datastore**: database · Local persistent store for user-domain data.

### Credit ML Pipeline

- [Synthetic data generator](https://github.com/dhruv2541/credit_compass/blob/main/scripts/generate_data.py): offline script · `scripts/generate_data.py`
- [Model training](https://github.com/dhruv2541/credit_compass/blob/main/scripts/train_model.py): offline script · Trains the LogisticRegression credit pipeline. · `scripts/train_model.py`
- [Deployed credit model](https://github.com/dhruv2541/credit_compass/blob/main/backend/models/model.pkl): pickle artifact · `backend/models/model.pkl`

## Connections

- Vite entry → SPA composition: mounts
- SPA composition → Auth state: uses
- SPA composition → Credit dashboard: routes to
- SPA composition → Investment advisor: routes to
- SPA composition → Intro animation: shows
- Auth state → API client: provides JWT
- Credit dashboard → API client: calls
- Investment advisor → API client: calls
- API client → Auth endpoints: signup/login
- API client → Credit API: protected requests
- API client → Investment API: protected requests
- FastAPI app → Auth endpoints: registers
- FastAPI app → Credit API: registers
- FastAPI app → Investment API: registers
- Auth endpoints → JWT and passwords: hashes and issues tokens
- Auth endpoints → API contracts: uses
- Credit API → Request dependencies: authorizes
- Investment API → Request dependencies: authorizes
- Request dependencies → JWT and passwords: verifies JWT
- Request dependencies → Database session: resolves session
- Credit API → API contracts: uses
- Credit API → Credit scoring service: delegates scoring
- Investment API → API contracts: uses
- Investment API → Investment service: delegates advice
- Credit scoring service → Deployed credit model: loads
- Database session → SQLite datastore: connects
- Domain models → Database session: persisted through
- Auth endpoints → Domain models: creates users
- Synthetic data generator → Model training: produces training data
- Model training → Deployed credit model: writes artifact
