Infrastructure

Package Overview

This package forms the core of the server-side application. It contains the foundational modules and configuration required to run and maintain the backend system.

Database Configuration

server.app.db_config.DB_CONFIG = {'dbname': 'myapp_test', 'host': 'localhost', 'password': 'test_password', 'port': '5432', 'user': 'test_user'}

Dictionary holding PostgreSQL connection details.

Each value is loaded from environment variables to enhance security and flexibility:
  • DB_NAME: Name of the PostgreSQL database.

  • DB_USER: Username for authentication.

  • DB_PASSWORD: Password for authentication.

  • DB_HOST: Hostname or IP address of the database server.

  • DB_PORT: Port number on which the database server is listening.

server.app.db_config.dsn = 'postgresql://test_user:test_password@localhost:5432/myapp_test'

Constructs a PostgreSQL connection string (DSN) from the DB_CONFIG dictionary.

This string follows the format:

postgresql://<user>:<password>@<host>:<port>/<dbname>

It is required by most PostgreSQL drivers, including psycopg, to initiate connections.

server.app.db_config.get_db()[source]

Returns the current database session. :Yields: Session – The current database session.

Return type:

Generator[Session, None, None]

server.app.db_config.init_engine()[source]

Creates the engine necessary for the SQLAlchemy connection, as well as the session maker. :returns: The engine for the SQLAlchemy connection (necessary for creating the tables later). :rtype: Engine

Rate Limiting

server.app.rate_limiter.limiter = <slowapi.extension.Limiter object>

Create a rate limiter instance using the client’s IP address as the unique identifier.

This Limiter is used with FastAPI to enforce rate limiting on specific endpoints. It uses get_remote_address to extract the client’s IP from the request, ensuring that limits are applied by ip address.

server.app.rate_limiter.limiter

The configured SlowAPI rate limiter instance.

Type:

Limiter

Application Entrypoint

server.app.main.create_app(dev=True)[source]

Create and configure a FastAPI application instance.

This function sets up the FastAPI app with necessary middleware, routes, and lifecycle event handlers. It optionally initializes the database engine and verifies configuration during development mode.

Parameters:

dev (bool) – Flag indicating whether the app runs in development mode. If True, config verification and database initialization are performed.

Returns:

Configured FastAPI application instance.

Return type:

FastAPI

Raises:

Exception – If configuration verification fails in development mode.