How thaleprechaun/agric-invest works
Project type and purpose
• This is a full-stack TypeScript application combining an Express.js server (with both REST and GraphQL endpoints) and a React front end.
• The server exposes /api REST routes and a GraphQL schema, handles authentication via JWT, and persists data in MongoDB.
• The React client consumes those APIs, uses Redux for state management, and employs Axios for HTTP/GraphQL calls.
File structure
• Top-level: CI/CD configs (.circleci/, Jenkinsfile), lint/format configs, package.json, tsconfig.json.
• src/: server code—app.ts bootstrap, routes/, controllers/, models/, middleware/, helpers/, schema.ts (GraphQL), types/.
• scripts/: auxiliary scripts (e.g., mongo-setup.ts).
• client/: React app—public/, src/ (components, pages, redux, axios wrapper, common utilities), its own configs.
• Test suites: __tests__/ for unit tests, cypress/ for end-to-end tests, jest.config.js.
README
• Confirms dual start process (yarn start server, then client).
• Describes server’s REST and GraphQL interfaces and client’s ability to consume either.
Key components
a. Frontend (React/TypeScript)
– Pages & components layer (pages → components → common UI).
– Redux store and actions/reducers.
– HTTP client (Axios) and GraphQL client.
b. Backend (Express/TypeScript)
– Entry point (app.ts, bin/www).
– Middleware (CORS, logging, JWT verification: verifyUserToken, verifyAdminToken).
– Routing layer (routes/*).
– Controller layer (controllers/*).
– Data layer (Mongoose models in models/*).
– GraphQL schema (schema.ts) and resolver functions.
c. Database
– MongoDB cluster or local instance (initialized via scripts/mongo-setup.ts).
d. External/infrastructure
– CI/CD (CircleCI, Jenkins).
– Testing frameworks (Jest, Cypress).
– Deployment shell scripts (scripts/build.sh).
Relationships and interactions
• The React UI dispatches Redux actions that invoke Axios or GraphQL requests → Express routes.
• Express routes call controller methods → interact with Mongoose models → read/write MongoDB.
• GraphQL queries/mutations map to resolvers that likewise call models.
• Middleware intercepts requests for authentication/authorization.
• CI/CD pipelines pull code → run tests → build artifacts → deploy.
Architectural patterns and design principles
• Layered architecture: Presentation (UI) → API (routes/controllers) → Persistence (models/DB).
• Separation of concerns: UI components vs. state (Redux) vs. data‐access models.
• Modularization: each feature (farms, investments, users) has its own routes/controllers/models.
• Use of middleware for cross-cutting concerns (auth, validation).
• Dual-API strategy: REST + GraphQL coexisting behind the same Express server.