Skip to content

Commit 1ebace3

Browse files
authored
Merge pull request #34 from fastapi-startkit/chore/remove-laravel-references
chore: remove all Laravel references from docs
2 parents 99174dd + 2c30402 commit 1ebace3

8 files changed

Lines changed: 180 additions & 14 deletions

File tree

docs/broadcasting.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,76 @@ app = Application(
4242
)
4343
```
4444

45+
### Passing a config object
46+
47+
If your app uses `BroadcastingConfig` to read env-vars explicitly, pass it as a tuple alongside the provider (the same pattern used for `DatabaseProvider`, `FastAPIProvider`, etc.):
48+
49+
```python
50+
from fastapi_startkit.broadcasting import ReverbProvider
51+
from fastapi_startkit.broadcasting.config import BroadcastingConfig
52+
53+
app = Application(
54+
base_path=...,
55+
providers=[
56+
# ... other providers
57+
(ReverbProvider, BroadcastingConfig),
58+
]
59+
)
60+
```
61+
62+
---
63+
64+
## Mounted Pattern
65+
66+
By default `ReverbProvider` registers the Reverb WebSocket server as a standalone ASGI app. When you need the WebSocket endpoint to live **under a sub-path of your existing FastAPI app** (e.g. `/reverb`) — useful when a single-origin constraint applies, or you want to avoid a separate port — mount it from inside your `AppProvider.boot()` method:
67+
68+
```python
69+
# providers/app_provider.py
70+
from fastapi_startkit.providers import Provider
71+
72+
class AppProvider(Provider):
73+
def boot(self) -> None:
74+
from routes.web import router
75+
self.app.fastapi.include_router(router.router)
76+
77+
# Mount Reverb under /reverb — same origin as the FastAPI app
78+
reverb_server = self.app.make('reverb.server')
79+
self.app.fastapi.mount('/reverb', reverb_server.as_starlette_app('local'))
80+
```
81+
82+
> [!IMPORTANT]
83+
> **Order matters.** Call `include_router` **before** `mount`. FastAPI resolves routes in registration order; mounting before the router causes the `/reverb` prefix to shadow any API routes whose paths start with `/r`.
84+
85+
With the mounted pattern the Reverb WebSocket is reachable at:
86+
87+
```
88+
ws://<host>:<port>/reverb/app/<REVERB_APP_KEY>
89+
```
90+
91+
The corresponding `pusher-js` config uses `wsPath` to point the client at the mount point:
92+
93+
```js
94+
import Pusher from "pusher-js";
95+
96+
const pusher = new Pusher("local", {
97+
wsHost: window.location.hostname,
98+
wsPort: Number(window.location.port) || 80,
99+
forceTLS: false,
100+
enabledTransports: ["ws"],
101+
cluster: "mt1",
102+
wsPath: "/reverb", // <-- tells pusher-js to prefix all WS paths
103+
});
104+
```
105+
106+
### When to use the mounted pattern vs the standalone default
107+
108+
| Scenario | Recommendation |
109+
|---|---|
110+
| Single-port deployment (e.g. `dist/` build on `:4545`) | **Mounted** — no second port to manage |
111+
| Separate WebSocket service / different host | Standalone (default) |
112+
| Reverse-proxy that routes `/reverb` to FastAPI | **Mounted** |
113+
| Simplest possible setup, two ports are fine | Standalone (default) |
114+
45115
---
46116

47117
## Configuration
@@ -217,6 +287,8 @@ Install `pusher-js` in your frontend project:
217287
npm install pusher-js
218288
```
219289

290+
### Standalone (separate port)
291+
220292
Connect to the Reverb server — point `wsHost` and `wsPort` at your FastAPI app:
221293

222294
```js
@@ -237,5 +309,99 @@ channel.bind("OrderShipped", (data) => {
237309
});
238310
```
239311

