# bharath3312/crowdfunding_backend architecture

> Architecture diagram of the GitHub repository bharath3312/crowdfunding_backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bharath3312/crowdfunding_backend
- Repository: https://github.com/bharath3312/crowdfunding_backend

## Overview

#### Purpose and runtime
This is a Node.js backend API organized around authentication, users, and MongoDB-backed domain models. The runtime bootstraps application configuration, logging, database connectivity, middleware, and HTTP server startup through `src/server.js`, `src/app.js`, and `src/config/mongo.database.js`.

#### Application composition and entry points
`src/server.js` is the process entry point and delegates HTTP application setup to `src/app.js`. The app layer is responsible for assembling route modules and cross-cutting middleware. Environment-derived configuration is centralized in `src/config/env.js`; logging configuration and output streams are defined in `src/config/logger.js` and `src/config/logger.streams.js`.

#### HTTP routing and controller boundary
Route modules expose the public API surface: authentication endpoints are defined in `src/routes/auth.route.js`, while user endpoints are defined in `src/routes/user.route.js`. Controllers translate HTTP request/response concerns into service calls, with authentication handling located in `src/controllers/auth.controller.js`. This separates transport behavior from business logic.

#### Authentication and user workflow
Authentication logic is implemented in `src/services/auth.service.js`, supported by password/encryption and JWT utilities in `src/utils/encryption.js` and `src/utils/jwt.js`. Protected routes pass through `src/middlewares/auth.middleware.js`, which forms the security boundary between externally supplied credentials and trusted application context. User-oriented business operations belong in `src/services/user.service.js`.

#### Persistence layer and domain models
MongoDB is the persistence infrastructure, configured via `src/config/mongo.database.js`. Mongoose-style domain entities include users and campaigns in `src/models/user.js` and `src/models/campaign.js`, with aggregation/export wiring in `src/models/index.js`. `src/repositories/base.repo.js` establishes a reusable persistence abstraction, intended to keep data-access concerns outside services and controllers.

#### Request lifecycle, validation, and errors
Incoming requests are logged by `src/middlewares/requestLogger.middleware.js`, validated through `src/middlewares/validate.middleware.js` using rules in `src/validations/model.validation.js`, then routed to controllers/services. Async failures are normalized through `src/utils/asyncHandler.js`, while unknown routes and application errors terminate in `src/middlewares/notFound.middleware.js` and `src/middlewares/errorHandler.middleware.js`. Responses and failures use shared contracts from `src/utils/apiResponse.js` and `src/utils/apiError.js`.

