# endorodrigo/factus-reto architecture

> Architecture diagram of the GitHub repository endorodrigo/factus-reto, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/endorodrigo/factus-reto
- Repository: https://github.com/endorodrigo/factus-reto

## Overview

This repository is a cross-platform Flutter app named `factus_retos`, built around a layered architecture with clear separation between UI, state management, domain models, and service/integration code.

1. **Platform shell**
   - The app targets Android, iOS, web, Windows, macOS, and Linux using the standard Flutter platform runners.
   - The platform folders are mostly generated wrappers; the real application logic lives under `lib/`.
   - Android includes `google-services.json`, which indicates Firebase is configured natively on that platform.

2. **App entry and initialization**
   - `lib/main.dart` is the runtime entry point.
   - `lib/firebase_options.dart` suggests Firebase is initialized through FlutterFire-generated configuration.
   - `lib/config/theme/app_theme.dart` centralizes visual styling for the app.

3. **Presentation layer**
   - `lib/presentation/views` contains the screens: splash, login/register, home, product detail, cart, orders, order detail, profile, admin dashboard, admin products, and product form.
   - This is the primary UI surface and appears to cover both customer and admin experiences in the same app.
   - Views are organized by feature rather than by generic widget type.

4. **State management and feature controllers**
   - `lib/presentation/controllers` contains GetX-style controllers and bindings, based on the `*controller.dart` and `*binding.dart` naming pattern.
   - Controllers exist for auth, home, cart, orders, order detail, profile, splash, and admin/product management.
   - Bindings such as `admin_binding.dart`, `profile_binding.dart`, and `product_form_binding.dart` indicate dependency injection is scoped per route/feature.

5. **Navigation and route boundaries**
   - `lib/core/routes/app_pages.dart` and `app_routes.dart` centralize route definitions.
   - `lib/core/middlewares/auth_middleware.dart` and `admin_middleware.dart` enforce access control at the routing layer.
   - This makes navigation a major architectural boundary: authenticated user flows, guest flows, and admin-only flows are separated before a screen is entered.

6. **Domain layer**
   - `lib/domain/entities` defines core business objects such as `ProductEntity`, `OrderEntity`, and `UserEntity`.
   - `lib/domain/repositories/auth_repository.dart` defines at least one repository contract, indicating the app follows a dependency-inversion pattern where controllers depend on abstractions, not concrete services.

7. **Data layer**
   - `lib/data/models` contains persisted/transport representations for cart items, orders, products, and users.
   - These models likely bridge between Firestore/Firebase records and the domain entities used by the UI and controllers.
   - The presence of both `entity` and `model` types suggests mapping between app business concepts and stored data format.

8. **Core services and infrastructure access**
   - `lib/core/utils` holds service wrappers for `auth_service.dart`, `firestore_service.dart`, `product_service.dart`, `order_service.dart`, and `stripe_service.dart`.
   - These are the main integration points to external systems:
     - Firebase Authentication for login/register/session state
     - Cloud Firestore for app data persistence
     - Stripe for payment processing
   - This layer is the technical backend of the Flutter app.

9. **Error handling**
   - `lib/core/errors/exceptions.dart` and `failures.dart` define a failure/exceptions boundary.
   - This suggests the app normalizes low-level service errors into app-level failure types before they reach the UI.

10. **Primary business flows**
   - The customer flow appears to be: splash → auth → home/product browsing → product detail → cart → order creation → order history/detail → profile.
   - The admin flow appears to be: auth/middleware check → admin dashboard → product management → product form.
   - Orders and products are the central business entities connecting most screens and services.

11. **Authentication and role-based access**
   - `auth_controller.dart`, `auth_service.dart`, and `auth_middleware.dart` together manage sign-in/sign-up, session gating, and route protection.
   - `admin_middleware.dart` indicates role-based authorization, likely distinguishing administrative users from regular users.
   - This is one of the key architectural control points in the app.