312+
### Mounted (same port, sub-path)
313+
314+
When using the [mounted pattern](#mounted-pattern), add `wsPath` to tell `pusher-js` the mount point:
315+
316+
```js
317+
import Pusher from "pusher-js";
318+
319+
const { hostname, port } = window.location;
320+
321+
const pusher = new Pusher("local", {
322+
wsHost: hostname,
323+
wsPort: port ? Number(port) : 80,
324+
forceTLS: false,
325+
enabledTransports: ["ws"],
326+
cluster: "mt1",
327+
wsPath: "/reverb",
328+
});
329+
330+
const channel = pusher.subscribe("orders.1");
331+
332+
channel.bind("OrderShipped", (data) => {
333+
console.log("Order shipped:", data);
334+
});
335+
```
336+
240337
> [!TIP]
241338
> The first argument to `new Pusher(...)` is the `REVERB_APP_KEY`. It must match the value configured in your `.env` file.
339+
340+
### React hook
341+
342+
A lightweight custom hook that wraps `pusher-js` and returns an accumulated messages array:
343+
344+
```ts
345+
// hooks/useBroadcastChannel.ts
346+
import { useEffect, useRef, useState } from 'react'
347+
import Pusher, { type Channel } from 'pusher-js'
348+
349+
export interface BroadcastMessage {
350+
event: string
351+
data: Record<string, unknown>
352+
receivedAt: number
353+
}
354+
355+
export function useBroadcastChannel(channelName: string): BroadcastMessage[] {
356+
const [messages, setMessages] = useState<BroadcastMessage[]>([])
357+
const pusherRef = useRef<Pusher | null>(null)
358+
const channelRef = useRef<Channel | null>(null)
359+
360+
useEffect(() => {
361+
const { hostname, port } = window.location
362+
363+
const pusher = new Pusher('local', {
364+
wsHost: hostname,
365+
wsPort: port ? Number(port) : 80,
366+
forceTLS: false,
367+
enabledTransports: ['ws'],
368+
cluster: 'mt1',
369+
wsPath: '/reverb',
370+
})
371+
372+
pusherRef.current = pusher
373+
const channel = pusher.subscribe(channelName)
374+
channelRef.current = channel
375+
376+
channel.bind_global((eventName: string, data: Record<string, unknown>) => {
377+
if (eventName.startsWith('pusher:')) return
378+
setMessages(prev => [...prev, { event: eventName, data, receivedAt: Date.now() }])
379+
})
380+
381+
return () => {
382+
channel.unbind_all()
383+
pusher.unsubscribe(channelName)
384+
pusher.disconnect()
385+
}
386+
}, [channelName])
387+
388+
return messages
389+
}
390+
```
391+
392+
Usage:
393+
394+
```tsx
395+
import { useBroadcastChannel } from '@/hooks/useBroadcastChannel'
396+
397+
export function OrderList() {
398+
const messages = useBroadcastChannel('orders')
399+
return (
400+
<ul>
401+
{messages.map((msg, i) => (
402+
<li key={i}>{JSON.stringify(msg.data)}</li>
403+
))}
404+
</ul>
405+
)
406+
}
407+
```

docs/console.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ keywords: cli, console, commands, automation, cleo
77

88
# Console Commands
99

10-
Fastapi Startkit uses [Cleo](https://cleo.readthedocs.io/en/latest/) to provide a powerful command-line interface, inspired by Laravel's Artisan.
10+
Fastapi Startkit uses [Cleo](https://cleo.readthedocs.io/en/latest/) to provide a powerful command-line interface, with an Artisan-style design.
1111

1212
## Creating a Command
1313

docs/database/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ keywords: database, orm, fastapi, python
77

88
# Database
99

10-
Fastapi Startkit ships with a built-in ORM layer powered by **MasoniteORM**, adapted for async Python. It gives you expressive model definitions, an async query builder, migrations, and seeders — all with a Laravel-inspired feel.
10+
Fastapi Startkit ships with a built-in ORM layer powered by **MasoniteORM**, adapted for async Python. It gives you expressive model definitions, an async query builder, migrations, and seeders — all with an expressive, Pythonic feel.
1111

1212
## Installation
1313

@@ -95,7 +95,7 @@ class DatabaseConfig:
9595
"mysql": DatabaseConnection(
9696
driver="mysql",
9797
host=env("DB_HOST", "127.0.0.1"),
98-
database=env("DB_DATABASE", "laravel"),
98+
database=env("DB_DATABASE", "app"),
9999
username=env("DB_USERNAME", "root"),
100100
password=env("DB_PASSWORD", ""),
101101
port=env("DB_PORT", "3306"),

docs/database/seeds.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ class PostSeeder(Seeder):
6666
return
6767

6868
# Create tags
69-
tag_laravel = await Tag.first_or_create({"name": "laravel"})
69+
tag_python = await Tag.first_or_create({"name": "python"})
7070
tag_fastapi = await Tag.first_or_create({"name": "fastapi"})
7171
tag_database = await Tag.first_or_create({"name": "database"})
7272

7373
# Create first post and attach tags
7474
post1 = await Post.create(
7575
user_id=user.id,
76-
title="Laravel and Databases",
77-
content="This is a post about Laravel and its database capabilities."
76+
title="Python and Databases",
77+
content="This is a post about Python and its database capabilities."
7878
)
79-
await PostTag.first_or_create({"post_id": post1.id, "tag_id": tag_laravel.id})
79+
await PostTag.first_or_create({"post_id": post1.id, "tag_id": tag_python.id})
8080
await PostTag.first_or_create({"post_id": post1.id, "tag_id": tag_database.id})
8181

8282
# Create second post and attach tags

docs/fastapi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class MyFastAPIProvider(Provider):
7171

7272
## Routing
7373

74-
Fastapi Startkit supports the standard FastAPI routing approach as well as a `Router` wrapper that adds a more expressive, Laravel-inspired API on top.
74+
Fastapi Startkit supports the standard FastAPI routing approach as well as a `Router` wrapper that adds a more expressive, MVC-style API on top.
7575

7676
### Standard FastAPI Routing
7777

@@ -108,7 +108,7 @@ class MyFastAPIProvider(Provider):
108108

109109
### Startkit Router
110110

111-
Fastapi Startkit also ships a `Router` wrapper that lets you register routes imperatively — passing the path and endpoint as arguments instead of using decorators. This style is closer to how Laravel and other MVC frameworks handle routing.
111+
Fastapi Startkit also ships a `Router` wrapper that lets you register routes imperatively — passing the path and endpoint as arguments instead of using decorators. This style is closer to how MVC frameworks handle routing.
112112

113113
#### Defining Routes
114114

docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jsonLd:
1313
"name": "Fastapi Startkit Team"
1414
---
1515

16-
Fastapi Startkit is a modular, provider-driven, Laravel-inspired framework for building robust FastAPI applications with minimal boilerplate. That said, **it doesn't enforce you to use FastAPI at all** — You can build entirely headless CLI utilities, cron scripts, or background task workers and still get access to the full suite of infrastructure components such as logging, database, configuration, and dependency injection.
16+
Fastapi Startkit is a modular, provider-driven framework for building robust FastAPI applications with minimal boilerplate. That said, **it doesn't enforce you to use FastAPI at all** — You can build entirely headless CLI utilities, cron scripts, or background task workers and still get access to the full suite of infrastructure components such as logging, database, configuration, and dependency injection.
1717

1818
## Prerequisites
1919

@@ -82,7 +82,7 @@ python main.py serve
8282

8383
## Way 2: Structured Setup (Recommended)
8484

85-
For larger applications, we recommend a Laravel-inspired structure for better organization and maintainability.
85+
For larger applications, we recommend a layered, provider-driven structure for better organization and maintainability.
8686

8787
### Option A: Use the Boilerplate Repository
8888
The fastest way to get a fully configured project (including FastAPI, logging, database support, etc.) is to clone our official boilerplate:

docs/logging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ keywords: logging, monitoring, debugging, fastapi
77

88
# Logging
99

10-
Fastapi Startkit provides a powerful, modular, and Laravel-inspired logging system. It is built upon the concepts of **Drivers** and **Channels**, allowing you to easily route logs to files, terminal, Slack, or other services.
10+
Fastapi Startkit provides a powerful, modular logging system. It is built upon the concepts of **Drivers** and **Channels**, allowing you to easily route logs to files, terminal, Slack, or other services.
1111

1212
> [!NOTE]
1313
> This logging system is based on [Masonite Logging](https://docs.masoniteproject.com/v3.0/official-packages/masonite-logging). We give full credit to the Masonite team for the architecture and design patterns used here.

index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jsonLd:
66
"name": "Fastapi Startkit"
77
"operatingSystem": "Linux, macOS, Windows"
88
"applicationCategory": "DeveloperApplication"
9-
"description": "A modular, Laravel-inspired framework for building robust FastAPI applications."
9+
"description": "A modular, provider-driven framework for building robust FastAPI applications."
1010
"offers":
1111
"@type": "Offer"
1212
"price": "0"
@@ -25,7 +25,7 @@ features:
2525
details: Built for FastAPI, but completely optional. Use it as a lightweight core for any Python application.
2626
icon: ⚡️
2727
- title: Console Commands
28-
details: Powerful CLI powered by Cleo, providing a Laravel-inspired developer experience.
28+
details: Powerful CLI powered by Cleo, providing an expressive Artisan-style developer experience.
2929
icon: 💻
3030
- title: Advanced Logging
3131
details: Robust logging with dynamic configuration support and customizable channels.

0 commit comments

Comments
 (0)