CognitixERP Developer Guide
Full architecture deep-dive for buyers and integrators — how the Blazor WebApp, API host, business modules, database, licensing, and customization paths fit together.
Source/CognitixERP/docs/Architecture.md (markdown mirror of this guide for IDE/Git workflows).
Start here if you purchased on CodeCanyon and want one offline HTML reference.
1. Introduction
CognitixERP is a modular monolith ERP: one deployable API and one Blazor WebAssembly client. Business logic lives in backend modules; the UI talks to the API over HTTP and SignalR.
| Audience | Use this guide for |
|---|---|
| Buyer / integrator | Understanding folders, safe customization, where UI vs API vs DB code lives |
| Developer extending ERP | Adding pages, endpoints, reports, permissions, module services |
| DevOps | How WebApp config, JWT, CORS, uploads, and same-origin deploy relate — see also Production Guide |
2. Big picture
At runtime there are two processes (development) or one public site (production same-origin):
| Goal | How CognitixERP achieves it |
|---|---|
| Clear module boundaries | Domain / Application / Infrastructure per business area |
| Single deployable API | All modules registered in Cognitix.API DI |
| UI decoupling | WebApp references Shared.DTOs only — never module Domain |
| Buyer-friendly install | Setup Wizard migrates 12 DbContexts — no dotnet ef required |
| Marketplace protection | Licensing ships as obfuscated DLLs in buyer ZIP (BuyerBuild) |
Production same-origin (recommended)
https://yourcompany.com/ → WebApp (nginx / IIS static)
https://yourcompany.com/api/... → API (reverse proxy)
https://yourcompany.com/uploads/ → file storage
https://yourcompany.com/chat-hub → SignalR
WebApp ApiBaseUrl = site origin with trailing slash — do not append /api.
3. Solution structure
Open Source/CognitixERP/CognitixERP.sln in Visual Studio. Top-level layout:
CognitixERP.sln
├── apps/
│ └── Cognitix.WebApp # Blazor WASM + MudBlazor UI
│
├── src/
│ ├── Cognitix.API # HTTP host, controllers, PDF, middleware
│ ├── Cognitix.Billing
│ ├── Cognitix.Procurement
│ ├── Cognitix.Inventory
│ ├── Cognitix.POS
│ ├── Cognitix.Financials
│ ├── Cognitix.Banking
│ ├── Cognitix.CRM
│ ├── Cognitix.HRM
│ ├── Cognitix.Branching
│ ├── Cognitix.Compliance
│ ├── Cognitix.Users
│ ├── Cognitix.BiometricAgent # Optional Windows HRM agent
│ └── Cognitix.CrossCuttingConcerns/
│ ├── Cognitix.Shared.DTOs
│ ├── Cognitix.SharedKernel
│ ├── Cognitix.Localization
│ ├── Cognitix.Notifications
│ ├── Cognitix.FileStorage
│ └── Cognitix.SyncContracts
│
├── lib/Cognitix.Licensing/ # Licensing DLLs (Setup Wizard, enforce, CognitiveCircle)
├── deploy/hetzner/ # Linux nginx + systemd samples
├── tools/ # Author migration scripts
├── test/ # Unit, Integration, Performance, E2E
└── docs/
└── Architecture.md
Important notes
-
Licensing is shipped as precompiled DLLs under
lib/Cognitix.Licensing/— there is no Licensing source project in the buyer package. Publish the API with-p:BuyerBuild=trueso the host references those DLLs. sync/(offline SyncEngine) may exist on disk but is not in the active v1.0 web release.- There is no mobile client in v1.0.
- Logging uses Serilog on the API host (not a separate logging module in production).
- Package root
Database/holds buyer notes and support recovery scripts — not the EF migration source (those live under each module's Infrastructure).
4. Request flow (end-to-end)
Typical authenticated API call from a Blazor page:
- User opens route e.g.
/billing/invoices→ Razor page inPages/Billing/ - Page injects a WebApp service e.g.
IInvoiceServicefromservices/Billing/ - Service uses injected
HttpClient(factory nameCognitix.API) AuthHeaderHandlerattaches JWT;CultureHeaderHandlersends culture- Request hits API controller e.g.
Controllers/Billing/InvoicesController.cs - Controller calls module Application service (validation, mapping, business rules)
- Service uses module Infrastructure
DbContext+ repositories - Response returns DTO JSON → WebApp renders MudBlazor UI
5. WebApp (Blazor WASM)
Location: apps/Cognitix.WebApp/
| Folder / file | Purpose |
|---|---|
Pages/ | Razor routes grouped by module (Billing, CRM, HRM, Settings, …) |
services/ | Thin API clients — one service per feature area |
Components/ | Reusable MudBlazor UI pieces |
Authorization/ | Client-side permission checks, route guards |
wwwroot/appsettings.json | ApiBaseUrl — required for API calls |
wwwroot/js/ | Preloader, theme, small JS interop |
Program.cs | HttpClient factory, DI registration, MudBlazor, auth state |
Configuration
// apps/Cognitix.WebApp/wwwroot/appsettings.json
{
"ApiBaseUrl": "https://localhost:7149/"
}
Trailing slash required. After Setup Wizard, copy the JSON from the completion screen into this file.
HttpClient pipeline
Cognitix.API— authenticated calls (default injected client)Cognitix.PublicApi— login branding, anonymous endpointsCognitix.AuthRefresh— token refresh (no auth handler — avoids recursion)
UI stack
- MudBlazor — tables, dialogs, forms, theme
- Localization —
@inject ISharedLocalizer LfromCognitix.Localization - Permissions — menu and pages hidden when role lacks page permission
- Culture / RTL —
en-US,bn-BD,ar-SA(Arabic RTL)
Key routes
| Route | Purpose |
|---|---|
/setup | First-run Setup Wizard (anonymous) |
/users/login | Login |
/ | Dashboard (authenticated) |
/settings/license | License activate / re-verify |
/pos/terminal | POS terminal |
6. API host
Location: src/Cognitix.API/ — single ASP.NET Core host for all modules.
| Area | Location | Role |
|---|---|---|
| Controllers | Controllers/{Module}/ | REST endpoints, route prefix /api/... |
| Platform | Controllers/Platform/ | Setup, license, system version/health |
| Reports | Reports/ | QuestPDF generators (invoices, payslips, analytics PDFs) |
| Middleware | Middleware/ | License enforcement, user/branch context |
| Authorization | Authorization/ | RequirePermission, ApiPermissionRegistry |
| Hubs | Hubs/ | SignalR + license hub filter |
| Extensions | Extensions/ | DB provider wiring, cache decorators, startup guards |
| Program.cs | Root | DI composition — registers all module services |
Controller modules (folders)
Controllers are grouped under:
Billing · Banking · Branching · Compliance · CRM · Dashboard · Financials · HRM · Inventory · Observability · Platform · POS · Procurement · Users
Composition root
Program.cs is the composition root: it registers DbContexts, application services,
validators, PDF generators, hosted jobs, and cached query decorators. Cross-module orchestration
(e.g. invoice posting → journal entry) is wired here via DI, not by modules referencing each other directly.
Configuration files
appsettings.json— JWT, CORS, database provider, licensing, SMTP, cacheappsettings.Development.json— local overrides- Environment variables —
COGNITIX_JWT_KEY,Cors__AllowedOrigins__0, etc.
7. Business modules
Each business module follows the same internal shape:
Cognitix.{Module}/
├── Domain/ # Entities, enums, domain interfaces
├── Application/ # Services, validators, mappers, use cases
└── Infrastructure/ # EF DbContext, repositories, Migrations/{SqlServer|PostgreSql|MySql}
| Module | Responsibility | DbContext (schema) |
|---|---|---|
| Users | JWT auth, roles, permissions, preferences, audit | Users |
| Branching | Company profile, branding, branches, multi-branch isolation | Branching |
| Financials | COA, JE, fiscal periods, tax, FX, financial reports | Financials |
| Billing | Quotations, orders, invoices, credit notes, AR | Billing |
| Procurement | PO, GRN, supplier invoices, AP, payments | Procurement |
| Inventory | Products, stock, warehouses, transfers, WMS | Inventory |
| POS | Terminal sales, sessions, receipts, stock integration | POS |
| Banking | Bank accounts, cheques, reconciliation | Banking |
| CRM | Leads, opportunities, customers, pipelines, chat hub | CRM |
| HRM | Employees, attendance, leave, payroll-oriented records | HRM |
| Compliance | Regional tax / e-invoice profiles & reports | Compliance |
lib/Cognitix.Licensing/*.dll. The Licensing database schema is still one of the 12 schemas applied by Setup Wizard Step 1.
See §11 Licensing & BuyerBuild.
BiometricAgent is an optional Windows desktop agent for biometric attendance devices — separate from the web stack.
8. Clean Architecture rules
- Dependency flow:
Domain←Application←Infrastructure←API - WebApp decoupling: references only
Shared.DTOs,SharedKernel,Localization - Business logic stays in Application / Domain — not in Razor code-behind or controllers
- Cross-module calls use contracts in
SyncContractsor are composed in API DI - No .resx in Domain/Application — localization strings live in
Cognitix.Localization
Shared projects (CrossCuttingConcerns)
| Project | Contains |
|---|---|
Shared.DTOs | API contracts, request/response models, shared enums |
SharedKernel | Base entities, Result, Guard, IRepository, user/branch context interfaces |
Localization | .resx resources, ISharedLocalizer |
Notifications | SMTP email sending |
FileStorage | Upload path helpers, file persistence |
SyncContracts | In-process cross-module event/contract types (not offline mobile sync) |
Cognitix.Billing.Domain (or any module Domain).
Add or extend DTOs in Shared.DTOs instead.
9. Authentication & authorization
JWT authentication
| Setting | Detail |
|---|---|
| Scheme | JWT Bearer — issuer, audience, signing key must match across API and login |
| Key | COGNITIX_JWT_KEY env var → Jwt:Key → auto-generate on first dev run |
| Token lifetime | Default 60 minutes (AccessTokenMinutes) |
| Refresh | Users module refresh-token flow |
| Production | Set strong 32+ char key via environment — never commit secrets |
Permission model
- Each UI page maps to a SystemPage key (e.g.
Invoices,POSTerminal) - Roles grant Create / Read / Update / Delete per page
- API:
[RequirePermission("Invoices", PermissionActions.Read)]on controller actions - Registry:
ApiPermissionRegistry.csmaps controller names → page keys - WebApp: menu and routes respect the same permission keys
Branch isolation
Users can be branch-scoped. API middleware and filters apply branch filters on queries. Company-wide admins see all branches; branch users see only assigned branch data.
License middleware
LicenseEnforcementMiddleware blocks API access when trial expired or license revoked.
SignalR uses LicenseEnforcementHubFilter. Setup and login endpoints are [AllowAnonymous].
10. Database & Setup Wizard
Buyers choose one engine in Setup Wizard Step 1: SQL Server, PostgreSQL, or MySQL. All 12 module schemas live in one database (buyer-chosen name).
Configuration
{
"Database": { "Provider": "SqlServer" },
"ConnectionStrings": { "DefaultConnection": "" }
}
Provider: SqlServer (default), PostgreSql, MySql. Connection string is written by the wizard.
Migration order (12 DbContexts)
Licensing → Users → Branching → Financials → Billing → Procurement → Inventory → POS → Banking → CRM → HRM → Compliance
Runtime components
| Component | Role |
|---|---|
UseConfiguredCognitixDatabase | Provider + connection per DbContext |
| Provider-filtered migrations | Only Migrations/{Provider}/ applied |
ProviderAwareModelCustomizer | Softens SQL Server–specific Fluent API for PG/MySQL |
POST /api/setup/prepare-database | Wizard Step 1 — test, create DB, migrate all contexts |
AutoMigrateOnlyWhenSetupComplete | Startup auto-migrate only after setup finished |
Setup Wizard steps
| Step | What happens |
|---|---|
| 1 | Engine + URLs + DB credentials → Continue (~3–8 min schema apply) |
| 2 | Create first admin (no default production password shipped) |
| 3 | Activate purchase code or 14-day trial |
dotnet ef for normal install. Use Setup Wizard Step 1.
Support recovery: Database/apply-migrations.ps1 (see Database/MIGRATION-NOTES.md).
Authors extending schema
Set COGNITIX_DATABASE_PROVIDER=PostgreSql|MySql|SqlServer before dotnet ef.
Bulk regenerate: tools/setup-multi-db-migrations.ps1 (authors only).
11. Licensing & BuyerBuild
In the CodeCanyon package, licensing is delivered only as DLLs — not as editable source under src/.
Where the binaries live
lib/Cognitix.Licensing/
Cognitix.Licensing.Application.dll
Cognitix.Licensing.Domain.dll
Cognitix.Licensing.Infrastructure.dll
Publish / build the API with -p:BuyerBuild=true so Cognitix.API references these HintPath DLLs.
The sample deploy.yml detects this layout automatically when the lib/ folder is present.
What the DLLs provide at runtime
- Setup Wizard at
/setup(database prepare, admin create, activate / trial) - CognitiveCircle: activate, verify, heartbeat (
https://api.cognitivebd.com) - License enforcement (API middleware + SignalR hub filter)
- 72h offline grace only when CognitiveCircle is unreachable
- Admin revoke → immediate lock on next heartbeat / re-verify (not 72h grace)
lib/Cognitix.Licensing/ as a black box.
Use Setup Wizard, Settings → License, and documented Licensing:* config — do not replace or reverse-engineer the DLLs.
Keep the three DLLs committed with your private deploy repo so CI can publish with BuyerBuild.
ERP config ships Licensing:ProductSlug (not Envato Item ID).
12. Cross-cutting services
| Concern | Implementation |
|---|---|
| User / branch context | UserContext — request-scoped; API middleware |
| Company branding | Branching brand provider → logos, display name, preloader |
| Company timezone | ICompanyTimeZoneService; WebApp CompanyTimeZoneState |
| File uploads | Cognitix.FileStorage → served at /uploads/ |
Cognitix.Notifications — SMTP via SmtpSettings | |
| Memory cache | IMemoryCache on API — hot read paths; restart clears cache |
| PDF reports | QuestPDF generators in Cognitix.API/Reports/ |
| SignalR | CRM ChatHub at /chat-hub (JWT via access_token query) |
Cache
- Config:
appsettings.json→Cache - Registration:
AddCognitixCachedQueryServices()— decorates read services - Invalidation on master-data writes and journal post/reverse
- Diagnostics:
GET /api/system/cache-probe(authenticated) - No Redis in v1.0 — in-process only
13. Localization
UI strings live in Cognitix.Localization (hybrid model):
- SharedResource — common / nav / shared labels
- Module resources — e.g.
CRM_*,Procurement_*,Billing_*
| Layer | Uses Localization? |
|---|---|
| WebApp | Yes — @inject ISharedLocalizer L |
| API | Request culture; many PDF/email strings still English |
| Domain / Application | No .resx files |
Cultures: en-US, bn-BD, ar-SA (RTL via MudRTLProvider).
Key shape: {Module}_{Context}_{Element} — e.g. Common_Save, Nav_HRM.
14. Cross-module wiring
Modules stay loosely coupled. Typical integrations:
| Flow | How it works |
|---|---|
| Billing invoice → Financials JE | Application service in Billing calls contract / orchestrator registered in API |
| POS sale → Inventory stock | POS Application posts stock movement via Inventory services |
| Procurement GRN → Inventory | Receipt updates stock balances |
| CRM won opportunity → Billing customer | CRM contracts + API-level composition |
| Compliance e-invoice | Compliance module profiles; Billing/Procurement trigger submission hooks |
Look for interfaces in SyncContracts and registration blocks in Cognitix.API/Program.cs
when tracing cross-module behavior.
15. Where to change what
| You want to… | Start here |
|---|---|
| Change UI layout / form on a page | apps/Cognitix.WebApp/Pages/{Module}/ |
| Add API call from UI | services/{Module}/ + inject HttpClient |
| Add REST endpoint | Controllers/{Module}/ + Application service |
| Add business rule / validation | Module Application/ (+ FluentValidation) |
| Add DB table / column | Module Domain/ + Infrastructure/Migrations/ (author tooling) |
| Add DTO for API | Shared.DTOs |
| Add menu item + permission | Nav component + ApiPermissionRegistry + role seed / admin UI |
| Change company logo / favicon | Setup Wizard / Company Setup (Branching) — not hardcoded in WebApp |
| Change PDF report layout | Cognitix.API/Reports/ |
| Change SMTP | API SmtpSettings or Settings → Email in WebApp |
| Change production URLs / CORS / JWT | API config + WebApp appsettings.json — see Production Guide |
16. Add a new feature (checklist)
Example: add a simple “Customer Notes” list under Billing.
- Define
CustomerNoteDtoinShared.DTOs - Add entity + configuration in
Cognitix.Billing.Domain/ Infrastructure - Add Application service methods (list, create, update)
- Register service in
Cognitix.API/Program.cs - Add
CustomerNotesControllerwith[RequirePermission(...)] - Add page key to
ApiPermissionRegistryand role management UI - Add
CustomerNoteService.csin WebAppservices/Billing/ - Add
Pages/Billing/CustomerNotes.razorwith route and nav link - Add localization keys in
Cognitix.Localization - Authors: add EF migration for your provider; buyers: ship migration in product update
- Test: unit test Application service; manual test via WebApp + API
17. API surface (selected)
| Endpoint | Notes |
|---|---|
GET /api/system/version | Public product version |
GET /api/system/health | Health check (respect AllowedHosts in production) |
GET /api/system/cache-probe | Authenticated cache smoke |
GET /api/branching/companysetup/timezone | Company TZ for WebApp |
POST /api/setup/* | Anonymous during first install |
GET /api/license/status | License state (Trial / Active / Revoked) |
/api/{module}/... | Module controllers — discover under Controllers/ |
/chat-hub | SignalR — CRM chat |
/uploads/... | Static files — logos, attachments |
Product version is centralized in Directory.Build.props.
18. Testing
| Project | Purpose |
|---|---|
Cognitix.Tests.Unit | Domain, validators, application services |
Cognitix.Tests.Integration | API + DB; licensing smoke categories |
Cognitix.Tests.Performance | Report / query performance gates |
Cognitix.Tests.E2E | End-to-end workflows |
test/QA/ | Manual smoke & security checklists |
dotnet test Source/CognitixERP/CognitixERP.sln
dotnet test --filter Category=LicensingSmoke
Related install notes: Installation Guide, Troubleshooting FAQ (license / uploads).
19. Tech stack
- .NET 10 / ASP.NET Core / Blazor WebAssembly
- EF Core — SQL Server, PostgreSQL, MySQL
- MudBlazor, FluentValidation, MediatR
- QuestPDF (MIT-pinned), SignalR
- Serilog, JWT auth, in-process
IMemoryCache
Third-party inventory: package root LICENSES.md / NOTICE.txt.
20. What v1.0 is not
| Do not assume | Reality in v1.0 |
|---|---|
| Offline-first / mobile ERP | Web-only release |
| SyncEngine in production path | Not in active solution host path |
| Redis / distributed cache | Memory cache on API process only |
| Default admin password in ZIP | Created only in Setup Wizard Step 2 |
Buyer runs dotnet ef | Wizard migrates all 12 schemas |
Editable Licensing project under src/ | Only lib/Cognitix.Licensing/*.dll |
21. Please Contact us
- Sign up at https://cognitivebd.com
- Create a Support Ticket.
- Within 48hr we will reply.
Or email support@cognitivebd.com with your purchase code, version, and screenshots/logs.
Developer Guide