19. Tourist and TouristTransaction Modules with Jinja2
Designing Tourist and TouristTransaction Collections
The Tourist and TouristTransaction collections represent distinct but related domain entities. Tourist documents store identity and profile information, while TouristTransaction documents capture spending or activity records linked by a reference identifier. This separation keeps documents focused and supports efficient querying and analytics.
Relational data is retrieved in FastAPI and passed to Jinja templates as structured context. Templates iterate over datasets to render tables or summaries without embedding database logic. This approach preserves separation of concerns while enabling dynamic, data-driven HTML views.
HTML Template for Relational Rendering
Jinja templates render related data using simple control structures. Presentation logic remains declarative, focusing only on how data is displayed. This keeps HTML readable and maintainable even as data relationships grow.
End-to-End Flow: Database → FastAPI → HTML
The complete flow begins with data stored in MongoDB, retrieved by FastAPI route handlers, and rendered into HTML via Jinja templates. Each layer has a single responsibility, enabling clear debugging and incremental enhancement. This architecture scales naturally from simple views to complex, data-rich dashboards.