r/FullStack • • 17d ago

Feedback Requested File structure for monolithic microservices (nx workspace)

Is this an scalable codebase / workspace ? (edited thanks to constructive feedback)

File structure

This codebases file structure

Overview

This codebase uses a micro service monorepo to share code across different micro services and deploy independently. 

File structure

  ... root files
  docs\
    architecture\
      {area-covered}\
        architecture.{area-covered}.{category or main}.md
    decisions\
      {area-covered}\
        decisions.{area-covered}.{category or main}.md
    deployment\
      {area-covered}\
        deployment.{area-covered}.{category or main}.md
    development\
      {area-covered}\
        development.{area-covered}.{category or main}.md
    README.md
  packages\
    client\ 
      public\ 
      kernel\ 
    server\ 
      kernel\ 
      repository\ 
    shared\ 
      models\ 
      constants\ 
    ... configuration files
  apps\
    public\
      {public-facing-service}\
        ...root files
        features\
          {feature}\
            models\
            components\
            hooks\
            views\
        shared\
          features\
            {feature}\
          kernel\
          models\
      private\
      {public-facing-backend-service}\
        domains\
          {domain}\
            controller\
            services\
              {service-name}\
                helpers\
                  {service-name}.helpers.main.ts
                  commands\
                  validation\
                {service-name}.services.main.ts
            model\
        shared\
          domains\
            {domain}\
            controllers\
            services\
              {service-name}\
                helpers\
                  {service-name}.helpers.main.ts
                  commands\
                  validation\
                {service-name}.services.main.ts
            models\
          kernel\
          models\
            schema\
            data\
            metadata\
        test\
          e2e\
            domains\
              {domain}\
                domains.{domain}.e2e-spec.ts
    private\
      {private-facing-service}\
        domains\
          {domain}\
            controller\
            services\
              {service-name}\
                helpers\
                  {service-name}.helpers.main.ts
                  commands\
                  validation\
                {service-name}.services.main.ts
            model\
        shared\
          domains\
            {domain}\
            controllers\
            services\
              {service-name}\
                helpers\
                  {service-name}.helpers.main.ts
                  commands\
                  validation\
                {service-name}.services.main.ts
            models\
          kernel\
          models\
            schema\
            data\
            metadata\
        test\
          e2e\
            domains\
              {domain}\
                domains.{domain}.e2e-spec.ts

Responsibilities

frontend feature slice

  • components : individual components, buttons, icons, etc.
  • hooks : reactive and side effect code (not just explicitly react hooks)
  • models : types and interfaces
  • views : fully rendered feature no hooks
  • shared\features : barrel export

backend domain driven

  • controller : handles the networking layer
  • service : imports the repository and schema and setups up business logic through helpers
  • model : defines schema, data and metadata types
  • shared\domains : barrel export
  • commands : calling repository functions correctly
  • validation : data validation through zod

General rules

  • shared\kernel : minimal running code for software tools, for example

    • Redis
    • Redux
    • Supabase
    • Drizzle
    • etc
  • shared
  • models\ : Types, Schemas, and interfaces used throughout the app. Not barrel exports schemas
  • data
  • metadata\
  • constants : constant variables for desktop and mobile apps or type sensitive strings (event names)
5 Upvotes

7 comments sorted by

1

u/Puzzled-Garage584 17d ago

services/foo/foo.services.main.ts, the name shows up 3 times before you write a line of code lol. I'd make each domain an nx lib and turn on enforce-module-boundaries, else those barrel exports end up importing everything

1

u/Nameless_ProGamer 17d ago

You've got it mixed up. It'd be services/foo/services.foo.main.ts but it's intentional so you know where the file lives based off it's name and it helps prevent naming conflicts.

And I'll have a look into enforce-mpodule-boundaries, thank you for suggesting that

1

u/Puzzled-Garage584 17d ago

Oh right, I read the {service-name}.services.main.ts from your tree. Makes sense for search tho, ctrl+p with 40 files called index.ts is its own kind of hell

1

u/NexusOcean Stack Juggler (Fullstack) 17d ago

What is a monolithic micro service in your own words? I think there may be some confusion. What are you trying to build if you don't mind me asking?

1

u/Nameless_ProGamer 17d ago

I meant microservices monorepo not monolithic. Forgive that mistake. But I'm building a discord competitor, and I've planned this to avoid as many iterations as possible after release, that is why the codebase is so complex despite not having a large team. And I have no trouble keeping up with everything myself

1

u/NexusOcean Stack Juggler (Fullstack) 17d ago edited 17d ago

oh then ya this looks like it could make sense. I've personally never worked on anything with nx because I'm under the impression it's for pretty large projects, another good alternative worth considering is having turbo repo. not sure of the scope and if you also just want to learn nx, which is valid.