# shardul2302/odoo-2026-hackathon architecture

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

- Interactive diagram: https://gitdiagram.com/shardul2302/odoo-2026-hackathon
- Repository: https://github.com/shardul2302/odoo-2026-hackathon

## Overview

1. **Overall shape**
   - EcoSphere is a two-tier MERN-style system: a **React/Vite single-page frontend** talks to an **Express/MongoDB backend** over a versioned REST API at **`/api/v1`**.
   - The main architectural boundary is **browser UI + client state** on one side, and **API + business rules + persistence** on the other.

2. **Backend entry and composition**
   - The backend is centered in `backend/server.js` / `backend/src/server.js` and `backend/src/app.js`.
   - `src/config/db.js` handles the MongoDB connection.
   - Express app composition likely includes global middleware, JSON parsing, route mounting, and centralized error handling via `middlewares/error.middleware.js`.

3. **Backend domain modules**
   - The backend follows a consistent **route → controller → model → validator** pattern.
   - Major modules are:
     - **Auth**
     - **Departments, Categories, Emission Factors**
     - **Carbon Transactions**
     - **CSR activities**
     - **Compliance issues/policies**
     - **Challenges, participations, badges, rewards**
     - **Dashboard aggregation**
   - Each domain has its own route file, controller, Mongoose model, and request validator, which makes the system diagram modular and easy to segment.

4. **Authentication and authorization**
   - Authentication is JWT-based, with password hashing via bcrypt.
   - `auth.controller.js`, `generateToken.js`, and `auth.middleware.js` form the core auth flow.
   - `role.middleware.js` indicates **role-based access control** for users such as admin/manager/employee, which is important for drawing access boundaries around management screens and protected APIs.

5. **Environmental data flow**
   - The environmental core is the **carbon transaction** pipeline.
   - Users submit activity data through carbon transaction endpoints; the backend uses `co2Calculator.js` and `emissionFactor` records to compute CO₂ impact.
   - This makes **emission factors** a reference/master-data dependency for carbon calculations rather than a standalone feature.

6. **Recognition and gamification**
   - `badgeChecker.js`, badge/reward models, and the challenge/participation module suggest a recognition loop:
     - user activity or carbon events are evaluated,
     - badges/rewards may be assigned,
     - participation records track engagement.
   - In an architecture diagram, this is a secondary business loop connected to environmental activity and user engagement.

7. **CSR, compliance, and governance**
   - Separate subsystems exist for **CSR activities**, **policies**, and **compliance issues**.
   - These represent the “governance” side of ESG and should be shown as distinct bounded contexts, even though they share the same MongoDB and auth layer.
   - They likely feed into the dashboard and reporting views rather than directly into carbon calculations.

8. **Dashboard aggregation**
   - `dashboard.controller.js` appears to aggregate metrics from multiple collections for the ESG overview.
   - This is a read-heavy cross-domain layer, not a source-of-truth subsystem.
   - In a diagram, it should be drawn as a consumer of several backend domains, especially carbon, departments, categories, CSR, compliance, and recognition data.

9. **Persistence model**
   - MongoDB collections listed in the README align with the backend models:
     - `users`, `departments`, `categories`, `emissionFactors`, `carbonTransactions`
     - `csrActivities`, `participations`, `challenges`
     - `policies`, `complianceIssues`, `badges`, `rewards`
   - The persistence layer is document-based and owned by Mongoose models; there is no separate relational DB or queue layer in this repo.

10. **Frontend application shell**
   - The frontend is a **React 19 + Vite** SPA.
   - `main.jsx`, `App.jsx`, `layout/AppLayout.jsx`, and `layouts/AuthLayout.jsx` define the primary routing/shell structure.
   - `components/layout/ProtectedRoute.jsx` is the client-side guard that complements backend JWT/role checks.

11. **Frontend data access and session state**
   - API access is centralized in `src/api/axiosInstance.js`, `src/lib/axios.js`, and `src/lib/api.js`.
   - Auth state is managed through `AuthContext` plus `useAuth.js`, with local storage helpers in `utils/storage.js`.
   - This means the frontend is responsible for storing and presenting session state, while the backend remains authoritative for token validation.

