|
4 | 4 |
|
5 | 5 | [](https://openstacks.dev) |
6 | 6 | [](LICENSE) |
7 | | -[]() |
| 7 | +[]() |
| 8 | +[]() |
8 | 9 |
|
9 | 10 | > The API layer for OpenStacks — connecting database to frontend. |
10 | 11 |
|
11 | 12 | --- |
12 | 13 |
|
13 | | -## Status |
| 14 | +## Quick Start |
14 | 15 |
|
15 | | -**This repository is in early development.** The architecture and goals are documented below, but the FastAPI application has not yet been implemented. Contributions are welcome to help build this out. |
| 16 | +```bash |
| 17 | +# Clone and install |
| 18 | +git clone https://github.com/Varnasr/BridgeStack.git |
| 19 | +cd BridgeStack |
| 20 | +pip install -r requirements.txt |
16 | 21 |
|
17 | | -## Vision |
| 22 | +# Run the API |
| 23 | +uvicorn app.main:app --reload |
18 | 24 |
|
19 | | -BridgeStack will provide a REST API layer connecting [RootStack](https://github.com/Varnasr/RootStack) (database) to [ViewStack](https://github.com/Varnasr/ViewStack) (frontend): |
| 25 | +# Open docs |
| 26 | +# http://localhost:8000/docs |
| 27 | +``` |
| 28 | + |
| 29 | +### With Docker |
20 | 30 |
|
21 | | -- **FastAPI application** with auto-generated API documentation |
22 | | -- **Data models** mapped to RootStack schemas |
23 | | -- **RESTful endpoints** for querying development sector data |
24 | | -- **Authentication** for write operations |
| 31 | +```bash |
| 32 | +docker compose up |
| 33 | +``` |
25 | 34 |
|
26 | | -### Planned Architecture |
| 35 | +## Architecture |
27 | 36 |
|
28 | 37 | ``` |
29 | | -RootStack (Database) → BridgeStack (API) → ViewStack (Frontend) |
| 38 | +RootStack (SQLite) → BridgeStack (FastAPI) → ViewStack / EquityStack / FieldStack |
30 | 39 | ``` |
31 | 40 |
|
32 | | -### Planned Structure |
| 41 | +BridgeStack serves as the middleware connecting [RootStack](https://github.com/Varnasr/RootStack) data to all consumer Stacks: |
| 42 | + |
| 43 | +| Stack | Role | Connection | |
| 44 | +|-------|------|------------| |
| 45 | +| [RootStack](https://github.com/Varnasr/RootStack) | SQLite schemas & seed data | Data source | |
| 46 | +| **BridgeStack** (this repo) | REST API (FastAPI) | You are here | |
| 47 | +| [ViewStack](https://github.com/Varnasr/ViewStack) | Frontend dashboards | Consumes API | |
| 48 | +| [EquityStack](https://github.com/Varnasr/EquityStack) | Python analysis workflows | Consumes API | |
| 49 | +| [FieldStack](https://github.com/Varnasr/FieldStack) | R fieldwork tools | Consumes API | |
| 50 | +| [InsightStack](https://github.com/Varnasr/InsightStack) | MEL tools | Consumes API | |
| 51 | +| [SignalStack](https://github.com/Varnasr/SignalStack) | Curated content | Consumes API | |
| 52 | + |
| 53 | +## API Endpoints |
| 54 | + |
| 55 | +All endpoints are prefixed with `/api/v1`. |
| 56 | + |
| 57 | +### Geography |
| 58 | + |
| 59 | +| Method | Endpoint | Description | |
| 60 | +|--------|----------|-------------| |
| 61 | +| GET | `/geography/states` | List all states (filter: `?region=`) | |
| 62 | +| GET | `/geography/states/{id}` | State detail with districts | |
| 63 | +| GET | `/geography/districts` | List districts (filter: `?state_id=`, `?tier=`) | |
| 64 | +| GET | `/geography/districts/{id}` | District detail | |
| 65 | + |
| 66 | +### Sectors |
| 67 | + |
| 68 | +| Method | Endpoint | Description | |
| 69 | +|--------|----------|-------------| |
| 70 | +| GET | `/sectors/` | List all development sectors | |
| 71 | +| GET | `/sectors/{id}` | Sector detail | |
| 72 | + |
| 73 | +### Indicators |
| 74 | + |
| 75 | +| Method | Endpoint | Description | |
| 76 | +|--------|----------|-------------| |
| 77 | +| GET | `/indicators/` | List indicators (filter: `?sector_id=`, `?source=`) | |
| 78 | +| GET | `/indicators/{id}` | Indicator detail with values | |
| 79 | +| GET | `/indicators/values/` | Query data points (filter: `?indicator_id=`, `?state_id=`, `?year=`) | |
| 80 | + |
| 81 | +### Policies |
| 82 | + |
| 83 | +| Method | Endpoint | Description | |
| 84 | +|--------|----------|-------------| |
| 85 | +| GET | `/policies/schemes` | List schemes (filter: `?sector_id=`, `?status=`, `?level=`) | |
| 86 | +| GET | `/policies/schemes/{id}` | Scheme detail with budgets & coverage | |
| 87 | +| GET | `/policies/budgets` | Budget data (filter: `?scheme_id=`, `?fiscal_year=`) | |
| 88 | +| GET | `/policies/coverage` | Coverage data (filter: `?scheme_id=`, `?state_id=`) | |
| 89 | + |
| 90 | +### Tools |
| 91 | + |
| 92 | +| Method | Endpoint | Description | |
| 93 | +|--------|----------|-------------| |
| 94 | +| GET | `/tools/` | List tools (filter: `?stack=`, `?language=`, `?tool_type=`, `?difficulty=`) | |
| 95 | +| GET | `/tools/{id}` | Tool detail | |
| 96 | + |
| 97 | +### Health |
| 98 | + |
| 99 | +| Method | Endpoint | Description | |
| 100 | +|--------|----------|-------------| |
| 101 | +| GET | `/` | API info and ecosystem map | |
| 102 | +| GET | `/health` | Health check | |
| 103 | + |
| 104 | +## Project Structure |
33 | 105 |
|
34 | 106 | ``` |
35 | 107 | BridgeStack/ |
36 | 108 | ├── app/ |
37 | | -│ ├── main.py # FastAPI application entry point |
38 | | -│ ├── routes/ # API endpoint definitions |
39 | | -│ ├── models/ # SQLAlchemy/Pydantic models |
40 | | -│ ├── schemas/ # Request/response schemas |
41 | | -│ └── core/ # Config, database connection, auth |
42 | | -├── tests/ # API tests |
43 | | -├── requirements.txt # Python dependencies |
44 | | -└── docker-compose.yml # Local development setup |
| 109 | +│ ├── main.py # FastAPI app entry point |
| 110 | +│ ├── core/ |
| 111 | +│ │ ├── config.py # Settings (env-configurable) |
| 112 | +│ │ └── database.py # SQLite/SQLAlchemy setup |
| 113 | +│ ├── models/ # SQLAlchemy ORM models |
| 114 | +│ │ ├── geography.py # States, Districts |
| 115 | +│ │ ├── sectors.py # Development sectors |
| 116 | +│ │ ├── indicators.py # Indicators & values |
| 117 | +│ │ ├── policies.py # Schemes, budgets, coverage |
| 118 | +│ │ └── tools.py # OpenStacks tool catalog |
| 119 | +│ ├── schemas/ # Pydantic response schemas |
| 120 | +│ │ ├── geography.py |
| 121 | +│ │ ├── sectors.py |
| 122 | +│ │ ├── indicators.py |
| 123 | +│ │ ├── policies.py |
| 124 | +│ │ └── tools.py |
| 125 | +│ └── routes/ # API route handlers |
| 126 | +│ ├── geography.py |
| 127 | +│ ├── sectors.py |
| 128 | +│ ├── indicators.py |
| 129 | +│ ├── policies.py |
| 130 | +│ └── tools.py |
| 131 | +├── tests/ |
| 132 | +│ └── test_api.py # 14 endpoint tests |
| 133 | +├── requirements.txt |
| 134 | +├── Dockerfile |
| 135 | +└── docker-compose.yml |
45 | 136 | ``` |
46 | 137 |
|
47 | | -## How to Contribute |
| 138 | +## Configuration |
| 139 | + |
| 140 | +Environment variables (prefix `BRIDGE_`): |
| 141 | + |
| 142 | +| Variable | Default | Description | |
| 143 | +|----------|---------|-------------| |
| 144 | +| `BRIDGE_DATABASE_URL` | `sqlite:///./rootstack.db` | Database connection string | |
| 145 | +| `BRIDGE_DEBUG` | `false` | Enable debug mode | |
| 146 | +| `BRIDGE_CORS_ORIGINS` | `["*"]` | Allowed CORS origins | |
| 147 | + |
| 148 | +## Using with RootStack |
| 149 | + |
| 150 | +To populate the database, clone and run [RootStack](https://github.com/Varnasr/RootStack) setup, then point BridgeStack at the generated SQLite file: |
48 | 151 |
|
49 | | -This is a great repo to contribute to if you have experience with: |
50 | | -- FastAPI or similar Python web frameworks |
51 | | -- REST API design |
52 | | -- SQLAlchemy and database integrations |
53 | | -- API testing (pytest, httpx) |
| 152 | +```bash |
| 153 | +# In RootStack directory |
| 154 | +bash scripts/setup.sh |
54 | 155 |
|
55 | | -See the [OpenStacks hub](https://github.com/Varnasr/OpenStacks-for-Change) for ecosystem-wide contribution guidelines. |
| 156 | +# Copy the database to BridgeStack |
| 157 | +cp rootstack.db ../BridgeStack/ |
| 158 | + |
| 159 | +# Start the API |
| 160 | +cd ../BridgeStack |
| 161 | +uvicorn app.main:app --reload |
| 162 | +``` |
| 163 | + |
| 164 | +## Running Tests |
| 165 | + |
| 166 | +```bash |
| 167 | +pytest tests/ -v |
| 168 | +``` |
| 169 | + |
| 170 | +## How to Contribute |
56 | 171 |
|
57 | | -## How It Connects |
| 172 | +See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. Areas where contributions are welcome: |
58 | 173 |
|
59 | | -| Stack | Role | Link | |
60 | | -|-------|------|------| |
61 | | -| [RootStack](https://github.com/Varnasr/RootStack) | Database schemas & seed data | Provides data to BridgeStack | |
62 | | -| **BridgeStack** (this repo) | API backend (FastAPI) | You are here | |
63 | | -| [ViewStack](https://github.com/Varnasr/ViewStack) | Frontend UI | Consumes BridgeStack API | |
| 174 | +- Additional query endpoints and aggregations |
| 175 | +- Authentication for write operations |
| 176 | +- Pagination and rate limiting |
| 177 | +- WebSocket support for real-time data |
| 178 | +- PostgreSQL adapter |
64 | 179 |
|
65 | 180 | ## License |
66 | 181 |
|
|
0 commit comments