A RESTful API for bank account management built with Python and Flask. It supports user registration, JWT-based authentication, and balance management backed by a SQLite database.
- User registration with bcrypt password hashing
- JWT-based authentication with configurable expiration
- Protected route for balance management
- SQLite persistence
- Clean Architecture pattern (Controllers, Views, Models, Drivers)
| Layer | Technology |
|---|---|
| Framework | Flask 3.1.3 |
| Database | SQLite (via sqlite3) |
| Auth | PyJWT 2.11.0 |
| Hashing | bcrypt |
| Config | python-dotenv 1.2.2 |
| Testing | pytest |
mintAPI/
├── init/
│ └── schema.sql # Database schema
├── src/
│ ├── configs/ # JWT and environment configs
│ ├── controllers/ # Business logic
│ ├── drivers/ # JWT and password utilities
│ ├── errors/ # Error types and handler
│ ├── main/
│ │ ├── composer/ # Dependency injection composers
│ │ ├── middlewares/ # JWT auth middleware
│ │ ├── routes/ # Flask Blueprints
│ │ └── server/ # Flask app factory
│ ├── models/
│ │ ├── interface/ # Repository interfaces
│ │ ├── repositories/ # SQLite repository implementation
│ │ └── settings/ # DB connection handler
│ └── views/ # Request/Response adapters
├── tests/
│ ├── controllers/ # Controller unit tests
│ ├── drivers/ # Driver unit tests
│ ├── models/ # Repository unit tests
│ └── views/ # View unit tests
├── pyproject.toml # Project and tool configuration
├── run.py # Application entry point
└── requirements.txt
- Python 3.10+
- pip
# Clone the repository
git clone https://github.com/schulzdimitri/mintAPI.git
cd mintAPI
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtCreate a .env file in the project root:
JWT_KEY=your_secret_key_here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_HOURS=24| Variable | Description | Example |
|---|---|---|
JWT_KEY |
Secret key used to sign JWT tokens | s3cr3t |
ALGORITHM |
JWT signing algorithm | HS256 |
ACCESS_TOKEN_EXPIRE_HOURS |
Token validity period in hours | 24 |
Run the SQL schema to initialize the SQLite database:
sqlite3 storage.db < init/schema.sqlpython run.pyThe server will start on http://localhost:3000.
Creates a new user account.
Endpoint: POST /bank/registry
Request Body:
{
"username": "johndoe",
"password": "strongpassword"
}Success Response — 201 Created:
{
"type": "User",
"count": 1,
"username": "johndoe"
}Authenticates a user and returns a JWT token.
Endpoint: POST /bank/login
Request Body:
{
"username": "johndoe",
"password": "strongpassword"
}Success Response — 200 OK:
{
"access": true,
"username": "johndoe",
"autorization": "<jwt_token>"
}Updates the balance of a user. Requires JWT authentication.
Endpoint: PATCH /bank/balance/:user_id
Headers:
| Header | Description |
|---|---|
Authorization |
Bearer <jwt_token> |
uid |
The ID of the authenticated user |
Request Body:
{
"new_balance": 1500.00
}Success Response — 200 OK:
{
"type": "User",
"count": 1,
"new_balance": 1500.00
}Error Responses:
| Status | Description |
|---|---|
400 |
Bad Request — invalid or missing fields |
401 |
Unauthorized — invalid or missing token |
404 |
Not Found — user does not exist |
pytestTests live in the tests/ directory, mirroring the structure of src/. Test files follow the test_*.py naming convention. Configuration is managed via pyproject.toml.
mintAPI follows Clean Architecture principles, keeping business logic decoupled from frameworks and infrastructure:
Routes → Composers → Views → Controllers → Models/Drivers
- Routes — Flask Blueprints; only handle HTTP input/output.
- Composers — Wire dependencies together (dependency injection).
- Views — Adapt HTTP requests, invoke controllers, and format responses.
- Controllers — Pure business logic; no framework dependencies.
- Models — Data access layer (repository pattern over SQLite).
- Drivers — Low-level utilities (JWT, bcrypt).
- Middlewares — Cross-cutting concerns (JWT verification).