# mahmoudg25/atls architecture

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

- Interactive diagram: https://gitdiagram.com/mahmoudg25/atls
- Repository: https://github.com/mahmoudg25/atls

## Overview

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: [`Front-End/src/routes`](https://github.com/mahmoudg25/atls/tree/main/Front-End/src/routes) (Routing guard), [`Back-End/apps/reports`](https://github.com/mahmoudg25/atls/tree/main/Back-End/apps/reports) (Reporting hub), [`Back-End/apps`](https://github.com/mahmoudg25/atls/tree/main/Back-End/apps) (Domain apps), [`Back-End/api/endpoints`](https://github.com/mahmoudg25/atls/tree/main/Back-End/api/endpoints) (API layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_backend_core["Core project<br/>django project"]
  node_backend_api["API layer<br/>drf endpoints"]
  node_backend_apps["Domain apps<br/>django apps"]
  node_backend_services["Services<br/>business logic"]
  node_backend_reports["Reporting hub<br/>reporting domain"]
  node_backend_production["Production flow<br/>workflow domain"]
  node_backend_farm["Farm hierarchy<br/>location domain"]
  node_backend_tenant["Tenant access<br/>tenant auth<br/>[tenant.py]"]
  node_backend_permissions["Permission registry<br/>access control"]
  node_backend_media["Media uploads<br/>file storage<br/>[upload_service.py]"]
end

subgraph group_frontend["Frontend"]
  node_frontend_shell["App shell<br/>react spa"]
  node_frontend_routes["Routing guard"]
  node_frontend_api["Client services<br/>api client"]
  node_frontend_farm["Farm screens<br/>feature pages"]
  node_frontend_reports["Reports screens<br/>feature pages"]
  node_frontend_production["Harvest workflow<br/>feature pages"]
  node_frontend_domain_pages["Domain pages<br/>feature pages"]
  node_frontend_ui["UI system<br/>design system"]
end

subgraph group_shared["Shared concerns"]
  node_shared_docs["Architecture docs"]
end

node_backend_core -->|"routes to"| node_backend_api
node_backend_api -->|"dispatches to"| node_backend_apps
node_backend_api -->|"calls"| node_backend_services
node_backend_apps -->|"contains"| node_backend_reports
node_backend_apps -->|"contains"| node_backend_production
node_backend_apps -->|"contains"| node_backend_farm
node_backend_services -->|"orchestrates"| node_backend_reports
node_backend_services -->|"orchestrates"| node_backend_production
node_backend_services -->|"stores files"| node_backend_media
node_backend_tenant -->|"enforces"| node_backend_permissions
node_backend_permissions -->|"protects"| node_backend_api
node_backend_farm -->|"feeds"| node_backend_reports
node_backend_production -->|"emits"| node_backend_reports
node_backend_reports -->|"attaches"| node_backend_media
node_frontend_shell -->|"hosts"| node_frontend_routes
node_frontend_routes -->|"drives"| node_frontend_api
node_frontend_api -->|"consumes"| node_backend_api
node_frontend_shell -->|"composes"| node_frontend_ui
node_frontend_routes -->|"opens"| node_frontend_farm
node_frontend_routes -->|"opens"| node_frontend_reports
node_frontend_routes -->|"opens"| node_frontend_production
node_frontend_routes -->|"opens"| node_frontend_domain_pages
node_frontend_farm -->|"reflects"| node_backend_farm
node_frontend_reports -->|"reflects"| node_backend_reports
node_frontend_production -->|"reflects"| node_backend_production
node_frontend_domain_pages -->|"covers"| node_backend_apps
node_shared_docs -.->|"defines"| node_backend_core
node_shared_docs -.->|"defines"| node_frontend_shell

click node_backend_core "https://github.com/mahmoudg25/atls/tree/main/Back-End/core"
click node_backend_api "https://github.com/mahmoudg25/atls/tree/main/Back-End/api/endpoints"
click node_backend_apps "https://github.com/mahmoudg25/atls/tree/main/Back-End/apps"
click node_backend_services "https://github.com/mahmoudg25/atls/tree/main/Back-End/services"
click node_backend_reports "https://github.com/mahmoudg25/atls/tree/main/Back-End/apps/reports"
click node_backend_production "https://github.com/mahmoudg25/atls/tree/main/Back-End/apps/production"
click node_backend_farm "https://github.com/mahmoudg25/atls/tree/main/Back-End/apps/farm"
click node_backend_tenant "https://github.com/mahmoudg25/atls/blob/main/Back-End/core/tenant.py"
click node_backend_permissions "https://github.com/mahmoudg25/atls/tree/main/Back-End/permissions/registry"
click node_backend_media "https://github.com/mahmoudg25/atls/blob/main/Back-End/services/upload_service.py"
click node_frontend_shell "https://github.com/mahmoudg25/atls/tree/main/Front-End/src"
click node_frontend_routes "https://github.com/mahmoudg25/atls/tree/main/Front-End/src/routes"
click node_frontend_api "https://github.com/mahmoudg25/atls/tree/main/Front-End/src/services"
click node_frontend_farm "https://github.com/mahmoudg25/atls/tree/main/Front-End/src/pages/farm"
click node_frontend_reports "https://github.com/mahmoudg25/atls/tree/main/Front-End/src/pages/reports"
click node_frontend_production "https://github.com/mahmoudg25/atls/tree/main/Front-End/src/features/production"
click node_frontend_domain_pages "https://github.com/mahmoudg25/atls/tree/main/Front-End/src/pages"
click node_frontend_ui "https://github.com/mahmoudg25/atls/tree/main/Front-End/src/components/ui"
click node_shared_docs "https://github.com/mahmoudg25/atls/tree/main/docs"

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_backend_core,node_backend_api,node_backend_apps,node_backend_services,node_backend_reports,node_backend_production,node_backend_farm,node_backend_tenant,node_backend_permissions,node_backend_media toneBlue
class node_frontend_shell,node_frontend_routes,node_frontend_api,node_frontend_farm,node_frontend_reports,node_frontend_production,node_frontend_domain_pages,node_frontend_ui toneAmber
class node_shared_docs toneMint
```

## Components

### Backend

Django REST stack, domain apps, and operational services

- [Core project](https://github.com/mahmoudg25/atls/tree/main/Back-End/core): django project · Bootstrap, settings, middleware, tenant context, and root URL routing · `Back-End/core`
- [API layer](https://github.com/mahmoudg25/atls/tree/main/Back-End/api/endpoints): drf endpoints · REST endpoint modules and URL composition per domain · `Back-End/api/endpoints`
- [Domain apps](https://github.com/mahmoudg25/atls/tree/main/Back-End/apps): django apps · Bounded modules for farm, reports, production, HR, warehouse, equipment, accounting, users, olive, and palm · `Back-End/apps`
- [Services](https://github.com/mahmoudg25/atls/tree/main/Back-End/services): business logic · Workflow orchestration and domain operations across modules · `Back-End/services`
- [Reporting hub](https://github.com/mahmoudg25/atls/tree/main/Back-End/apps/reports): reporting domain · Operational logs, daily task reports, selectors, and analytics generation · `Back-End/apps/reports`
- [Production flow](https://github.com/mahmoudg25/atls/tree/main/Back-End/apps/production): workflow domain · Harvest and sorting workflows with serializers, filters, models, and views · `Back-End/apps/production`
- [Farm hierarchy](https://github.com/mahmoudg25/atls/tree/main/Back-End/apps/farm): location domain · Unified farm structure and shared location model for sectors, stages, and enclosures · `Back-End/apps/farm`
- [Tenant access](https://github.com/mahmoudg25/atls/blob/main/Back-End/core/tenant.py): tenant auth · Multi-tenant request context and centralized role-based permissions · `Back-End/core/tenant.py`
- [Permission registry](https://github.com/mahmoudg25/atls/tree/main/Back-End/permissions/registry): access control · Domain-aware role permissions and registry-based access rules · `Back-End/permissions/registry`
- [Media uploads](https://github.com/mahmoudg25/atls/blob/main/Back-End/services/upload_service.py): file storage · 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](https://github.com/mahmoudg25/atls/tree/main/Front-End/src): react spa · Top-level app, contexts, theme, and layout scaffolding · `Front-End/src`
- [Routing guard](https://github.com/mahmoudg25/atls/tree/main/Front-End/src/routes): routing · Protected routes and feature-gated navigation · `Front-End/src/routes`
- [Client services](https://github.com/mahmoudg25/atls/tree/main/Front-End/src/services): api client · Feature-oriented API clients and shared HTTP layer · `Front-End/src/services`
- [Farm screens](https://github.com/mahmoudg25/atls/tree/main/Front-End/src/pages/farm): feature pages · Farm structure, enclosure profile, and operational timeline UI · `Front-End/src/pages/farm`
- [Reports screens](https://github.com/mahmoudg25/atls/tree/main/Front-End/src/pages/reports): feature pages · Analytics, daily tasks, irrigation, pest control, fertilization, and custom fields UI · `Front-End/src/pages/reports`
- [Harvest workflow](https://github.com/mahmoudg25/atls/tree/main/Front-End/src/features/production): feature pages · Harvest management and guided production forms · `Front-End/src/features/production`
- [Domain pages](https://github.com/mahmoudg25/atls/tree/main/Front-End/src/pages): feature pages · Accounting, HR, equipment, warehouse, admin, dashboard, and public pages · `Front-End/src/pages`
- [UI system](https://github.com/mahmoudg25/atls/tree/main/Front-End/src/components/ui): design 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](https://github.com/mahmoudg25/atls/tree/main/docs): docs · Core rules, ADRs, and architecture guidance that define the system contract · `docs`

## Connections

- 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
