How shubratha/organization_management works
Project type and purpose
• This is a single microservice (“Organization Management Service”) built with FastAPI.
• It manages multi‐tenant organizations by creating and isolating per‐tenant PostgreSQL databases, handles authentication/authorization (JWT + role‐based access), and exposes RESTful endpoints.
File structure
• Top-level:
• Dockerfile, docker-compose.yml → containerized deployment
• alembic/ + alembic.ini → database migrations
• app/ → FastAPI application code
• tests/ → Pytest suite
• Under app/:
• core/ → application config, middleware, health checks, logging, security
• database/ → SQLAlchemy base, session management, DAO utilities
• auth/ → authentication router, schemas, services, DAO, models
• organization/ → organization router, schemas, services, DAO, models
• main.py → application entrypoint
• Configuration:
• requirements.txt/in → Python dependencies
• .env (via README instructions) → runtime configuration
README for additional insights
• Tech stack: FastAPI, PostgreSQL + SQLAlchemy, JWT, Docker, Pytest, OpenAPI
• Features: dynamic database provisioning, role‐based access, async REST API
Main components & their relationships
a. External Clients
• Super Admin UI/CLI
• Organization Admin UI/CLI
• (Could also be other services consuming the API)
b. API Layer (FastAPI container)
• Routers: /org/*, /admin/*, /auth/*
• Middleware & security: JWT validation, CORS, logging
• Health Endpoint: /health
c. Business Logic Layer
• auth.services → user lookup, token generation
• organization.services → org creation, dynamic DB provisioning
d. Data Access Layer
• dao.py modules → low-level CRUD against SQLAlchemy models
• SQLAlchemy session management (session.py)
e. Persistence
• Central PostgreSQL database (“central_org”) for superadmins & org metadata
• Dynamically created tenant PostgreSQL databases for each org
• Alembic migrations for schema versioning
f. Infrastructure
• Docker container for the service
• Docker Compose orchestrating service and PostgreSQL
• Logging & configuration via core modules
Architectural patterns & design principles
• Layered (Router → Service → DAO → Database)
• Dependency Injection via FastAPI’s dependencies (app/auth/dependencies.py)
• Single‐responsibility & modular structure (auth vs organization)
• Dynamic provisioning: service triggers separate DB creation API/CLI
• Async I/O for high throughput