Modularize Flows
Issue
My application grew so large that I was having trouble maintaining it and the code was becoming spaghetti code.
Possible Solution
As our projects grow we will need to implement a better way to maintain the project, in this case it is highly recommended to implement a module view.
In the following example we will show how we have migrated the modules to a directory, as well as the provider and the database.
import { createBot } from '@builderbot/bot';
import { flow } from "./flow";
import { database } from "./database";
import { provider } from "./provider";
import { ai } from "./services/ai";
const main = async () => {
await createBot({
flow,
provider,
database,
},
extensions: {
ai // Dependency AI
})
provider.initHttpServer(3000)
}
main()
An example of the scaffolding you can use in your project. Or a more user friendly folder structure.
structure
src
βββ app.ts
βββ database
β βββ index.ts
βββ flow
β βββ index.ts
β βββ welcome.flow.ts
β βββ bye.flow.ts
β βββ media.flow.ts
βββ provider
β βββ index.ts
βββ services
βββ ai.ts