Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Smart API Gateway

An enterprise-grade API Gateway built using FastAPI.

Features

  • JWT Authentication
  • API Key Management
  • Rate Limiting
  • Request Logging
  • Redis Cache
  • Analytics
  • Monitoring
  • Docker Support

Run

docker compose up --build

ERROR FACING

  1. on of the error that i faced with the docker setting. First Created Docker container where at the begining the postgersql db password it makes by it self, so later when try to change the the password using 'docker compose up --build' the password didn't change and throw us the error beacuse we can't change a databases password.So, Docker still using the old password, even if we update the password.So, to fix this run docker compose down -v.Now the old container is removed and new container is created.

  2. The devices posgresql listening to the 5432 port also trying to run postgre from docker so its created a mismatch when tring run postgre for docker so now removed the postgre db that listening to that port using 'Stop-Service postgresql-x64-18'.Also if we want to check which is listening to 5432 poort then run 'Stop-Service postgresql-x64-18'.

  3. Windows PostgreSQL service is already running on port 5432. Then Docker either:

Failed to bind port 5432, or Is running on another port.

So when FastAPI connects to:

localhost:5432

it's talking to the Windows PostgreSQL instead of the Docker PostgreSQL.

  1. Docker may still be using an old configuration so to remove all the cache we need to use 'docker compose build --no-cache'.

  2. getting error every time when trying to run the 'uvicorn app.main:app --reload' because its for when we are using postgre sql, but here we are using docker for db so don't need to run this.

Swagger:

Info:

  1. These lines prove the database connection is successful:

select pg_catalog.version() select current_schema() show standard_conforming_strings COMMIT

These are SQLAlchemy's startup queries.

If these execute, your PostgreSQL connection is working correctly.

  1. I used:

Base.metadata.create_all(bind=engine)

For a learning project, that's okay.

For an IBM-quality project, we should NOT use create_all() anymore.

Real companies use Alembic migrations because they need to keep track of database changes over time.

So from Day 3 onward, we're going to use Alembic.

  1. Alembic in Python is a lightweight database migration tool used with SQLAlchemy.It helps you manage changes to your database schema over time in a controlled and versioned way — similar to how Git tracks changes in code.

  2. why use password hashing(hashing.py).?? if our hash_password("Sourav123") then it returns a string($2b$12$R8....) not actual password.

  3. To Check the created table after the alembic migration we need to run - "docker exec -it nexusapigateway-db-1 psql -U postgres -d gateway" using the postgresql container name in docker, then it will show someting like '#gateway' after that run \dt, Check table structure by "\d users", to show how many row is created we need to run - SELECT * FROM users; after that if we see like this - '172.19.0.1:55380 - "POST /auth/register HTTP/1.1" 201 Created'in our terminal means our api is actually working. this is the structural diagram that i build so far.

React / Swagger

    │

    ▼

FastAPI Router

    │

    ▼

Service Layer

    │

    ▼

Repository Layer

    │

    ▼

SQLAlchemy ORM

    │

    ▼

PostgreSQL

  1. Why bcrypt is used in hash- bcrypt is designed for password storage, not normal data hashing. It is intentionally slow, which helps protect against brute-force attacks, and it uses a salt so two users with the same password still get different hashes.

  2. how to open the postgresql in the terminal- Open the PostgreSQL shell From your PowerShell terminal, run: docker exec -it nexusapigateway-db-1 psql -U postgres -d gateway

  3. "docker exec -it nexus-backend alembic upgrade head" ALSO used to create table using the alembic migration inside the api.

  4. To use the docker inside the terminal run 'docker exec -it nexusapigateway-db-1 psql -U postgres -d gateway' also can run sql to update or see the table inside it.

Here’s the breakdown:

Part Meaning docker exec Runs a command inside an already running Docker container. -it Combines -i (interactive mode) and -t (allocate a pseudo-TTY) so you can type commands and see output in real time. nexusapigateway-db-1 The name (or ID) of the running container. In this case, it’s your PostgreSQL container. psql The PostgreSQL command-line client used to connect to and manage PostgreSQL databases. -U postgres Specifies the PostgreSQL username to connect with — here, postgres (the default superuser). -d gateway Specifies the database name to connect to — here, gateway. What happens when you run it Docker finds the container named nexusapigateway-db-1. It starts an interactive session inside it. It launches the psql client. You are logged in as user postgres to the gateway database. You can now run SQL commands directly.

DOCS

http://localhost:8000/docs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages