Skip to content

KianAnbarestani/API_gateway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

90 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 API Gateway

Welcome to the API Gateway!
This project is a modern, scalable, and modular API Gateway for managing KYC/KYB (Know Your Customer/Business), Bank Accounts, Addresses, and other core services. Built with a microservice architecture, it leverages Django REST Framework and gRPC for robust, high-performance communication.


✨ Features

  • Modular Microservice Architecture: Each domain (KYC, KYB, Address, Bank Account) is a separate, maintainable service.
  • gRPC & REST Integration: Fast, type-safe internal communication with gRPC; developer-friendly REST API for clients.
  • OpenAPI/Swagger Documentation: Auto-generated, interactive API docs with drf-spectacular.
  • Extensible & Scalable: Easily add new services or endpoints as your platform grows.
  • Security-Ready: Designed for integration with authentication/authorization (e.g., Keycloak, JWT).
  • Production-Grade: Suitable for enterprise and startup environments.

πŸ—οΈ Architecture Overview

graph TD
    Client[Client Apps (Web/Mobile)]
    APIGW[API Gateway (Django REST)]
    KYC[KYC Service (gRPC)]
    KYB[KYB Service (gRPC)]
    Address[Address Service (gRPC)]
    Bank[Bank Account Service (gRPC)]
    DB[(Database)]
    Docs[Swagger / OpenAPI Docs]

    Client -->|REST| APIGW
    APIGW -->|gRPC| KYC
    APIGW -->|gRPC| KYB
    APIGW -->|gRPC| Address
    APIGW -->|gRPC| Bank
    APIGW --> Docs
    KYC --> DB
    KYB --> DB
    Address --> DB
    Bank --> DB
Loading

πŸ—‚οΈ Project Structure

kyc_service/
  views/
    kyc.py           # KYC logic & endpoints
    kyb.py           # KYB logic & endpoints
    bank_account.py  # Bank Account logic & endpoints
    address.py       # Address logic & endpoints
    province.py      # Province endpoints
    city.py          # City endpoints
  urls.py            # All endpoint routing
  serializers.py     # DRF serializers (if needed)
core/
  protos/            # gRPC proto files and generated code

πŸ“˜ API Endpoint Reference

πŸ”Ή Address

Method Endpoint Description
GET /address/addresses/ List all addresses
POST /address/addresses/ Create a new address
POST /address/addresses/kyc/{kyc_id}/address/ Create address for KYC
PATCH /address/addresses/{id}/ Update an address
GET /address/provinces/ List all provinces
GET /address/provinces/{id}/ Get province details
GET /address/cities/ List all cities
GET /address/cities/{id}/ Get city details

πŸ”Ή KYC

Method Endpoint Description
GET /kyc/me/ Get current user's KYC
GET /kyc/ List all KYC records
GET /kyc/{id}/ Get KYC by ID
PATCH /kyc/ Update current user's KYC
PATCH /kyc/{id}/ Update KYC by ID

πŸ”Ή KYB

Method Endpoint Description
GET /kyb/me/ Get current user's KYB
GET /kyb/ List all KYB records
GET /kyb/{id}/ Get KYB by ID
POST /kyb/ Create a new KYB
PATCH /kyb/{id}/ Update KYB by ID

πŸ”Ή Bank Accounts

Method Endpoint Description
GET /bank-accounts/ List all bank accounts
PATCH /bank-accounts/{id}/ Update a bank account

πŸ› οΈ Quick Start

1. Clone the Repository

git clone https://github.com/your-org/api-gateway.git
cd api-gateway

2. Install Dependencies

pip install -r requirements.txt

3. Run Database Migrations

python manage.py migrate

4. Start the Development Server

python manage.py runserver

5. Access the API


🧩 How It Works

  • API Gateway receives REST requests from clients.
  • Each endpoint is mapped to a ViewSet in kyc_service/views/.
  • The ViewSet communicates with the appropriate gRPC service (KYC, KYB, Address, Bank Account).
  • gRPC services handle business logic and database operations.
  • Responses are returned to the client in a RESTful format.

πŸ§‘β€πŸ’» Example: Creating a New Address

Request:

POST /address/addresses/
Content-Type: application/json

{
  "kyc_id": "123e4567-e89b-12d3-a456-426614174000",
  "address_type": "home",
  "province": "Tehran",
  "city": "Tehran",
  "address": "123 Main St",
  "postal_code": "1234567890",
  "tel_number": "02112345678"
}

Response:

{
  "address": "987e6543-e21b-12d3-a456-426614174999"
}

πŸ§‘β€πŸ’» Example: Get Current User's KYC

Request:

GET /kyc/me/
Authorization: Bearer <token>

Response:

{
  "kyc": "123e4567-e89b-12d3-a456-426614174000",
  "first_name": "John",
  "last_name": "Doe",
  "national_id": "0012345678"
  ...
}

πŸ“ Contribution Guide

We welcome contributions! To get started:

  1. Fork the repository and create your branch from main.
  2. Add your feature (or fix a bug).
  3. Write tests for your code.
  4. Ensure all tests pass.
  5. Submit a pull request with a clear description.

Coding Standards

  • Use PEP8 for Python code.
  • Write docstrings for all public classes and methods.
  • Use descriptive commit messages.

Adding a New Service

  1. Define your gRPC proto in core/protos/.
  2. Generate Python code from the proto.
  3. Create a new ViewSet in kyc_service/views/.
  4. Register the ViewSet in kyc_service/urls.py.
  5. Add tests and documentation.

πŸ“„ API Documentation

  • Swagger/OpenAPI: Auto-generated at /schema/
  • gRPC Protos: Located in core/protos/

πŸ›‘οΈ Security

  • Designed to be secured with JWT, OAuth2, or Keycloak.
  • Sensitive endpoints require authorization.
  • Always use HTTPS in production.

🏒 About API Gateway

API Gateway is a next-generation platform for digital identity, business onboarding, and financial services.
This gateway provides secure, scalable, and maintainable integration for all microservices.


πŸ§‘β€πŸ”¬ Testing

Run all tests:

python manage.py test

Add your tests in the appropriate app’s tests.py.


🧰 Troubleshooting

  • gRPC errors β†’ Check if microservices are running.
  • DB issues β†’ Verify connection settings in settings.py.
  • Swagger not loading β†’ Ensure drf-spectacular is installed and enabled.

πŸ—ΊοΈ Roadmap

  • Add user authentication & RBAC
  • Add rate limiting & analytics
  • Add more business services
  • Improve error handling & logging
  • Add CI/CD pipeline

πŸ‘₯ Team


πŸ“œ License

This project is licensed under the MIT License.
See the LICENSE file for details.


πŸ’‘ Tips

  • Keep proto files synchronized.
  • Use environment variables for configuration.
  • Update dependencies regularly.

🏁 Quick Links


β€œBuild APIs that scale, are secure, and delight developers!”


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages