--- title: Neuro API emoji: 🧠 colorFrom: indigo colorTo: blue sdk: docker app_port: 8000 pinned: false --- # Neuro backend FastAPI + SQLAlchemy 2 (async) + PostgreSQL 16 + Alembic. ## Run with Docker ```bash docker compose up --build # migrates, then serves on http://localhost:8000 (hot reload) docker compose exec app python -m app.modules.demo.seed ``` API docs: http://localhost:8000/docs. Log in with `POST /api/v1/auth/login` and an email and password. The demo accounts all start with the password `123456` (change it): `dc_staff@neuro.local`, `dc_manager@neuro.local`, `outlet_staff@neuro.local`, `outlet_manager@neuro.local`, `head_office@neuro.local`. Schema changed since an earlier build? Reset the database volume: `docker compose down -v`. ## Run locally ```bash python -m venv .venv && .venv/Scripts/pip install fastapi "uvicorn[standard]" "sqlalchemy[asyncio]" asyncpg alembic pydantic-settings pyjwt pytest pytest-asyncio httpx cp .env.example .env alembic upgrade head && python -m app.modules.demo.seed uvicorn app.main:app --reload ``` ## Tests ```bash pytest # DB tests are skipped without a database TEST_DATABASE_URL=postgresql+asyncpg://u:p@localhost/neuro_test pytest # also DB tests ``` The DB tests wipe the `public` schema of `TEST_DATABASE_URL`, so point it at a throwaway database. ## Documentation | file | for | |---|---| | `../docs/FRONTEND_API_GUIDE.md` | the frontend: every screen's calls, rules and roles | | `../docs/INTEGRATION_GUIDE.md` | credentials (what each is, how to make real ones), server settings, POS/ERP and frontend integration, go-live checklist | | `../docs/DEPLOY_FREE.md` | deploying for free (Render + Neon), step by step, and what the free plan cannot do | | `../docs/AGENT_CONTRACT.md` | the decision agent (built by Azra): request/response, guardrails, how to connect. The agent itself is bundled in `neuro_agent/` (`python -m pytest neuro_agent`) | | `../docs/TODO_offline_fallback.txt` | what is still to do for offline replay | | `../samples/README.md` | sample POS/ERP files (generic and Odoo style) and how to load them | | `../openapi.json`, `/docs`, `/openapi.json` | the API spec and Swagger UI | ## Status Phases 1-8 are built: schema, clock, auth; receiving and QR labels; FEFO dispatch, arrival and scan; sales, POS/ERP connect (webhook, REST, CSV) and reconciliation; shelf-life, exposure, forecast, risk and action candidates; recommendations with the decision-agent hook and rules fallback, outlet transfers, write-offs and outcomes; the 15-minute and 00:30 jobs and the scheduler; waste and impact reports, the simulation and demo reset. Every endpoint is real. Still open: no SSO or emailed password reset (head office resets passwords); shelf-life science is placeholder; offline replay (idempotency keys, device timestamps); Docker has not been run on the dev machine.