# victormanoel-timbo/extensao-3-projeto architecture

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

- Interactive diagram: https://gitdiagram.com/victormanoel-timbo/extensao-3-projeto
- Repository: https://github.com/victormanoel-timbo/extensao-3-projeto

## Overview

1. **Repository shape**
   - This is a two-part monorepo: a **Django backend** in `BACKEND/` and a **React + TypeScript frontend** in `FRONTEND/`.
   - The system is organized around a food/health assistant domain, with chat, user anamnesis, and product lookup flows.

2. **Backend role**
   - The backend is the system of record and API gateway.
   - It exposes Django-based endpoints from `foodguard/api`, persists domain state in `foodguard/core` models, and manages users through a separate `foodguard/users` app.
   - `config/` holds the Django project bootstrap, settings, ASGI/WSGI entrypoints, and root URL routing.

3. **Backend domain model**
   - The core domain centers on three main entities: **Anamnese** (user health/intake profile), **Chat**, and **Message**.
   - Migrations show this domain evolved over time, including fields such as activity status, timestamps, user linkage, and message roles.
   - `core/models/base.py` suggests shared model behavior or common fields.

4. **Backend API surface**
   - The API is split by feature: `anamnese`, `chat`, `message`, and `openfoodfacts`.
   - Each feature has its own `views`, `serializers`, `urls`, and `exceptions`, which is a clear modular boundary for diagramming.
   - This is likely a REST-style API, given the serializer-heavy structure and frontend service layer.

5. **AI and external service integration**
   - `core/services/gemini_client.py` and `ai_signatures.py` indicate the backend calls an LLM service, most likely **Google Gemini**, for assistant logic.
   - The backend also has an `openfoodfacts` API path, suggesting integration with the **Open Food Facts** dataset/service for product nutrition or barcode-based lookup.
   - These integrations sit behind backend services, not directly in the frontend, which keeps external credentials and orchestration server-side.

6. **User subsystem**
   - `foodguard/users` is a dedicated app for the custom user model, validation, admin integration, and migrations.
   - This separation implies authentication/profile concerns are treated independently from the food/chat domain.

7. **Frontend role**
   - The frontend is a single-page application built with **Vite, React, TypeScript, and Tailwind-based styling**.
   - It acts as the interactive client for chat, barcode/product lookup, and likely anamnesis entry or review.
   - Routing is centralized in `src/router/router.tsx`, with `src/pages/Index.tsx` as the main page entry.

8. **Frontend component structure**
   - UI is organized into feature components: `chatInput`, `chatMessages`, `emptyChat`, `navbar`, and `sideBar`.
   - `src/components/ui` contains reusable primitives, suggesting a design-system-style layer beneath the feature components.
   - This gives a clean separation between layout, interaction widgets, and shared UI building blocks.

9. **Frontend data flow**
   - The frontend uses `hooks/` such as `use-chat`, `use-messages`, `use-chat-list`, `use-open-food`, and `use-barcode` to manage feature state and side effects.
   - Those hooks call `services/`, which in turn wrap REST access under `services/rest/`.
   - The data path is therefore: UI components → hooks → service layer → backend API.

10. **Frontend integration points**
   - `open-food.service.ts` and `algo.service.ts` suggest the frontend coordinates both product data retrieval and some higher-level algorithmic workflow.
   - A web worker at `src/workers/index.worker.ts` indicates some client-side work is offloaded from the main thread, likely to support scanning or processing without blocking the UI.

11. **Persistence and deployment**
   - The backend uses Django migrations for schema evolution and likely a relational database.
   - Local containerization is supported with Docker/Compose under `BACKEND/compose/local` and `docker-compose.local.yml`, which means the backend can be run in a containerized dev environment.
   - The presence of `ASGI` and `WSGI` entrypoints means it can be served in both synchronous and asynchronous deployment modes.

12. **What to show in an architecture diagram**
   - Draw two major boxes: **Frontend SPA** and **Django Backend/API**.
   - From the frontend, show separate flows for **chat**, **messages**, **barcode/open food lookup**, and **anamnesis/user profile**.
   - From the backend, show persistence into the Django models/database layer and outbound calls to **Gemini** and **Open Food Facts** as external services.
   - Keep the user subsystem as a parallel backend module, not part of the frontend feature layer.

