Local Development Setup
Relevant source files
The following files were used as context for generating this wiki page:This document provides a comprehensive guide for setting up the Becathlon project for local development. Becathlon is an e-commerce platform powered by Django, designed to mirror the user experience of a modern sports retailer. The setup process involves configuring the environment, initializing the database, and running the development server.
The project is structured with a modular design, where different functionalities are encapsulated within separate Django apps located in the apps/ directory. For local development, the application is configured to use a simple SQLite database by default, making the initial setup straightforward.
1. Prerequisites
Before starting, ensure you have a compatible version of Python installed. The project's dependencies are managed via a requirements.txt file, which is not provided in the context but is a standard for Python projects. The primary backend framework is Django 5.2.5.
Sources: IMPLEMENTATION.md:31
2. Project Structure and Configuration
The project follows a standard Django layout with a modular approach, placing distinct applications inside the apps/ directory. The main project settings are located in becathlon/settings.py.
Sources: IMPLEMENTATION.md:43-59, becathlon/settings.py:17-18
Application Layout
The diagram below illustrates the high-level structure of the project, with a central configuration directory and multiple feature-specific apps.
This diagram shows the main project directories and the modular app structure.
Sources: IMPLEMENTATION.md:43-59, README.md:91-103
Installed Applications
The core functionalities are divided into several Django apps, which are registered in the INSTALLED_APPS setting.
| App Name | Purpose |
|---|---|
main | Homepage, navigation, footer, about pages |
authentication | User login, registration, logout |
catalog | Product listings, categories, product details |
cart | Shopping cart management |
profiles | User profiles and preferences |
stores | Store locator with mock locations |
recommendation | Recommendation system |
order | Order history and mock refunds |
Sources: README.md:91-103, becathlon/settings.py:70-80
Environment Configuration
The application uses environment variables for critical settings, with sensible defaults for local development.
| Variable | becathlon/settings.py Location | Default Value | Description |
|---|---|---|---|
SECRET_KEY | Line 25 | django-insecure-... | Django's secret key for cryptographic signing. |
DEBUG | Line 28 | True | Toggles Django's debug mode. Should be False in production. |
ALLOWED_HOSTS | Line 30 | localhost,127.0.0.1,testserver | A list of strings representing the host/domain names that this Django site can serve. |
DB_NAME | Line 116 | None | Name of the PostgreSQL database. If not set, SQLite is used. |
DB_USER | Line 117 | None | Username for the PostgreSQL database. |
DB_PASSWORD | Line 118 | None | Password for the PostgreSQL database. |
DB_HOST | Line 119 | None | Host for the PostgreSQL database. |
Sources: becathlon/settings.py:25-30, 116-120
3. Database Setup
The project is configured to use a PostgreSQL database when environment variables like DB_NAME and DB_USER are provided. For local development, it conveniently falls back to a file-based SQLite database if these variables are not set.
Sources: becathlon/settings.py:115-142
Database Configuration Flow
The following diagram shows the logic used in becathlon/settings.py to determine which database to use.
This flow ensures that a developer can get started without configuring a database server.
Sources: becathlon/settings.py:122-142
Initializing the Database
To set up the database for the first time, run the standard Django migration command. This will create the necessary tables based on the models defined in the apps.
-
Run Migrations: This command applies all database migrations.
python manage.py migrateSources: pbp-deploy.sh:15, reset_production_db.py:56
-
Seed Initial Data: The project includes a script to pre-populate the database with 12 product types.
# The reset_production_db.py script executes this file, # implying it's part of the setup process. python seed_product_types.pySources: IMPLEMENTATION.md:28-29, 64-77, reset_production_db.py:64-66
4. Running the Application
Once the dependencies are installed and the database is migrated, you can start the local development server.
Start the Development Server
Use the runserver management command to start the Django development server.
python manage.py runserver
The application will be accessible at the following local URLs:
- Homepage:
http://127.0.0.1:8000/ - Login:
http://127.0.0.1:8000/auth/login/ - Sign Up:
http://127.0.0.1:8000/auth/signup/
Sources: IMPLEMENTATION.md:16-24
Local Development Request Flow
This sequence diagram illustrates how a request is handled by the local development server.
5. Running Tests
The project is configured with coverage to measure test coverage. The README.md file provides instructions for running tests.
Running All Tests
To run the complete test suite and generate a coverage report:
# Run all tests and report coverage
coverage run --source='apps' manage.py test; coverage report
Generating a Detailed Report
To save the coverage report to a file:
# This command is specified for PowerShell
coverage report -m | Out-File -FilePath coverage_output.txt -Encoding utf8; Get-Content coverage_output.txt
The project aims for a 90% total test coverage.
Sources: README.md:121, 124-131
Summary
Setting up the Becathlon project locally involves standard Django procedures. The key steps are installing dependencies, migrating the database which defaults to SQLite, and running the local development server using manage.py. The project's settings are designed to be developer-friendly, minimizing the configuration needed to get started. The provided documentation also includes clear instructions for running the test suite to ensure code quality and reliability.