Main entry points: [`src/app.js`](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/app.js) (App composition), [`src/services/auth.service.js`](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/services/auth.service.js) (Auth service), [`src/server.js`](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/server.js) (Server entry), [`src/routes/auth.route.js`](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/routes/auth.route.js) (Auth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime &amp; config"]
  node_server["Server entry<br/>Node.js process<br/>[server.js]"]
  node_app["App composition<br/>Express app<br/>[app.js]"]
  node_env["Environment config<br/>configuration<br/>[env.js]"]
  node_logger["Logging<br/>logger config<br/>[logger.js]"]
end

subgraph group_http["HTTP API"]
  node_request_logging["Request logger<br/>middleware"]
  node_validation["Request validation<br/>middleware"]
  node_auth_routes["Auth routes<br/>route module<br/>[auth.route.js]"]
  node_user_routes["User routes<br/>route module<br/>[user.route.js]"]
  node_auth_guard["Auth guard<br/>middleware<br/>[auth.middleware.js]"]
  node_auth_controller["Auth controller<br/>[auth.controller.js]"]
  node_error_boundary["Error handling<br/>middleware"]
end

subgraph group_domain["Domain &amp; security"]
  node_auth_service["Auth service<br/>business service<br/>[auth.service.js]"]
  node_user_service["User service<br/>business service<br/>[user.service.js]"]
  node_crypto["Encryption<br/>security utility<br/>[encryption.js]"]
  node_jwt["JWT utility<br/>security utility<br/>[jwt.js]"]
end

subgraph group_data["Persistence"]
  node_mongo[("MongoDB connection<br/>database setup<br/>[mongo.database.js]")]
  node_repository["Base repository<br/>data abstraction<br/>[base.repo.js]"]
  node_models["Domain models<br/>Mongoose models<br/>[index.js]"]
end

node_server -->|"starts"| node_app
node_server -->|"connects"| node_mongo
node_env -.->|"configures"| node_server
node_env -.->|"configures"| node_mongo
node_logger -.->|"writes request logs"| node_request_logging
node_app -->|"registers"| node_request_logging
node_app -->|"registers"| node_validation
node_app -->|"mounts"| node_auth_routes
node_app -->|"mounts"| node_user_routes
node_app -->|"terminates failures"| node_error_boundary
node_auth_routes -->|"dispatches"| node_auth_controller
node_user_routes -->|"protects"| node_auth_guard
node_auth_controller -->|"calls"| node_auth_service
node_auth_service -->|"hashes passwords"| node_crypto
node_auth_service -->|"issues tokens"| node_jwt
node_auth_guard -->|"verifies token"| node_jwt
node_auth_service -->|"persists through"| node_repository
node_user_service -->|"persists through"| node_repository
node_repository -->|"uses"| node_models
node_models -->|"stores in"| node_mongo
node_validation -.->|"validates requests"| node_auth_routes

click node_server "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/server.js"
click node_app "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/app.js"
click node_env "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/config/env.js"
click node_logger "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/config/logger.js"
click node_mongo "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/config/mongo.database.js"
click node_request_logging "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/middlewares/requestLogger.middleware.js"
click node_validation "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/middlewares/validate.middleware.js"
click node_auth_routes "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/routes/auth.route.js"
click node_user_routes "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/routes/user.route.js"
click node_auth_guard "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/middlewares/auth.middleware.js"
click node_auth_controller "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/controllers/auth.controller.js"
click node_error_boundary "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/middlewares/errorHandler.middleware.js"
click node_auth_service "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/services/auth.service.js"
click node_user_service "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/services/user.service.js"
click node_crypto "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/utils/encryption.js"
click node_jwt "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/utils/jwt.js"
click node_repository "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/repositories/base.repo.js"
click node_models "https://github.com/bharath3312/crowdfunding_backend/blob/main/src/models/index.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_app,node_env,node_logger toneBlue
class node_request_logging,node_validation,node_auth_routes,node_user_routes,node_auth_guard,node_auth_controller,node_error_boundary toneAmber
class node_auth_service,node_user_service,node_crypto,node_jwt toneMint
class node_mongo,node_repository,node_models toneRose
```

## Components

### Runtime & config

- [Server entry](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/server.js): Node.js process · `src/server.js`
- [App composition](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/app.js): Express app · Assembles middleware and route modules. · `src/app.js`
- [Environment config](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/config/env.js): configuration · `src/config/env.js`
- [Logging](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/config/logger.js): logger config · `src/config/logger.js`

### HTTP API

- [Request logger](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/middlewares/requestLogger.middleware.js): middleware · `src/middlewares/requestLogger.middleware.js`
- [Request validation](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/middlewares/validate.middleware.js): middleware · `src/middlewares/validate.middleware.js`
- [Auth routes](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/routes/auth.route.js): route module · `src/routes/auth.route.js`
- [User routes](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/routes/user.route.js): route module · `src/routes/user.route.js`
- [Auth guard](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/middlewares/auth.middleware.js): middleware · Establishes trusted context for protected routes. · `src/middlewares/auth.middleware.js`
- [Auth controller](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/controllers/auth.controller.js): controller · `src/controllers/auth.controller.js`
- [Error handling](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/middlewares/errorHandler.middleware.js): middleware · Handles unknown routes and application failures. · `src/middlewares/errorHandler.middleware.js`

### Domain & security

- [Auth service](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/services/auth.service.js): business service · `src/services/auth.service.js`
- [User service](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/services/user.service.js): business service · `src/services/user.service.js`
- [Encryption](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/utils/encryption.js): security utility · `src/utils/encryption.js`
- [JWT utility](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/utils/jwt.js): security utility · `src/utils/jwt.js`

### Persistence

- [MongoDB connection](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/config/mongo.database.js): database setup · `src/config/mongo.database.js`
- [Base repository](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/repositories/base.repo.js): data abstraction · Keeps data access outside services. · `src/repositories/base.repo.js`
- [Domain models](https://github.com/bharath3312/crowdfunding_backend/blob/main/src/models/index.js): Mongoose models · Exports user and campaign entities. · `src/models/index.js`

## Connections

- Server entry → App composition: starts
- Server entry → MongoDB connection: connects
- Environment config → Server entry: configures
- Environment config → MongoDB connection: configures
- Logging → Request logger: writes request logs
- App composition → Request logger: registers
- App composition → Request validation: registers
- App composition → Auth routes: mounts
- App composition → User routes: mounts
- App composition → Error handling: terminates failures
- Auth routes → Auth controller: dispatches
- User routes → Auth guard: protects
- Auth controller → Auth service: calls
- Auth service → Encryption: hashes passwords
- Auth service → JWT utility: issues tokens
- Auth guard → JWT utility: verifies token
- Auth service → Base repository: persists through
- User service → Base repository: persists through
- Base repository → Domain models: uses
- Domain models → MongoDB connection: stores in
- Request validation → Auth routes: validates requests
