# charan379/flierly-erp architecture

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

- Interactive diagram: https://gitdiagram.com/charan379/flierly-erp
- Repository: https://github.com/charan379/flierly-erp

## Overview

#### Purpose and topology
FLIERLY is a PERN ERP repository split into a React/Vite administrative SPA and an Express/Node API backed by PostgreSQL through TypeORM. Implemented areas center on IAM, product master data, branches, UOM, and inventory; purchase/account entities exist but are less fully routed. Entry points are `flierly-admin-web/src/main.tsx`, `flierly-admin-web/src/App.tsx`, `flierly-backend/src/server.ts`, and `flierly-backend/src/app.ts`.

#### Frontend composition and routing
The SPA bootstraps Redux-backed application state and route selection, with top-level feature routers composed in `flierly-admin-web/src/router/AppRouter.tsx`. Auth routes are isolated in `flierly-admin-web/src/modules/auth/router/AuthRouter.tsx`; authenticated screens use the dashboard shell at `flierly-admin-web/src/modules/core/layouts/Dashboard/Dashboard.tsx`. Domain routers define page exposure: `flierly-admin-web/src/modules/iam/router/IamRoutes.tsx`, `flierly-admin-web/src/modules/product/router/ProductRouter.tsx`, and `flierly-admin-web/src/modules/inventory/router/InventoryRouter.tsx`.

#### Identity, authorization, and client state
Authentication has dedicated forms, services, Redux state, and re-authentication flow: `flierly-admin-web/src/modules/auth/service/auth.service.ts`, `flierly-admin-web/src/modules/auth/redux/auth.slice.ts`, `flierly-admin-web/src/modules/auth/features/ReAuthenticate/ReAuthenticate.tsx`. `flierly-admin-web/src/modules/core/features/ProtectedRoute/ProtectedRoute.tsx` is the UI authorization boundary, while persistent/global state is configured by `flierly-admin-web/src/redux/store.ts` and `flierly-admin-web/src/redux/state-persist.ts`. Theme, locale, and selected branch are separate stateful cross-cutting concerns.

#### Metadata-driven administration UI
A reusable CRUD layer drives most master-data pages: `flierly-admin-web/src/modules/core/features/CrudModule/CrudModule.tsx`, `flierly-admin-web/src/modules/core/features/CrudTable/CrudTable.tsx`, and `flierly-admin-web/src/modules/core/features/GenericAssociationManager/GenericAssociationManager.tsx`. Domain pages supply form fields, table columns, and query definitions rather than duplicating mechanics; for example `flierly-admin-web/src/modules/product/pages/ProductsPage/ProductsPage.tsx` and `flierly-admin-web/src/modules/iam/pages/UsersPage/UsersPage.tsx`. Query builders and remote selects form the client/API query boundary.

#### API pipeline and generic persistence
Express application/router assembly is in `flierly-backend/src/app.ts` and `flierly-backend/src/router/app.routes.ts`. Requests pass logging, validation, authorization, controller error boundary, and centralized error handling, notably `flierly-backend/src/middlewares/authorization.middleware.ts` and `flierly-backend/src/middlewares/error-handler.middleware.ts`. Generic CRUD controllers/services implement paged reads, search, soft delete/restore, activation, and association updates via `flierly-backend/src/modules/core/controllers/crud-controller/index.ts` and `flierly-backend/src/modules/core/services/crud-service/index.ts`.

#### Domain services and security
IAM models roles, privileges, users, and passwords in `flierly-backend/src/modules/iam/entities/User.entity.ts`, with credential workflows in `flierly-backend/src/modules/iam/services/user-service/UserServiceImpl.ts`. JWT and bcrypt are abstracted behind IoC-configured services: `flierly-backend/src/lib/jwt/jwt-service/JwtServiceImpl.ts` and `flierly-backend/src/lib/hashing/bcrypt-service/BcryptServiceImpl.ts`. Product and stock operations have dedicated controllers/services beyond generic CRUD: `flierly-backend/src/modules/product/service/product-service/ProductServiceImpl.ts` and `flierly-backend/src/modules/product/service/product-stock-service/ProductStockServiceImpl.ts`.