12. **Frontend feature areas**
   - The pages map closely to backend domains: **Login/Register**, **Overview/Dashboard**, **Departments**, **Categories**, **Emission Factors**, **Carbon Transactions**, **Companies/Contacts/Activities/Pipeline**.
   - Shared UI is built from reusable dialogs, forms, tables, cards, and layout components, with shadcn-style primitives under `components/ui/`.
   - `ThemeContext` suggests a client-side presentation concern separate from business data.

13. **Cross-cutting validation and error handling**
   - Both tiers have validation layers:
     - backend request validators in `src/validators`
     - frontend form schemas in `src/validation`
   - Backend standardized responses/utilities (`ApiError`, `ApiResponse`, `asyncHandler`) indicate a uniform API contract, which is useful to represent as a shared service pattern.

14. **Seed and demo data**
   - `backend/src/seed/seed.js` populates MongoDB with demo users and data.
   - The README’s sample credentials and screenshots indicate the app is designed to be demonstrated against seeded collections rather than requiring external services.

15. **What to emphasize in an architecture diagram**
   - Show three primary layers:
     - **React SPA**
     - **Express API**
     - **MongoDB collections**
   - Overlay the key trust boundaries:
     - unauthenticated auth routes,
     - authenticated role-protected routes,
     - dashboard/reporting reads across domains.
   - Also note that `frontend/src123` looks like a parallel/legacy scaffold and is not part of the primary application path.

