Any recommendation on how should I organize my `in...
# sst
a
Any recommendation on how should I organize my
index.ts
file? Currently I have 14 stacks referenced from index, and expecting to double that amount in the next month. My index contains not also the stacks but also the
addDependency
for each of them. So currently it’s a mess. I been thinking to create
function
s for each of the “Features” that I have, which is basically a grouping of stacks… but to do that I have to create types for each Stack, due most of them has
readonly
attributes which are exposed to other stacks. Maybe I can create TS classes? and create
input
and
output
types? Input will be construct dependencies and output will be anything that has to be shared.
Well, I’ve decided to create some Groups of stacks, and send the dependent stacks over typed parameters.
What I’m not sure is how to call these “stacks group”.
t
What do you mean you have to create types for each stack?
a
Yeah that was my mistake, I was planning to use types for each stack because of the
readonly
attributes. But I can use the actual class type too, and worked.
t
One pattern I use, which I'm not even sure if I love is this
Copy code
const mystack = new MyStack() // stores all exported properties in a field called outputs
const nextstack = new NextStack({ mystack: mystack.outputs })

// Prop types for NextStack
type Props = {
  mystack: typeof MyStack["outputs"]
}
a
Kind of similar to what I did.
But not exactly.
Did you think about “stack of stacks”?
I mean, my index has to be separated into different classes, how I can call them? “groups”?
t
My inclination would just be to wrap it in a function call that returns an object
a
I’ve created classes.
t
I don't like using classes 😛
Copy code
const groupA = GroupA(app)

function GroupA(app) {
   const stackA = new StackA(app, ...)
   const stackB = new StackB(app, ...)
   return { stackA: stackA.outputs, stackB: stackB.outputs } 
}
// can use ReturnType<typeof GroupA> to get the type of that group if you want to pass it into something else
a
Cool yeah.
I did something similar.
My index is something like this…
Copy code
const network = new Network(app);

  const yabble = new Yabble(app, {
    networkStack: network.networkStack,
  });

  new Marketing(app, {
    yabbleApiStack: yabble.yabbleApiStack,
    yabblePlatformStack: yabble.yabblePlatformStack,
  });

  new HeyYabble(app, {
    networkStack: network.networkStack,
    yabbleApiStack: yabble.yabbleApiStack,
    yabblePlatformStack: yabble.yabblePlatformStack,
    openAiApiStack: yabble.openAiApiStack,
    iamAuthStack: yabble.iamAuthStack,
  });
What I don’t know yet is how to call the “group” class.
Still not convinced with “group” word.
t
Does it need a name? Looks like you're just naming it specifically to what the group represents
a
Yeah, it doesn’t need it, but well… still not convinced, haha.
t
StackyStacks
a
😂
I was thinking to call it
*Stacks
.
YabbleStacks
… but could be confusing.