# alonecol/stem-financelab architecture

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

- Interactive diagram: https://gitdiagram.com/alonecol/stem-financelab
- Repository: https://github.com/alonecol/stem-financelab

## Overview

STEM FinanceLab is a Streamlit educational simulator for financial management. The participant identifies themself, diagnoses financial knowledge, chooses a scenario and funding strategy, plans a budget, responds to execution events, and reviews financial results and learning feedback. The app coordinates these stages; the financial motor calculates cash flow, statements, and indicators, while persistence and reporting support review. Research-mode consent and the optional AI tutor are distinct capabilities. Edges follow the README and shown app imports/calls; unsampled implementation details are not inferred.

Main entry points: [`app.py`](https://github.com/alonecol/stem-financelab/blob/main/app.py) (Streamlit workflow), [`core/database.py`](https://github.com/alonecol/stem-financelab/blob/main/core/database.py) (Persistence operations), [`core/eventos.py`](https://github.com/alonecol/stem-financelab/blob/main/core/eventos.py) (Event selection), [`core/tutor_ia.py`](https://github.com/alonecol/stem-financelab/blob/main/core/tutor_ia.py) (AI tutor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Participant experience"]
  node_app["Streamlit workflow<br/>[app.py]"]
  node_session["Session state<br/>[session.py]"]
  node_consent["Research consent<br/>[tcle.py]"]
  node_questionnaire["Knowledge diagnosis<br/>[questionario.py]"]
  node_ui["Shared UI<br/>[ui.py]"]
end

subgraph group_simulation["Simulation domain"]
  node_scenarios["Scenario and choices<br/>[cenario.py]"]
  node_concepts["Finance concepts<br/>[conceitos.py]"]
  node_funding["Funding options<br/>[cenario.py]"]
  node_event_options["Event scenarios<br/>[eventos.py]"]
  node_event_logic["Event selection<br/>[eventos.py]"]
  node_simulation_math["Financial motor"]
  node_finance_helpers["Finance calculations<br/>[financeiro.py]"]
end

subgraph group_insight["Results and guidance"]
  node_feedback["Rule-based feedback<br/>[feedback.py]"]
  node_ai_tutor["AI tutor<br/>[tutor_ia.py]"]
  node_report["Simulation report<br/>[relatorio.py]"]
end

subgraph group_platform["Persistence and configuration"]
  node_database_api["Persistence operations<br/>[database.py]"]
  node_database[("SQLite database")]
  node_config["Runtime configuration<br/>[config.py]"]
  node_logging["Logging setup<br/>[logging_config.py]"]
end

node_participant(("Participant"))
node_openai{{"OpenAI API"}}

node_participant -->|"uses"| node_app
node_app -->|"initializes state"| node_session
node_app -->|"presents consent"| node_consent
node_app -->|"loads diagnosis"| node_questionnaire
node_app -->|"renders"| node_ui
node_app -->|"loads scenarios"| node_scenarios
node_app -->|"loads concepts"| node_concepts
node_app -->|"records funding"| node_funding
node_app -->|"selects events"| node_event_logic
node_event_logic -->|"imports events"| node_event_options
node_app -->|"records decisions"| node_simulation_math
node_app -->|"uses calculations"| node_finance_helpers
node_app -->|"generates feedback"| node_feedback
node_app -->|"requests guidance"| node_ai_tutor
node_ai_tutor -->|"requests completion"| node_openai
node_app -->|"builds report"| node_report
node_app -->|"saves simulation"| node_database_api
node_database_api -->|"reads and writes"| node_database
node_database_api -->|"gets database path"| node_config
node_app -->|"loads settings"| node_config
node_app -->|"configures logging"| node_logging

click node_app "https://github.com/alonecol/stem-financelab/blob/main/app.py"
click node_session "https://github.com/alonecol/stem-financelab/blob/main/core/session.py"
click node_consent "https://github.com/alonecol/stem-financelab/blob/main/core/tcle.py"
click node_questionnaire "https://github.com/alonecol/stem-financelab/blob/main/data/questionario.py"
click node_ui "https://github.com/alonecol/stem-financelab/blob/main/core/ui.py"
click node_scenarios "https://github.com/alonecol/stem-financelab/blob/main/data/cenario.py"
click node_concepts "https://github.com/alonecol/stem-financelab/blob/main/data/conceitos.py"
click node_funding "https://github.com/alonecol/stem-financelab/blob/main/data/cenario.py"
click node_event_options "https://github.com/alonecol/stem-financelab/blob/main/data/eventos.py"
click node_event_logic "https://github.com/alonecol/stem-financelab/blob/main/core/eventos.py"
click node_simulation_math "https://github.com/alonecol/stem-financelab/blob/main/core/motor_financeiro.py"
click node_finance_helpers "https://github.com/alonecol/stem-financelab/blob/main/core/financeiro.py"
click node_feedback "https://github.com/alonecol/stem-financelab/blob/main/core/feedback.py"
click node_ai_tutor "https://github.com/alonecol/stem-financelab/blob/main/core/tutor_ia.py"
click node_report "https://github.com/alonecol/stem-financelab/blob/main/core/relatorio.py"
click node_database_api "https://github.com/alonecol/stem-financelab/blob/main/core/database.py"
click node_database "https://github.com/alonecol/stem-financelab/tree/main/database"
click node_config "https://github.com/alonecol/stem-financelab/blob/main/core/config.py"
click node_logging "https://github.com/alonecol/stem-financelab/blob/main/core/logging_config.py"

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_app,node_session,node_consent,node_questionnaire,node_ui toneBlue
class node_scenarios,node_concepts,node_funding,node_event_options,node_event_logic,node_simulation_math,node_finance_helpers toneAmber
class node_feedback,node_ai_tutor,node_report,node_openai toneMint
class node_database_api,node_database,node_config,node_logging toneRose
class node_participant toneIndigo
```

## Components

### Participant experience

- [Streamlit workflow](https://github.com/alonecol/stem-financelab/blob/main/app.py): `app.py`
- [Session state](https://github.com/alonecol/stem-financelab/blob/main/core/session.py): `core/session.py`
- [Research consent](https://github.com/alonecol/stem-financelab/blob/main/core/tcle.py): `core/tcle.py`
- [Knowledge diagnosis](https://github.com/alonecol/stem-financelab/blob/main/data/questionario.py): `data/questionario.py`
- [Shared UI](https://github.com/alonecol/stem-financelab/blob/main/core/ui.py): `core/ui.py`

### Simulation domain

- [Scenario and choices](https://github.com/alonecol/stem-financelab/blob/main/data/cenario.py): `data/cenario.py`
- [Finance concepts](https://github.com/alonecol/stem-financelab/blob/main/data/conceitos.py): `data/conceitos.py`
- [Funding options](https://github.com/alonecol/stem-financelab/blob/main/data/cenario.py): `data/cenario.py`
- [Event scenarios](https://github.com/alonecol/stem-financelab/blob/main/data/eventos.py): `data/eventos.py`
- [Event selection](https://github.com/alonecol/stem-financelab/blob/main/core/eventos.py): `core/eventos.py`
- [Financial motor](https://github.com/alonecol/stem-financelab/blob/main/core/motor_financeiro.py): `core/motor_financeiro.py`
- [Finance calculations](https://github.com/alonecol/stem-financelab/blob/main/core/financeiro.py): `core/financeiro.py`

### Results and guidance

- [Rule-based feedback](https://github.com/alonecol/stem-financelab/blob/main/core/feedback.py): `core/feedback.py`
- [AI tutor](https://github.com/alonecol/stem-financelab/blob/main/core/tutor_ia.py): `core/tutor_ia.py`
- [Simulation report](https://github.com/alonecol/stem-financelab/blob/main/core/relatorio.py): `core/relatorio.py`

### Persistence and configuration

- [Persistence operations](https://github.com/alonecol/stem-financelab/blob/main/core/database.py): `core/database.py`
- [SQLite database](https://github.com/alonecol/stem-financelab/tree/main/database): `database`
- [Runtime configuration](https://github.com/alonecol/stem-financelab/blob/main/core/config.py): `core/config.py`
- [Logging setup](https://github.com/alonecol/stem-financelab/blob/main/core/logging_config.py): `core/logging_config.py`

### Other components

- **Participant**
- **OpenAI API**

## Connections

- Participant → Streamlit workflow: uses (evidence: `README.md`)
- Streamlit workflow → Session state: initializes state (evidence: `app.py`)
- Streamlit workflow → Research consent: presents consent (evidence: `app.py`)
- Streamlit workflow → Knowledge diagnosis: loads diagnosis (evidence: `app.py`)
- Streamlit workflow → Shared UI: renders (evidence: `app.py`)
- Streamlit workflow → Scenario and choices: loads scenarios (evidence: `app.py`)
- Streamlit workflow → Finance concepts: loads concepts (evidence: `app.py`)
- Streamlit workflow → Funding options: records funding (evidence: `app.py`)
- Streamlit workflow → Event selection: selects events (evidence: `app.py`)
- Event selection → Event scenarios: imports events (evidence: `core/eventos.py`)
- Streamlit workflow → Financial motor: records decisions (evidence: `app.py`)
- Streamlit workflow → Finance calculations: uses calculations (evidence: `app.py`)
- Streamlit workflow → Rule-based feedback: generates feedback (evidence: `app.py`)
- Streamlit workflow → AI tutor: requests guidance (evidence: `app.py`)
- AI tutor → OpenAI API: requests completion (evidence: `core/tutor_ia.py`)
- Streamlit workflow → Simulation report: builds report (evidence: `app.py`)
- Streamlit workflow → Persistence operations: saves simulation (evidence: `app.py`)
- Persistence operations → SQLite database: reads and writes (evidence: `core/database.py`)
- Persistence operations → Runtime configuration: gets database path (evidence: `core/database.py`)
- Streamlit workflow → Runtime configuration: loads settings (evidence: `app.py`)
- Streamlit workflow → Logging setup: configures logging (evidence: `app.py`)
