Skip to content

Commit da338e5

Browse files
Add CLAUDE.md documentation for AI-assisted development
Create comprehensive guide covering project architecture, API client design with SSL handling, date range management, CLI patterns, development commands, version management, and REST API integration details to help future Claude Code instances work effectively in this codebase. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent d261f6f commit da338e5

1 file changed

Lines changed: 154 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a Python CLI tool for interacting with Dhaka Electric Supply Company Limited (DESCO) prepaid electricity account APIs. It provides read-only access to balance, customer information, monthly consumption, and recharge history through a command-line interface.
8+
9+
## Architecture
10+
11+
### Core Components
12+
13+
**desco/desco.py** - API Client Layer
14+
- `DescoPrepaid` class handles all HTTP communication with DESCO endpoints
15+
- Base URL: `https://prepaid.desco.org.bd/api/tkdes/customer`
16+
- **No authentication required** - only account number needed
17+
- SSL verification disabled with `verify=False` due to DESCO's certificate issues
18+
- urllib3 warnings suppressed via `urllib3.disable_warnings()`
19+
- Type hints throughout using `typing` module
20+
- Methods return tuple of `(data, headers)` or `List[List[str]]`
21+
22+
**desco/main.py** - CLI Layer
23+
- Click-based CLI using decorator pattern (`@app.command(name="...")`)
24+
- Commands use `--accountid` / `-a` option (STRING type, not INT)
25+
- Error handling through `handle_api_error` decorator wrapper
26+
- Entry point: `app()` function mapped to `desco-cli` in pyproject.toml
27+
- Uses tabulate for formatted output display
28+
29+
**desco/__init__.py** - Package Entry Point
30+
- Exports `DescoPrepaid` class for programmatic use
31+
- Version controlled by GitHub Actions during release (format: `1.{run_number}.0`)
32+
33+
### API Design Pattern
34+
35+
All API methods follow this pattern:
36+
1. Build params dict with `accountNo` as base
37+
2. Add method-specific params (date ranges for history queries)
38+
3. Call `_make_request(endpoint, params)` helper
39+
4. Parse JSON response from `response['data']`
40+
5. Return formatted data structure
41+
42+
### Date Range Handling
43+
44+
Historical data methods (`get_recharge_history`, `get_monthly_consumption`) use:
45+
- `DEFAULT_HISTORY_DAYS = 335` (~11 months)
46+
- Auto-calculate `dateFrom` and `dateTo` using `datetime` and `timedelta`
47+
- Date format: `"%Y-%m-%d"` for recharge, `"%Y-%m"` for monthly consumption
48+
49+
### API Endpoints
50+
51+
```python
52+
ENDPOINTS = {
53+
'customer_info': '/getCustomerInfo',
54+
'balance': '/getBalance',
55+
'monthly_consumption': '/getCustomerMonthlyConsumption',
56+
'recharge_history': '/getRechargeHistory'
57+
}
58+
```
59+
60+
## Development Commands
61+
62+
### Setup
63+
```bash
64+
# Install in development mode
65+
pip install -e .
66+
67+
# Or create virtual environment first
68+
python -m venv venv
69+
source venv/bin/activate # Windows: venv\Scripts\activate
70+
pip install -e .
71+
```
72+
73+
### Testing the CLI
74+
```bash
75+
# Test balance check
76+
desco-cli get-balance -a 987654321
77+
78+
# Test customer info
79+
desco-cli get-customer-info -a 987654321
80+
81+
# Test recharge history
82+
desco-cli get-recharge-history -a 987654321
83+
84+
# Test monthly consumption
85+
desco-cli get-monthly-consumption -a 987654321
86+
```
87+
88+
### Building
89+
```bash
90+
# Build distribution packages
91+
python -m pip install build
92+
python -m build
93+
94+
# Output: dist/*.whl and dist/*.tar.gz
95+
```
96+
97+
## Version Management
98+
99+
- Version is defined in `desco/__init__.py` as `__version__ = "1.0.0"`
100+
- GitHub Actions workflow (`.github/workflows/pypi.yml`) auto-updates version on push to main
101+
- Version format: `1.{github.run_number}.0`
102+
- Workflow uses sed to replace version string: `sed -i "s/__version__ = \".*\"/__version__ = \"$VERSION\"/" desco/__init__.py`
103+
104+
## Publishing
105+
106+
Automated via GitHub Actions on push to main:
107+
1. Version number updated automatically
108+
2. Build artifacts created with `python -m build`
109+
3. Published to PyPI using trusted publisher with OIDC token
110+
111+
Manual workflow dispatch also available via GitHub Actions UI.
112+
113+
## API Response Structures
114+
115+
### Balance Response
116+
Returns `List[List[str]]` of `[key, value]` pairs from `response['data']`:
117+
- accountNo, meterNo, balance, currentMonthConsumption, readingTime
118+
119+
### Customer Info Response
120+
Returns `List[List[str]]` of `[key, value]` pairs from `response['data']`:
121+
- accountNo, contactNo, customerName, feederName, installationAddress
122+
- installationDate, meterNo, phaseType, registerDate, sanctionLoad
123+
- tariffSolution, meterModel, transformer, SDName
124+
125+
### Recharge History Response
126+
Returns tuple `(data, headers)`:
127+
- Headers: `['rechargeDate', 'totalAmount', 'vat', 'energyAmount']`
128+
- Data extracted from `response['data']` array, mapping `VAT` (uppercase) to vat
129+
130+
### Monthly Consumption Response
131+
Returns tuple `(data, headers)`:
132+
- Headers: `['month', 'consumedTaka', 'consumedUnit', 'maximumDemand']`
133+
- Data extracted from `response['data']` array
134+
135+
## CLI Design Pattern
136+
137+
Commands using `@app.command(name="...")` decorator pattern (different from bpdb's `app.add_command()` pattern):
138+
1. Click decorator defines command with `--accountid` option
139+
2. `@handle_api_error` decorator catches exceptions and exits with error code 1
140+
3. Print status message with emoji
141+
4. Instantiate `DescoPrepaid(accountid)`
142+
5. Call API method
143+
6. Format output with tabulate
144+
145+
## Important Notes
146+
147+
- This is part of a multi-repository project with sibling repositories: `python-bpdb` and `python-nesco` (similar utility tools for other Bangladesh power companies)
148+
- All three repositories share similar CLI structure but different API integration patterns
149+
- **No authentication or token storage** - simpler than bpdb
150+
- SSL verification disabled - DESCO's certificate has issues
151+
- API uses HTTPS but with `verify=False`
152+
- Type hints included for better IDE support
153+
- Dependencies include `urllib3` explicitly (not in other projects)
154+
- Account ID treated as STRING in CLI (not INT like nesco)

0 commit comments

Comments
 (0)