This directory contains the backend API for the LAMFO website, built with FastAPI and SQLAlchemy. It provides endpoints and database models for managing LAMFO members, projects, and related data.
This backend serves as the core API for the LAMFO group, supporting member and project management, and is designed for easy integration with both development (SQLite) and production (PostgreSQL) databases.
app/— Main application code (FastAPI app, models, schemas, CRUD, database setup)tests/— Unit tests using pytest and SQLite for isolationpyproject.toml— Project configuration and dependenciesdocker-compose.yml— For running with Docker and PostgreSQLalembic.ini, etc. — Configuration files
-
Install dependencies:
pip install -e . -
Run the API (development):
uvicorn app.main:app --reload
-
Run tests:
pytest
The project includes several test suites:
- Database Tests: Test basic CRUD operations and database interactions
- API Tests: Test the API endpoints for expected behavior
- PostgreSQL Tests: Integration tests with the PostgreSQL database (these are skipped if PostgreSQL is not available)
To run the tests:
# Run all tests
pytest
# Run specific test files
pytest tests/test_api.py
pytest tests/test_database.py
pytest tests/test_postgres.py
# Run with verbose output
pytest -vThe project includes a docker-compose.yml file for several reasons:
- Environment consistency: Ensures the same environment across development and production
- Service orchestration: Manages the API and database services together
- Dependency management: Handles the dependency between the API and the database
- Volume management: Manages persistent data storage for the database
- Network configuration: Creates isolated networks for services
- Easy deployment: Simplifies deployment with a single command
To use Docker Compose:
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop all services
docker-compose downBefore running the application, you need to set up environment variables:
-
Copy the example environment file:
cp .env.example .env
-
Edit the
.envfile and fill in the actual values for your environment.
The application uses the following environment variables:
ENVIRONMENT: Application environment (default: "production") - Options: production, development, stagingTEST_MODE: Set to "true" for SQLite, "false" for PostgreSQL (default: "false")
SQLITE_URL: SQLite database URL (default: "sqlite:///./test.db") - Used when TEST_MODE=truePOSTGRES_USER: PostgreSQL user (default: "lamfo")POSTGRES_PASSWORD: PostgreSQL password (required - no default for security)POSTGRES_HOST: PostgreSQL host (default: "database")POSTGRES_PORT: PostgreSQL port (default: "5432")POSTGRES_DB: PostgreSQL database name (default: "lamfo_db")
Important: When TEST_MODE=false, all PostgreSQL environment variables must be properly set.
These variables can be set in the .env file or passed as environment variables.
To check database connectivity, run:
python check_db.py- The API docs are available at
/docswhen running the server. - See
app/populate_db.pyfor mock data generation.
For questions or contributions, contact the LAMFO team.