Scalable API Infrastructure for E-Commerce Tools

01 Challenge

Internal tools like price calculators, AI bots or stock checkers need to be secure, fast and reliably accessible – without setting up the server infrastructure from scratch for every tool.

02 Approach

A microservices foundation of FastAPI as an asynchronous Python backend and Caddy as a reverse proxy with automatic HTTPS, forwarding every request under /api to the services.

03 Result

New tools can be deployed as small services under the same domain as the frontend – demonstrated with two live demos: a text analyzer and an AI code explainer.

Stack
PythonFastAPIPydanticCaddyOpenRouter

Digital process optimization needs a stable foundation. In this project, I built a microservices infrastructure that serves as the foundation for internal business applications: the speed of Python (FastAPI) combined with the security of a modern reverse proxy (Caddy).

Why This Architecture?

In e-commerce, time-to-market is critical. New small tools should be available quickly – without setting up the complete server infrastructure from scratch each time.

Security First
HTTPS
Automatic encryption via Caddy
Scalability
n : 1
Load balancing across multiple internal services
Efficiency
async
Ideal for I/O-heavy database and AI calls
Live demos
2
Text analyzer · AI code explainer

Architecture

Every request from the browser goes through Caddy. The proxy terminates HTTPS, strips the /api prefix and forwards the request to FastAPI, which validates the payload and hands it to the right service.

  1. 01FrontendBrowser calls /api/… on the same domainfetch
  2. 02CaddyAutomatic HTTPS, strips the /api prefixhandle_path
  3. 03FastAPIAsynchronous backend on 127.0.0.1:8000Python
  4. 04ValidationPydantic models with length limitsPydantic
  5. 05ServicesText pipeline and LLM integrationOpenRouter
Fig. 1 — Request path from the browser to the LLM provider

The Backend: FastAPI

Two example business functions run on the platform:

  1. /generate – a text analysis pipeline, e.g. for automated product descriptions.
  2. /ask-ai – an interface to large language models for the internal support bot.
from fastapi import FastAPI
from pydantic import BaseModel, Field

app = FastAPI()


class TextPayload(BaseModel):
    text: str = Field(..., max_length=500)


class AssistantPayload(BaseModel):
    prompt: str = Field(..., max_length=2000)
    model: str = Field("example/free-model")


@app.post("/api/text-tools")
async def text_tools(payload: TextPayload):
    value = payload.text
    return {
        "uppercase": value.upper(),
        "length": len(value),
    }


@app.get("/api/models")
async def list_models():
    # In practice, free models are loaded from a provider.
    return {
        "models": [
            {"id": "provider/model-a:free", "name": "Model A Free"},
            {"id": "provider/model-b:free", "name": "Model B Free"},
        ]
    }


@app.post("/api/assistant")
async def assistant(payload: AssistantPayload):
    # In practice: validation, rate limiting, provider request, error handling.
    return {"result": f"Explanation for model {payload.model}"}

The Web Server: Caddy

To make the API available under the same domain as the frontend, Caddy uses handle_path to strip the /api prefix before the request reaches FastAPI:

handle_path /api/* {
    reverse_proxy 127.0.0.1:8000
}

Live Demo: Text Analyzer

Enter a text – it is sent to /api/generate and analyzed by the Python backend. If the backend is unreachable, an error message appears.

Text Analysis API

Results appear here…

Extension: AI Code Explainer

The second example uses the /ask-ai endpoint: the backend securely forwards a code snippet to an LLM (via OpenRouter). The demo loads the available models on startup via /api/models.

AI Code Explainer

By submitting, your text is sent to OpenRouter (USA) and the provider of the selected model, who may log inputs. Please do not enter personal or confidential data. Details in the privacy policy.

The AI explanation will appear here…

Learnings

  • One proxy, many tools: With handle_path, every new service lives under the same domain – no CORS, no separate certificate per tool.
  • Validate at the edge: Pydantic length limits (500 and 2,000 characters) apply server-side; the demo also checks client-side for faster feedback.
  • Secrets stay in the backend: API key and system prompt live only on the server; the browser only sees the result.