mern-stack-architecture
Skill2 starsChanged 4 months agoMITView on GitHub
Architect full MERN/Next-stack applications end to end — deciding the boundary between Next.js (frontend + server actions/API), MongoDB/Postgres data layer, and Express/standalone API services when one is needed. Use whenever the user is starting a full-stack project, asks "should this be a separate backend or Next.js API routes", is structuring a monorepo, or asks about the overall system architecture for a MERN/JAMstack-adjacent app.
In this repository22 other files it gives its agents.
- accessibility-a11ySkill
- design-system-tailwindSkill
- motion-design-toolkitSkill
- nextjs-architectureSkill
- react-component-engineeringSkill
- react-three-fiber-3dSkill
- responsive-mobile-firstSkill
- auth-authorizationSkill
- database-schema-designSkill
- form-validation-error-handlingSkill
- rest-api-integrationSkill
- state-managementSkill
- landing-page-conversionSkill
- payment-gateway-integrationSkill
- saas-dashboard-adminSkill
- startup-mvp-developmentSkill
- ux-research-flow-designSkill
- visual-design-languageSkill
- ai-assisted-frontend-workflowSkill
- deployment-vercel-productionSkill
- performance-seo-optimizationSkill
- project-architecture-clean-codeSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 32
Use Turborepo or pnpm workspaces to manage the monorepo.
- Very specific: line 41
Keep business logic out of route handlers/server actions directly — put it in lib/services so it's reusable and unit-testable without …
- Distinctive: line 46
No shared types package in a monorepo — frontend and backend types drift and silently break
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
MERN / Full-Stack Architecture Skill
Helps decide the right full-stack shape instead of defaulting to "add an Express server" out of habit.
Decision: do you even need a separate Express backend?
- No separate backend (default for most SaaS/web apps): Next.js Server Actions + Route Handlers talking directly to the database (via an ORM) cover the vast majority of CRUD, auth, and mutation needs with less operational overhead.
- Separate backend service justified when: you need a long-running process (websockets/queues/cron beyond what serverless allows), the API must be consumed by multiple independent clients (mobile app + web + third parties) with its own versioned contract, or you have heavy compute that shouldn't run in the Next.js deploy target.
Modern MERN stack (2026 defaults)
- M: MongoDB (Atlas) with Mongoose, or increasingly Postgres (Supabase/Neon) with Prisma/Drizzle when relational integrity matters — pick based on data shape, not habit.
- E: Express only when a standalone service is justified (see above); otherwise Next.js Route Handlers replace it.
- R: React (via Next.js App Router, not bare CRA/Vite for anything production-facing that needs SSR/SEO).
- N: Node.js runtime, or Next.js's own server runtime for the unified case.
Monorepo structure (when a separate API is justified)
apps/
├── web/ # Next.js app
├── api/ # Express/Fastify service (if needed)
└── worker/ # background jobs, if any
packages/
├── ui/ # shared component library
├── config/ # shared eslint/ts/tailwind config
├── db/ # shared Prisma/Mongoose schema + client
└── types/ # shared TypeScript types/contractsUse Turborepo or pnpm workspaces to manage the monorepo; share the DB client and types package between web and api so contracts don't drift.
Layering within a single Next.js app (no separate backend)
lib/db/ # ORM client singleton, connection handling
lib/services/ # business logic, pure functions, testable independent of Next
actions/ # thin server actions calling lib/services
app/api/ # thin route handlers for webhooks onlyKeep business logic out of route handlers/server actions directly — put it in lib/services so it's reusable and unit-testable without spinning up the framework.
Anti-patterns to flag
- Standing up a full Express server "just in case" when Next.js Server Actions cover the actual requirements
- Business logic embedded directly in route handlers, untestable in isolation
- No shared types package in a monorepo — frontend and backend types drift and silently break
- Mixing MongoDB (document) modeling habits into a Postgres/relational schema (or vice versa) without adapting the data model to the engine
Example prompt this skill should trigger on
"I'm starting a new full-stack SaaS product — should I use MongoDB or Postgres, and do I need a separate Express API?"
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

