# saylogfake/simpos architecture

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

- Interactive diagram: https://gitdiagram.com/saylogfake/simpos
- Repository: https://github.com/saylogfake/simpos

## Overview

1. **System shape**
   - The repository is a two-part SaaS point-of-sale system:
     - `backend/`: ASP.NET Core Web API in C#.
     - `saas-pos/`: Next.js + React + TypeScript frontend.
   - The frontend is the user-facing application; the backend owns business logic and persistence.

2. **Primary boundary between tiers**
   - All domain operations appear to flow from the frontend through `saas-pos/lib/api.ts` into backend controllers.
   - The backend exposes resource-oriented endpoints for authentication, users/roles, tenants, products, inventory, sales, cash, customers, debt, notifications, and seeding.

3. **Backend API layer**
   - Controllers are separated by business domain: `AuthController`, `UsersController`, `RolesController`, `TenantsController`, `ProductsController`, `InventoryController`, `SalesController`, `CashController`, `CustomersController`, `DebtController`, `NotificationsController`, and `SeedController`.
   - This suggests the API is organized as a modular monolith, with each controller handling a bounded functional area rather than a generic CRUD layer.

4. **Backend application services**
   - Business rules are extracted into services under `backend/Services`:
     - `CashService`
     - `DebtService`
     - `InventoryService`
     - `FactPyService`
   - The controllers likely orchestrate requests while these services contain transactional logic, especially for stock movements, cash sessions, and debt handling.

5. **Data and persistence**
   - `AppDbContext` and EF Core migrations show the backend uses Entity Framework Core as the ORM.
   - The presence of `InitialSQLite` migrations strongly indicates SQLite as the default or local development database.
   - The model layer is in `backend/Models/Entities.cs`, with DTOs such as `RoleDtos.cs` for API payload shaping.

6. **Multi-tenant architecture**
   - `TenantsController` plus a dedicated migration to add tenants indicate the system supports tenant separation.
   - The presence of `RolesController`, `UsersController`, and `AuthController` suggests tenant-scoped access control, likely with role-based permissions layered on top of tenancy.

7. **Frontend application structure**
   - The frontend uses the Next.js App Router with route groups:
     - `(auth)` for login
     - `(dashboard)` for operational back-office screens
     - `(pos)` for point-of-sale flows
   - This separation is important: POS workflows are isolated from administrative dashboard workflows.

8. **Frontend state and interaction model**
   - `app/context/UserContext.tsx` likely provides authenticated user/session state across pages.
   - Most user interactions are implemented through modal components in `components/`, which suggests a highly interactive SPA-like experience for tasks such as editing products, cash operations, returns, discounts, waste, and restocking.

9. **Domain-oriented UI composition**
   - UI components are grouped by function:
     - `components/pos`: checkout, returns, quick waste
     - `components/cash`: open/close sessions, movement details
     - `components/customers`: customer details
     - `components/inventory`: kardex, waste, categories, product tabs
   - This mirrors the backend domain boundaries and is a good cue for an architecture diagram: UI modules map closely to API modules.

10. **Operational flows**
   - Typical flows likely look like:
     - Login/authentication via `AuthController`
     - User loads dashboard or POS page
     - Frontend calls API through `lib/api.ts`
     - Backend services execute business rules
     - EF Core persists changes to the database
   - High-value transactional flows include sales checkout, inventory adjustments, cash opening/closing, debt tracking, and customer management.

11. **Notifications and automation**
   - `NotificationsController` and the frontend `NotificationsPanel.tsx` indicate push/pull notification support inside the app.
   - `SeedController` suggests bootstrapping of reference data or initial tenant/admin setup, which is important in a fresh deployment or demo environment.

12. **Deployment and environment**
   - The repo includes Docker support for both backend and frontend, plus `docker-compose.yml` at the root.
   - Railway deployment files and multiple backend environment configs (`Development`, `Staging`, `Production`) indicate the system is designed for containerized hosting with environment-specific settings.
   - `.env.example` implies runtime configuration is externalized, likely for API URLs, database connection, and auth-related settings.

13. **Architecture summary for diagramming**
   - Draw the backend as an ASP.NET Core API with domain controllers, service layer, and EF Core persistence beneath it.
   - Draw the frontend as a Next.js app with auth/dashboard/POS route groups, shared context, and modal-heavy domain components.
   - Connect them with a single API boundary; then show the database beneath the backend and deployment/containerization around both tiers.

