How shardul2302/odoo-2026-hackathon works
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: dashboard.routes.js API Routes · user.model.js Models · axios.js API Client · app.js Express App
Components 23
Frontend SPA
React/Vite client, routing, state, and API access
- App Shell · Main client application shell and routing entry
frontend/src/App.jsx - Boot · Frontend bootstrap entrypoint
frontend/src/main.jsx - Auth State · Client session state and auth helpers
frontend/src/context/AuthContext.jsx - API Client · Centralized axios and API helpers
frontend/src/lib/axios.js - Protected Route · Client-side access gate for protected screens
frontend/src/components/layout/ProtectedRoute.jsx - Login UI · Authentication screens and forms
frontend/src/pages/Auth/Login.jsx - Overview · Primary ESG overview and summary views
frontend/src/pages/Overview/Dashboard.jsx - Domain Pages · Department, category, emission factor, and carbon transaction screens
frontend/src/pages/CarbonTransactions.jsx - Layouts · Authenticated and auth-specific layout composition
frontend/src/layout/AppLayout.jsx
Backend API
Express application, domain routes, middleware, and business logic
- Server · Backend process entrypoint and app bootstrapping
backend/src/server.js - Express App · Middleware, route mounting, and error handling
backend/src/app.js - DB Connect · MongoDB connection setup
backend/src/config/db.js - Middleware · Auth, role checks, validation, and error handling
backend/src/middlewares/auth.middleware.js - Auth Flow · JWT auth, token generation, and login logic
backend/src/controllers/auth.controller.js - API Routes · Versioned REST endpoints for all major domains
backend/src/routes/dashboard.routes.js - Carbon Pipeline · Carbon transaction processing and CO2 calculation
backend/src/controllers/carbonTransaction.controller.js - Master Data · Departments, categories, and emission factors
backend/src/controllers/department.controller.js - Governance · CSR, policies, and compliance issue handling
backend/src/controllers/csr.controller.js - Recognition · Challenges, participations, badges, and rewards
backend/src/controllers/challenge.controller.js - Dashboard · Cross-domain metrics for ESG overview screens
backend/src/controllers/dashboard.controller.js
MongoDB
Mongoose-backed document collections and seed data
Legacy scaffold
Parallel frontend scaffold not on the main application path
- Legacy SPA · Parallel scaffold not used by the primary application path
frontend/src123/App.jsx
Connections 25
- 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