Skip to content

GhostMEn20034/short-ly

Repository files navigation

short.ly

Features

  • Users
    • Signup
    • Auth
    • Create, read, update user's information
    • Password Change
  • Links
    • Create, Read, Update, Delete Shortened URL
    • Custom short codes for shortened URLs
    • A public API that redirects to a long URL using a short code.
    • Send each URL visit to Analytical DB (It will be the same DB for simplicity, data will be sent in asynchronous way using RabbitMQ to have a low latency)
  • QR codes
    • CRUD for the QR code entity
    • QR Code customization
      • Background color change
      • Dots color change
      • Dots pattern customization
      • Corners pattern customization
      • Ability to add a logo
    • Download a QR code in different formats
      • PNG
      • JPEG
      • SVG
      • WEBP
  • Analytics
    • Top performing Date ( The date when the user's urls had the most clicks and scans )
    • Clicks + scans by device
    • Clicks + scans over time
    • Top-Performing Location (The location with the highest number of scans)
    • Clicks + scans by location

Frontend Repository

https://github.com/GhostMEn20034/short-ly-frontend

Setup

Note that the setup assumes you are using any Linux distribution

1. Clone the project:

git clone https://github.com/GhostMEn20034/short-ly.git

2. Change permissions for init-database.sh:

chmod +x init-database.sh

3. Create a .env file, using the following command:

touch .env

4. Open the file created above in whatever editor you want

5. Insert the next variables:

DB_CONNECTION_STRING=postgresql+asyncpg://<SQL_USER>:<SQL_PASSWORD>@db:5432/<SQL_DATABASE>
DB_LOG_QUERIES=false | true
SQL_USER=your_db_user
SQL_PASSWORD=your_db_password
SQL_DATABASE=your_database_name
SUPER_USER_PWD=your_postgres_user_password
JWT_SECRET_KEY=your_jwt_secret key # Secret key required for signing JWT Tokens, you can generate it on https://jwtsecret.com/generate
REDIS_HOST=redis # If you use docker compose to run the app, then the specified value must be "redis"
REDIS_PASSWORD=your_redis_pwd # if you use docker compose, it's not necessary to include the variable into this file
REDIS_PORT=your_redis_port # It’s not necessary to include the value if the port of your redis db is 6379

Running the App

1. Make sure you are in the root project directory and the .env file is populated.

2. Use the following command to run the app:

docker compose up -d --build

Running integration tests

1. Make sure you are in the root project directory.

2. Create env file with the name .env.test:

touch .env.test

3. Open the file in any editor and paste the same variables as in .env.test file:

DB_CONNECTION_STRING=postgresql+asyncpg://<SQL_USER>:<SQL_PASSWORD>@db:5432/<SQL_DATABASE>
DB_LOG_QUERIES=false | true
SQL_USER=your_db_user
SQL_PASSWORD=your_db_password
SQL_DATABASE=your_database_name
SUPER_USER_PWD=your_postgres_user_password
JWT_SECRET_KEY=your_jwt_secret key # Secret key required for signing JWT Tokens, you can generate it on https://jwtsecret.com/generate
REDIS_HOST=redis # If you use docker compose to run the app, then the specified value must be "redis"
REDIS_PASSWORD=your_redis_pwd # if you use docker compose, it's not necessary to include the variable into this file
REDIS_PORT=your_redis_port # It’s not necessary to include the value if the port of your redis db is 6379

4. Use the following command to run containers:

docker-compose -f docker-compose-test.yml --env-file .env.test up --build

5. Create another terminal session and get into a Docker container's shell using command:

docker exec -it fastapi_url_fold_test sh

6. Inside the container enter the command:

pytest -v --tb=short --disable-warnings ./tests/integration/

7. After the tests' execution, switch back to the first session and click Ctrl + C to stop containers

Running unit tests

Note:

  • To run unit tests you don't need docker containers
  • You can just create a virtual environment using venv or conda for example

If you want to run unit tests in virtual environment, you also need to install all dependencies using command:

pip install -r requirements.txt

1. Command to run unit tests:

pytest -v --tb=short --disable-warnings ./tests/unit/

About

URL Shortener written in Python, FastAPI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages