Skip to content

Commit 95c8a5e

Browse files
committed
feat: Introduce FastAPI backend with API type generation setup and update project configuration.
1 parent 8678ee4 commit 95c8a5e

File tree

6 files changed

+137
-1
lines changed

6 files changed

+137
-1
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,8 @@ logs/
137137
# GENERATED FILES
138138
# ========================================
139139
last_generated_post.txt
140+
141+
# Shared contracts (auto-generated from OpenAPI)
142+
shared/contracts/*.ts
143+
shared/contracts/*.json
144+
!shared/contracts/README.md

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,31 @@ cd web && npm run dev
211211

212212
Open [http://localhost:3000](http://localhost:3000) to access the dashboard.
213213

214+
### API Documentation
215+
216+
The FastAPI backend provides OpenAPI documentation at stable URLs:
217+
218+
| Endpoint | Description |
219+
|----------|-------------|
220+
| `/openapi.json` | OpenAPI 3.0 specification (JSON) |
221+
| `/docs` | Interactive Swagger UI documentation |
222+
| `/redoc` | ReDoc alternative documentation |
223+
224+
**Local development:**
225+
- OpenAPI spec: [http://localhost:8000/openapi.json](http://localhost:8000/openapi.json)
226+
- Swagger UI: [http://localhost:8000/docs](http://localhost:8000/docs)
227+
- ReDoc: [http://localhost:8000/redoc](http://localhost:8000/redoc)
228+
229+
**Production:** The same endpoints are available at your deployed backend URL.
230+
231+
```bash
232+
# Download OpenAPI spec for code generation
233+
curl http://localhost:8000/openapi.json > openapi.json
234+
235+
# Or in production
236+
curl https://your-backend.railway.app/openapi.json > openapi.json
237+
```
238+
214239
---
215240

216241
## Project Structure

backend/app.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,35 @@
137137
api_limiter = None
138138
RateLimitExceededError = Exception
139139

140-
app = FastAPI(title="LinkedIn Post Bot API")
140+
app = FastAPI(
141+
title="LinkedIn Post Bot API",
142+
description="""
143+
AI-powered LinkedIn content automation API.
144+
145+
## Features
146+
- Generate LinkedIn posts from GitHub activity
147+
- Multiple AI writing templates (Standard, Build in Public, Thought Leadership, Job Search)
148+
- Post history and analytics
149+
- Image selection from Unsplash
150+
- Scheduled posting
151+
152+
## OpenAPI Documentation
153+
- OpenAPI JSON: `/openapi.json`
154+
- Interactive Docs (Swagger): `/docs`
155+
- ReDoc: `/redoc`
156+
""",
157+
version="1.0.0",
158+
openapi_url="/openapi.json", # Explicit stable URL for OpenAPI spec
159+
docs_url="/docs", # Swagger UI
160+
redoc_url="/redoc", # ReDoc alternative
161+
contact={
162+
"name": "LinkedIn Post Bot",
163+
"url": "https://github.com/cliff-de-tech/Linkedin-Post-Bot",
164+
},
165+
license_info={
166+
"name": "MIT",
167+
},
168+
)
141169

142170
# Initialize databases
143171
if init_db:

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "linkedin-post-bot",
3+
"version": "1.0.0",
4+
"description": "AI-powered LinkedIn content automation from GitHub activity",
5+
"private": true,
6+
"scripts": {
7+
"dev": "cd web && npm run dev",
8+
"build": "cd web && npm run build",
9+
"start": "cd web && npm run start",
10+
"lint": "cd web && npm run lint",
11+
"backend": "cd backend && python app.py",
12+
"generate:types": "curl -s http://localhost:8000/openapi.json > shared/contracts/openapi.json && npx openapi-typescript shared/contracts/openapi.json -o shared/contracts/api.ts",
13+
"postinstall": "echo 'Run npm run generate:types after starting backend to generate API types'"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/cliff-de-tech/Linkedin-Post-Bot.git"
18+
},
19+
"keywords": [
20+
"linkedin",
21+
"automation",
22+
"github",
23+
"ai",
24+
"content-generation"
25+
],
26+
"author": "Clifford Opoku-Sarkodie",
27+
"license": "MIT",
28+
"devDependencies": {
29+
"openapi-typescript": "^7.0.0"
30+
}
31+
}

shared/contracts/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Shared API Contracts
2+
3+
This directory contains TypeScript types auto-generated from the FastAPI OpenAPI specification.
4+
5+
## Purpose
6+
7+
- **Type Safety**: Ensures frontend API calls match backend schemas
8+
- **Auto-generated**: Types are generated from `/openapi.json`
9+
- **Single Source of Truth**: Backend schemas define the contract
10+
11+
## Regenerating Types
12+
13+
Run the generation script from the project root:
14+
15+
```bash
16+
npm run generate:types
17+
```
18+
19+
Or manually:
20+
21+
```bash
22+
# Ensure backend is running
23+
curl http://localhost:8000/openapi.json > shared/contracts/openapi.json
24+
25+
# Generate TypeScript types (requires openapi-typescript)
26+
npx openapi-typescript shared/contracts/openapi.json -o shared/contracts/api.ts
27+
```
28+
29+
## Usage
30+
31+
```typescript
32+
import type { paths, components } from '@/shared/contracts/api';
33+
34+
// Use generated types
35+
type Post = components['schemas']['SavePostRequest'];
36+
type GenerateResponse = paths['/api/post/generate-batch']['post']['responses']['200'];
37+
```
38+
39+
## Files
40+
41+
| File | Description |
42+
|------|-------------|
43+
| `api.ts` | Generated TypeScript types (do not edit manually) |
44+
| `openapi.json` | Cached OpenAPI spec (auto-updated) |
45+
| `README.md` | This file |
46+
47+
> ⚠️ Files in this directory (except README.md) are auto-generated. Do not edit manually.

user_settings.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)