How victormanoel-timbo/extensao-3-projeto works
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: models/chat.py Core Domain · views/chat.py API Layer · use-chat.ts Feature Hooks · Index.tsx Main Page
Components 19
Django Backend
API, domain models, and server-side integrations
- Django Project · Settings, ASGI/WSGI entrypoints, and root URL routing
BACKEND/config/urls.py - API Layer · Feature-scoped API views, serializers, exceptions, and URLs
BACKEND/foodguard/api/views/chat.py - Core Domain · Primary business models and server-side AI orchestration
BACKEND/foodguard/core/models/chat.py - Anamnese · User health and intake profile persisted in the core domain
BACKEND/foodguard/core/models/anamnese.py - Chat · Conversation aggregate used to organize assistant sessions
BACKEND/foodguard/core/models/chat.py - Message · Individual chat messages with roles and timestamps
BACKEND/foodguard/core/models/message.py - Gemini Service · Server-side client and prompt/signature layer for assistant logic
BACKEND/foodguard/core/services/gemini_client.py - Open Food Facts · Backend access path for external product and nutrition lookup
BACKEND/foodguard/api/serializers/openfoodfacts.py - Users App · Custom user model, validation, admin, and migrations
BACKEND/foodguard/users/models.py - Migrations · Relational persistence layer managed through Django migrations
BACKEND/foodguard/core/migrations/0001_initial.py
React Frontend
SPA, client state, and UI composition
- SPA Shell · Top-level client application and page composition
FRONTEND/src/App.tsx - Router · Client-side navigation and page entrypoints
FRONTEND/src/router/router.tsx - Main Page · Primary screen that assembles the assistant experience
FRONTEND/src/pages/Index.tsx - Chat UI · Conversation input, message list, and empty-state presentation
FRONTEND/src/components/chatInput/ChatInput.tsx - Shell UI · Navigation and side panel around the main workspace
FRONTEND/src/components/navbar/Navbar.tsx - Feature Hooks · Client-side orchestration for chats, messages, barcode, and product lookup
FRONTEND/src/hooks/use-chat.ts - Service Layer · Client wrappers around REST endpoints and higher-level workflows
FRONTEND/src/services/chat.service.ts - REST Clients · Low-level API calls for chat, message, Open Food Facts, and algorithm flows
FRONTEND/src/services/rest/chat.rest.ts - Web Worker · Off-main-thread client processing for heavier interactive work
FRONTEND/src/workers/index.worker.ts
Connections 21
- 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