Skip to content

DBMS-PM-007/pagbantay-be

Repository files navigation

Pagbantay Backend Setup

The Pagbantay backend is a serverless FastAPI application that uses SQLAlchemy with CockroachDB , following the Clean Architecture pattern.

It supports Alembic migrations and is ready for deployment to AWS Lambda using Mangum.

Clean Architecure

This project follows the Clean Architecture pattern, which separates the code into different layers of different logic. This setup is common in real-world projects because it keeps the code organized, easier to test, and flexible for changes.

Read more about Clean Architecure

Clean Architecture Cone

Creating and Activating a Virtual Environment

For Python3.11:

  1. Install Python 3.11 if you have not yet:

  2. Verify installation

    • Locate Python 3.11:
    where python3.11 # Windows
    which python3.11 # Linux/Ubuntu

    It should output something like Your_Path\python3.11.exe

  3. Create venv

    python3.11 -m venv venv
  4. Then activate:

    source venv/bin/activate   # Mac/Linux
    venv\Scripts\activate      # Windows

    A "(venv)" prefix indicates that you are in a virtual environment:

    (venv) C:\YourDirectory...
  5. To exit the virtual environment (venv):

    deactivate

Installation of Dependencies

Install python dependencies:

pip install -r requirements.txt

Running and managing database migrations

  1. Configure base schema at /models/base.py

  2. Generate a Migration Script:

    alembic revision --autogenerate -m "your message"
    • Migration files will appear under alembic/versions/
    • Filename may look like somecode_your_message.py
  3. Apply the migration (Push to Database):

    alembic upgrade head

Accessing AWS resources

  1. Go to the AWS Sign-In Page

  2. Log in using the IAM user credentials provided by the AWS account owner/admin

  3. After logging in, you can now view and access AWS services through the console.

Setting up AWS CLI and Configuring with an IAM user

  1. Install AWS CLI v2 if you have not yet:

  2. Verify installation:

    aws --version
  3. Configure AWS CLI:

    aws configure
  4. Enter credentials as prompted (follow format below):

    AWS Access Key ID [None]: <your-access-key-id>
    AWS Secret Access Key [None]: <your-secret-access-key>
    Default region name [None]: ap-southeast-1
    Default output format [None]: json

(Note: Your Access Keys are found along with the login credentials that you were given)

You have now successfuly configured AWS CLI with IAM

Set-up via Serverless Framework

  1. Ensure Node 14 or later is installed

  2. Install Serverless Framework:

    npm install -g serverless@3.39.0
  3. Verify installation:

    serverless --version
  4. Install serverless plugins:

    npm install
  5. Install Python Requirements Plugin:

    sls plugin install -n serverless-python-requirements

Deploy via Serverless Framewrok

  1. Set-up Docker

  2. Set AWS Profile

    • Use the project's AWS profile
    export AWS_PROFILE=pagbantay-user
  3. Deploy the backend:

    serverless deploy
    # or shorthand
    sls deploy
  4. Check if deployment is successful:

    • After deployment, you should be given a URL
    • Visit URL in browser and append /docs at the end
    • It should render correctly (see screenshot below):

Screenshot

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors