How krish-void/multi-telnet-saas works
Purpose and entry points
This is a SaaS core for isolated multi-tenant company administration with hierarchical RBAC, dual authentication, and database-enforced audit/integrity controls. The API entry point is backend/main.py; the operator UI is the Streamlit app at frontend/app.py. Database bootstrap runs through backend/init_db.py, directly or via container startup scripts.
Runtime and deployment topology
The system runs three services under Compose: MariaDB 10.6, a Python/FastAPI backend, and a Python/Streamlit frontend. Container definitions and orchestration are in Dockerfile.backend, Dockerfile.frontend, and docker-compose.yml. Backend initialization/start sequencing is handled by backend/startup.sh and start_backend.sh; frontend startup uses frontend/startup.sh.
Database as the integrity boundary
MariaDB/MySQL is the authoritative persistence and business-rule layer. backend/init_db.py creates and seeds companies, users, roles, system-admin credentials, and logs; it also establishes foreign-key behavior, audit triggers, a restricted user view, and a per-company counting function. Connection configuration is centralized in backend/database.py. Tenant identity is represented by company ownership and tenant UUIDs, while database-side constructs protect integrity even if API code is bypassed.
API composition
FastAPI assembles authentication, company, and user-management route groups in backend/main.py and backend/routes/__init__.py. Domain endpoint boundaries are separated into backend/routes/auth.py, backend/routes/companies.py, and backend/routes/users.py. Request payload validation and API-facing schemas live in backend/models.py, keeping route handlers distinct from raw SQL/database operations.
Authentication and authorization flow
Clients use separate super-admin and tenant-employee login flows exposed by backend/routes/auth.py. Credential verification, password hashing, and JWT/session-token behavior are implemented in backend/auth.py. Protected requests pass through RBAC and tenant-isolation checks in backend/middleware.py: tenant users are scoped to the company in their authenticated session, and role permissions gate user writes and deletes. This middleware-to-route boundary is the primary application-layer defense against cross-tenant reads or mutations.
Tenant administration flow
A privileged actor authenticates, receives authenticated session/token context, then calls company or user routes. Company management in backend/routes/companies.py defines tenant lifecycle operations; user operations in backend/routes/users.py operate within the resolved company scope and role policy. User creation persists through the database schema, whose trigger records audit entries automatically rather than relying on application handlers.
Frontend and contract artifacts
frontend/app.py is a separate Streamlit dashboard that consumes the backend rather than hosting the business model itself. The repository also contains TypeScript contract packages: OpenAPI source at lib/api-spec/openapi.yaml, generated client bindings in lib/api-client-react/src/generated/api.ts, and generated Zod contracts in lib/api-zod/src/generated/api.ts. These are integration artifacts for typed API consumers; the active UI runtime remains Streamlit. A separate TypeScript database package, including schema exports at lib/db/src/schema/index.ts, appears to support external/shared consumers rather than the Python backend’s primary MariaDB access path.
Main entry points: auth.py Authentication routes · main.py FastAPI application · companies.py Company & user routes · docker-compose.yml Compose orchestration
Components 19
Compose Runtime
- Compose orchestration · Runs database, backend, and frontend services.
docker-compose.yml - Backend container
Dockerfile.backend - Backend startup sequence · Initializes and starts the API service.
backend/startup.sh
FastAPI Backend
- FastAPI application · Assembles the API route groups.
backend/main.py - Route registry
backend/routes/__init__.py - Authentication routes · Separate super-admin and tenant-employee login flows.
backend/routes/auth.py - Company & user routes · Tenant lifecycle and scoped user administration.
backend/routes/companies.py - Request schemas
backend/models.py - Auth token service · Verifies credentials, hashes passwords, and issues JWT/session tokens.
backend/auth.py - RBAC & tenant isolation · Scopes tenant sessions and gates protected writes and deletes.
backend/middleware.py
MariaDB Integrity Layer
- MariaDB 10.6 · Authoritative persistence and database-rule boundary.
- Schema bootstrap & seed · Creates seed data, triggers, view, and counting function.
backend/init_db.py - Database connection
backend/database.py - Integrity & audit controls · Foreign keys, audit triggers, restricted view, and tenant-aware function.
backend/init_db.py
Clients & Contracts
- Streamlit dashboard · Separate UI that consumes the backend API.
frontend/app.py - OpenAPI contract
lib/api-spec/openapi.yaml - Generated React client
lib/api-client-react/src/generated/api.ts - Generated Zod contracts
lib/api-zod/src/generated/api.ts - Shared TypeScript DB schema · Supports external or shared consumers outside the Python MariaDB path.
lib/db/src/schema/index.ts
Connections 23
- Compose orchestration → MariaDB 10.6: runs
- Compose orchestration → Backend container: runs
- Compose orchestration → Streamlit dashboard: runs
- Backend container → Backend startup sequence: executes
- Backend startup sequence → Schema bootstrap & seed: initializes
- Schema bootstrap & seed → MariaDB 10.6: creates and seeds
- Schema bootstrap & seed → Integrity & audit controls: establishes
- Integrity & audit controls → MariaDB 10.6: enforced by
- Backend startup sequence → FastAPI application: starts
- FastAPI application → Route registry: assembles
- Route registry → Authentication routes: registers
- Route registry → Company & user routes: registers
- Authentication routes → Auth token service: authenticates with
- FastAPI application → RBAC & tenant isolation: protects requests through
- RBAC & tenant isolation → Company & user routes: authorizes and scopes
- Authentication routes → Request schemas: validates with
- Company & user routes → Request schemas: validates with
- Authentication routes → Database connection: queries
- Company & user routes → Database connection: persists through
- Database connection → MariaDB 10.6: connects to
- Streamlit dashboard → FastAPI application: consumes API
- OpenAPI contract → Generated React client: generates
- OpenAPI contract → Generated Zod contracts: generates