========================================================== TA-ATS + MCP — SETUP GUIDE FOR A NEW SYSTEM ========================================================== Project folder :- [E:\xampp\htdocs] = You can clone or downloaded file put inside "python" folder Python [Main folder ] a) TA-ATS-interns b) auth_mcp Note: 1)create new "python" folder and put "downloaded" or clone project inside python folder Note: 2)copy "auth_mcp_backup_alone"folder from "TA-ATS-interns" and put inside python folder and rename with "auth_mcp" ---------------------------------------------------------- 0) WHAT YOU ARE SETTING UP ---------------------------------------------------------- 4 services + 2 databases: Service Tech Port Folder ------- ---- ---- ------ MCP FastMCP/Python 9000 mcp\ (MFA tools + its own DB) Backend Django + DRF 8002 backend\ Gateway FastAPI 8000 gateway\ Frontend Next.js 3000 frontend\ (Demo3 PHP/Apache 80 ../demo3\ optional sample project) Databases (PostgreSQL): ats_main -> backend (users, auth, logs) ats_mcp_db -> MCP (MFA enrollment: mfa_users) Database (MariaDB): demo3 -> Demo3 sample project (optional) ---------------------------------------------------------- 1) PREREQUISITES (install once) ---------------------------------------------------------- - Python 3.12+ (python --version) Download Python from official website (https://www.python.org/downloads/) - Node.js 20+ (node --version) Download Node.js from official website (https://nodejs.org/download/) - PostgreSQL 16/18 (psql --version) Download PostgreSQL from official website (https://www.postgresql.org/download/) ---------------------------------------------------------- 2) CREATE THE DATABASES (run once) ---------------------------------------------------------- Open a terminal (psql). Example uses user "postgres" password "root". psql -U postgres -c "CREATE DATABASE ats_main;" psql -U postgres -c "CREATE DATABASE ats_mcp_db;" (For Demo3 / MariaDB, in XAMPP:) mysql -u root -proot -e "CREATE DATABASE demo3;" NOTE: tables are created automatically later (you only create the empty DBs here). ---------------------------------------------------------- 2b) (OPTIONAL) RESTORE DATA FROM BACKUP ---------------------------------------------------------- If you have the backups in database\backups\ : psql -U postgres -d ats_main -f database\backups\ats_main.sql psql -U postgres -d ats_mcp_db -f database\backups\ats_mcp_db.sql ---------------------------------------------------------- 3) MCP SERVICE (mcp\) — port 9000 ---------------------------------------------------------- cd mcp python -m venv venv .\venv\Scripts\activate pip install -r requirements.txt (if no requirements.txt:) pip install fastmcp pyotp "qrcode[pil]" pdfminer.six python-docx psycopg2-binary python-dotenv Create mcp\.env (copy from .env.example) and set: MCP_TRANSPORT=http MCP_PORT=9000 MFA_METHOD=email # admin's method: totp | email | sms EMAIL_HOST=smtp.gmail.com EMAIL_PORT=587 EMAIL_USE_TLS=true EMAIL_HOST_USER=YOUR_GMAIL EMAIL_HOST_PASSWORD=YOUR_APP_PASSWORD DEFAULT_FROM_EMAIL=App OTP_EXPIRY_MINUTES=5 MCP_DB_HOST=localhost MCP_DB_PORT=5432 MCP_DB_NAME=ats_mcp_db MCP_DB_USER=postgres MCP_DB_PASSWORD=root Run: .\venv\Scripts\python.exe server.py (On start it auto-creates the mfa_users table in ats_mcp_db.) ---------------------------------------------------------- 4) BACKEND (backend\) — port 8002 (Django + PostgreSQL) ---------------------------------------------------------- cd backend python -m venv venv .\venv\Scripts\activate pip install -r requirements\base.txt (if missing:) pip install django djangorestframework djangorestframework-simplejwt ^ django-cors-headers psycopg2-binary python-dotenv pyotp "qrcode[pil]" ^ Pillow fastmcp drf-spectacular Create backend\.env (copy from .env.example) and set: SECRET_KEY=change-me DJANGO_SETTINGS_MODULE=config.settings.dev DB_HOST=localhost DB_PORT=5432 DB_NAME=ats_main DB_USER=postgres DB_PASSWORD=root INTERNAL_API_SECRET=internal-secret-dev MCP_URL=http://127.0.0.1:9000/mcp CORS_ALLOWED_ORIGINS=http://localhost:3000 Build tables + admin user (see DB MIGRATIONS section below for details): python manage.py migrate python manage.py createsuperuser (email + password) Run: python manage.py runserver 8002 ---------------------------------------------------------- 4b) DB MIGRATIONS (Django ORM -> PostgreSQL "ats_main") ---------------------------------------------------------- Run all commands from backend\ with the venv active: cd backend .\venv\Scripts\activate ALWAYS run migrate on a fresh clone AND after pulling new code. (Skipping it => 500 errors on login: "column ... does not exist".) # 1) Generate migration files from any model changes (all apps) python manage.py makemigrations # 2) Apply all migrations to the database. # This also runs the post_migrate seeders: # - apps/users/apps.py -> seeds role Groups + default permissions # - apps/menus/apps.py -> seeds the default sidebar menu tree python manage.py migrate # 3) Create the admin login (only once, on a fresh DB) python manage.py createsuperuser ---- Handy variants ---- # Make / apply migrations for ONE app only python manage.py makemigrations users python manage.py migrate menus # See which migrations are applied [X] vs pending [ ] python manage.py showmigrations # Preview the SQL a migration will run (does not apply it) python manage.py sqlmigrate users 0006 ---- Fix a broken / stale migration (e.g. "relation ... does not exist" while showmigrations marks it [X]) ---- # Roll the app back to zero, then re-apply cleanly: python manage.py migrate menus zero python manage.py migrate menus NOTE: the MCP service (auth_mcp) has NO Django migrations — it auto-creates its own "mfa_users" table in ats_mcp_db on startup. ---------------------------------------------------------- 5) GATEWAY (gateway\) — port 8000 (FastAPI) ---------------------------------------------------------- cd gateway python -m venv venv .\venv\Scripts\activate pip install -r requirements.txt (if missing:) pip install fastapi uvicorn httpx pydantic-settings python-dotenv Create gateway\.env (copy from .env.example): BACKEND_URL=http://localhost:8002 FRONTEND_ORIGIN=http://localhost:3000 RATE_LIMIT_PER_MINUTE=120 Run: uvicorn app.main:app --reload --port 8000 ---------------------------------------------------------- 6) FRONTEND (frontend\) — port 3000 (Next.js) ---------------------------------------------------------- cd frontend npm install Create frontend\.env.local : NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1 Run: npm run dev ---------------------------------------------------------- 7) DEMO3 (optional sample project, PHP + MariaDB) — port 80 ---------------------------------------------------------- - Put the demo3 folder under XAMPP htdocs (so it is served by Apache). - Edit demo3\db.php -> set host/port/db/user/password for MariaDB. - Make sure MariaDB has database "demo3". - Open http://localhost/demo3/ (table auto-creates on first load). ---------------------------------------------------------- 8) START ORDER (every time) ---------------------------------------------------------- 1. PostgreSQL + (MariaDB for Demo3) 2. MCP (port 9000) <-- first, others depend on it 3. Backend (port 8002) 4. Gateway (port 8000) 5. Frontend (port 3000) OR double-click run.bat (starts the 4 services in their own windows). ---------------------------------------------------------- 9) URLS & LOGIN ---------------------------------------------------------- App (frontend) http://localhost:3000 API docs (Swagger) http://localhost:8002/api/docs/ Django admin http://localhost:8002/admin/ (set MFA method here) Gateway health http://localhost:8000/health Demo3 (optional) http://localhost/demo3/ Admin login: the superuser you created in step 4. ---------------------------------------------------------- 10) HOW MFA WORKS (quick reminder) ---------------------------------------------------------- - Admin picks ONE method in Django admin (MFA Settings) -> pushed to MCP. - Every project reads the MCP policy and enforces that method. - Email OTP = no setup (code emailed). Authenticator = scan QR once. - MFA data: stored in ats_mcp_db (MCP's own DB) via mfa_setup/mfa_verify, OR in each project's own DB (stateless mode) depending on which tools are used. - The MCP never stores the password; the project checks the password. ---------------------------------------------------------- 11) COMMON ISSUES ---------------------------------------------------------- - "next is not recognized" -> run: npm install (in frontend\) - "django-admin not found" -> activate the venv first - DB connection refused -> PostgreSQL/MariaDB not running - MFA returns 503 -> MCP server (9000) is not running - email not received -> check Spam, or SMTP creds in mcp\.env ========================================================== 12) Install the follwoing dependencies : FontAwesome :- npm install @fortawesome/fontawesome-free SweetAlert2 :- npm install sweetalert2 React Toastify :- npm install react-toastify TanStack :- npm install @tanstack/react-table pdfplumber - pip install django-filter pdfplumber (06-07-2026)