You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: backend/knowledge.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,31 @@ The backend handles file operations for the Manicode project:
70
70
-**Reading Files**: The `read_files` tool allows the AI to access project file contents.
71
71
-**Applying Changes**: The `applyChanges` function in `prompts.ts` processes and applies file modifications suggested by the AI.
72
72
73
+
## Code Organization and Best Practices
74
+
75
+
1.**Centralize Shared Logic**: When implementing functionality that's used in multiple places (e.g., web API and backend), create shared functions to promote code reuse and consistency. This is particularly important for business logic like referral handling and usage calculations.
76
+
77
+
2.**Shared Function Location**: Place shared functions in a common directory accessible to both the web API and backend. Consider creating a `common/src/utils` directory for such shared functionality.
78
+
79
+
3.**DRY Principle**: Always look for opportunities to refactor repeated code into shared, reusable functions. This not only reduces code duplication but also makes maintenance and updates easier.
80
+
81
+
4.**Consistent API**: When creating shared functions, ensure they have a consistent API that can be easily used by different parts of the application.
82
+
83
+
5.**Testing Shared Functions**: Implement unit tests for shared functions to ensure they work correctly in all contexts where they are used.
84
+
85
+
6.**Documentation**: Document shared functions clearly, including their purpose, inputs, outputs, and any side effects, so that other developers can use them effectively.
86
+
87
+
7.**Version Control**: When making changes to shared functions, consider the impact on all parts of the application that use them, and test thoroughly.
88
+
89
+
8.**Dependency Injection**: Prefer pulling common dependencies (like database connections or environment variables) from centralized locations rather than passing them as parameters. This reduces function complexity and improves maintainability.
90
+
91
+
9.**Single Responsibility Principle**: Design functions to have a single, well-defined purpose. For example, separate the logic of determining eligibility for a referral code from the generation of the full referral link.
92
+
93
+
10.**Abstraction Refinement**: Be prepared to refine initial implementations as the system's needs become clearer. This might involve changing function signatures, splitting functions, or adjusting their purposes to better fit the overall architecture.
94
+
95
+
96
+
97
+
73
98
## Development Guidelines
74
99
75
100
1.**Type Safety**: Utilize TypeScript's type system to ensure code reliability and catch errors early.
3.**CentralizedLogic**: The`hasMaxedReferrals`function in `common/src/util/referral.ts` is used to check if a user has reached their referral limit. This function should be used consistently across the application to ensure uniform enforcement of the referral limit.
-Whenencountering"Cannot find module"errorsinaDockercontainer, it's important to verify the contents of the container itself, not just the local build.
@@ -194,3 +242,5 @@ This project uses Bun for testing instead of Jest. When writing tests, keep the
194
242
-Bun's test API is similar to Jest's, buttherearesomedifferencesinimplementation.
ALTERTABLE"referral" ADD CONSTRAINT"referral_referrer_id_user_id_fk"FOREIGN KEY ("referrer_id") REFERENCES"public"."user"("id") ON DELETE no action ONUPDATE no action;
20
+
EXCEPTION
21
+
WHEN duplicate_object THEN null;
22
+
END $$;
23
+
--> statement-breakpoint
24
+
DO $$ BEGIN
25
+
ALTERTABLE"referral" ADD CONSTRAINT"referral_referred_id_user_id_fk"FOREIGN KEY ("referred_id") REFERENCES"public"."user"("id") ON DELETE no action ONUPDATE no action;
0 commit comments