# oussemaharrabi/kanz-petitfour architecture

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

- Interactive diagram: https://gitdiagram.com/oussemaharrabi/kanz-petitfour
- Repository: https://github.com/oussemaharrabi/kanz-petitfour

## Overview

KANZ is a Tunisian investing assistant with separate investor and CMF-inspector experiences. Users enter through role selection, then explore market and portfolio information, predictions, sentiment, alerts, and investment guidance; inspectors monitor anomalies and investigate suspicious activity. The backend exposes these capabilities through FastAPI, backed by market/ML services and persistent data, with a separate multilingual news collection and analysis subsystem. Edges rely on excerpted imports, the startup excerpt, or README architecture statements; unsampled implementation details are not asserted.

Main entry points: [`backend/app/main.py`](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/main.py) (FastAPI application), [`frontend/src/App.jsx`](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/App.jsx) (Role and route entry), [`backend/app/api/routes/stocks.py`](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/stocks.py) (Stock endpoints), [`backend/app/db/database.py`](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/db/database.py) (Market and user store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web experience"]
  node_app["Role and route entry<br/>[App.jsx]"]
  node_analysis["Stock analysis<br/>[Analysis.jsx]"]
  node_profile["Investor profile<br/>[Profile.jsx]"]
  node_simulator["Portfolio simulator<br/>[Simulator.jsx]"]
  node_inspectorui["Inspector dashboards"]
  node_mockstocks["Stock sample data<br/>[stocks.js]"]
  node_webapi["API client<br/>[api.js]"]
end

subgraph group_backend["API and identity"]
  node_entry["FastAPI application<br/>[main.py]"]
  node_authroutes["Authentication routes<br/>[auth.py]"]
  node_auth["Identity and roles<br/>[auth.py]"]
  node_stockroutes["Stock endpoints<br/>[stocks.py]"]
  node_marketroutes["Market endpoints<br/>[market.py]"]
  node_newsroutes["News endpoints<br/>[news.py]"]
  node_portfolioroutes["Portfolio endpoints<br/>[portfolio.py]"]
  node_alertroutes["Alert endpoints<br/>[alerts.py]"]
  node_agentroute["Agent endpoint<br/>[agent.py]"]
end

subgraph group_analytics["Market intelligence"]
  node_prediction["Price prediction<br/>[prediction.py]"]
  node_anomaly["Anomaly detection<br/>[anomaly.py]"]
  node_decision["Decision service<br/>[decision.py]"]
  node_sentiment["Sentiment service<br/>[sentiment.py]"]
  node_mlprediction["Forecast model<br/>[prediction.py]"]
  node_mlanomaly["Anomaly model<br/>[anomaly.py]"]
end

subgraph group_data["Data and news"]
  node_store[("Market and user store<br/>[database.py]")]
  node_scraper["News scrapers<br/>[news_scrapers.py]"]
  node_scheduler["News scheduler<br/>[scheduler.py]"]
  node_analyzer["French-Arabic analyzer<br/>[analyzer.py]"]
end

node_investor(("Investor"))
node_inspector(("CMF inspector"))
node_supabase["Supabase auth"]

node_investor -->|"opens"| node_app
node_inspector -->|"opens"| node_app
node_app -->|"routes to"| node_analysis
node_app -->|"routes to"| node_profile
node_app -->|"routes to"| node_simulator
node_app -->|"routes to"| node_inspectorui
node_analysis -->|"requests data"| node_webapi
node_profile -->|"requests data"| node_webapi
node_webapi -->|"uses fallback"| node_mockstocks
node_app -->|"uses REST API"| node_entry
node_entry -->|"registers"| node_stockroutes
node_entry -->|"registers"| node_marketroutes
node_entry -->|"registers"| node_authroutes
node_entry -->|"registers"| node_newsroutes
node_entry -->|"registers"| node_portfolioroutes
node_entry -->|"registers"| node_alertroutes
node_entry -->|"registers"| node_agentroute
node_authroutes -->|"resolves user"| node_auth
node_auth -->|"reads users"| node_store
node_authroutes -->|"authenticates"| node_supabase
node_stockroutes -->|"reads market data"| node_store
node_marketroutes -->|"reads market data"| node_store
node_portfolioroutes -->|"reads portfolio"| node_store
node_alertroutes -->|"reads alerts"| node_store
node_newsroutes -->|"reads news"| node_store
node_stockroutes -->|"requests forecasts"| node_prediction
node_stockroutes -->|"requests detection"| node_anomaly
node_stockroutes -->|"requests sentiment"| node_sentiment
node_stockroutes -->|"requests guidance"| node_decision
node_marketroutes -->|"requests sentiment"| node_sentiment
node_newsroutes -->|"analyzes articles"| node_analyzer
node_prediction -->|"uses model"| node_mlprediction
node_anomaly -->|"uses model"| node_mlanomaly
node_sentiment -->|"delegates analysis"| node_analyzer
node_scheduler -->|"schedules collection"| node_scraper
node_scheduler -->|"uses analysis"| node_analyzer
node_entry -.->|"starts optionally"| node_scheduler
node_agentroute -->|"uses guidance"| node_decision

click node_app "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/App.jsx"
click node_analysis "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/pages/investor/Analysis.jsx"
click node_profile "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/pages/investor/Profile.jsx"
click node_simulator "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/pages/investor/Simulator.jsx"
click node_inspectorui "https://github.com/oussemaharrabi/kanz-petitfour/tree/main/frontend/src/pages/inspector"
click node_mockstocks "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/data/stocks.js"
click node_webapi "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/services/api.js"
click node_entry "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/main.py"
click node_authroutes "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/auth.py"
click node_auth "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/core/auth.py"
click node_stockroutes "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/stocks.py"
click node_marketroutes "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/market.py"
click node_newsroutes "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/news.py"
click node_portfolioroutes "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/portfolio.py"
click node_alertroutes "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/alerts.py"
click node_agentroute "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/agent.py"
click node_store "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/db/database.py"
click node_prediction "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/services/prediction.py"
click node_anomaly "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/services/anomaly.py"
click node_decision "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/services/decision.py"
click node_sentiment "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/services/sentiment.py"
click node_mlprediction "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/ml/src/prediction.py"
click node_mlanomaly "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/ml/src/anomaly.py"
click node_scraper "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/nlp/scrapers/news_scrapers.py"
click node_scheduler "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/nlp/scrapers/scheduler.py"
click node_analyzer "https://github.com/oussemaharrabi/kanz-petitfour/blob/main/nlp/sentiment/analyzer.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_analysis,node_profile,node_simulator,node_inspectorui,node_mockstocks,node_webapi toneBlue
class node_entry,node_authroutes,node_auth,node_stockroutes,node_marketroutes,node_newsroutes,node_portfolioroutes,node_alertroutes,node_agentroute toneAmber
class node_prediction,node_anomaly,node_decision,node_sentiment,node_mlprediction,node_mlanomaly toneMint
class node_store,node_scraper,node_scheduler,node_analyzer toneRose
class node_investor,node_inspector,node_supabase toneIndigo
```

## Components

### Web experience

- [Role and route entry](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Stock analysis](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/pages/investor/Analysis.jsx): `frontend/src/pages/investor/Analysis.jsx`
- [Investor profile](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/pages/investor/Profile.jsx): `frontend/src/pages/investor/Profile.jsx`
- [Portfolio simulator](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/pages/investor/Simulator.jsx): `frontend/src/pages/investor/Simulator.jsx`
- [Inspector dashboards](https://github.com/oussemaharrabi/kanz-petitfour/tree/main/frontend/src/pages/inspector): `frontend/src/pages/inspector`
- [Stock sample data](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/data/stocks.js): `frontend/src/data/stocks.js`
- [API client](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### API and identity

- [FastAPI application](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication routes](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/auth.py): `backend/app/api/routes/auth.py`
- [Identity and roles](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/core/auth.py): `backend/app/core/auth.py`
- [Stock endpoints](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/stocks.py): `backend/app/api/routes/stocks.py`
- [Market endpoints](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/market.py): `backend/app/api/routes/market.py`
- [News endpoints](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/news.py): `backend/app/api/routes/news.py`
- [Portfolio endpoints](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/portfolio.py): `backend/app/api/routes/portfolio.py`
- [Alert endpoints](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/alerts.py): `backend/app/api/routes/alerts.py`
- [Agent endpoint](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/api/routes/agent.py): `backend/app/api/routes/agent.py`

### Market intelligence

- [Price prediction](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/services/prediction.py): `backend/app/services/prediction.py`
- [Anomaly detection](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/services/anomaly.py): `backend/app/services/anomaly.py`
- [Decision service](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/services/decision.py): `backend/app/services/decision.py`
- [Sentiment service](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/services/sentiment.py): `backend/app/services/sentiment.py`
- [Forecast model](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/ml/src/prediction.py): `ml/src/prediction.py`
- [Anomaly model](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/ml/src/anomaly.py): `ml/src/anomaly.py`

### Data and news

- [Market and user store](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/backend/app/db/database.py): `backend/app/db/database.py`
- [News scrapers](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/nlp/scrapers/news_scrapers.py): `nlp/scrapers/news_scrapers.py`
- [News scheduler](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/nlp/scrapers/scheduler.py): `nlp/scrapers/scheduler.py`
- [French-Arabic analyzer](https://github.com/oussemaharrabi/kanz-petitfour/blob/main/nlp/sentiment/analyzer.py): `nlp/sentiment/analyzer.py`

### Other components

- **Investor**
- **CMF inspector**
- **Supabase auth**

## Connections

- Investor → Role and route entry: opens (evidence: `frontend/src/App.jsx`)
- CMF inspector → Role and route entry: opens (evidence: `frontend/src/App.jsx`)
- Role and route entry → Stock analysis: routes to (evidence: `frontend/src/App.jsx`)
- Role and route entry → Investor profile: routes to (evidence: `frontend/src/App.jsx`)
- Role and route entry → Portfolio simulator: routes to (evidence: `frontend/src/App.jsx`)
- Role and route entry → Inspector dashboards: routes to (evidence: `frontend/src/App.jsx`)
- Stock analysis → API client: requests data (evidence: `frontend/src/pages/investor/Analysis.jsx`)
- Investor profile → API client: requests data (evidence: `frontend/src/pages/investor/Profile.jsx`)
- API client → Stock sample data: uses fallback (evidence: `frontend/src/services/useApi.js`)
- Role and route entry → FastAPI application: uses REST API
- FastAPI application → Stock endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI application → Market endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI application → Authentication routes: registers (evidence: `backend/app/main.py`)
- FastAPI application → News endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI application → Portfolio endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI application → Alert endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI application → Agent endpoint: registers (evidence: `backend/app/main.py`)
- Authentication routes → Identity and roles: resolves user (evidence: `backend/app/api/routes/auth.py`)
- Identity and roles → Market and user store: reads users (evidence: `backend/app/core/auth.py`)
- Authentication routes → Supabase auth: authenticates (evidence: `backend/app/api/routes/auth.py`)
- Stock endpoints → Market and user store: reads market data (evidence: `backend/app/api/routes/stocks.py`)
- Market endpoints → Market and user store: reads market data (evidence: `backend/app/api/routes/market.py`)
- Portfolio endpoints → Market and user store: reads portfolio (evidence: `backend/app/api/routes/portfolio.py`)
- Alert endpoints → Market and user store: reads alerts (evidence: `backend/app/api/routes/alerts.py`)
- News endpoints → Market and user store: reads news (evidence: `backend/app/api/routes/news.py`)
- Stock endpoints → Price prediction: requests forecasts (evidence: `backend/app/api/routes/stocks.py`)
- Stock endpoints → Anomaly detection: requests detection (evidence: `backend/app/api/routes/stocks.py`)
- Stock endpoints → Sentiment service: requests sentiment (evidence: `backend/app/api/routes/stocks.py`)
- Stock endpoints → Decision service: requests guidance (evidence: `backend/app/api/routes/stocks.py`)
- Market endpoints → Sentiment service: requests sentiment (evidence: `backend/app/api/routes/market.py`)
- News endpoints → French-Arabic analyzer: analyzes articles (evidence: `backend/app/api/routes/news.py`)
- Price prediction → Forecast model: uses model (evidence: `backend/app/services/prediction.py`)
- Anomaly detection → Anomaly model: uses model (evidence: `backend/app/services/anomaly.py`)
- Sentiment service → French-Arabic analyzer: delegates analysis (evidence: `backend/app/services/sentiment.py`)
- News scheduler → News scrapers: schedules collection (evidence: `nlp/scrapers/scheduler.py`)
- News scheduler → French-Arabic analyzer: uses analysis (evidence: `nlp/scrapers/scheduler.py`)
- FastAPI application → News scheduler: starts optionally (evidence: `backend/app/main.py`)
- Agent endpoint → Decision service: uses guidance (evidence: `backend/app/api/routes/agent.py`)
