What are some ways of structuring modular code

ps: I already have my own way of doing this, I was more asking around to see how other people do it

Structure is an important thing when working with ModuleScripts, I was wondering how you structure your modules when working on projects.

For example, I tend to create a few core systems, then make a folder to hold modules and a separate one for packages

If a core system works by using small blocks of modular code, ie: ObjectHandler or a closed source remote library I wrote, I end up with extra folders for those.

Here’s a simple example of that structure

Game
  Packages
    external codebases, ie: fusion

  Modules
    game modules

  Core
    core game systems, ie: an object handler

  Objects
    scripts for creating scriptable objects

  Remotes
    scripts for binding remoteevents

But anyway, how would you create a structure around modular code

2 Likes

I don’t really know how to explain my way of doing it, but here’s a screenshot of how I typically organize my systems. I have a CoreModules folder that contains the main modules that are called by the script that handles the system but may also be called by other scripts outside the system. Then, inside of the script that handles the system I keep scripts that are only used by that one script.
image

Pretty much the same as you. I call nearly everything from my “Boot” scripts that access the CORE. Anything that is specific to the game is put under ServerStorage, StarterPlayerScripts, and ReplicatedStorage.

ReplicatedStorage
	Assets -- Assets that every player needs on loadup
	Core -- Main module using lazy loading
		Class -- Store my OOP here
		Color3 -- Class folders for large script systems
		Math
		ObjectCache -- System ModuleScripts are uppercase
		weld -- Function ModuleScripts are lowercase
	Library -- Stores massive lists/tables
	Remotes

ServerScriptStorage
	Server -- Access and require CORE once by server (CRITICAL)

ServerStorage -- Store local assets
	Assets -- Local assets for each player to avoid loading everything at once
	Library -- Store hidden lists so player can't use hacks n' stuff to find out everything

StarterPlayer
	StarterPlayerScripts -- Store player-only scripts and GUI
		User -- Access and require CORE once by player (CRITICAL)
			-- Scripts
			-- GUI
3 Likes

how do you name your libraries? are they further separated by folders or is it just a massive list of em?

1 Like