# rafael-be/aleteia architecture

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

- Interactive diagram: https://gitdiagram.com/rafael-be/aleteia
- Repository: https://github.com/rafael-be/aleteia

## Overview

AleteIA is a Portuguese fact-checking chat application. Users authenticate through Firebase, synchronize a business profile to MongoDB, then send verified-email chat requests; the backend enforces daily usage limits, retrieves conversation history, asks OpenAI to fact-check with web search, and saves the result and token usage. The README documents Firebase providers and the 10-question daily limit. A legacy Gemini implementation is present but not active in the current chat route. Edges reflect shown calls or README workflow; unsampled frontend details are kept conservative.

Main entry points: [`src/controller/chatController.py`](https://github.com/rafael-be/aleteia/blob/main/src/controller/chatController.py) (Chat controller), [`static/js/firebase-init.js`](https://github.com/rafael-be/aleteia/blob/main/static/js/firebase-init.js) (Firebase client), [`src/controller/authController.py`](https://github.com/rafael-be/aleteia/blob/main/src/controller/authController.py) (Auth controller), [`app.py`](https://github.com/rafael-be/aleteia/blob/main/app.py) (Flask application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_webpages["App pages"]
  node_authui["Auth interface<br/>[auth.js]"]
  node_chatui["Chat interface<br/>[chat.js]"]
  node_firebaseui["Firebase client<br/>[firebase-init.js]"]
  node_mainjs["Main interactions<br/>[main.js]"]
end

subgraph group_identity["Identity and profiles"]
  node_authroutes["Auth routes<br/>[authRoutes.py]"]
  node_authcontroller["Auth controller<br/>[authController.py]"]
  node_tokencheck["Token verification<br/>[auth.py]"]
  node_emailcheck["Email reputation"]
  node_usermodel["User model<br/>[userModel.py]"]
end

subgraph group_chat["Chat and fact-checking"]
  node_chatroutes["Chat routes<br/>[chatRoutes.py]"]
  node_chatcontroller["Chat controller<br/>[chatController.py]"]
  node_chatmodel["Conversation model<br/>[chatModel.py]"]
  node_openai["Fact-check service<br/>[openai_services.py]"]
  node_geminicontroller["Legacy Gemini handler"]
  node_gemini["Gemini service<br/>[gemini_services.py]"]
end

subgraph group_platform["Data and integrations"]
  node_app["Flask application<br/>[app.py]"]
  node_dbprovider["Mongo provider<br/>[database.py]"]
  node_mongodb[("MongoDB")]
  node_firebase["Firebase Authentication"]
  node_abstractapi["Abstract Email API"]
  node_openaiservice["OpenAI API"]
  node_websearch["Web search"]
end

node_visitor(("User"))

node_visitor -->|"uses"| node_webpages
node_app -->|"renders"| node_webpages
node_visitor -->|"uses"| node_authui
node_visitor -->|"uses"| node_chatui
node_app -->|"registers"| node_authroutes
node_app -->|"registers"| node_chatroutes
node_authui -->|"uses"| node_firebaseui
node_chatui -->|"uses"| node_firebaseui
node_mainjs -->|"uses"| node_firebaseui
node_firebaseui -->|"authenticates"| node_firebase
node_firebaseui -->|"synchronizes profile"| node_authroutes
node_authroutes -->|"dispatches"| node_authcontroller
node_authcontroller -->|"verifies token"| node_tokencheck
node_authcontroller -->|"syncs profile"| node_usermodel
node_authcontroller -->|"checks email"| node_emailcheck
node_emailcheck -.->|"queries"| node_abstractapi
node_chatroutes -->|"dispatches"| node_chatcontroller
node_chatcontroller -->|"verifies token"| node_tokencheck
node_chatcontroller -->|"checks usage"| node_usermodel
node_chatcontroller -->|"reads and saves"| node_chatmodel
node_chatcontroller -->|"requests answer"| node_openai
node_openai -->|"sends request"| node_openaiservice
node_openai -->|"enables search"| node_websearch
node_usermodel -->|"gets database"| node_dbprovider
node_dbprovider -->|"connects"| node_mongodb
node_geminicontroller -.->|"delegates"| node_gemini
node_gemini -.->|"fact-checks online"| node_websearch

click node_webpages "https://github.com/rafael-be/aleteia/tree/main/public"
click node_authui "https://github.com/rafael-be/aleteia/blob/main/static/js/auth.js"
click node_chatui "https://github.com/rafael-be/aleteia/blob/main/static/js/chat.js"
click node_firebaseui "https://github.com/rafael-be/aleteia/blob/main/static/js/firebase-init.js"
click node_mainjs "https://github.com/rafael-be/aleteia/blob/main/static/js/main.js"
click node_app "https://github.com/rafael-be/aleteia/blob/main/app.py"
click node_authroutes "https://github.com/rafael-be/aleteia/blob/main/src/routes/authRoutes.py"
click node_authcontroller "https://github.com/rafael-be/aleteia/blob/main/src/controller/authController.py"
click node_tokencheck "https://github.com/rafael-be/aleteia/blob/main/src/utils/auth.py"
click node_emailcheck "https://github.com/rafael-be/aleteia/blob/main/src/services/abstract_email_service.py"
click node_chatroutes "https://github.com/rafael-be/aleteia/blob/main/src/routes/chatRoutes.py"
click node_chatcontroller "https://github.com/rafael-be/aleteia/blob/main/src/controller/chatController.py"
click node_chatmodel "https://github.com/rafael-be/aleteia/blob/main/src/models/chatModel.py"
click node_usermodel "https://github.com/rafael-be/aleteia/blob/main/src/models/userModel.py"
click node_openai "https://github.com/rafael-be/aleteia/blob/main/src/services/openai_services.py"
click node_geminicontroller "https://github.com/rafael-be/aleteia/blob/main/src/controller/gemini_controller.py"
click node_gemini "https://github.com/rafael-be/aleteia/blob/main/src/services/gemini_services.py"
click node_dbprovider "https://github.com/rafael-be/aleteia/blob/main/src/database.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_webpages,node_authui,node_chatui,node_firebaseui,node_mainjs,node_visitor toneBlue
class node_authroutes,node_authcontroller,node_tokencheck,node_emailcheck,node_usermodel toneAmber
class node_chatroutes,node_chatcontroller,node_chatmodel,node_openai,node_geminicontroller,node_gemini toneMint
class node_app,node_dbprovider,node_mongodb,node_firebase,node_abstractapi,node_openaiservice,node_websearch toneRose
```

## Components

### Web experience

- [App pages](https://github.com/rafael-be/aleteia/tree/main/public): `public`
- [Auth interface](https://github.com/rafael-be/aleteia/blob/main/static/js/auth.js): `static/js/auth.js`
- [Chat interface](https://github.com/rafael-be/aleteia/blob/main/static/js/chat.js): `static/js/chat.js`
- [Firebase client](https://github.com/rafael-be/aleteia/blob/main/static/js/firebase-init.js): `static/js/firebase-init.js`
- [Main interactions](https://github.com/rafael-be/aleteia/blob/main/static/js/main.js): `static/js/main.js`

### Identity and profiles

- [Auth routes](https://github.com/rafael-be/aleteia/blob/main/src/routes/authRoutes.py): `src/routes/authRoutes.py`
- [Auth controller](https://github.com/rafael-be/aleteia/blob/main/src/controller/authController.py): `src/controller/authController.py`
- [Token verification](https://github.com/rafael-be/aleteia/blob/main/src/utils/auth.py): `src/utils/auth.py`
- [Email reputation](https://github.com/rafael-be/aleteia/blob/main/src/services/abstract_email_service.py): `src/services/abstract_email_service.py`
- [User model](https://github.com/rafael-be/aleteia/blob/main/src/models/userModel.py): `src/models/userModel.py`

### Chat and fact-checking

- [Chat routes](https://github.com/rafael-be/aleteia/blob/main/src/routes/chatRoutes.py): `src/routes/chatRoutes.py`
- [Chat controller](https://github.com/rafael-be/aleteia/blob/main/src/controller/chatController.py): `src/controller/chatController.py`
- [Conversation model](https://github.com/rafael-be/aleteia/blob/main/src/models/chatModel.py): `src/models/chatModel.py`
- [Fact-check service](https://github.com/rafael-be/aleteia/blob/main/src/services/openai_services.py): `src/services/openai_services.py`
- [Legacy Gemini handler](https://github.com/rafael-be/aleteia/blob/main/src/controller/gemini_controller.py): `src/controller/gemini_controller.py`
- [Gemini service](https://github.com/rafael-be/aleteia/blob/main/src/services/gemini_services.py): `src/services/gemini_services.py`

### Data and integrations

- [Flask application](https://github.com/rafael-be/aleteia/blob/main/app.py): `app.py`
- [Mongo provider](https://github.com/rafael-be/aleteia/blob/main/src/database.py): `src/database.py`
- **MongoDB**
- **Firebase Authentication**
- **Abstract Email API**
- **OpenAI API**
- **Web search**

### Other components

- **User**

## Connections

- User → App pages: uses
- Flask application → App pages: renders (evidence: `app.py`)
- User → Auth interface: uses
- User → Chat interface: uses
- Flask application → Auth routes: registers (evidence: `app.py`)
- Flask application → Chat routes: registers (evidence: `app.py`)
- Auth interface → Firebase client: uses (evidence: `static/js/auth.js`)
- Chat interface → Firebase client: uses (evidence: `static/js/chat.js`)
- Main interactions → Firebase client: uses (evidence: `static/js/main.js`)
- Firebase client → Firebase Authentication: authenticates (evidence: `README.md`)
- Firebase client → Auth routes: synchronizes profile (evidence: `README.md`)
- Auth routes → Auth controller: dispatches (evidence: `src/routes/authRoutes.py`)
- Auth controller → Token verification: verifies token (evidence: `src/controller/authController.py`)
- Auth controller → User model: syncs profile (evidence: `src/controller/authController.py`)
- Auth controller → Email reputation: checks email (evidence: `src/controller/authController.py`)
- Email reputation → Abstract Email API: queries (evidence: `src/services/abstract_email_service.py`)
- Chat routes → Chat controller: dispatches (evidence: `src/routes/chatRoutes.py`)
- Chat controller → Token verification: verifies token (evidence: `src/controller/chatController.py`)
- Chat controller → User model: checks usage (evidence: `src/controller/chatController.py`)
- Chat controller → Conversation model: reads and saves (evidence: `src/controller/chatController.py`)
- Chat controller → Fact-check service: requests answer (evidence: `src/controller/chatController.py`)
- Fact-check service → OpenAI API: sends request (evidence: `src/services/openai_services.py`)
- Fact-check service → Web search: enables search (evidence: `src/services/openai_services.py`)
- User model → Mongo provider: gets database (evidence: `src/models/userModel.py`)
- Mongo provider → MongoDB: connects (evidence: `src/database.py`)
- Legacy Gemini handler → Gemini service: delegates (evidence: `src/controller/gemini_controller.py`)
- Gemini service → Web search: fact-checks online (evidence: `src/services/gemini_services.py`)
