electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.51k stars 520 forks source link

Improve Template File System Layout to better support large projects. #3766

Open dopry opened 5 days ago

dopry commented 5 days ago

Pre-flight checklist

Problem description

As an electron developer I like to keep my code bundled by where it runs. ex) main, renderer, both so I easily know what APIs are available and how to communicate with the other parts of my app.

On one of my projects we used on of the templates and all the code was in the /src folder... As the project grew to over 200 files, this became a real challenge to manage and understand where the code in a particular file would run.

Proposed solution

We ended up updating to the following filesystem layout

/src/common - types, classes, and functions used in both the main and renderers. /src/main/ - code that runs on main. /src/renderers/{renderer name}/ - code that runs in the renderer (preload, html, rendered js, css) /src/renderers/common/* - code shared between multiple renderers (common preload imports, component library, etc)

This has really helped us navigating our codebase and helped new team members get familiar more quickly. I think it would be nice if the templates provided this structure for new projects so others building with electron won't have to go through the complex file moving and organizing we had to after their projects have organically grown into a mess.

Alternatives considered

I haven't considered other file system layouts, but would find any that organize things in a similar fashion in spirit an improvement.

Additional information

No response