Getting Started – Running the Application

This section walks you through starting the Flask development server for the Library REST API. Ensure you have cloned the repository, activated your Python 3.8 virtual environment, and installed all dependencies before proceeding.

1. Activate Your Virtual Environment

Make sure your virtual environment is active in the directory containing app.py:

# macOS / Linux
source venv/bin/activate

# Windows (PowerShell)
venv\Scripts\Activate.ps1

2. Launch the Server

From the same directory, run:

python app.py

This command:

  • Imports your Flask app and initializes extensions
  • Configures the database and JWT
  • Registers all REST resources
  • Starts the server on port 5000 in debug mode

3. Configuration Overview

Configuration Key Purpose
SQLALCHEMY_DATABASE_URI Points to the SQLite file data.db.
SQLALCHEMY_TRACK_MODIFICATIONS Enables event notifications (set to True by default).
PROPAGATE_EXCEPTIONS Forces Flask to bubble up exceptions for debugging.
secret_key Used by Flask-JWT to sign and verify JWT tokens.

All settings live in app.config at the top of app.py .

4. Initialization Flow

flowchart TD
    A[Run python app.py] --> B[db.init_app app]
    B --> C[before_first_request creates tables]
    C --> D[JWT app authenticate identity]
    D --> E[api.add_resource registrations]
    E --> F[app.run port 5000 debug True]
  1. **db.init_app(app)**
  2. Binds the SQLAlchemy instance from db.py to your Flask app.
  3. **@app.before_first_request**
  4. Calls create_tables() once to run db.create_all(), creating users, stores, and books tables in data.db.
  5. **JWT(app, authenticate, identity)**
  6. Sets up the /auth endpoint for user login and token issuance.
  7. **api.add_resource(...)**
  8. Registers five resources:
  9. Store/store/<name>
  10. StoreList/stores
  11. Book/book/<title>
  12. BookList/books
  13. UserRegister/register
  14. **app.run(port=5000, debug=True)**
  15. Starts the development server on http://localhost:5000 with debug mode enabled.

5. Important Notes

{
    "title": "Development Mode",
    "content": "The server runs with debug=True. Disable this in production to avoid exposing sensitive information."
}
{
    "title": "Database File",
    "content": "A local SQLite file named data.db is created on first run. Back it up before schema changes."
}

Once the server is running, you can explore all endpoints (books, stores, authentication, and user registration) using the provided Postman collection or your tool of choice.