# mo574216/pm-eland-system architecture

> Architecture diagram of the GitHub repository mo574216/pm-eland-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mo574216/pm-eland-system
- Repository: https://github.com/mo574216/pm-eland-system

## Overview

#### Purpose and Delivery Shape
A metadata-driven enterprise architecture and project-knowledge platform: administrators define entity types, attributes, hierarchies, relationships, forms, and workflows as data rather than domain-specific code. The implemented baseline currently centers on identity, authentication, authorization, health, and a Persian-first application shell. Normative product design is in `ai_context/`; shared integration contracts are in `contracts/openapi.yaml`, `contracts/permissions.yaml`, and `contracts/error-codes.yaml`.

#### Runtime Entry Points
The backend is an async Python/FastAPI service entered through `backend/app/main.py`; its versioned HTTP API is assembled at `backend/app/api/v1/router.py`, with live/readiness probes in `backend/app/api/health.py`. The frontend is a React/TypeScript Vite SPA bootstrapped by `frontend/src/main.tsx`, rooted at `frontend/src/app/App.tsx`, and routed by `frontend/src/app/router.tsx`.

#### Backend Application Boundary
FastAPI routes are thin transport handlers: authentication and user endpoints in `backend/app/api/v1/auth.py` and `backend/app/api/v1/users.py` rely on request dependencies for bearer authentication and permission enforcement in `backend/app/api/dependencies/authentication.py` and `backend/app/api/dependencies/authorization.py`. API envelopes and centralized error handling establish the HTTP/error-code boundary in `backend/app/api/envelopes.py` and `backend/app/api/error_handlers.py`.

#### Identity and Authorization Flow
Identity state is modeled in `backend/app/models/identity.py`, accessed through `backend/app/repositories/auth.py`, and coordinated by `backend/app/services/auth.py`. Authentication implements bearer access tokens with rotating refresh sessions, while `backend/app/services/authorization.py` evaluates authorization policy. This layering isolates HTTP concerns from persistence and security logic. Security primitives, permission definitions, and request context reside in `backend/app/core/security.py`, `backend/app/core/permissions.py`, and `backend/app/core/request_context.py`.

#### Persistence and Schema Evolution
The service uses async SQLAlchemy database/session infrastructure in `backend/app/core/database.py`, consistent with the async-session ADR. PostgreSQL is the material datastore; Alembic migrations create extensions, identity schema, auth sessions, and audit-related identity evolution under `backend/alembic/versions/0001_enable_postgresql_extensions.py`, `backend/alembic/versions/0002_identity_schema.py`, and `backend/alembic/versions/0004_identity_management_and_audit.py`. Future metadata-defined domain capabilities should extend this generic platform model rather than introduce per-domain tables.

#### Frontend Composition and API Flow
The SPA configures global providers, query caching, RTL rendering, and theme in `frontend/src/app/providers.tsx`, `frontend/src/app/queryClient.ts`, and `frontend/src/app/rtlCache.ts`. `frontend/src/api/client.ts` is the backend integration boundary. Feature modules currently provide login and workspace-list surfaces at `frontend/src/modules/auth/LoginPage.tsx` and `frontend/src/modules/workspaces/WorkspaceListPage.tsx`; shared authenticated navigation/layout is `frontend/src/layouts/AppShell.tsx`.

#### Localization and Platform Infrastructure
The product is Persian-first/RTL for end users, with frontend translations in `frontend/src/i18n/fa.ts` and backend localization/text handling in `backend/app/core/localization.py` and `backend/app/core/persian_text.py`; identifiers, APIs, logs, and contracts remain English. Local development packages backend, frontend, PostgreSQL-adjacent service dependencies, and planned Redis/MinIO-compatible integrations via `infrastructure/compose/docker-compose.dev.yml` and container definitions in `infrastructure/docker/backend.Dockerfile` and `infrastructure/docker/frontend.Dockerfile`.