12. **Assets and presentation resources**
   - `assets/images` stores app imagery.
   - Native splash/launch assets exist in each platform folder, while Flutter-side visual theming is centralized in `app_theme.dart`.
   - These resources support the UI but do not drive business logic.

13. **Platform-specific configuration**
   - `firebase.json` plus the Firebase config in Android and FlutterFire-generated options indicate the app is wired to Firebase services across platforms.
   - The repository includes normal Flutter desktop/web scaffolding, so the architecture is multi-target but still centered on the same shared Dart codebase.

14. **Testing and quality**
   - `test/widget_test.dart` exists as the default Flutter widget test entry point.
   - `analysis_options.yaml` indicates static analysis/linting is enabled to keep the codebase consistent.

Overall, this is a Flutter client application with a layered, feature-oriented structure: route-driven presentation on top, GetX-style controllers/bindings for state and dependency management, domain entities and repositories for business structure, and core service wrappers around Firebase/Firestore/Stripe integrations.

Main entry points: [`lib/core/routes/app_pages.dart`](https://github.com/endorodrigo/factus-reto/blob/master/lib/core/routes/app_pages.dart) (Routes), [`lib/core/utils/firestore_service.dart`](https://github.com/endorodrigo/factus-reto/blob/master/lib/core/utils/firestore_service.dart) (Services), [`lib/main.dart`](https://github.com/endorodrigo/factus-reto/blob/master/lib/main.dart) (main.dart), [`lib/presentation/views/orders_view.dart`](https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/orders_view.dart) (Orders)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_platforms["Platforms"]
  node_firebase["Firebase config<br/>platform config"]
end

subgraph group_app["App Core"]
  node_main["main.dart<br/>entrypoint<br/>[main.dart]"]
  node_theme["App theme<br/>ui theme<br/>[app_theme.dart]"]
  node_routes["Routes<br/>navigation<br/>[app_pages.dart]"]
  node_middleware{{"Auth guards<br/>routing guard"}}
  node_services[("Services<br/>integration layer")]
  node_errors["Failures<br/>error boundary<br/>[failures.dart]"]
end

subgraph group_presentation["Presentation"]
  node_splash["Splash<br/>screen+controller<br/>[splash_view.dart]"]
  node_auth["Auth flow<br/>screen+controller<br/>[login_view.dart]"]
  node_home["Home<br/>screen+controller<br/>[home_view.dart]"]
  node_product["Product detail<br/>screen"]
  node_cart["Cart<br/>screen+controller<br/>[cart_view.dart]"]
  node_orders["Orders<br/>screen+controller<br/>[orders_view.dart]"]
  node_profile["Profile<br/>screen+controller<br/>[profile_view.dart]"]
  node_admin["Admin dashboard<br/>screen+controller"]
  node_catalog["Admin products<br/>screen+controller"]
  node_form["Product form<br/>screen+controller"]
end

subgraph group_domain["Domain"]
  node_authmodel["Auth repo<br/>contract"]
  node_entities{{"Entities<br/>domain models"}}
end

subgraph group_data["Data"]
  node_datamodels{{"Data models<br/>transport models<br/>[product_model.dart]"}}
end

node_main -->|"uses"| node_theme
node_main -->|"boots"| node_routes
node_main -->|"initializes"| node_firebase
node_routes -->|"protects"| node_middleware
node_routes -->|"opens"| node_splash
node_routes -->|"opens"| node_auth
node_routes -->|"opens"| node_home
node_routes -->|"opens"| node_admin
node_routes -->|"opens"| node_cart
node_routes -->|"opens"| node_orders
node_routes -->|"opens"| node_profile
node_routes -->|"opens"| node_product
node_routes -->|"opens"| node_catalog
node_routes -->|"opens"| node_form
node_splash -->|"checks session"| node_services
node_auth -->|"authenticates"| node_services
node_home -->|"consumes"| node_entities
node_cart -->|"persists"| node_datamodels
node_orders -->|"loads"| node_datamodels
node_profile -->|"depends on"| node_authmodel
node_services -->|"wraps"| node_firebase
node_services -->|"normalizes"| node_errors
node_datamodels -->|"maps to"| node_entities
node_admin -->|"navigates"| node_catalog
node_catalog -->|"edits"| node_form
node_product -->|"adds to"| node_cart
node_orders -->|"drills into"| node_product

click node_main "https://github.com/endorodrigo/factus-reto/blob/master/lib/main.dart"
click node_theme "https://github.com/endorodrigo/factus-reto/blob/master/lib/config/theme/app_theme.dart"
click node_routes "https://github.com/endorodrigo/factus-reto/blob/master/lib/core/routes/app_pages.dart"
click node_middleware "https://github.com/endorodrigo/factus-reto/blob/master/lib/core/middlewares/auth_middleware.dart"
click node_services "https://github.com/endorodrigo/factus-reto/blob/master/lib/core/utils/firestore_service.dart"
click node_errors "https://github.com/endorodrigo/factus-reto/blob/master/lib/core/errors/failures.dart"
click node_splash "https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/splash_view.dart"
click node_auth "https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/login_view.dart"
click node_home "https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/home_view.dart"
click node_product "https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/product_detail_view.dart"
click node_cart "https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/cart_view.dart"
click node_orders "https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/orders_view.dart"
click node_profile "https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/profile_view.dart"
click node_admin "https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/admin_dashboard_view.dart"
click node_catalog "https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/admin_products_view.dart"
click node_form "https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/product_form_view.dart"
click node_authmodel "https://github.com/endorodrigo/factus-reto/blob/master/lib/domain/repositories/auth_repository.dart"
click node_entities "https://github.com/endorodrigo/factus-reto/blob/master/lib/domain/entities/product_entity.dart"
click node_datamodels "https://github.com/endorodrigo/factus-reto/blob/master/lib/data/models/product_model.dart"
click node_firebase "https://github.com/endorodrigo/factus-reto/blob/master/lib/firebase_options.dart"

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_firebase toneBlue
class node_main,node_theme,node_routes,node_middleware,node_services,node_errors toneAmber
class node_splash,node_auth,node_home,node_product,node_cart,node_orders,node_profile,node_admin,node_catalog,node_form toneMint
class node_authmodel,node_entities toneRose
class node_datamodels toneIndigo
```

## Components

### Platforms

Flutter host shells and platform-specific wiring.

- [Firebase config](https://github.com/endorodrigo/factus-reto/blob/master/lib/firebase_options.dart): platform config · FlutterFire options and native Firebase wiring · `lib/firebase_options.dart`

### App Core

Bootstrap, configuration, routing, and shared infrastructure.

- [main.dart](https://github.com/endorodrigo/factus-reto/blob/master/lib/main.dart): entrypoint · App startup and dependency bootstrap · `lib/main.dart`
- [App theme](https://github.com/endorodrigo/factus-reto/blob/master/lib/config/theme/app_theme.dart): ui theme · Centralized styling and visual system · `lib/config/theme/app_theme.dart`
- [Routes](https://github.com/endorodrigo/factus-reto/blob/master/lib/core/routes/app_pages.dart): navigation · Route table and app-level navigation boundaries · `lib/core/routes/app_pages.dart`
- [Auth guards](https://github.com/endorodrigo/factus-reto/blob/master/lib/core/middlewares/auth_middleware.dart): routing guard · Authentication and admin access control · `lib/core/middlewares/auth_middleware.dart`
- [Services](https://github.com/endorodrigo/factus-reto/blob/master/lib/core/utils/firestore_service.dart): integration layer · Firebase, Firestore, payments, and backend access · `lib/core/utils/firestore_service.dart`
- [Failures](https://github.com/endorodrigo/factus-reto/blob/master/lib/core/errors/failures.dart): error boundary · Exceptions and failure normalization · `lib/core/errors/failures.dart`

### Presentation

Screens, controllers, and route-scoped bindings.

- [Splash](https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/splash_view.dart): screen+controller · Startup screen and session handoff · `lib/presentation/views/splash_view.dart`
- [Auth flow](https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/login_view.dart): screen+controller · Login and registration experience · `lib/presentation/views/login_view.dart`
- [Home](https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/home_view.dart): screen+controller · Primary browsing and product entry point · `lib/presentation/views/home_view.dart`
- [Product detail](https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/product_detail_view.dart): screen · Single product inspection and actions · `lib/presentation/views/product_detail_view.dart`
- [Cart](https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/cart_view.dart): screen+controller · Checkout basket and purchase preparation · `lib/presentation/views/cart_view.dart`
- [Orders](https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/orders_view.dart): screen+controller · Order history and order inspection · `lib/presentation/views/orders_view.dart`
- [Profile](https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/profile_view.dart): screen+controller · User account and profile management · `lib/presentation/views/profile_view.dart`
- [Admin dashboard](https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/admin_dashboard_view.dart): screen+controller · Admin landing page and management hub · `lib/presentation/views/admin_dashboard_view.dart`
- [Admin products](https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/admin_products_view.dart): screen+controller · Product administration and catalog maintenance · `lib/presentation/views/admin_products_view.dart`
- [Product form](https://github.com/endorodrigo/factus-reto/blob/master/lib/presentation/views/product_form_view.dart): screen+controller · Create and edit product records · `lib/presentation/views/product_form_view.dart`

### Domain

Business entities and repository contracts.

- [Auth repo](https://github.com/endorodrigo/factus-reto/blob/master/lib/domain/repositories/auth_repository.dart): contract · Repository abstraction for authentication · `lib/domain/repositories/auth_repository.dart`
- [Entities](https://github.com/endorodrigo/factus-reto/blob/master/lib/domain/entities/product_entity.dart): domain models · Core business objects: users, products, orders · `lib/domain/entities/product_entity.dart`

### Data

Transport and persistence models.

- [Data models](https://github.com/endorodrigo/factus-reto/blob/master/lib/data/models/product_model.dart): transport models · Firestore-oriented representations of app data · `lib/data/models/product_model.dart`

## Connections

- main.dart → App theme: uses · Applies shared styling at startup
- main.dart → Routes: boots · Installs route-driven app structure
- main.dart → Firebase config: initializes · Configures Firebase for the client app
- Routes → Auth guards: protects · Applies authentication and admin gating
- Routes → Splash: opens · Entry screen for startup flow
- Routes → Auth flow: opens · Guest authentication flow
- Routes → Home: opens · Main customer browsing flow
- Routes → Admin dashboard: opens · Admin-only control surface
- Routes → Cart: opens · Checkout and purchase flow
- Routes → Orders: opens · Order history flow
- Routes → Profile: opens · Account management flow
- Routes → Product detail: opens · Product detail flow
- Routes → Admin products: opens · Admin catalog management
- Routes → Product form: opens · Product create/edit flow
- Splash → Services: checks session · Reads auth/session state from backend services
- Auth flow → Services: authenticates · Uses auth and persistence integrations
- Home → Entities: consumes · Works with core product and user domain objects
- Cart → Data models: persists · Stores cart/order data through transport models
- Orders → Data models: loads · Reads stored order records
- Profile → Auth repo: depends on · Relies on repository contract for user auth state
- Services → Firebase config: wraps · Bridges to Firebase/Firestore/Stripe infrastructure
- Services → Failures: normalizes · Converts low-level failures into app-level errors
- Data models → Entities: maps to · Transforms persisted records into domain objects
- Admin dashboard → Admin products: navigates · Admin hub routes to product management
- Admin products → Product form: edits · Opens product creation/editing form
- Product detail → Cart: adds to · Sends selected products into purchase flow
- Orders → Product detail: drills into · Allows inspection of order-related product details
