How wikiepeidia/anser works
Purpose and Entry Points
ANSER is a Flask-based retail-operations platform: invoice OCR, sales/inventory forecasting, AI-assisted operations, workflow automation, and back-office management. The main web-process entry point is app.py; the separately runnable ML/OCR process is run_dl_service.py / dl_service/model_app.py.
Web Application Boundary
The Flask application follows a route-to-service-to-persistence shape. HTTP handlers are partitioned by domain—inventory, sales, workflows, AI, Google, administration, wallet, and workspace—then delegate business work to core/ services. Key paths: routes/inventory_routes.py, routes/ai_routes.py, routes/workflow_routes.py.
Identity, Ownership, and Persistence
Authentication, request/agent middleware, configuration, database setup, and ORM/domain models are centralized in core/. This is the primary trust boundary for user-scoped business data and authenticated actions. PostgreSQL is the stated production datastore and SQLite supports local development. Key paths: core/auth.py, core/database.py, core/models.py.
Retail Operations Domain
Inventory mutations are isolated behind a transaction service rather than implemented directly in routes; sales, product/catalog, customer, reporting, subscription, and wallet surfaces are exposed through domain route modules. This separation is important for consistent stock updates and ownership enforcement. Key paths: core/services/inventory_tx_service.py, routes/sales_routes.py, routes/operations_routes.py.
Automation and External Integrations
Workflow definitions and execution are split between workflow/automation engines and integration adapters. The application connects to Google Workspace capabilities and Make.com; README also identifies n8n and generic webhooks as automation targets. Treat outbound integration code as a security boundary, particularly for webhook destination validation. Key paths: core/workflow_engine.py, core/automation_engine.py, core/google_integration.py, core/make_integration.py.
AI, OCR, and Forecasting Service
The web app reaches a separate deep-learning service through a client abstraction. That service exposes model/OCR/history API modules and composes OCR, invoice/layout extraction, and forecasting services. Model assets include LSTM forecasting and Vietnamese OCR/vision implementations. Key paths: core/services/dl_client.py, dl_service/model_app.py, dl_service/api/ocr_routes.py, dl_service/services/forecast_service.py.
UI and Asynchronous Work
The UI is server-rendered Jinja templates with static JavaScript/CSS enhancement, not a separate SPA. Page and domain routes render or serve these interfaces, including dashboard, sales, workspace builder, and chat. README states Redis/RQ is used for slow jobs such as AI chat; its queue bootstrap is not present in the supplied tree. Key paths: ui/templates/base.html, ui/templates/workspace_builder.html, static/js/chat.js, core/services/ai_chat_service.py.
Main entry points: inventory_routes.py Domain routes · model_app.py Model API · models.py Domain models · app.py Web process
Components 22
Flask Web App
- Web process
app.py - Domain routes · Inventory, sales, workflow, AI, admin, wallet, and workspace endpoints.
routes/inventory_routes.py - Sales & operations routes
routes/sales_routes.py
Core Domain & Trust
- Auth & request boundary · Protects authenticated, user-scoped actions.
core/auth.py - Database setup
core/database.py - Domain models · Ownership-scoped retail and back-office data.
core/models.py - Inventory transactions · Centralizes consistent stock mutations.
core/services/inventory_tx_service.py - AI chat service
core/services/ai_chat_service.py - DL service client
core/services/dl_client.py
Automation & Integrations
- Workflow engine
core/workflow_engine.py - Automation engine
core/automation_engine.py - Google Workspace adapter
core/google_integration.py - Make.com adapter · Outbound webhook destinations require validation.
core/make_integration.py
ML / OCR Service
- DL service process
run_dl_service.py - Model API
dl_service/model_app.py - OCR endpoints
dl_service/api/ocr_routes.py - Forecasting service · Uses forecasting model assets including LSTM.
dl_service/services/forecast_service.py
Server-Rendered UI
- Jinja templates
ui/templates/base.html - Workspace builder
ui/templates/workspace_builder.html - Chat enhancement
static/js/chat.js
Other components
- PostgreSQL / SQLite · PostgreSQL in production; SQLite locally.
- Redis / RQ · Runs slow jobs such as AI chat.
Connections 23
- Web process → Domain routes: registers
- Web process → Sales & operations routes: registers
- Web process → Auth & request boundary: uses
- Domain routes → Inventory transactions: mutates stock through
- Sales & operations routes → Domain models: serves domain data
- Auth & request boundary → Domain models: enforces ownership on
- Inventory transactions → Domain models: updates
- Domain models → Database setup: persists via
- Database setup → PostgreSQL / SQLite: connects to
- Domain routes → Workflow engine: runs workflows
- Workflow engine → Automation engine: delegates automation
- Automation engine → Google Workspace adapter: invokes
- Automation engine → Make.com adapter: invokes
- Domain routes → DL service client: requests OCR and forecasts
- DL service client → Model API: calls
- DL service process → Model API: serves
- Model API → OCR endpoints: exposes
- Model API → Forecasting service: uses
- Domain routes → AI chat service: handles AI requests
- AI chat service → Redis / RQ: queues slow work
- Domain routes → Jinja templates: renders
- Jinja templates → Workspace builder: includes
- Workspace builder → Chat enhancement: enhanced by