# elsantiago31/proyecto_grado_campo_directo architecture

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

- Interactive diagram: https://gitdiagram.com/elsantiago31/proyecto_grado_campo_directo
- Repository: https://github.com/elsantiago31/proyecto_grado_campo_directo

## Overview

1. **Overall shape: a single Django monolith with two delivery modes**
   - The repository is organized as one Django project, `campo_directo`, with several domain apps.
   - It serves both **HTML pages** from `templates/` and `static/`, and a **REST API** used by browser-side JavaScript and external clients.
   - The architecture is not microservices-based; the app logic, API, and admin all share the same Django runtime and database.

2. **Project-level core**
   - `campo_directo/settings.py`, `urls.py`, `wsgi.py`, and `asgi.py` define the application boundary.
   - `routers.py` suggests centralized database routing or separation logic, but the main deployment model is still a single Django process connecting to one configured database.
   - `manage.py` and management commands are the operational entry points.

3. **Presentation layer**
   - Server-rendered pages live in `templates/` and are styled/bootstrapped with `static/css` and `static/js`.
   - There are distinct flows for general users and buyers, reflected in templates like `dashboard.html`, `dashboard-comprador.html`, `login.html`, `login-comprador.html`, and `registro.html`.
   - Frontend behavior is largely driven by JavaScript files such as `dashboard.js`, `dashboard-comprador.js`, and `static/js/config/api.js`, which likely bind pages to the REST API.

4. **Primary domain apps**
   - `users/` handles the custom user model, authentication, profile data, and account lifecycle.
   - `farms/` models farm records and certification-related data.
   - `products/` owns the product catalog, categories, images, stock, and market price integration.
   - `orders/` manages purchase orders, order state transitions, and audit/history.
   - `anti_intermediarios/` contains the platform’s differentiating features: direct messaging, price transparency, and impact-oriented reporting.
   - `frontend/` appears to contain page-facing orchestration and additional UI-facing logic, separate from the pure domain apps.

5. **User and identity flow**
   - The `users` app is the identity boundary: it defines `Usuario` and exposes serializers/views/URLs for registration, login, profile management, password changes, and dashboard data.
   - The README indicates role-based behavior for **campesino** and **comprador**, so this app is the source of the role split that drives the rest of the system.
   - JWT authentication is used for API access, so browser or client requests likely authenticate through token issuance and refresh endpoints rather than session-only login.

6. **Farm-to-product catalog flow**
   - A farmer’s account is associated with farm data in `farms/`, then with product listings in `products/`.
   - The product layer is responsible for media handling and category population, with migrations showing category seeding and product schema evolution.
   - This is the core supply-side catalog: farm metadata provides provenance, while products provide purchasable inventory.

7. **Buyer-to-order flow**
   - The `orders` app sits between buyers and product/farm sellers.
   - Its data model includes state tracking and audit logging, which means order lifecycle is a first-class process rather than a simple transaction record.
   - `orders/notifications.py` indicates asynchronous or side-effect-driven communication around order events, such as status changes or alerts.

8. **Anti-intermediary and market transparency flow**
   - `anti_intermediarios/` captures the platform’s differentiating business logic.
   - The README and file names point to direct messaging, transparency over traditional market prices, and reporting of savings/impact.
   - This subsystem is tightly coupled to the product and order flows, but it is logically separate because it represents value-added comparison and communication rather than core commerce data.

9. **Pricing intelligence and external reference data**
   - The `products` app contains `SIPSA` price-related support, and there is a top-level `sipsa_data.json` plus a `sync_sipsa` management command.
   - This indicates an ingestion pipeline for external market reference prices, used to compare local selling prices against a national benchmark.
   - Architecturally, this is an external-data boundary feeding the product/pricing layer, not a standalone service.

10. **Persistence and file storage**
   - Development uses SQLite per the README, while production is configured for MySQL.
   - Uploaded files and images are stored under `media/`, while static assets are under `static/`.
   - `utils/file_handlers.py` and image-related commands such as `compress_images.py` and `products/management/commands/setup_media_dirs.py` show that file validation and media organization are part of the system boundary.

