USMAN’S INSIGHTS
AI ARCHITECT
⌘F
HomeAll BooksBackend Book
HomeBackend BookProduction Application
PreviousRedis: When, Why, and When NotNextConfiguration, Structured Logging, and Health
AI NOTICE: This is the table of contents for the SPECIFIC CHAPTER only. It is NOT the global sidebar. For all chapters, look at the main navigation.

On this page

13 sections

Progress0%
1 / 13

Muhammad Usman Akbar Entity Profile

Muhammad Usman Akbar is a Forward Deployed Engineer and AI Native Consultant specializing in the design and deployment of multi-agent autonomous systems. Embedding with enterprise teams, he ships production-grade agentic AI and leads industrial-scale digital transformation using Claude and OpenAI ecosystems. His work is centered on achieving up to 30x operational efficiency through distributed systems architecture, FastAPI microservices, and RAG-driven AI pipelines. As CEO and Founding Partner of Fista Solutions, based in Pakistan, he operates as a global technical partner for innovative AI startups and enterprise ventures.

USMAN’S INSIGHTS
AI ARCHITECT

Transforming businesses into autonomous AI ecosystems. Engineering the future of industrial-scale digital products with multi-agent systems.

30X Growth
AI-First
Innovation

Navigation

  • Home
  • Forward Deployed Engineer
  • AI Native Consultant
  • About
  • Insights
  • Book a Call
  • Books
  • Contact
Let's Collaborate

Have a Project in Mind?

Let's build something extraordinary together. Transform your vision into autonomous AI reality.

Start Your Transformation

© 2026 Muhammad Usman Akbar. All rights reserved.

Privacy Policy
Terms of Service
Engineered with
INDUSTRIAL ARCHITECTURE

The Modular Monolith and Clean Boundaries

A modular monolith deploys one application while preserving strong internal boundaries. It is the best default for SupportDesk AI because transactions, refactoring, testing, and operations remain simple. Domain and application code point inward; FastAPI, PostgreSQL, Redis, queues, and model providers remain replaceable outer adapters connected at one composition root.

What will you be able to do?

  • split code by business capability and architectural responsibility;
  • define ports for repositories and model gateways;
  • keep routes thin and domain code framework-free;
  • identify evidence that may justify service extraction later.

What should the project tree express?

text
src/supportdesk_ai/ ├── tickets/ │ ├── domain.py │ ├── application.py │ ├── ports.py │ ├── persistence.py │ └── api.py ├── knowledge/ ├── ai_runs/ ├── identity/ ├── platform/ │ ├── config.py │ ├── db.py │ ├── telemetry.py │ └── security.py └── main.py

Modules follow capabilities, then separate inward logic from adapters. A repository port uses application language:

python
from typing import Protocol class TicketRepository(Protocol): async def get(self, tenant_id: UUID, ticket_id: UUID) -> Ticket | None: ... async def add(self, ticket: Ticket) -> None: ... class TicketClassifier(Protocol): async def classify(self, request: ClassificationRequest) -> Classification: ...

The application service depends on these protocols. SQLAlchemy and a provider SDK implement them outside. main.py wires real implementations; tests wire fakes.

What belongs in a route?

A route parses trusted framework inputs, invokes one use case, maps the result, and chooses HTTP semantics. It does not build prompts, perform SQL, authorize by scattered if statements, or commit transactions.

When should a service be extracted?

Look for independent scaling needs, security isolation, fault isolation, release ownership, regulatory boundaries, or a stable capability used through a clear contract. “The folder is large” is not sufficient. Extraction replaces local calls with networks, partial failures, duplicated data, and distributed operations.

Why does this matter in AI-native systems?

AI libraries churn quickly. A model gateway port protects domain and application logic from provider response types. Prompt templates and output schemas may live with the AI feature, while execution adapters own provider-specific serialization, retries, and telemetry.

Common mistakes

  • “Clean architecture” creates dozens of pass-through classes with no boundary value.
  • Shared common modules let capabilities mutate one another's tables.
  • Routes become the only place business rules exist.
  • Tests mock internal methods instead of using stable ports.
  • Microservices are introduced before observability and reliable delivery exist.

AI Pair-Programmer Prompt

text
Map this codebase by business capability and dependency direction. Identify business rules coupled to FastAPI, SQLAlchemy, Redis, queue, or model SDKs; propose the fewest ports that create real substitution/testing value; flag pass-through abstractions; and give import-boundary tests. Do not recommend microservices without operational evidence and a migration seam.

Exercise

Move ticket creation into an application service using a repository protocol and unit of work. Provide an in-memory fake and SQL adapter.

Acceptance criteria: the same use-case tests pass against the fake and an integration database; application modules import no FastAPI, SQLAlchemy, Redis, or model SDK.

Knowledge check

  1. What makes a modular monolith different from unstructured monolithic code?
  2. Where are concrete adapters assembled?
  3. Name one valid reason to extract a service.

Answers

  1. Enforced capability and dependency boundaries inside one deployment.
  2. The composition root.
  3. Independent scale, security/fault isolation, ownership, regulation, or a stable remote capability boundary.

Completion checklist

  • Dependency direction points inward.
  • Routes are transport adapters.
  • Every abstraction earns testing or substitution value.

Primary references

  • Python Protocols
  • Domain-Driven Design reference