Main entry points: [`backend/Controllers`](https://github.com/saylogfake/simpos/tree/main/backend/Controllers) (Controllers), [`backend/Data/AppDbContext.cs`](https://github.com/saylogfake/simpos/blob/main/backend/Data/AppDbContext.cs) (DbContext), [`docker-compose.yml`](https://github.com/saylogfake/simpos/blob/main/docker-compose.yml) (Compose Stack), [`backend/Program.cs`](https://github.com/saylogfake/simpos/blob/main/backend/Program.cs) (Program)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["App Router<br/>Next.js routes"]
  node_frontend_context["User Context<br/>session state<br/>[UserContext.tsx]"]
  node_frontend_api["API Client<br/>http client<br/>[api.ts]"]
  node_frontend_pos["POS UI<br/>sales UI"]
  node_frontend_dashboard["Dashboard UI<br/>ops UI"]
  node_frontend_modals["Domain Modals<br/>interaction components"]
end

subgraph group_backend["Backend"]
  node_backend_api["Controllers<br/>ASP.NET API"]
  node_backend_auth["Auth Users<br/>identity endpoints<br/>[AuthController.cs]"]
  node_backend_ops["Business APIs<br/>domain endpoints"]
  node_backend_services["Services<br/>business logic"]
  node_backend_dbcontext[("DbContext<br/>EF Core context<br/>[AppDbContext.cs]")]
  node_backend_models["Entities & DTOs<br/>domain model<br/>[Entities.cs]"]
  node_backend_migrations["Migrations<br/>schema history"]
  node_backend_program["Program<br/>startup<br/>[Program.cs]"]
  node_db[("SQLite DB<br/>relational store")]
end

subgraph group_ops["Operations"]
  node_ops_backend["Backend Docker<br/>container build"]
  node_ops_frontend["Frontend Docker<br/>container build"]
  node_ops_compose["Compose Stack<br/>local orchestration<br/>[docker-compose.yml]"]
  node_ops_railway["Railway Config<br/>deployment config<br/>[railway.json]"]
end

node_frontend_app -->|"uses session"| node_frontend_context
node_frontend_app -->|"calls API"| node_frontend_api
node_frontend_pos -->|"opens"| node_frontend_modals
node_frontend_dashboard -->|"uses"| node_frontend_modals
node_frontend_context -.->|"auth headers"| node_frontend_api
node_frontend_api -->|"http"| node_backend_api
node_backend_api -->|"identity"| node_backend_auth
node_backend_api -->|"domain"| node_backend_ops
node_backend_ops -->|"orchestrates"| node_backend_services
node_backend_services -->|"persists via"| node_backend_dbcontext
node_backend_dbcontext -->|"maps"| node_backend_models
node_backend_migrations -.->|"evolves schema"| node_backend_dbcontext
node_backend_program -->|"registers"| node_backend_api
node_backend_program -->|"injects"| node_backend_services
node_backend_program -->|"configures"| node_backend_dbcontext
node_backend_dbcontext -->|"stores"| node_db
node_ops_compose -->|"builds"| node_ops_backend
node_ops_compose -->|"builds"| node_ops_frontend
node_ops_railway -.->|"deploys"| node_ops_backend
node_ops_railway -.->|"deploys"| node_ops_frontend
node_ops_compose -.->|"runs"| node_backend_api
node_ops_compose -.->|"runs"| node_frontend_app

click node_frontend_app "https://github.com/saylogfake/simpos/tree/main/saas-pos/app"
click node_frontend_context "https://github.com/saylogfake/simpos/blob/main/saas-pos/app/context/UserContext.tsx"
click node_frontend_api "https://github.com/saylogfake/simpos/blob/main/saas-pos/lib/api.ts"
click node_frontend_pos "https://github.com/saylogfake/simpos/tree/main/saas-pos/components/pos"
click node_frontend_dashboard "https://github.com/saylogfake/simpos/tree/main/saas-pos/app/(dashboard)"
click node_frontend_modals "https://github.com/saylogfake/simpos/tree/main/saas-pos/components"
click node_backend_api "https://github.com/saylogfake/simpos/tree/main/backend/Controllers"
click node_backend_auth "https://github.com/saylogfake/simpos/blob/main/backend/Controllers/AuthController.cs"
click node_backend_ops "https://github.com/saylogfake/simpos/tree/main/backend/Controllers"
click node_backend_services "https://github.com/saylogfake/simpos/tree/main/backend/Services"
click node_backend_dbcontext "https://github.com/saylogfake/simpos/blob/main/backend/Data/AppDbContext.cs"
click node_backend_models "https://github.com/saylogfake/simpos/blob/main/backend/Models/Entities.cs"
click node_backend_migrations "https://github.com/saylogfake/simpos/tree/main/backend/Migrations"
click node_backend_program "https://github.com/saylogfake/simpos/blob/main/backend/Program.cs"
click node_ops_backend "https://github.com/saylogfake/simpos/tree/main/backend/Dockerfile"
click node_ops_frontend "https://github.com/saylogfake/simpos/tree/main/saas-pos/Dockerfile"
click node_ops_compose "https://github.com/saylogfake/simpos/blob/main/docker-compose.yml"
click node_ops_railway "https://github.com/saylogfake/simpos/blob/main/railway.json"

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_frontend_app,node_frontend_context,node_frontend_api,node_frontend_pos,node_frontend_dashboard,node_frontend_modals toneBlue
class node_backend_api,node_backend_auth,node_backend_ops,node_backend_services,node_backend_dbcontext,node_backend_models,node_backend_migrations,node_backend_program,node_db toneAmber
class node_ops_backend,node_ops_frontend,node_ops_compose,node_ops_railway toneMint
```

## Components

### Frontend

Next.js + React POS and dashboard UI

- [App Router](https://github.com/saylogfake/simpos/tree/main/saas-pos/app): Next.js routes · Route groups for auth, dashboard, and POS flows · `saas-pos/app`
- [User Context](https://github.com/saylogfake/simpos/blob/main/saas-pos/app/context/UserContext.tsx): session state · Authenticated user/session state for the UI · `saas-pos/app/context/UserContext.tsx`
- [API Client](https://github.com/saylogfake/simpos/blob/main/saas-pos/lib/api.ts): http client · Shared frontend gateway for backend calls · `saas-pos/lib/api.ts`
- [POS UI](https://github.com/saylogfake/simpos/tree/main/saas-pos/components/pos): sales UI · Checkout and point-of-sale interaction screens · `saas-pos/components/pos`
- [Dashboard UI](https://github.com/saylogfake/simpos/tree/main/saas-pos/app/(dashboard)): ops UI · Administrative screens for cash, inventory, customers, roles, and superadmin · `saas-pos/app/(dashboard)`
- [Domain Modals](https://github.com/saylogfake/simpos/tree/main/saas-pos/components): interaction components · Modal-driven workflows for inventory, cash, customers, discounts, and notifications · `saas-pos/components`

### Backend

ASP.NET Core API and domain services

- [Controllers](https://github.com/saylogfake/simpos/tree/main/backend/Controllers): ASP.NET API · Domain-oriented REST controllers · `backend/Controllers`
- [Auth Users](https://github.com/saylogfake/simpos/blob/main/backend/Controllers/AuthController.cs): identity endpoints · Authentication, users, roles, and tenant access · `backend/Controllers/AuthController.cs`
- [Business APIs](https://github.com/saylogfake/simpos/tree/main/backend/Controllers): domain endpoints · Products, inventory, sales, cash, customers, debt, notifications, and seed · `backend/Controllers`
- [Services](https://github.com/saylogfake/simpos/tree/main/backend/Services): business logic · Transactional domain logic for cash, debt, inventory, and external factoring · `backend/Services`
- [DbContext](https://github.com/saylogfake/simpos/blob/main/backend/Data/AppDbContext.cs): EF Core context · Entity Framework Core persistence gateway · `backend/Data/AppDbContext.cs`
- [Entities & DTOs](https://github.com/saylogfake/simpos/blob/main/backend/Models/Entities.cs): domain model · Database entities and API payload shapes · `backend/Models/Entities.cs`
- [Migrations](https://github.com/saylogfake/simpos/tree/main/backend/Migrations): schema history · EF Core migrations including SQLite bootstrap and tenants · `backend/Migrations`
- [Program](https://github.com/saylogfake/simpos/blob/main/backend/Program.cs): startup · Application composition and host startup · `backend/Program.cs`
- **SQLite DB**: relational store · Default local persistence target implied by migrations

### Operations

Containerization and deployment files

- [Backend Docker](https://github.com/saylogfake/simpos/tree/main/backend/Dockerfile): container build · Backend container image definition · `backend/Dockerfile`
- [Frontend Docker](https://github.com/saylogfake/simpos/tree/main/saas-pos/Dockerfile): container build · Frontend container image definition · `saas-pos/Dockerfile`
- [Compose Stack](https://github.com/saylogfake/simpos/blob/main/docker-compose.yml): local orchestration · Root multi-service container orchestration · `docker-compose.yml`
- [Railway Config](https://github.com/saylogfake/simpos/blob/main/railway.json): deployment config · Hosting configuration for deployed environments · `railway.json`

## Connections

- App Router → User Context: uses session · Pages consume authenticated user state
- App Router → API Client: calls API · Routes invoke backend operations through the shared client
- POS UI → Domain Modals: opens · POS flows are composed from modal interactions
- Dashboard UI → Domain Modals: uses · Operational screens reuse modal components
- User Context → API Client: auth headers · Session state informs request identity
- API Client → Controllers: http · Frontend communicates with the backend controllers
- Controllers → Auth Users: identity · Auth, users, roles, and tenancy endpoints
- Controllers → Business APIs: domain · Business controllers for core POS workflows
- Business APIs → Services: orchestrates · Controllers delegate transactional rules to services
- Services → DbContext: persists via · Services use the EF Core context for data access
- DbContext → Entities & DTOs: maps · Context is built over entities and DTO-shaping models
- Migrations → DbContext: evolves schema · Migrations define the database shape used by the context
- Program → Controllers: registers · Startup wires controllers into the host
- Program → Services: injects · Startup configures domain services for DI
- Program → DbContext: configures · Startup sets up persistence and database access
- DbContext → SQLite DB: stores · The context writes to the SQLite-backed database
- Compose Stack → Backend Docker: builds · Compose includes the backend image
- Compose Stack → Frontend Docker: builds · Compose includes the frontend image
- Railway Config → Backend Docker: deploys · Railway config supports backend hosting
- Railway Config → Frontend Docker: deploys · Railway config supports frontend hosting
- Compose Stack → Controllers: runs · Local orchestration starts the API service
- Compose Stack → App Router: runs · Local orchestration starts the web app
