Skip to content

Commit ce9a2d3

Browse files
Merge pull request #113 from goldlabelapps/staging
Restructure docs and simplify main README
2 parents 82ee18c + 270520f commit ce9a2d3

13 files changed

Lines changed: 423 additions & 93 deletions

File tree

README.md

Lines changed: 14 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,82 +2,23 @@
22

33
![Python°](app/static/python.png)
44

5-
> Production ready, open-source FastAPI application with PostgreSQL and blazing-fast full-text search
5+
This project is a FastAPI-based backend for collecting, organizing, and serving business data. It brings together PostgreSQL storage, API endpoints, and a few practical automation features such as AI prompt handling, email sending, and data integration with services like GitHub, Flickr, and YouTube.
66

7-
#### Overview
7+
The app is designed to be a reliable backend layer for internal tools, admin workflows, or front-end applications that need structured data and simple API access.
88

9-
This project provides a scalable API backend using FastAPI and PostgreSQL, featuring:
9+
## Table of contents
1010

11-
- Automatic full-text search on all text fields (via tsvector)
12-
- Endpoints for health checks, product management, prompt handling (via `/prompt`), notify email, and prospect management
13-
- Efficient ingestion and processing of large CSV files
11+
- [Project overview](docs/overview.md)
12+
- [Architecture](docs/architecture.md)
13+
- [Setup and development](docs/setup.md)
14+
- [API reference](docs/api.md)
15+
- [Integrations](docs/integrations.md)
16+
- [Database](docs/database.md)
17+
- [Testing](docs/testing.md)
18+
- [Deployment](docs/deployment.md)
1419

15-
#### Features
20+
## Quick note
1621

17-
- **Python 3.11+**
18-
- **FastAPI** — Modern, high-performance REST API
19-
- **PostgreSQL** — Robust relational database
20-
- **tsvector + GIN** — Superfast full-text search
21-
- **Uvicorn** — Lightning-fast ASGI server
22-
- **Pytest** — Comprehensive testing
22+
If you want to get started, the best place to begin is the [setup guide](docs/setup.md). If you want to understand the system as a whole, start with the [overview](docs/overview.md).
2323