#### Data and external infrastructure
PostgreSQL access is centralized through TypeORM datasource and a database-service abstraction: `flierly-backend/src/lib/database/typeorm/app-datasource.ts` and `flierly-backend/src/lib/database/database-service/DatabaseServiceImpl.ts`. Entities cover ERP relationships and read-model views; `flierly-backend/migrations/1740305729750-createviews.ts` creates views used for product availability/latest prices. File upload is mediated by `flierly-backend/src/modules/storage/controllers/upload-controller/upload-file.controller.ts` and pluggable storage adapters, including AWS S3, Azure Blob, GCP, Cloudflare, Backblaze, DigitalOcean, Tencent, or local storage.

Main entry points: [`flierly-backend/src/router/app.routes.ts`](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/router/app.routes.ts) (API route assembly), [`flierly-backend/src/app.ts`](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/app.ts) (Express application), [`flierly-admin-web/src/App.tsx`](https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/App.tsx) (App composition), [`flierly-admin-web/src/router/AppRouter.tsx`](https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/router/AppRouter.tsx) (Application router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Admin SPA"]
  node_web_entry["SPA bootstrap<br/>React entry<br/>[main.tsx]"]
  node_web_app["App composition<br/>React app<br/>[App.tsx]"]
  node_web_store["Redux persisted state<br/>state store<br/>[store.ts]"]
  node_app_router["Application router<br/>route assembly<br/>[AppRouter.tsx]"]
  node_auth_ui["Auth flow<br/>feature routes<br/>[AuthRouter.tsx]"]
  node_protected_route["Protected route<br/>UI auth boundary<br/>[ProtectedRoute.tsx]"]
  node_dashboard["Dashboard shell<br/>authenticated layout<br/>[Dashboard.tsx]"]
  node_domain_routes["Domain routes<br/>feature routers<br/>[ProductRouter.tsx]"]
  node_crud_ui["Metadata CRUD UI<br/>reusable UI layer<br/>[CrudModule.tsx]"]
  node_auth_client["Auth client state<br/>service and slice<br/>[auth.service.ts]"]
end

subgraph group_api["API Service"]
  node_server["API server<br/>Node entry<br/>[server.ts]"]
  node_express_app["Express application<br/>middleware pipeline<br/>[app.ts]"]
  node_api_routes["API route assembly<br/>router<br/>[app.routes.ts]"]
  node_authorization["Authorization middleware<br/>API auth boundary"]
  node_crud_api["Generic CRUD layer<br/>controllers and services<br/>[index.ts]"]
  node_iam_service["IAM credential service<br/>domain service<br/>[UserServiceImpl.ts]"]
  node_security["JWT and bcrypt<br/>security services<br/>[JwtServiceImpl.ts]"]
  node_product_service["Product and stock services<br/>domain services"]
end

subgraph group_data["Data &amp; Storage"]
  node_database[("TypeORM database service<br/>persistence abstraction")]
  node_postgres[("PostgreSQL and ERP views<br/>database")]
  node_uploads["Upload controller and adapters<br/>storage boundary"]
end

node_web_entry -->|"mounts"| node_web_app
node_web_app -->|"provides state"| node_web_store
node_web_app -->|"renders"| node_app_router
node_app_router -->|"public routes"| node_auth_ui
node_app_router -->|"authenticated routes"| node_protected_route
node_protected_route -->|"authorizes shell"| node_dashboard
node_dashboard -->|"hosts"| node_domain_routes
node_domain_routes -->|"renders master-data pages"| node_crud_ui
node_auth_ui -->|"uses"| node_auth_client
node_auth_client -->|"updates auth state"| node_web_store
node_auth_client -->|"auth API calls"| node_express_app
node_crud_ui -->|"CRUD and query calls"| node_express_app
node_server -->|"starts"| node_express_app
node_express_app -->|"mounts"| node_api_routes
node_api_routes -->|"protects routes"| node_authorization
node_authorization -->|"permits requests"| node_crud_api
node_authorization -->|"validates identity"| node_iam_service
node_iam_service -->|"issues JWTs and hashes passwords"| node_security
node_crud_api -->|"persists generic entities"| node_database
node_product_service -->|"persists products and stock"| node_database
node_api_routes -->|"product endpoints"| node_product_service
node_database -->|"TypeORM access"| node_postgres
node_api_routes -->|"upload endpoints"| node_uploads

click node_web_entry "https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/main.tsx"
click node_web_app "https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/App.tsx"
click node_web_store "https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/redux/store.ts"
click node_app_router "https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/router/AppRouter.tsx"
click node_auth_ui "https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/modules/auth/router/AuthRouter.tsx"
click node_protected_route "https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/modules/core/features/ProtectedRoute/ProtectedRoute.tsx"
click node_dashboard "https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/modules/core/layouts/Dashboard/Dashboard.tsx"
click node_domain_routes "https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/modules/product/router/ProductRouter.tsx"
click node_crud_ui "https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/modules/core/features/CrudModule/CrudModule.tsx"
click node_auth_client "https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/modules/auth/service/auth.service.ts"
click node_server "https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/server.ts"
click node_express_app "https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/app.ts"
click node_api_routes "https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/router/app.routes.ts"
click node_authorization "https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/middlewares/authorization.middleware.ts"
click node_crud_api "https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/modules/core/controllers/crud-controller/index.ts"
click node_iam_service "https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/modules/iam/services/user-service/UserServiceImpl.ts"
click node_security "https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/lib/jwt/jwt-service/JwtServiceImpl.ts"
click node_product_service "https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/modules/product/service/product-service/ProductServiceImpl.ts"
click node_database "https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/lib/database/database-service/DatabaseServiceImpl.ts"
click node_postgres "https://github.com/charan379/flierly-erp/blob/main/flierly-backend/migrations/1740305729750-createviews.ts"
click node_uploads "https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/modules/storage/controllers/upload-controller/upload-file.controller.ts"

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_web_entry,node_web_app,node_web_store,node_app_router,node_auth_ui,node_protected_route,node_dashboard,node_domain_routes,node_crud_ui,node_auth_client toneBlue
class node_server,node_express_app,node_api_routes,node_authorization,node_crud_api,node_iam_service,node_security,node_product_service toneAmber
class node_database,node_postgres,node_uploads toneMint
```

## Components

### Admin SPA

React/Vite administrative client.

- [SPA bootstrap](https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/main.tsx): React entry · `flierly-admin-web/src/main.tsx`
- [App composition](https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/App.tsx): React app · `flierly-admin-web/src/App.tsx`
- [Redux persisted state](https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/redux/store.ts): state store · Global state persists auth and cross-cutting preferences. · `flierly-admin-web/src/redux/store.ts`
- [Application router](https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/router/AppRouter.tsx): route assembly · `flierly-admin-web/src/router/AppRouter.tsx`
- [Auth flow](https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/modules/auth/router/AuthRouter.tsx): feature routes · Includes login and re-authentication screens. · `flierly-admin-web/src/modules/auth/router/AuthRouter.tsx`
- [Protected route](https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/modules/core/features/ProtectedRoute/ProtectedRoute.tsx): UI auth boundary · `flierly-admin-web/src/modules/core/features/ProtectedRoute/ProtectedRoute.tsx`
- [Dashboard shell](https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/modules/core/layouts/Dashboard/Dashboard.tsx): authenticated layout · `flierly-admin-web/src/modules/core/layouts/Dashboard/Dashboard.tsx`
- [Domain routes](https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/modules/product/router/ProductRouter.tsx): feature routers · IAM, product, and inventory page exposure. · `flierly-admin-web/src/modules/product/router/ProductRouter.tsx`
- [Metadata CRUD UI](https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/modules/core/features/CrudModule/CrudModule.tsx): reusable UI layer · Renders forms, tables, queries, and associations from domain metadata. · `flierly-admin-web/src/modules/core/features/CrudModule/CrudModule.tsx`
- [Auth client state](https://github.com/charan379/flierly-erp/blob/main/flierly-admin-web/src/modules/auth/service/auth.service.ts): service and slice · `flierly-admin-web/src/modules/auth/service/auth.service.ts`

### API Service

Express ERP API and domain logic.

- [API server](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/server.ts): Node entry · `flierly-backend/src/server.ts`
- [Express application](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/app.ts): middleware pipeline · Applies logging, validation, authorization, and error handling. · `flierly-backend/src/app.ts`
- [API route assembly](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/router/app.routes.ts): router · `flierly-backend/src/router/app.routes.ts`
- [Authorization middleware](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/middlewares/authorization.middleware.ts): API auth boundary · `flierly-backend/src/middlewares/authorization.middleware.ts`
- [Generic CRUD layer](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/modules/core/controllers/crud-controller/index.ts): controllers and services · Provides paging, search, lifecycle, and association operations. · `flierly-backend/src/modules/core/controllers/crud-controller/index.ts`
- [IAM credential service](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/modules/iam/services/user-service/UserServiceImpl.ts): domain service · Manages users, roles, privileges, and password workflows. · `flierly-backend/src/modules/iam/services/user-service/UserServiceImpl.ts`
- [JWT and bcrypt](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/lib/jwt/jwt-service/JwtServiceImpl.ts): security services · `flierly-backend/src/lib/jwt/jwt-service/JwtServiceImpl.ts`
- [Product and stock services](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/modules/product/service/product-service/ProductServiceImpl.ts): domain services · `flierly-backend/src/modules/product/service/product-service/ProductServiceImpl.ts`

### Data & Storage

Persistence and upload infrastructure.

- [TypeORM database service](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/lib/database/database-service/DatabaseServiceImpl.ts): persistence abstraction · `flierly-backend/src/lib/database/database-service/DatabaseServiceImpl.ts`
- [PostgreSQL and ERP views](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/migrations/1740305729750-createviews.ts): database · TypeORM entities and migrations provide transactional data and availability/price views. · `flierly-backend/migrations/1740305729750-createviews.ts`
- [Upload controller and adapters](https://github.com/charan379/flierly-erp/blob/main/flierly-backend/src/modules/storage/controllers/upload-controller/upload-file.controller.ts): storage boundary · Selects local or cloud object-storage adapters. · `flierly-backend/src/modules/storage/controllers/upload-controller/upload-file.controller.ts`

## Connections

- SPA bootstrap → App composition: mounts
- App composition → Redux persisted state: provides state
- App composition → Application router: renders
- Application router → Auth flow: public routes
- Application router → Protected route: authenticated routes
- Protected route → Dashboard shell: authorizes shell
- Dashboard shell → Domain routes: hosts
- Domain routes → Metadata CRUD UI: renders master-data pages
- Auth flow → Auth client state: uses
- Auth client state → Redux persisted state: updates auth state
- Auth client state → Express application: auth API calls
- Metadata CRUD UI → Express application: CRUD and query calls
- API server → Express application: starts
- Express application → API route assembly: mounts
- API route assembly → Authorization middleware: protects routes
- Authorization middleware → Generic CRUD layer: permits requests
- Authorization middleware → IAM credential service: validates identity
- IAM credential service → JWT and bcrypt: issues JWTs and hashes passwords
- Generic CRUD layer → TypeORM database service: persists generic entities
- Product and stock services → TypeORM database service: persists products and stock
- API route assembly → Product and stock services: product endpoints
- TypeORM database service → PostgreSQL and ERP views: TypeORM access
- API route assembly → Upload controller and adapters: upload endpoints