Main entry points: [`BACKEND/foodguard/core/models/chat.py`](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/models/chat.py) (Core Domain), [`BACKEND/foodguard/api/views/chat.py`](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/api/views/chat.py) (API Layer), [`FRONTEND/src/hooks/use-chat.ts`](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/hooks/use-chat.ts) (Feature Hooks), [`FRONTEND/src/pages/Index.tsx`](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/pages/Index.tsx) (Main Page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Django Backend"]
  node_backend_config["Django Project<br/>project bootstrap<br/>[urls.py]"]
  node_backend_api["API Layer<br/>REST modules<br/>[chat.py]"]
  node_backend_domain["Core Domain<br/>models and services<br/>[chat.py]"]
  node_backend_anamnese_model[("Anamnese<br/>domain model<br/>[anamnese.py]")]
  node_backend_chat_model[("Chat<br/>domain model<br/>[chat.py]")]
  node_backend_message_model[("Message<br/>domain model<br/>[message.py]")]
  node_backend_ai{{"Gemini Service<br/>LLM integration<br/>[gemini_client.py]"}}
  node_backend_openfood{{"Open Food Facts<br/>product integration<br/>[openfoodfacts.py]"}}
  node_backend_users[("Users App<br/>auth/profile module<br/>[models.py]")]
  node_backend_persistence["Migrations<br/>schema evolution<br/>[0001_initial.py]"]
end

subgraph group_frontend["React Frontend"]
  node_frontend_app["SPA Shell<br/>React app<br/>[App.tsx]"]
  node_frontend_router["Router<br/>route config<br/>[router.tsx]"]
  node_frontend_index_page["Main Page<br/>[Index.tsx]"]
  node_frontend_chat_ui["Chat UI<br/>feature components<br/>[ChatInput.tsx]"]
  node_frontend_nav_ui["Shell UI<br/>layout components<br/>[Navbar.tsx]"]
  node_frontend_hooks["Feature Hooks<br/>state hooks<br/>[use-chat.ts]"]
  node_frontend_services["Service Layer<br/>API services<br/>[chat.service.ts]"]
  node_frontend_rest["REST Clients<br/>HTTP adapters<br/>[chat.rest.ts]"]
  node_frontend_worker(("Web Worker<br/>background task<br/>[index.worker.ts]"))
end

node_frontend_app -->|"routes"| node_frontend_router
node_frontend_router -->|"loads"| node_frontend_index_page
node_frontend_index_page -->|"renders"| node_frontend_chat_ui
node_frontend_index_page -->|"renders"| node_frontend_nav_ui
node_frontend_index_page -->|"uses"| node_frontend_hooks
node_frontend_chat_ui -->|"binds"| node_frontend_hooks
node_frontend_hooks -->|"calls"| node_frontend_services
node_frontend_services -->|"wraps"| node_frontend_rest
node_frontend_hooks -.->|"offloads"| node_frontend_worker
node_frontend_rest -->|"requests"| node_backend_api
node_backend_config -->|"mounts"| node_backend_api
node_backend_api -->|"uses"| node_backend_domain
node_backend_domain -->|"contains"| node_backend_anamnese_model
node_backend_domain -->|"contains"| node_backend_chat_model
node_backend_domain -->|"contains"| node_backend_message_model
node_backend_domain -->|"orchestrates"| node_backend_ai
node_backend_api -->|"exposes"| node_backend_openfood
node_backend_domain -->|"persists via"| node_backend_persistence
node_backend_users -->|"persists via"| node_backend_persistence
node_backend_api -.->|"auth/profile"| node_backend_users
node_frontend_hooks -->|"chat/anamnese"| node_backend_api

click node_frontend_app "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/App.tsx"
click node_frontend_router "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/router/router.tsx"
click node_frontend_index_page "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/pages/Index.tsx"
click node_frontend_chat_ui "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/components/chatInput/ChatInput.tsx"
click node_frontend_nav_ui "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/components/navbar/Navbar.tsx"
click node_frontend_hooks "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/hooks/use-chat.ts"
click node_frontend_services "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/services/chat.service.ts"
click node_frontend_rest "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/services/rest/chat.rest.ts"
click node_frontend_worker "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/workers/index.worker.ts"
click node_backend_config "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/config/urls.py"
click node_backend_api "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/api/views/chat.py"
click node_backend_domain "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/models/chat.py"
click node_backend_anamnese_model "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/models/anamnese.py"
click node_backend_chat_model "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/models/chat.py"
click node_backend_message_model "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/models/message.py"
click node_backend_ai "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/services/gemini_client.py"
click node_backend_openfood "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/api/serializers/openfoodfacts.py"
click node_backend_users "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/users/models.py"
click node_backend_persistence "https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/migrations/0001_initial.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_backend_config,node_backend_api,node_backend_domain,node_backend_anamnese_model,node_backend_chat_model,node_backend_message_model,node_backend_ai,node_backend_openfood,node_backend_users,node_backend_persistence toneBlue
class node_frontend_app,node_frontend_router,node_frontend_index_page,node_frontend_chat_ui,node_frontend_nav_ui,node_frontend_hooks,node_frontend_services,node_frontend_rest,node_frontend_worker toneAmber
```

## Components

### Django Backend

API, domain models, and server-side integrations

- [Django Project](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/config/urls.py): project bootstrap · Settings, ASGI/WSGI entrypoints, and root URL routing · `BACKEND/config/urls.py`
- [API Layer](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/api/views/chat.py): REST modules · Feature-scoped API views, serializers, exceptions, and URLs · `BACKEND/foodguard/api/views/chat.py`
- [Core Domain](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/models/chat.py): models and services · Primary business models and server-side AI orchestration · `BACKEND/foodguard/core/models/chat.py`
- [Anamnese](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/models/anamnese.py): domain model · User health and intake profile persisted in the core domain · `BACKEND/foodguard/core/models/anamnese.py`
- [Chat](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/models/chat.py): domain model · Conversation aggregate used to organize assistant sessions · `BACKEND/foodguard/core/models/chat.py`
- [Message](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/models/message.py): domain model · Individual chat messages with roles and timestamps · `BACKEND/foodguard/core/models/message.py`
- [Gemini Service](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/services/gemini_client.py): LLM integration · Server-side client and prompt/signature layer for assistant logic · `BACKEND/foodguard/core/services/gemini_client.py`
- [Open Food Facts](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/api/serializers/openfoodfacts.py): product integration · Backend access path for external product and nutrition lookup · `BACKEND/foodguard/api/serializers/openfoodfacts.py`
- [Users App](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/users/models.py): auth/profile module · Custom user model, validation, admin, and migrations · `BACKEND/foodguard/users/models.py`
- [Migrations](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/BACKEND/foodguard/core/migrations/0001_initial.py): schema evolution · Relational persistence layer managed through Django migrations · `BACKEND/foodguard/core/migrations/0001_initial.py`

### React Frontend

SPA, client state, and UI composition

- [SPA Shell](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/App.tsx): React app · Top-level client application and page composition · `FRONTEND/src/App.tsx`
- [Router](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/router/router.tsx): route config · Client-side navigation and page entrypoints · `FRONTEND/src/router/router.tsx`
- [Main Page](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/pages/Index.tsx): page · Primary screen that assembles the assistant experience · `FRONTEND/src/pages/Index.tsx`
- [Chat UI](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/components/chatInput/ChatInput.tsx): feature components · Conversation input, message list, and empty-state presentation · `FRONTEND/src/components/chatInput/ChatInput.tsx`
- [Shell UI](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/components/navbar/Navbar.tsx): layout components · Navigation and side panel around the main workspace · `FRONTEND/src/components/navbar/Navbar.tsx`
- [Feature Hooks](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/hooks/use-chat.ts): state hooks · Client-side orchestration for chats, messages, barcode, and product lookup · `FRONTEND/src/hooks/use-chat.ts`
- [Service Layer](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/services/chat.service.ts): API services · Client wrappers around REST endpoints and higher-level workflows · `FRONTEND/src/services/chat.service.ts`
- [REST Clients](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/services/rest/chat.rest.ts): HTTP adapters · Low-level API calls for chat, message, Open Food Facts, and algorithm flows · `FRONTEND/src/services/rest/chat.rest.ts`
- [Web Worker](https://github.com/victormanoel-timbo/extensao-3-projeto/blob/main/FRONTEND/src/workers/index.worker.ts): background task · Off-main-thread client processing for heavier interactive work · `FRONTEND/src/workers/index.worker.ts`

## Connections

- SPA Shell → Router: routes · Application shell delegates navigation to the router
- Router → Main Page: loads · Router resolves the main assistant page
- Main Page → Chat UI: renders · Page composes the chat interaction surface
- Main Page → Shell UI: renders · Page composes navigation and sidebar chrome
- Main Page → Feature Hooks: uses · Page and child components rely on feature hooks for state
- Chat UI → Feature Hooks: binds · Chat widgets read and update conversational state
- Feature Hooks → Service Layer: calls · Hooks orchestrate business actions through service wrappers
- Service Layer → REST Clients: wraps · Services delegate network I/O to REST adapters
- Feature Hooks → Web Worker: offloads · Some client work runs in a background worker
- REST Clients → API Layer: requests · Frontend communicates with Django feature endpoints
- Django Project → API Layer: mounts · Project URL routing exposes the API modules
- API Layer → Core Domain: uses · Views and serializers operate on core domain objects
- Core Domain → Anamnese: contains · Core domain includes user intake profiles
- Core Domain → Chat: contains · Core domain includes chat aggregates
- Core Domain → Message: contains · Core domain includes individual messages
- Core Domain → Gemini Service: orchestrates · Server-side logic calls the Gemini integration
- API Layer → Open Food Facts: exposes · API surface includes product lookup integration
- Core Domain → Migrations: persists via · Models evolve through Django migrations
- Users App → Migrations: persists via · Custom user schema is also managed by migrations
- API Layer → Users App: auth/profile · API flows depend on the dedicated user subsystem
- Feature Hooks → API Layer: chat/anamnese · Feature hooks drive the backend domain flows