Main entry points: [`backend/app/api/v1/router.py`](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/api/v1/router.py) (Versioned API), [`infrastructure/compose/docker-compose.dev.yml`](https://github.com/mo574216/pm-eland-system/blob/main/infrastructure/compose/docker-compose.dev.yml) (Development compose), [`frontend/src/modules/auth/LoginPage.tsx`](https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/modules/auth/LoginPage.tsx) (Login and workspaces), [`backend/app/api/v1/auth.py`](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/api/v1/auth.py) (Auth and user routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React SPA"]
  node_spa_bootstrap["SPA bootstrap<br/>Vite entry<br/>[main.tsx]"]
  node_app_router["App and router<br/>React routing<br/>[router.tsx]"]
  node_providers["Global providers<br/>query, theme, RTL<br/>[providers.tsx]"]
  node_feature_surfaces["Login and workspaces<br/>feature pages<br/>[LoginPage.tsx]"]
  node_app_shell["Authenticated shell<br/>navigation layout<br/>[AppShell.tsx]"]
  node_frontend_api["API client<br/>HTTP integration boundary<br/>[client.ts]"]
  node_persian_ui["Persian UI text<br/>RTL localization<br/>[fa.ts]"]
end

subgraph group_backend["FastAPI Service"]
  node_service_entry["FastAPI application<br/>async service entry<br/>[main.py]"]
  node_api_router["Versioned API<br/>HTTP route assembly<br/>[router.py]"]
  node_identity_routes["Auth and user routes<br/>transport handlers<br/>[auth.py]"]
  node_api_boundary["API error boundary<br/>envelopes and handlers<br/>[error_handlers.py]"]
  node_access_dependencies["Access dependencies<br/>bearer auth and permissions<br/>[authentication.py]"]
  node_identity_services["Identity services<br/>auth and authorization<br/>[auth.py]"]
  node_identity_repository["Identity repository<br/>persistence access<br/>[auth.py]"]
  node_security_core["Security and context<br/>security primitives<br/>[security.py]"]
  node_health_probes["Health probes<br/>live/readiness endpoints<br/>[health.py]"]
end

subgraph group_data["Persistence"]
  node_identity_model["Identity model<br/>SQLAlchemy models<br/>[identity.py]"]
  node_database[("PostgreSQL<br/>primary datastore<br/>[database.py]")]
  node_migrations["Identity migrations<br/>Alembic evolution"]
end

subgraph group_contracts["Product Contracts"]
  node_contracts["OpenAPI contract<br/>integration contract<br/>[openapi.yaml]"]
  node_product_design["Metadata platform design<br/>normative product design"]
end

subgraph group_infra["Local Infrastructure"]
  node_dev_compose["Development compose<br/>local runtime stack"]
end

node_spa_bootstrap -->|"starts"| node_app_router
node_spa_bootstrap -->|"installs"| node_providers
node_app_router -->|"routes to"| node_feature_surfaces
node_feature_surfaces -->|"uses after sign-in"| node_app_shell
node_providers -->|"renders RTL text"| node_persian_ui
node_feature_surfaces -->|"calls"| node_frontend_api
node_frontend_api -->|"versioned HTTP"| node_api_router
node_service_entry -->|"mounts"| node_api_router
node_service_entry -->|"exposes"| node_health_probes
node_api_router -->|"dispatches"| node_identity_routes
node_identity_routes -->|"enforces"| node_access_dependencies
node_identity_routes -->|"delegates"| node_identity_services
node_api_router -->|"uses"| node_api_boundary
node_access_dependencies -->|"validates tokens"| node_security_core
node_access_dependencies -->|"checks policy"| node_identity_services
node_identity_services -->|"coordinates"| node_identity_repository
node_identity_repository -->|"loads and persists"| node_identity_model
node_identity_model -->|"stored in"| node_database
node_migrations -->|"evolves schema"| node_database
node_contracts -.->|"defines API"| node_api_router
node_product_design -.->|"guides platform extension"| node_identity_model
node_dev_compose -->|"runs backend"| node_service_entry
node_dev_compose -->|"runs frontend"| node_spa_bootstrap
node_dev_compose -->|"provisions dependencies"| node_database

click node_spa_bootstrap "https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/main.tsx"
click node_app_router "https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/app/router.tsx"
click node_providers "https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/app/providers.tsx"
click node_feature_surfaces "https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/modules/auth/LoginPage.tsx"
click node_app_shell "https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/layouts/AppShell.tsx"
click node_frontend_api "https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/api/client.ts"
click node_persian_ui "https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/i18n/fa.ts"
click node_service_entry "https://github.com/mo574216/pm-eland-system/blob/main/backend/app/main.py"
click node_api_router "https://github.com/mo574216/pm-eland-system/blob/main/backend/app/api/v1/router.py"
click node_identity_routes "https://github.com/mo574216/pm-eland-system/blob/main/backend/app/api/v1/auth.py"
click node_api_boundary "https://github.com/mo574216/pm-eland-system/blob/main/backend/app/api/error_handlers.py"
click node_access_dependencies "https://github.com/mo574216/pm-eland-system/blob/main/backend/app/api/dependencies/authentication.py"
click node_identity_services "https://github.com/mo574216/pm-eland-system/blob/main/backend/app/services/auth.py"
click node_identity_repository "https://github.com/mo574216/pm-eland-system/blob/main/backend/app/repositories/auth.py"
click node_security_core "https://github.com/mo574216/pm-eland-system/blob/main/backend/app/core/security.py"
click node_health_probes "https://github.com/mo574216/pm-eland-system/blob/main/backend/app/api/health.py"
click node_identity_model "https://github.com/mo574216/pm-eland-system/blob/main/backend/app/models/identity.py"
click node_database "https://github.com/mo574216/pm-eland-system/blob/main/backend/app/core/database.py"
click node_migrations "https://github.com/mo574216/pm-eland-system/blob/main/backend/alembic/versions/0004_identity_management_and_audit.py"
click node_contracts "https://github.com/mo574216/pm-eland-system/blob/main/contracts/openapi.yaml"
click node_dev_compose "https://github.com/mo574216/pm-eland-system/blob/main/infrastructure/compose/docker-compose.dev.yml"

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_spa_bootstrap,node_app_router,node_providers,node_feature_surfaces,node_app_shell,node_frontend_api,node_persian_ui toneBlue
class node_service_entry,node_api_router,node_identity_routes,node_api_boundary,node_access_dependencies,node_identity_services,node_identity_repository,node_security_core,node_health_probes toneAmber
class node_identity_model,node_database,node_migrations toneMint
class node_contracts,node_product_design toneRose
class node_dev_compose toneIndigo
```

## Components

### React SPA

Persian-first client application.

- [SPA bootstrap](https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/main.tsx): Vite entry · `frontend/src/main.tsx`
- [App and router](https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/app/router.tsx): React routing · `frontend/src/app/router.tsx`
- [Global providers](https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/app/providers.tsx): query, theme, RTL · `frontend/src/app/providers.tsx`
- [Login and workspaces](https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/modules/auth/LoginPage.tsx): feature pages · `frontend/src/modules/auth/LoginPage.tsx`
- [Authenticated shell](https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/layouts/AppShell.tsx): navigation layout · `frontend/src/layouts/AppShell.tsx`
- [API client](https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/api/client.ts): HTTP integration boundary · `frontend/src/api/client.ts`
- [Persian UI text](https://github.com/mo574216/pm-eland-system/blob/main/frontend/src/i18n/fa.ts): RTL localization · `frontend/src/i18n/fa.ts`

### FastAPI Service

Async identity and authorization baseline.

- [FastAPI application](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/main.py): async service entry · `backend/app/main.py`
- [Versioned API](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/api/v1/router.py): HTTP route assembly · `backend/app/api/v1/router.py`
- [Auth and user routes](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/api/v1/auth.py): transport handlers · `backend/app/api/v1/auth.py`
- [API error boundary](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/api/error_handlers.py): envelopes and handlers · Standardizes HTTP responses and error codes. · `backend/app/api/error_handlers.py`
- [Access dependencies](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/api/dependencies/authentication.py): bearer auth and permissions · `backend/app/api/dependencies/authentication.py`
- [Identity services](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/services/auth.py): auth and authorization · Issues rotating refresh sessions and evaluates policy. · `backend/app/services/auth.py`
- [Identity repository](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/repositories/auth.py): persistence access · `backend/app/repositories/auth.py`
- [Security and context](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/core/security.py): security primitives · `backend/app/core/security.py`
- [Health probes](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/api/health.py): live/readiness endpoints · `backend/app/api/health.py`

### Persistence

PostgreSQL-backed identity state and schema evolution.

- [Identity model](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/models/identity.py): SQLAlchemy models · `backend/app/models/identity.py`
- [PostgreSQL](https://github.com/mo574216/pm-eland-system/blob/main/backend/app/core/database.py): primary datastore · `backend/app/core/database.py`
- [Identity migrations](https://github.com/mo574216/pm-eland-system/blob/main/backend/alembic/versions/0004_identity_management_and_audit.py): Alembic evolution · Creates extensions, identity schema, sessions, and audit evolution. · `backend/alembic/versions/0004_identity_management_and_audit.py`

### Product Contracts

Normative design and shared integration definitions.

- [OpenAPI contract](https://github.com/mo574216/pm-eland-system/blob/main/contracts/openapi.yaml): integration contract · `contracts/openapi.yaml`
- **Metadata platform design**: normative product design · Defines metadata-driven future domain capabilities.

### Local Infrastructure

Containerized development environment.

- [Development compose](https://github.com/mo574216/pm-eland-system/blob/main/infrastructure/compose/docker-compose.dev.yml): local runtime stack · Packages backend, frontend, PostgreSQL-adjacent dependencies, Redis, and MinIO plans. · `infrastructure/compose/docker-compose.dev.yml`

## Connections

- SPA bootstrap → App and router: starts
- SPA bootstrap → Global providers: installs
- App and router → Login and workspaces: routes to
- Login and workspaces → Authenticated shell: uses after sign-in
- Global providers → Persian UI text: renders RTL text
- Login and workspaces → API client: calls
- API client → Versioned API: versioned HTTP
- FastAPI application → Versioned API: mounts
- FastAPI application → Health probes: exposes
- Versioned API → Auth and user routes: dispatches
- Auth and user routes → Access dependencies: enforces
- Auth and user routes → Identity services: delegates
- Versioned API → API error boundary: uses
- Access dependencies → Security and context: validates tokens
- Access dependencies → Identity services: checks policy
- Identity services → Identity repository: coordinates
- Identity repository → Identity model: loads and persists
- Identity model → PostgreSQL: stored in
- Identity migrations → PostgreSQL: evolves schema
- OpenAPI contract → Versioned API: defines API
- Metadata platform design → Identity model: guides platform extension
- Development compose → FastAPI application: runs backend
- Development compose → SPA bootstrap: runs frontend
- Development compose → PostgreSQL: provisions dependencies
