Application Design and Layout - jbrucker/home-log GitHub Wiki

Backend

Uses SqlAlchemy, FastAPI, and Pydantic. Application deployed in a Docker container.


backend/                        # Boring name :-)
├── app/
│   ├── core/
│   │   ├── config.py           # App settings from .env
│   │   ├── database.py         # DB engine, Base class for models, and session creation
│   │   └── security.py         # Password hash and validation, for local user accounts
│   ├── data_access/
│   │   └── user_dao.py         # Persistence operations using SQLAlchemy
│   ├── models.py               # SqlAlchemy ORM model definitions, User, Measurement, Location, etc.
│   │                           # All models put in one module for now, can transparently repackage later
│   ├── routers/                # FastAPI route definitions
│   │   └── user.py             
│   ├── schemas.py              # Pydantic "schema" for validation, serialization, and external representation of model data
│   │                           # All schema classes put in one module for now, can transparently repackage later
│   └── main.py                 # FastAPI app entry point
├── tests/                      # Unit tests for backend
├── .env                        # Environment variables, not committed to git (of course)
├── Dockerfile
├── requirements.txt
└── docker-compose.yml

To support multiple API versions, some sources suggest nesting the router definitions:

```text
backend/
├── app/                                   # Main application package
│   ├── api/                               # API layer (routes and dependencies)
│   │   └── v1/                            # Versioned API namespace
│   │       ├── deps.py                    # Dependency injection utilities
│   │       └── routers/                   # Routers for v1 API
│   │           ├── auth.py                # Authentication endpoints (login, register)
│   │           ├── users.py               # Endpoints related to user accounts
│   │           ├── etc.

other parts of the layout (models, schema) are same as above.