Closed liebalogh closed 5 years ago
Same question: How to organize project structure ? I need to create a nestjs apis for my frontend UI and backend (admin dashboard) UI, should I create two projects for that or just one (I prefer just one)? AFAIK, I could use just one project. Each module has both frontend and backend apis. Like this:
nest g mo cats
to create cats module.nest g co cats
to create cat apis for frontend.nest g co cats/admin
( or --flat
) to create cat apis for backend. @Controller('admin')
to @Controller('admin/cats')
in admin controller file.That's all what I think. Hope you could give me some advice, thanks a lot.
Same question: How to organize project structure ? I need to create a nestjs apis for my frontend UI and backend (admin dashboard) UI, should I create two projects for that or just one (I prefer just one)? AFAIK, I could use just one project. Each module has both frontend and backend apis. Like this:
nest g mo cats
to create cats module.nest g co cats
to create cat apis for frontend.nest g co cats/admin
( or--flat
) to create cat apis for backend.- change
@Controller('admin')
to@Controller('admin/cats')
in admin controller file.That's all what I think. Hope you could give me some advice, thanks a lot.
Thanks for you answer,
In my case frontend and backend are not same server, backend on standalone server and my app will consume it. And my question not about frontend and backend in one project but i need know how i manage scalable files and folder structure on my project
I think you should follow the official documention: just move to modularize from MVC. Think all of your resource as modules:
nest g mo users
nest g co users
nest g mo products
nest g co products
...
It will create the right structure for you.
btw, thanks for your comment, maybe I shouldn't put both frontend and backend apis together.
I think you should follow the official documention: just move to modularize from MVC. Think all of your resource as modules:
nest g mo users nest g co users nest g mo products nest g co products
...
It will create the right structure for you.
btw, thanks for your comment, maybe I shouldn't put both frontend and backend apis together.
Oh, now i understand. will i move project structure like this
- src
- modules
- user
- user.controller.ts
- user.model.ts
- store
- store.controller.ts
- store.model.ts
- middleware
- interceptor
- guard
That's right ?
That's right, but it seems thers is no modules
folder.
I need to create a nestjs apis for my frontend UI and backend (admin dashboard) UI, should I create two projects for that or just one (I prefer just one)?
@wxs77577 you can always use monorepo approach - create 2 projects in 1 repo and share common things between them as libraries/packages
@liebalogh without modules
directory. Also, you can group common/core things as separate directories + sometimes interceptors/guards/pipes will be scoped by modules. See the following example:
- src
- core
- common
- middleware
- interceptors
- guards
- user
- interceptors (scoped interceptors)
- user.controller.ts
- user.model.ts
- store
- store.controller.ts
- store.model.ts
I need to create a nestjs apis for my frontend UI and backend (admin dashboard) UI, should I create two projects for that or just one (I prefer just one)?
@wxs77577 you can always use monorepo approach - create 2 projects in 1 repo and share common things between them as libraries/packages
@liebalogh without
modules
directory. Also, you can group common/core things as separate directories + sometimes interceptors/guards/pipes will be scoped by modules. See the following example:- src - core - common - middleware - interceptors - guards - user - interceptors (scoped interceptors) - user.controller.ts - user.model.ts - store - store.controller.ts - store.model.ts
I create global interceptor, that will transform object to response template. And What file should on core folder ?
I need to create a nestjs apis for my frontend UI and backend (admin dashboard) UI, should I create two projects for that or just one (I prefer just one)?
@wxs77577 you can always use monorepo approach - create 2 projects in 1 repo and share common things between them as libraries/packages @liebalogh without
modules
directory. Also, you can group common/core things as separate directories + sometimes interceptors/guards/pipes will be scoped by modules. See the following example:- src - core - common - middleware - interceptors - guards - user - interceptors (scoped interceptors) - user.controller.ts - user.model.ts - store - store.controller.ts - store.model.ts
I create global interceptor, that will transform object to response template. And What file should on core folder ?
Core would be for example where your actual business logic and rules live.
I would like Angular with Nestjs in a same repo, the folder both are src . I am thinking a repo with two folder ?
But this cannot manage same package.json together . Anyone has solution ?
@karocksjoelee what about https://www.youtube.com/watch?v=y24fC9Pqr8I
@karocksjoelee what about https://www.youtube.com/watch?v=y24fC9Pqr8I
umm.. looks great , although I am not going with AngularUniversal , cause I don't want SSR . Good reference of folder structure , thanks man . I will try to put together a starter file for Angular & Nestjs .
@karocksjoelee for big project is better to separate between Api and Frontend
@sbacem it depends. Either approach has its own pros and cons honestly
I need to create a nestjs apis for my frontend UI and backend (admin dashboard) UI, should I create two projects for that or just one (I prefer just one)?
@wxs77577 you can always use monorepo approach - create 2 projects in 1 repo and share common things between them as libraries/packages
@liebalogh without
modules
directory. Also, you can group common/core things as separate directories + sometimes interceptors/guards/pipes will be scoped by modules. See the following example:- src - core - common - middleware - interceptors - guards - user - interceptors (scoped interceptors) - user.controller.ts - user.model.ts - store - store.controller.ts - store.model.ts
@kamilmysliwiec I'm just asking myself how to properly architecture the project, so far I create all my module in the src:
- src
- database
- database.module.ts
- logger
- config
- users
- auth
- shared
- date-manager.ts
- shared.module.ts
I'm thinking about moving the database/logger module inside a core module and maybe the Date manager as well but for the last, I'm not sure, I think it's better to let it in a shared module containing helpers for example... But is could also live in the core one,
What do you think? What would be the "best" way to architecture it?
I have a question concerning the module's folder structure :
Let's say I have a BasePet module. Then a Cat module which extends BasePet, but with it's own service and controller, same for a Dog module which extends BasePet.
Would you suggest to encapsulate even more the module's folders ?
@kamilmysliwiec I'm just asking myself how to properly architecture the project, so far I create all my module in the src:
- src - database - database.module.ts - logger - config - users - auth - shared - date-manager.ts - shared.module.ts
If you will use libs, it will be much simple to separate the application logic etc:
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I have big e-commerce apps, i planning move previous codebase from express (Typescript) to NestJS.
After reading documentation and try create nestjs project, I'm confused with project structure. In my opinion generated project structure not scalable, it strange when large codebase have project structure like that.
Currently on my backend have Controller, Model, Event, Middleware, Validator, interface, static file server (subdomain), websocket, here my current project structure
I'm not angular developer so i dont know how to manage project structure like that
How i for best project structure on awesome nestjs framework ?