11. **Operational tooling and data bootstrap**
   - There are management commands for seeding and production setup in `frontend/`, `products/`, `users/`, and top-level `management/`.
   - `create_sample_data`, `create_test_data`, `create_production_data`, `create_production_users`, `backup_db`, and `sync_sipsa` show that the repository includes deployment and data-population workflows, not just application code.
   - `DEPLOYMENT_GUIDE.md` and `PRODUCTION_DATABASE.md` reinforce that production operations are a documented concern.

12. **Security and quality boundaries**
   - The stack includes DRF, SimpleJWT, CORS headers, filtering, and Swagger/OpenAPI docs via `drf-yasg`.
   - There are security-focused test files like `orders/test_security.py`, `products/test_security.py`, and `security_tools/test_sqli.py`.
   - The architecture therefore has an explicit API/security boundary: authenticated API access, validation, and security regression checks are part of the repo’s design.

13. **How the major pieces connect**
   - Requests enter through Django URLs at the project level.
   - Authentication and profiles are handled in `users/`.
   - Farmers populate `farms/` and `products/`; buyers browse product data and place `orders/`.
   - Order events and direct communication flow through `orders/` and `anti_intermediarios/`.
   - Reference market data from SIPSA feeds the pricing/transparency features in `products/` and related reporting logic.

14. **What an architecture diagram should emphasize**
   - A central Django application core with multiple domain apps around it.
   - A split between **server-rendered UI** and **JWT-secured REST APIs**.
   - The supply chain flow: users → farms → products → orders → notifications/transparency.
   - Supporting infrastructure: relational database, media/static storage, external pricing reference data, and operational management commands.