Main entry points: [`backend/src/routes/dashboard.routes.js`](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/routes/dashboard.routes.js) (API Routes), [`backend/src/models/user.model.js`](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/models/user.model.js) (Models), [`frontend/src/lib/axios.js`](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/lib/axios.js) (API Client), [`backend/src/app.js`](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/app.js) (Express App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend SPA"]
  node_fe_shell["App Shell<br/>React SPA<br/>[App.jsx]"]
  node_fe_main["Boot<br/>Vite entry<br/>[main.jsx]"]
  node_fe_auth["Auth State<br/>context+hooks<br/>[AuthContext.jsx]"]
  node_fe_api["API Client<br/>HTTP layer<br/>[axios.js]"]
  node_fe_guard["Protected Route<br/>route guard<br/>[ProtectedRoute.jsx]"]
  node_fe_auth_pages["Login UI<br/>auth pages<br/>[Login.jsx]"]
  node_fe_dashboard["Overview<br/>dashboard pages<br/>[Dashboard.jsx]"]
  node_fe_domain_pages["Domain Pages<br/>feature pages"]
  node_fe_layouts["Layouts<br/>UI shell<br/>[AppLayout.jsx]"]
end

subgraph group_backend["Backend API"]
  node_be_entry["Server<br/>Express entry<br/>[server.js]"]
  node_be_app["Express App<br/>app composition<br/>[app.js]"]
  node_be_db["DB Connect<br/>mongo config<br/>[db.js]"]
  node_be_mw["Middleware<br/>cross-cutting<br/>[auth.middleware.js]"]
  node_be_auth["Auth Flow<br/>security module<br/>[auth.controller.js]"]
  node_be_routes["API Routes<br/>route layer"]
  node_be_carbon{{"Carbon Pipeline<br/>core domain"}}
  node_be_master["Master Data<br/>reference domain"]
  node_be_governance["Governance<br/>esg domain<br/>[csr.controller.js]"]
  node_be_rewards["Recognition<br/>engagement loop"]
  node_be_dashboard["Dashboard<br/>aggregation"]
end

subgraph group_persistence["MongoDB"]
  node_be_models[("Models<br/>[user.model.js]")]
  node_be_seed["Seed Data<br/>demo bootstrap<br/>[seed.js]"]
end

subgraph group_legacy["Legacy scaffold"]
  node_legacy_fe["Legacy SPA<br/>legacy frontend<br/>[App.jsx]"]
end

node_fe_main -->|"boots"| node_fe_shell
node_fe_shell -->|"uses"| node_fe_layouts
node_fe_layouts -->|"protects"| node_fe_guard
node_fe_auth_pages -->|"updates"| node_fe_auth
node_fe_auth -->|"calls"| node_fe_api
node_fe_domain_pages -->|"fetches"| node_fe_api
node_fe_dashboard -->|"reads"| node_fe_api
node_fe_api -->|"REST /api/v1"| node_be_routes
node_be_entry -->|"creates"| node_be_app
node_be_app -->|"connects"| node_be_db
node_be_app -->|"mounts"| node_be_mw
node_be_app -->|"mounts"| node_be_routes
node_be_routes -->|"auth"| node_be_auth
node_be_routes -->|"carbon"| node_be_carbon
node_be_carbon -->|"uses factors"| node_be_master
node_be_routes -->|"governance"| node_be_governance
node_be_routes -->|"engagement"| node_be_rewards
node_be_routes -->|"aggregates"| node_be_dashboard
node_be_auth -->|"persists"| node_be_models
node_be_carbon -->|"writes"| node_be_models
node_be_governance -->|"writes"| node_be_models
node_be_rewards -->|"writes"| node_be_models
node_be_dashboard -->|"reads"| node_be_models
node_be_seed -->|"populates"| node_be_models
node_legacy_fe -.->|"parallel"| node_fe_api

click node_fe_shell "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/App.jsx"
click node_fe_main "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/main.jsx"
click node_fe_auth "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/context/AuthContext.jsx"
click node_fe_api "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/lib/axios.js"
click node_fe_guard "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/components/layout/ProtectedRoute.jsx"
click node_fe_auth_pages "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/pages/Auth/Login.jsx"
click node_fe_dashboard "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/pages/Overview/Dashboard.jsx"
click node_fe_domain_pages "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/pages/CarbonTransactions.jsx"
click node_fe_layouts "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/layout/AppLayout.jsx"
click node_be_entry "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/server.js"
click node_be_app "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/app.js"
click node_be_db "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/config/db.js"
click node_be_mw "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/middlewares/auth.middleware.js"
click node_be_auth "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/controllers/auth.controller.js"
click node_be_routes "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/routes/dashboard.routes.js"
click node_be_carbon "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/controllers/carbonTransaction.controller.js"
click node_be_master "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/controllers/department.controller.js"
click node_be_governance "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/controllers/csr.controller.js"
click node_be_rewards "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/controllers/challenge.controller.js"
click node_be_dashboard "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/controllers/dashboard.controller.js"
click node_be_models "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/models/user.model.js"
click node_be_seed "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/seed/seed.js"
click node_legacy_fe "https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src123/App.jsx"

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_fe_shell,node_fe_main,node_fe_auth,node_fe_api,node_fe_guard,node_fe_auth_pages,node_fe_dashboard,node_fe_domain_pages,node_fe_layouts toneBlue
class node_be_entry,node_be_app,node_be_db,node_be_mw,node_be_auth,node_be_routes,node_be_carbon,node_be_master,node_be_governance,node_be_rewards,node_be_dashboard toneAmber
class node_be_models,node_be_seed toneMint
class node_legacy_fe toneRose
```

## Components

### Frontend SPA

React/Vite client, routing, state, and API access

- [App Shell](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/App.jsx): React SPA · Main client application shell and routing entry · `frontend/src/App.jsx`
- [Boot](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/main.jsx): Vite entry · Frontend bootstrap entrypoint · `frontend/src/main.jsx`
- [Auth State](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/context/AuthContext.jsx): context+hooks · Client session state and auth helpers · `frontend/src/context/AuthContext.jsx`
- [API Client](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/lib/axios.js): HTTP layer · Centralized axios and API helpers · `frontend/src/lib/axios.js`
- [Protected Route](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/components/layout/ProtectedRoute.jsx): route guard · Client-side access gate for protected screens · `frontend/src/components/layout/ProtectedRoute.jsx`
- [Login UI](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/pages/Auth/Login.jsx): auth pages · Authentication screens and forms · `frontend/src/pages/Auth/Login.jsx`
- [Overview](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/pages/Overview/Dashboard.jsx): dashboard pages · Primary ESG overview and summary views · `frontend/src/pages/Overview/Dashboard.jsx`
- [Domain Pages](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/pages/CarbonTransactions.jsx): feature pages · Department, category, emission factor, and carbon transaction screens · `frontend/src/pages/CarbonTransactions.jsx`
- [Layouts](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src/layout/AppLayout.jsx): UI shell · Authenticated and auth-specific layout composition · `frontend/src/layout/AppLayout.jsx`

### Backend API

Express application, domain routes, middleware, and business logic

- [Server](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/server.js): Express entry · Backend process entrypoint and app bootstrapping · `backend/src/server.js`
- [Express App](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/app.js): app composition · Middleware, route mounting, and error handling · `backend/src/app.js`
- [DB Connect](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/config/db.js): mongo config · MongoDB connection setup · `backend/src/config/db.js`
- [Middleware](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/middlewares/auth.middleware.js): cross-cutting · Auth, role checks, validation, and error handling · `backend/src/middlewares/auth.middleware.js`
- [Auth Flow](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/controllers/auth.controller.js): security module · JWT auth, token generation, and login logic · `backend/src/controllers/auth.controller.js`
- [API Routes](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/routes/dashboard.routes.js): route layer · Versioned REST endpoints for all major domains · `backend/src/routes/dashboard.routes.js`
- [Carbon Pipeline](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/controllers/carbonTransaction.controller.js): core domain · Carbon transaction processing and CO2 calculation · `backend/src/controllers/carbonTransaction.controller.js`
- [Master Data](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/controllers/department.controller.js): reference domain · Departments, categories, and emission factors · `backend/src/controllers/department.controller.js`
- [Governance](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/controllers/csr.controller.js): esg domain · CSR, policies, and compliance issue handling · `backend/src/controllers/csr.controller.js`
- [Recognition](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/controllers/challenge.controller.js): engagement loop · Challenges, participations, badges, and rewards · `backend/src/controllers/challenge.controller.js`
- [Dashboard](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/controllers/dashboard.controller.js): aggregation · Cross-domain metrics for ESG overview screens · `backend/src/controllers/dashboard.controller.js`

### MongoDB

Mongoose-backed document collections and seed data

- [Models](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/models/user.model.js): mongoose models · Document schemas for users and business collections · `backend/src/models/user.model.js`
- [Seed Data](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/backend/src/seed/seed.js): demo bootstrap · Demo users and sample collection data · `backend/src/seed/seed.js`

### Legacy scaffold

Parallel frontend scaffold not on the main application path

- [Legacy SPA](https://github.com/shardul2302/odoo-2026-hackathon/blob/main/frontend/src123/App.jsx): legacy frontend · Parallel scaffold not used by the primary application path · `frontend/src123/App.jsx`

## Connections

- Boot → App Shell: boots · Vite entry initializes the main React app
- App Shell → Layouts: uses · Main app composes authenticated and auth layouts
- Layouts → Protected Route: protects · Authenticated layout flows through client-side route protection
- Login UI → Auth State: updates · Login and register screens manage session state
- Auth State → API Client: calls · Auth state relies on centralized API clients
- Domain Pages → API Client: fetches · Feature screens retrieve domain data through the API layer
- Overview → API Client: reads · Overview screens consume aggregated backend metrics
- API Client → API Routes: REST /api/v1 · Frontend talks to versioned backend routes
- Server → Express App: creates · Server entry initializes the Express app
- Express App → DB Connect: connects · App bootstraps MongoDB connectivity
- Express App → Middleware: mounts · Global middleware and error handling are applied in app composition
- Express App → API Routes: mounts · Domain routers are registered on the Express app
- API Routes → Auth Flow: auth · Authentication routes terminate in auth controller logic
- API Routes → Carbon Pipeline: carbon · Carbon transaction endpoints drive the main emissions pipeline
- Carbon Pipeline → Master Data: uses factors · Carbon calculations depend on emission factors and related master data
- API Routes → Governance: governance · CSR, policy, and compliance routes expose governance features
- API Routes → Recognition: engagement · Challenge, participation, badge, and reward routes support recognition workflows
- API Routes → Dashboard: aggregates · Dashboard routes gather data across domains
- Auth Flow → Models: persists · Auth uses user documents and shared persistence models
- Carbon Pipeline → Models: writes · Carbon transactions and calculations persist through MongoDB models
- Governance → Models: writes · Governance records are stored in document collections
- Recognition → Models: writes · Recognition records are stored in document collections
- Dashboard → Models: reads · Dashboard aggregates from multiple collections
- Seed Data → Models: populates · Seed script loads demo data into collections
- Legacy SPA → API Client: parallel · Legacy scaffold mirrors the main client API pattern
