How mahmoudg25/atls works
1. Overall shape
ATLS is a split-stack ERP monorepo: a Django 5 REST backend in Back-End/ and a React 19 + Vite SPA in Front-End/. The system is designed for multi-tenant farm management, with business data scoped to a Company and organized around farm operations, reports, inventory, HR, equipment, and accounting.
2. Backend boundary: API-first Django app
The backend is organized as a classic layered Django/DRF architecture:
• core/ holds project bootstrap, settings, middleware, tenant handling, and top-level URL routing.
• api/ contains the REST endpoint layer and URL wiring.
• apps/ contains the domain modules with models, migrations, admin, signals, filters, serializers, views, and some module-specific commands.
• services/ holds the business logic layer and is the main place where workflows are implemented.
• serializers/ exposes domain objects to the API.
• permissions/ centralizes role and tenant-based access rules.
3. Main domain modules
The backend domain is split into bounded modules that roughly correspond to business areas:
• farm: farm structure and hierarchy
• reports: operational reporting and analytics
• production: harvest and related workflows
• hr: workers, payroll, documents, approvals
• warehouse: inventory and alerts
• equipment: fleet and maintenance
• accounting: finance objects
• users: auth-adjacent content, announcements, profile, config
• olive and palm: crop/domain-specific extensions
Each module has its own models and migrations, and some have dedicated admin, views, filters, selectors, and serializers.
4. Core domain spine
The repository’s central architecture is event-driven around farm operations. The README explicitly states that an OperationLog is the atomic event, and the codebase reflects that through the reports and production modules. DailyTaskReport groups operational events by day and engineer. This means most higher-level reporting is derived from operational records rather than stored as separate, unrelated data.
5. Farm hierarchy and location model
The farm structure is unified under a shared location hierarchy. The docs and naming suggest a single location abstraction such as LocationNode, with farm structure entities organized as Sector → Stage → Enclosure. The farm app and the frontend farm pages indicate this hierarchy is foundational and reused by reports, production, and operational screens.
6. Tenant, auth, and permissions boundary
Multi-tenancy is a first-class concern. core/tenant.py, core/middleware.py, and the permissions/registry/ plus permissions/role_permissions.py files show that request context, tenant scoping, and role permissions are enforced centrally. Permission registries are split by domain (accounting.py, hr.py, reports.py, warehouse.py, governance.py), which suggests access control is module-aware rather than purely global.
7. Reporting and analytics subsystem
apps/reports/ is one of the most important backend subsystems. It includes:
• models for reports and operational logs
• selectors.py for query/read optimization
• services.py for report generation and orchestration
• permissions.py for report-specific access rules
• many migrations, indicating a mature and evolving reporting schema
This subsystem likely acts as the hub for analytics, custom fields, operational summaries, and cross-domain reporting.
8. Production workflow subsystem
apps/production/ and services/production_workflows.py indicate a dedicated workflow layer for harvest-related business processes. The frontend mirrors this with HarvestForm, HarvestWorkflow, SortingForm, and production pages for create/edit/management. This suggests production is a guided workflow domain, not just CRUD.
9. Backend API composition
api/endpoints/ contains per-domain view modules such as farm_views.py, reports_views.py, production_views.py, equipment_views.py, hr_views.py, warehouse_views.py, accounting_views.py, and notification_views.py. These are wired through api/urls.py and the project-level core/urls.py. The structure implies a thin view layer delegating logic downward into services and models.
10. Frontend architecture
The frontend is a single-page app with feature-oriented organization:
• pages/ contains route-level screens
• components/ contains reusable UI pieces
• features/ contains feature-specific service modules and some domain components
• layouts/ provides dashboard shell and top navigation
• contexts/ and app/ provide cross-cutting app state
• services/ contains API client modules
• routes/ defines protected and feature-guarded routing
• i18n/ stores AR/EN translations
The frontend is clearly structured for modular domain pages rather than a monolithic component tree.
11. Frontend domain surfaces
The visible screens map closely to backend domains:
• dashboard and announcements
• auth and profile
• farm structure and enclosure profiles
• HR dashboards and payroll
• production and harvest management
• reports dashboards and report-specific forms/lists
• warehouse inventory and alerts
• equipment fleet management
• accounting finance dashboard
• admin and intelligence pages
This makes the UI a direct presentation layer over the backend bounded contexts.
12. Shared frontend platform concerns
Several cross-cutting frontend systems materially affect architecture:
• AuthContext and ProtectedRoute enforce session-aware navigation
• FeatureGuard and accessControl.js imply role/feature gating in the UI
• ThemeContext and theme/ support theming
• i18n.js, ar.json, and en.json support bilingual RTL/LTR rendering
• reusable design-system style components in components/ui/ provide the base UI layer
This indicates the app is built to support role-based and locale-aware UX across modules.
13. Data and API flow
The dominant runtime flow is:
user action in React page/component → feature service in src/features/.../services.js or src/services/*.js → backend REST endpoint in api/endpoints/... → Django view/service/model layer → PostgreSQL persistence. Read-heavy paths often go through selectors in backend modules, especially reports/selectors.py. This separation suggests reads and writes are intentionally distinct in some domains.
14. Files, media, and operational assets
The backend has a media/ tree with harvested attachments and farm-management files, showing that file storage is part of the system architecture. There is also an upload_views.py endpoint and services/upload_service.py, so media handling is a dedicated backend concern rather than an incidental add-on.
15. Operational tooling and data lifecycle
The repo includes many management commands, seed scripts, validation utilities, and scratch/debug scripts under Back-End/scripts/, Back-End/scratch/, and app-specific management/commands/. This indicates significant operational support for:
• seeding master and test data
• repairing or backfilling data
• migrating legacy operational logs
• verifying database integrity and permissions
These are part of the architecture because the system has a long-lived, data-heavy domain with ongoing schema evolution.
16. Documentation as architecture source
The docs/ and docs_v2/ directories are extensive and appear to be an explicit architecture contract: core rules, domain language, ADRs, module overviews, frontend/backend architecture docs, and testing guidance. For an architecture diagram, the most important documented concepts are the multi-tenant model, the event-driven farm operation log spine, the unified farm hierarchy, and the separation between API, services, and UI feature modules.
Main entry points: routes Routing guard · reports Reporting hub · apps Domain apps · endpoints API layer
Components 19
Backend
Django REST stack, domain apps, and operational services
- Core project · Bootstrap, settings, middleware, tenant context, and root URL routing
Back-End/core - API layer · REST endpoint modules and URL composition per domain
Back-End/api/endpoints - Domain apps · Bounded modules for farm, reports, production, HR, warehouse, equipment, accounting, users, olive, and palm
Back-End/apps - Services · Workflow orchestration and domain operations across modules
Back-End/services - Reporting hub · Operational logs, daily task reports, selectors, and analytics generation
Back-End/apps/reports - Production flow · Harvest and sorting workflows with serializers, filters, models, and views
Back-End/apps/production - Farm hierarchy · Unified farm structure and shared location model for sectors, stages, and enclosures
Back-End/apps/farm - Tenant access · Multi-tenant request context and centralized role-based permissions
Back-End/core/tenant.py - Permission registry · Domain-aware role permissions and registry-based access rules
Back-End/permissions/registry - Media uploads · Attachment handling, upload service, and persisted farm and harvest files
Back-End/services/upload_service.py
Frontend
React SPA, feature pages, and client-side platform
- App shell · Top-level app, contexts, theme, and layout scaffolding
Front-End/src - Routing guard · Protected routes and feature-gated navigation
Front-End/src/routes - Client services · Feature-oriented API clients and shared HTTP layer
Front-End/src/services - Farm screens · Farm structure, enclosure profile, and operational timeline UI
Front-End/src/pages/farm - Reports screens · Analytics, daily tasks, irrigation, pest control, fertilization, and custom fields UI
Front-End/src/pages/reports - Harvest workflow · Harvest management and guided production forms
Front-End/src/features/production - Domain pages · Accounting, HR, equipment, warehouse, admin, dashboard, and public pages
Front-End/src/pages - UI system · Reusable components, controls, and shared visual building blocks
Front-End/src/components/ui
Shared concerns
Cross-cutting tenancy, permissions, and documentation contracts
- Architecture docs · Core rules, ADRs, and architecture guidance that define the system contract
docs
Connections 28
- Core project → API layer: routes to · Project URLs expose the REST API surface
- API layer → Domain apps: dispatches to · Endpoint modules delegate into domain apps
- API layer → Services: calls · Thin views hand off workflow logic to services
- Domain apps → Reporting hub: contains · Reporting app owns logs, selectors, and analytics models
- Domain apps → Production flow: contains · Production app owns harvest workflow domain
- Domain apps → Farm hierarchy: contains · Farm app defines location hierarchy and structure
- Services → Reporting hub: orchestrates · Report generation and operational summaries
- Services → Production flow: orchestrates · Harvest workflow and production actions
- Services → Media uploads: stores files · Upload and attachment handling
- Tenant access → Permission registry: enforces · Tenant scope and role access are centrally checked
- Permission registry → API layer: protects · Domain registries constrain endpoint access
- Farm hierarchy → Reporting hub: feeds · Operational reports are built on shared farm structure and events
- Production flow → Reporting hub: emits · Harvest activity becomes operational reporting input
- Reporting hub → Media uploads: attaches · Reports can carry media and harvested attachments
- App shell → Routing guard: hosts · SPA shell mounts guarded navigation and layouts
- Routing guard → Client services: drives · Route-level features use client API modules
- Client services → API layer: consumes · Frontend feature services call the REST endpoints
- App shell → UI system: composes · Shared design-system components power screens
- Routing guard → Farm screens: opens · Farm pages are route-backed feature screens
- Routing guard → Reports screens: opens · Reporting pages are route-backed feature screens
- Routing guard → Harvest workflow: opens · Harvest workflow screens are route-backed features
- Routing guard → Domain pages: opens · Other business modules are exposed through guarded pages
- Farm screens → Farm hierarchy: reflects · UI mirrors the farm hierarchy domain
- Reports screens → Reporting hub: reflects · UI mirrors reporting and analytics domain
- Harvest workflow → Production flow: reflects · UI mirrors harvest workflow domain
- Domain pages → Domain apps: covers · Business pages span accounting, HR, equipment, warehouse, and admin domains
- Architecture docs → Core project: defines · Docs codify tenancy, event-driven architecture, and project rules
- Architecture docs → App shell: defines · Docs codify frontend architecture, i18n, and UI system rules