Main entry points: [`campo_directo/urls.py`](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/campo_directo/urls.py) (URL router), [`campo_directo/settings.py`](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/campo_directo/settings.py) (Settings), [`users/views.py`](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/users/views.py) (Auth API), [`products/views.py`](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/products/views.py) (Catalog API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Django core"]
  node_campo_directo_settings["Settings<br/>[settings.py]"]
  node_campo_directo_urls["URL router<br/>django urls<br/>[urls.py]"]
  node_campo_directo_wsgi["WSGI<br/>deployment entry<br/>[wsgi.py]"]
  node_campo_directo_asgi["ASGI<br/>deployment entry<br/>[asgi.py]"]
  node_campo_directo_routers["Routers<br/>db routing<br/>[routers.py]"]
  node_manage_py["Manage<br/>ops entry<br/>[manage.py]"]
end

subgraph group_ui["Presentation"]
  node_frontend_views["Frontend<br/>ui orchestration<br/>[views.py]"]
  node_templates["Templates<br/>server pages"]
  node_static_assets["Static assets<br/>frontend assets"]
end

subgraph group_domain["Domain apps"]
  node_users_models[("Users<br/>identity model<br/>[models.py]")]
  node_users_views["Auth API<br/>identity views<br/>[views.py]"]
  node_users_serializers["User serializers<br/>identity dto<br/>[serializers.py]"]
  node_farms_models[("Farms<br/>provenance model<br/>[models.py]")]
  node_farms_views["Farm API<br/>farm views<br/>[views.py]"]
  node_products_models[("Products<br/>catalog model<br/>[models.py]")]
  node_products_views["Catalog API<br/>catalog views<br/>[views.py]"]
  node_orders_models[("Orders<br/>order model<br/>[models.py]")]
  node_orders_views["Order API<br/>order views<br/>[views.py]"]
  node_anti_models[("Transparency<br/>platform model<br/>[models.py]")]
  node_anti_views["Transparency API<br/>platform views<br/>[views.py]"]
end

subgraph group_ops["Operations"]
  node_sync_sipsa["SIPSA sync<br/>data import<br/>[sync_sipsa.py]"]
  node_backup_db["Backup DB<br/>maintenance<br/>[backup_db.py]"]
  node_file_handlers["File utils<br/>media handling<br/>[file_handlers.py]"]
end

node_manage_py -->|"loads"| node_campo_directo_settings
node_campo_directo_settings -->|"uses"| node_campo_directo_urls
node_campo_directo_settings -->|"configures"| node_campo_directo_routers
node_campo_directo_urls -->|"routes"| node_users_views
node_campo_directo_urls -->|"routes"| node_farms_views
node_campo_directo_urls -->|"routes"| node_products_views
node_campo_directo_urls -->|"routes"| node_orders_views
node_campo_directo_urls -->|"routes"| node_anti_views
node_campo_directo_urls -->|"routes"| node_frontend_views
node_campo_directo_wsgi -->|"serves"| node_campo_directo_settings
node_campo_directo_asgi -->|"serves"| node_campo_directo_settings
node_users_views -->|"uses"| node_users_serializers
node_users_views -->|"persists"| node_users_models
node_users_views -->|"renders"| node_templates
node_frontend_views -->|"renders"| node_templates
node_templates -->|"loads"| node_static_assets
node_farms_views -->|"persists"| node_farms_models
node_products_views -->|"persists"| node_products_models
node_products_views -->|"uses"| node_file_handlers
node_orders_views -->|"persists"| node_orders_models
node_orders_views -->|"emits"| node_anti_views
node_anti_views -->|"persists"| node_anti_models
node_products_models -.->|"fed by"| node_sync_sipsa
node_sync_sipsa -.->|"updates"| node_products_models
node_backup_db -.->|"targets"| node_campo_directo_settings
node_static_assets -->|"calls"| node_products_views
node_static_assets -->|"calls"| node_users_views

click node_campo_directo_settings "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/campo_directo/settings.py"
click node_campo_directo_urls "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/campo_directo/urls.py"
click node_campo_directo_wsgi "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/campo_directo/wsgi.py"
click node_campo_directo_asgi "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/campo_directo/asgi.py"
click node_campo_directo_routers "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/campo_directo/routers.py"
click node_manage_py "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/manage.py"
click node_users_models "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/users/models.py"
click node_users_views "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/users/views.py"
click node_users_serializers "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/users/serializers.py"
click node_farms_models "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/farms/models.py"
click node_farms_views "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/farms/views.py"
click node_products_models "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/products/models.py"
click node_products_views "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/products/views.py"
click node_orders_models "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/orders/models.py"
click node_orders_views "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/orders/views.py"
click node_anti_models "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/anti_intermediarios/models.py"
click node_anti_views "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/anti_intermediarios/views.py"
click node_frontend_views "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/frontend/views.py"
click node_templates "https://github.com/elsantiago31/proyecto_grado_campo_directo/tree/main/templates"
click node_static_assets "https://github.com/elsantiago31/proyecto_grado_campo_directo/tree/main/static"
click node_sync_sipsa "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/products/management/commands/sync_sipsa.py"
click node_backup_db "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/management/commands/backup_db.py"
click node_file_handlers "https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/utils/file_handlers.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_campo_directo_settings,node_campo_directo_urls,node_campo_directo_wsgi,node_campo_directo_asgi,node_campo_directo_routers,node_manage_py toneBlue
class node_frontend_views,node_templates,node_static_assets toneAmber
class node_users_models,node_users_views,node_users_serializers,node_farms_models,node_farms_views,node_products_models,node_products_views,node_orders_models,node_orders_views,node_anti_models,node_anti_views toneMint
class node_sync_sipsa,node_backup_db,node_file_handlers toneRose
```

## Components

### Django core

Project-wide runtime, routing, and deployment entry points.

- [Settings](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/campo_directo/settings.py): django settings · Global configuration, apps, middleware, auth, and database setup. · `campo_directo/settings.py`
- [URL router](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/campo_directo/urls.py): django urls · Top-level request routing into apps and views. · `campo_directo/urls.py`
- [WSGI](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/campo_directo/wsgi.py): deployment entry · Synchronous server entry point. · `campo_directo/wsgi.py`
- [ASGI](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/campo_directo/asgi.py): deployment entry · Async server entry point. · `campo_directo/asgi.py`
- [Routers](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/campo_directo/routers.py): db routing · Central database routing or separation logic. · `campo_directo/routers.py`
- [Manage](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/manage.py): ops entry · Django management entry point. · `manage.py`

### Presentation

Server-rendered pages and browser assets.

- [Frontend](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/frontend/views.py): ui orchestration · Page-facing orchestration and UI-specific logic. · `frontend/views.py`
- [Templates](https://github.com/elsantiago31/proyecto_grado_campo_directo/tree/main/templates): server pages · Server-rendered HTML for public pages, auth, and dashboards. · `templates`
- [Static assets](https://github.com/elsantiago31/proyecto_grado_campo_directo/tree/main/static): frontend assets · CSS, JavaScript, and browser-side integration with the API. · `static`

### Domain apps

Business logic apps for identity, catalog, ordering, and transparency.

- [Users](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/users/models.py): identity model · Custom user model, roles, profile fields, and account lifecycle. · `users/models.py`
- [Auth API](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/users/views.py): identity views · Registration, login, profile, password, and dashboard endpoints. · `users/views.py`
- [User serializers](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/users/serializers.py): identity dto · API payload shaping for user flows. · `users/serializers.py`
- [Farms](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/farms/models.py): provenance model · Farm records and certification/provenance data. · `farms/models.py`
- [Farm API](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/farms/views.py): farm views · Endpoints for farm-related CRUD and presentation. · `farms/views.py`
- [Products](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/products/models.py): catalog model · Product catalog, categories, images, stock, and SIPSA-linked pricing. · `products/models.py`
- [Catalog API](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/products/views.py): catalog views · Product browsing, pricing, and catalog endpoints. · `products/views.py`
- [Orders](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/orders/models.py): order model · Purchase orders, state transitions, and audit history. · `orders/models.py`
- [Order API](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/orders/views.py): order views · Order lifecycle endpoints and related business actions. · `orders/views.py`
- [Transparency](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/anti_intermediarios/models.py): platform model · Direct messaging, price transparency, and impact reporting data. · `anti_intermediarios/models.py`
- [Transparency API](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/anti_intermediarios/views.py): platform views · Endpoints for anti-intermediary features and reporting. · `anti_intermediarios/views.py`

### Operations

Data import, maintenance, and security tooling.

- [SIPSA sync](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/products/management/commands/sync_sipsa.py): data import · External market price ingestion for pricing intelligence. · `products/management/commands/sync_sipsa.py`
- [Backup DB](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/management/commands/backup_db.py): maintenance · Operational database backup command. · `management/commands/backup_db.py`
- [File utils](https://github.com/elsantiago31/proyecto_grado_campo_directo/blob/main/utils/file_handlers.py): media handling · Validation and organization helpers for uploaded files. · `utils/file_handlers.py`

## Connections

- Manage → Settings: loads · Bootstraps the project configuration.
- Settings → URL router: uses · Configures installed apps and route wiring.
- Settings → Routers: configures · Defines database routing behavior.
- URL router → Auth API: routes · Top-level requests enter identity flows.
- URL router → Farm API: routes · Routes farm endpoints.
- URL router → Catalog API: routes · Routes catalog endpoints.
- URL router → Order API: routes · Routes order endpoints.
- URL router → Transparency API: routes · Routes transparency endpoints.
- URL router → Frontend: routes · Routes page orchestration views.
- WSGI → Settings: serves · Production WSGI runtime uses project config.
- ASGI → Settings: serves · Async runtime uses project config.
- Auth API → User serializers: uses · Shapes request and response data.
- Auth API → Users: persists · Reads and writes the identity boundary.
- Auth API → Templates: renders · Supports login, registration, and dashboard pages.
- Frontend → Templates: renders · Serves server-rendered HTML pages.
- Templates → Static assets: loads · Pages depend on browser assets.
- Farm API → Farms: persists · Manages farm and provenance data.
- Catalog API → Products: persists · Manages catalog and pricing data.
- Catalog API → File utils: uses · Handles media upload and validation.
- Order API → Orders: persists · Manages order state and audit trails.
- Order API → Transparency API: emits · Order events feed transparency and messaging flows.
- Transparency API → Transparency: persists · Stores transparency and communication data.
- Products → SIPSA sync: fed by · External market price data updates product pricing.
- SIPSA sync → Products: updates · Imports SIPSA benchmark prices.
- Backup DB → Settings: targets · Operational backup uses project database settings.
- Static assets → Catalog API: calls · Browser scripts integrate with the REST API.
- Static assets → Auth API: calls · Auth and dashboard scripts consume identity endpoints.
