Skip to content

geekinks/geekink-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

GeekInk Backend Starter

This backend follows the GeekInk Backend Standard.

Read this README before writing any code. If you are confused, reread the comments inside each file.

If it’s not here, you don’t need it.

This structure exists to:

  • Keep code readable
  • Separate responsibilities
  • Prevent spaghetti code
  • Remove dependency on mentors

If you follow this structure correctly, your backend will scale.


📁 Root Files

LICENSE

Legal license for the project.
Do not modify unless instructed.


README.md

Explains:

  • What the project does
  • How to run it
  • How it is structured

If someone asks you “how does this backend work?”
The answer should be: “Read the README.”


📁 src/

All application code lives here.
Nothing outside src/ should contain logic.


📁 src/config/

Configuration and setup files ONLY.

env.js

Responsible for:

  • Loading environment variables
  • Validating required variables

DO

  • Read from process.env
  • Export a config object

DO NOT

  • Write logic
  • Connect to databases here

database.js

Responsible for:

  • Connecting to the database
  • Exporting the database connection

DO

  • Handle connection logic
  • Handle connection errors

DO NOT

  • Define models
  • Write queries

📁 src/models/

Defines data structure only.

user.model.js

Responsible for:

  • Defining database schema
  • Defining relationships

DO

  • Define fields and types
  • Export the model

DO NOT

  • Handle requests
  • Write business logic
  • Send responses

Rule:
Models do NOT know about HTTP.


📁 src/controllers/

Handles application logic.

user.controller.js

Responsible for:

  • Receiving requests from routes
  • Processing data
  • Calling models
  • Returning responses

DO

  • Validate request data
  • Call model methods
  • Return structured responses

DO NOT

  • Define routes
  • Access environment variables directly

Rule:
Controllers think. Routes only route.


📁 src/routes/

Defines URL endpoints only.

user.routes.js

Responsible for:

  • Mapping URLs to controllers
  • Defining HTTP methods

DO

  • Use Express Router
  • Call controller functions

DO NOT

  • Write logic
  • Access database
  • Handle validation

Example:

router.post("/users", createUser);

src/utils/

Shared helper functions.

response.js

Responsible for:

Standard API responses

Error formatting

Success formatting

DO

Create reusable helpers

DO NOT

Write business logic

### 📄 src/app.js

Main application entry.

Responsible for:

Creating Express app

Registering middleware

Registering routes

Starting server

DO

Keep it clean

Import routes

DO NOT

Write feature logic here

🔥 NON-NEGOTIABLE RULES

 No logic in routes

 No database access outside models

 No response formatting outside utils

 No direct res.json() inside models

##  One responsibility per file

> Breaking these rules = rewrite required.

# 🧠 How to Know Where Code Goes

### Ask yourself:

- Is this about data structure?  models

- Is this about handling a request?  controllers

- Is this about URL mapping?  routes

- Is this about configuration?  config

- Is this reusable helper logic?  utils

>If you’re unsure  you’re probably putting it in the wrong place.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors