How elsantiago31/proyecto_grado_campo_directo works
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: urls.py URL router · settings.py Settings · users/views.py Auth API · products/views.py Catalog API
Components 23
Django core
Project-wide runtime, routing, and deployment entry points.
- Settings · Global configuration, apps, middleware, auth, and database setup.
campo_directo/settings.py - URL router · Top-level request routing into apps and views.
campo_directo/urls.py - WSGI · Synchronous server entry point.
campo_directo/wsgi.py - ASGI · Async server entry point.
campo_directo/asgi.py - Routers · Central database routing or separation logic.
campo_directo/routers.py - Manage · Django management entry point.
manage.py
Presentation
Server-rendered pages and browser assets.
- Frontend · Page-facing orchestration and UI-specific logic.
frontend/views.py - Templates · Server-rendered HTML for public pages, auth, and dashboards.
templates - Static assets · CSS, JavaScript, and browser-side integration with the API.
static
Domain apps
Business logic apps for identity, catalog, ordering, and transparency.
- Users · Custom user model, roles, profile fields, and account lifecycle.
users/models.py - Auth API · Registration, login, profile, password, and dashboard endpoints.
users/views.py - User serializers · API payload shaping for user flows.
users/serializers.py - Farms · Farm records and certification/provenance data.
farms/models.py - Farm API · Endpoints for farm-related CRUD and presentation.
farms/views.py - Products · Product catalog, categories, images, stock, and SIPSA-linked pricing.
products/models.py - Catalog API · Product browsing, pricing, and catalog endpoints.
products/views.py - Orders · Purchase orders, state transitions, and audit history.
orders/models.py - Order API · Order lifecycle endpoints and related business actions.
orders/views.py - Transparency · Direct messaging, price transparency, and impact reporting data.
anti_intermediarios/models.py - Transparency API · Endpoints for anti-intermediary features and reporting.
anti_intermediarios/views.py
Operations
Data import, maintenance, and security tooling.
- SIPSA sync · External market price ingestion for pricing intelligence.
products/management/commands/sync_sipsa.py - Backup DB · Operational database backup command.
management/commands/backup_db.py - File utils · Validation and organization helpers for uploaded files.
utils/file_handlers.py
Connections 27
- 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.