Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ElthonJohan/Sistema-MRP/llms.txt

Use this file to discover all available pages before exploring further.

Sistema MRP is organized around a strict three-layer pattern that keeps UI rendering, business logic, and data access cleanly separated. Pages drive the Streamlit interface and own the lifecycle of every database session. Services hold all business logic but are stateless with respect to sessions. Models are pure SQLAlchemy ORM classes with no embedded logic.

Three-layer pattern

Data flows in one direction through the stack:
Pages (Streamlit UI) → Services (business logic) → Models (SQLAlchemy ORM) → DB
LayerLocationResponsibility
Pagespages/Render UI, call guards, open and close db sessions
Servicesservices/Receive db: Session, execute all business logic
Modelsmodels/Pure SQLAlchemy ORM declarations, no logic
DBSQLite / PostgreSQLPersistent storage
Database sessions are opened and closed exclusively by pages. A page calls db = SessionLocal() before invoking any service and calls db.close() (or uses a try/finally block) when finished. Services receive the session as a parameter and must never open or close one themselves.

Entry points

The project has three meaningful entry points:
  • pages/login.py — The real user-facing entry point. All unauthenticated users land here.
  • app.py — A legacy redirect shell. It renders a brief hero page on startup but immediately redirects users to login. It is not the active UI.
  • init_db.py — One-time (and idempotent) setup script. Runs Base.metadata.create_all(), executes run_migrations(), and seeds the superadmin account if it does not already exist.
# First-time setup
python init_db.py

# Start the application
streamlit run app.py

Directory tree

Sistema-MRP/
├── app.py                  # Legacy redirect shell
├── init_db.py              # DB initializer + migration runner
├── database.py             # SQLAlchemy engine + SessionLocal
├── pages/
│   ├── login.py            # Auth entry point
│   ├── dashboard.py        # Client home
│   ├── admin.py            # Superadmin panel
│   ├── access_logs.py      # Login audit log (superadmin only)
│   └── ...                 # Operational pages
├── services/
│   ├── requirement_service.py
│   ├── dispatch_service.py
│   ├── inventory_service.py
│   ├── dashboard_service.py
│   └── ...
├── models/
│   ├── user.py
│   ├── warehouse.py
│   ├── inventory.py
│   ├── requirement.py
│   └── ...
└── utils/
    ├── auth.py
    ├── session_manager.py
    ├── pdf_generator.py
    ├── navbar.py
    └── theme.py

Key utilities

utils/auth.py — Access control guards used at the top of every page:
FunctionBehavior
require_login()Redirects to pages/login.py if no active session exists
require_cliente()Calls require_login(), then redirects superadmin to /admin unless impersonation is active
require_superadmin()Calls require_login(), then redirects non-superadmin users to /dashboard
get_current_user_id()Returns the impersonated user’s ID when impersonation is active, otherwise the real user’s ID
utils/session_manager.py — Provides init_session(), which reads the token from st.query_params["token"] and validates it against the user_sessions table, and logout_session(), which invalidates the session record and clears st.session_state. utils/pdf_generator.pygenerate_dispatch_pdf(dispatch) builds a “Guía de Remisión” PDF using fpdf2 and saves it to storage/guides/<guia_number>.pdf. The guide number format is GR-YYYYMMDD-{dispatch_id:05d}. The storage/guides/ directory is created on demand.

Build docs developers (and LLMs) love