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.
- 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.
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
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
| 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 |
| 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 |
| 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 |
| Method | Endpoint | Description |
|---|---|---|
| GET | /bank-accounts/ | List all bank accounts |
| PATCH | /bank-accounts/{id}/ | Update a bank account |
git clone https://github.com/your-org/api-gateway.git
cd api-gatewaypip install -r requirements.txtpython manage.py migratepython manage.py runserver- API Root: http://localhost:8000/
- Swagger Docs: http://localhost:8000/schema/
- 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.
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"
}Request:
GET /kyc/me/
Authorization: Bearer <token>Response:
{
"kyc": "123e4567-e89b-12d3-a456-426614174000",
"first_name": "John",
"last_name": "Doe",
"national_id": "0012345678"
...
}We welcome contributions! To get started:
- Fork the repository and create your branch from
main. - Add your feature (or fix a bug).
- Write tests for your code.
- Ensure all tests pass.
- Submit a pull request with a clear description.
- Use PEP8 for Python code.
- Write docstrings for all public classes and methods.
- Use descriptive commit messages.
- Define your gRPC proto in
core/protos/. - Generate Python code from the proto.
- Create a new ViewSet in
kyc_service/views/. - Register the ViewSet in
kyc_service/urls.py. - Add tests and documentation.
- Swagger/OpenAPI: Auto-generated at
/schema/ - gRPC Protos: Located in
core/protos/
- Designed to be secured with JWT, OAuth2, or Keycloak.
- Sensitive endpoints require authorization.
- Always use HTTPS in production.
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.
Run all tests:
python manage.py testAdd your tests in the appropriate appβs tests.py.
- gRPC errors β Check if microservices are running.
- DB issues β Verify connection settings in
settings.py. - Swagger not loading β Ensure
drf-spectacularis installed and enabled.
- Add user authentication & RBAC
- Add rate limiting & analytics
- Add more business services
- Improve error handling & logging
- Add CI/CD pipeline
- Lead Developer: Your Name
- Contributors: List of contributors
- Contact: kian.anbarestanii@gmail.com
This project is licensed under the MIT License.
See the LICENSE file for details.
- Keep proto files synchronized.
- Use environment variables for configuration.
- Update dependencies regularly.
- https://www.django-rest-framework.org/
- https://grpc.io/docs/languages/python/
- https://drf-spectacular.readthedocs.io/
βBuild APIs that scale, are secure, and delight developers!β