python API/Backend 4 files • 69 lines

Python FastAPI Microservice

Production-ready Python REST API starter with structured routing, data validation models, health checks, and clean service architecture.

Repository Files:
main.py (python) 22 lines
"""FastAPI Microservice Entrypoint."""
from routes import register_routes


class AppServer:
    def __init__(self, title: str, version: str = "1.0.0"):
        self.title = title
        self.version = version
        self.routes = {}

    def route(self, path: str, method: str = "GET"):
        def decorator(fn):
            self.routes[(method.upper(), path)] = fn
            return fn
        return decorator


app = AppServer(title="WorkMA Service API", version="1.0.0")
register_routes(app)

if __name__ == "__main__":
    print(f"Starting {app.title} v{app.version} with {len(app.routes)} routes...")
models.py (python) 21 lines
"""Domain data models and payload validators."""
from dataclasses import dataclass, field
from typing import List, Optional


@dataclass
class TaskItem:
    id: int
    title: str
    status: str = "todo"
    priority: str = "medium"
    tags: List[str] = field(default_factory=list)

    def to_dict(self) -> dict:
        return {
            "id": self.id,
            "title": self.title,
            "status": self.status,
            "priority": self.priority,
            "tags": self.tags,
        }
routes.py (python) 18 lines
"""API route handlers."""
from models import TaskItem


SAMPLE_TASKS = [
    TaskItem(id=1, title="Configure API Gateway", status="completed", priority="high", tags=["infra"]),
    TaskItem(id=2, title="Implement OAuth2 Token Guard", status="in_progress", priority="high", tags=["security"]),
]


def register_routes(app):
    @app.route("/health", method="GET")
    def health_check():
        return {"status": "healthy", "service": app.title}

    @app.route("/api/v1/tasks", method="GET")
    def list_tasks():
        return {"count": len(SAMPLE_TASKS), "items": [t.to_dict() for t in SAMPLE_TASKS]}
README.md (markdown) 8 lines
# Python FastAPI Microservice Starter

A clean, modular Python API project template for **WorkMA Code Nexus**.

## Project Structure
- `main.py` — Application server initialization
- `models.py` — Typed domain dataclasses & serializers
- `routes.py` — Endpoint handlers and health check

How to Customize Inside WorkMA

Runtime: Python 3.12 + WorkMA Code Runner / Virtualenv

  1. Open the template directly inside WorkMA Code Nexus or fork it inside your workspace gallery.
  2. Configure any API tokens in the project's Encrypted Secrets Vault.
  3. Edit code in the browser Monaco editor with real-time file locking and 3-way merge safety.
  4. Sync upstream to GitHub with Sentinel regex + AI PR checks enabled.

DLP & Secrets Vault Readiness

All database URIs, JWT secrets, and third-party API keys should live inside WorkMA Encrypted Secrets Vault and inject strictly at runtime rather than committing plaintext .env configs.

More Code Nexus Starter Templates