24-
#### Install & Use
25-
26-
#### 1. Clone & Setup Environment
27-
28-
```bash
29-
git clone https://github.com/goldlabelapps/python.git
30-
cd python
31-
cp .env.sample .env # Add your Postgres credentials and settings
32-
python -m venv venv
33-
source venv/bin/activate
34-
pip install -r requirements.txt
35-
```
36-
37-
#### 2. Run the App
38-
39-
```bash
40-
uvicorn app.main:app --reload
41-
```
42-
43-
Visit [localhost:8000](http://localhost:8000) or [onrender](https://nx-ai.onrender.com)
44-
45-
#### API Documentation
46-
47-
FastAPI auto-generates interactive docs:
48-
49-
- [Swagger UI](https://nx-ai.onrender.com/docs)
50-
- [ReDoc](https://nx-ai.onrender.com/redoc)
51-
52-
#### Notable Endpoints
53-
54-
- `GET /health` — Health check
55-
- `GET /prompt` or `GET /prompts` — Prompt table metadata (`record_count`, `columns`)
56-
- `POST /prompt` — LLM prompt completion (formerly `/llm`)
57-
- `GET/POST /notify/email` — Send email via Resend API (see implementation in `app/api/notify/email.py`)
58-
- `GET /prospects` — Paginated prospects
59-
- `POST /prospects/process` — Bulk CSV ingestion
60-
61-
#### Full-Text Search (tsvector)
62-
63-
The `prospects` table includes a `search_vector` column (type: tsvector) computed from all text fields on insert/update. A GIN index enables fast, scalable full-text search:
64-
65-
```sql
66-
SELECT * FROM prospects WHERE search_vector @@ plainto_tsquery('english', 'search terms');
67-
```
68-
69-
**How it works:**
70-
- On every insert/update, `search_vector` is computed using PostgreSQL's `to_tsvector('english', ...)`.
71-
- The GIN index (`idx_prospects_search_vector`) enables efficient search across large datasets.
72-
73-
#### Processing Large CSV Files
74-
75-
The `/prospects/process` endpoint supports robust ingestion of large CSVs (e.g., 1300+ rows, 300KB+), following the same normalization and insertion pattern as `/prospects/seed` but optimized for scale.
76-
77-
#### Contributing
78-
79-
Contributions welcome. Please open issues or submit pull requests.
80-
81-
#### License
82-
83-
This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
24+
Before deployment, make sure the frontend origin is included in `ALLOWED_ORIGINS`; otherwise browser requests from that domain will be rejected by CORS.

app/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Python° - FastAPI, Postgres, tsvector"""
22

33
# Current Version
4-
__version__ = "3.1.3"
4+
__version__ = "3.1.4"
55

app/main.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,28 @@
1515
version=__version__,
1616
)
1717

18-
# CORS middleware for development
18+
def get_allowed_origins() -> list[str]:
19+
configured_origins = os.getenv("ALLOWED_ORIGINS", "")
20+
if configured_origins:
21+
return [origin.strip() for origin in configured_origins.split(",") if origin.strip()]
22+
23+
return [
24+
"http://localhost:3000",
25+
"http://localhost:8000",
26+
"http://127.0.0.1:3000",
27+
"http://127.0.0.1:8000",
28+
"https://goldlabel.pro"
29+
]
30+
31+
32+
# CORS middleware with an explicit, environment-driven allow-list.
1933
app.add_middleware(
2034
CORSMiddleware,
21-
allow_origins=[
22-
"http://localhost:1999",
23-
"http://localhost:1998",
24-
"http://localhost:1975",
25-
"http://localhost:1980",
26-
"http://localhost:2027",
27-
"http://localhost:2020",
28-
"http://localhost:2000",
29-
"https://goldlabel.pro",
30-
"https://nx-admin.goldlabel.pro",
31-
"https://free.goldlabel.pro",
32-
"https://listingslab.com",
33-
"https://ed-tech.co",
34-
"https://notheretofuckspiders.art",
35-
],
36-
allow_credentials=True,
37-
allow_methods=["*"],
38-
allow_headers=["*"]
35+
allow_origins=get_allowed_origins(),
36+
allow_origin_regex=os.getenv("CORS_ALLOW_ORIGIN_REGEX"),
37+
allow_credentials=False,
38+
allow_methods=["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
39+
allow_headers=["Accept", "Accept-Language", "Content-Language", "Content-Type", "Authorization", "X-API-Key"],
3940
)
4041

4142

app/static/SVGIcon.sketch

-7.07 KB
Binary file not shown.

docs/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Project Documentation
2+
3+
This directory contains the main documentation for the Python backend service in this repository.
4+
5+
## Documentation map
6+
7+
- [Overview](overview.md) — What the application does and why it exists
8+
- [Architecture](architecture.md) — Application structure, runtime flow, and major components
9+
- [Setup](setup.md) — Installation, environment variables, and local development
10+
- [API Reference](api.md) — Routes, request patterns, and response shape
11+
- [Integrations](integrations.md) — Gemini, email, and third-party data connectors
12+
- [Database](database.md) — PostgreSQL usage, schemas, and search capabilities
13+
- [Testing](testing.md) — How the project is tested and how to run tests
14+
- [Deployment](deployment.md) — Render-style deployment considerations and runtime configuration
15+
16+
## Quick start
17+
18+
1. Install dependencies with `pip install -r requirements.txt`
19+
2. Create a local environment file with the required variables
20+
3. Start the app with `uvicorn app.main:app --reload`
21+
4. Open the interactive documentation at `/docs`
22+
23+
## Project summary
24+
25+
This repository is a FastAPI-based backend that exposes APIs for data storage, retrieval, and automation. It is designed to support business workflows involving prospects, prompts, orders, queue operations, and integrations with external services.

docs/api.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# API Reference
2+
3+
## Core endpoints
4+
5+
### Root
6+
7+
- `GET /` — returns basic service metadata such as title, version, and base URL
8+
9+
### Health
10+
11+
- `GET /health` — health check endpoint used to confirm the service is available
12+
13+
### Prompt endpoints
14+
15+
- `GET /prompt` or `GET /prompts` — returns metadata for the prompt table, including row count and columns
16+
- `POST /prompt` — accepts a prompt payload and returns either cached output or a generated response from Gemini
17+
18+
### Prospects
19+
20+
- `GET /prospects` — returns paginated prospects, with optional filtering and search
21+
- `GET /prospects/{id}` — returns one prospect and any related prompt records
22+
- `PATCH /prospects/{id}` — updates flag and hide state
23+
- `PATCH /prospects/factoryreset` — resets prospect flags and hidden state
24+
25+
### Orders
26+
27+
- `GET /orders` — returns paginated and filterable order data
28+
29+
### Queue routes
30+
31+
The queue module exposes routes for creating, reading, deleting, emptying, and altering queue-related data.
32+
33+
### Notifications
34+
35+
- `GET /notify/email` — returns usage information for the email endpoint
36+
- `POST /notify/email` — sends an email through Resend
37+
38+
### External data endpoints
39+
40+
- `GET /github` — returns GitHub-related table data
41+
- `GET /flickr` — returns Flickr-related table data
42+
- `GET /youtube` — returns YouTube-related table data
43+
44+
## Response style
45+
46+
Most endpoints return a response object shaped like:
47+
48+
```json
49+
{
50+
"meta": {
51+
"status": "success",
52+
"message": "..."
53+
},
54+
"data": {}
55+
}
56+
```
57+
58+
## Authentication
59+
60+
Some routes depend on an API key header:
61+
62+
```http
63+
X-API-Key: your_key
64+
```
65+
66+
The key is validated through the shared authentication utility.

docs/architecture.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Architecture
2+
3+
## Runtime stack
4+
5+
The application is built around the following core components:
6+
7+
- FastAPI for HTTP routing and request handling
8+
- PostgreSQL for persistent storage
9+
- Pydantic for request/response validation
10+
- Uvicorn as the ASGI server
11+
- Python dotenv for environment configuration
12+
13+
## Application entry point
14+
15+
The main application is initialized in [app/main.py](../app/main.py). It creates the FastAPI app, configures CORS, mounts static files, and includes the API router.
16+
17+
## Router structure
18+
19+
The main router is assembled in [app/api/routes.py](../app/api/routes.py). It includes multiple route modules for:
20+
21+
- root metadata
22+
- health checks
23+
- prompt endpoints
24+
- prospects
25+
- orders
26+
- queue routes
27+
- notifications
28+
- GitHub, Flickr, and YouTube integrations
29+
30+
## Request flow
31+
32+
A typical request follows this pattern:
33+
34+
1. The FastAPI app receives an HTTP request
35+
2. A route handler validates or parses input
36+
3. The handler connects to PostgreSQL through the database utilities
37+
4. Queries or updates are executed
38+
5. A standardized response payload is returned using the shared metadata helper
39+
40+
## Core modules
41+
42+
### app/main.py
43+
44+
Defines the application object and global middleware.
45+
46+
### app/api
47+
48+
Contains the route modules and feature-specific endpoints.
49+
50+
### app/utils
51+
52+
Contains shared support code for:
53+
54+
- database connections
55+
- API-key authentication
56+
- response metadata
57+
- health checks
58+
59+
## Design characteristics
60+
61+
The architecture favors a simple, service-oriented approach:
62+
63+
- route modules are feature focused
64+
- database access is centralized
65+
- shared metadata responses keep output consistent
66+
- integrations are isolated into dedicated modules

docs/database.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Database
2+
3+
## Storage approach
4+
5+
The application relies on PostgreSQL for persistent storage. Database connection helpers are defined in [app/utils/db.py](../app/utils/db.py).
6+
7+
## Main data areas
8+
9+
The app uses several logical data areas:
10+
11+
- prospects
12+
- prompt history
13+
- orders
14+
- queue-related records
15+
- platform-specific tables for GitHub, Flickr, and YouTube
16+
17+
## Search capabilities
18+
19+
The README describes PostgreSQL full-text search support for prospects using `tsvector` and a GIN index. This allows efficient search across text fields.
20+
21+
## Why the database is central
22+
23+
The database is the system of record for most application features. It provides:
24+
25+
- reliable persistence
26+
- filtering and pagination support
27+
- search ability
28+
- historical storage for AI prompt outputs and business records
29+
30+
## Operational note
31+
32+
The app expects database connection settings to be present in the environment. If the database is unavailable, many endpoints will not function properly.

docs/deployment.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Deployment
2+
3+
## Deployment target
4+
5+
The project is compatible with deployment platforms such as Render. The repository includes a [render.yaml](../render.yaml) configuration file.
6+
7+
## Runtime considerations
8+
9+
For deployment, ensure the following are configured:
10+
11+
- database environment variables
12+
- `PYTHON_KEY` if protected routes are used
13+
- `GEMINI_API_KEY` for prompt generation
14+
- `RESEND_API_KEY` for email sending
15+
- `BASE_URL` for environment-aware metadata
16+
- `ALLOWED_ORIGINS` with the exact frontend origin(s) that will call the API from the browser
17+
18+
> Deployment gotcha: CORS will block browser requests unless the frontend URL is explicitly allowed. Before deploying, add the production frontend URL to `ALLOWED_ORIGINS` (for example, `https://your-app.example.com`). If you use a different subdomain or preview URL, include that exact origin as well.
19+
20+
## Recommended deployment checklist
21+
22+
1. Set all required environment variables
23+
2. Ensure PostgreSQL is available and reachable
24+
3. Install Python dependencies
25+
4. Run the application with Uvicorn or the deployment platform's startup command
26+
5. Verify core endpoints such as `/health` and `/docs`
27+
28+
## Notes
29+
30+
Because the app depends on external services and a database, deployment should be treated as a full-stack environment rather than a simple static app.

0 commit comments

Comments
 (0)